@import url("https://fonts.googleapis.com/css2?family=Playfair+Display:wght@600;700&family=Sora:wght@300;400;500;600&display=swap");

:root {
  --bg-1: #050f1f;
  --bg-2: #0c2238;
  --bg-3: #12374f;
  --glass: rgba(8, 20, 36, 0.58);
  --glass-line: rgba(103, 166, 216, 0.26);
  --text-main: #e8f2fb;
  --text-sub: #8da9c4;
  --accent: #f5a53f;
  --accent-2: #f2b35c;
  --control-accent: #e5ae63;
  --danger: #f07272;
}

* {
  box-sizing: border-box;
  /* 全ての要素でスクロールバーを非表示にする */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

*::-webkit-scrollbar {
  /* Chrome, Safari, Edge 用のスクロールバー非表示設定 */
  display: none;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  position: relative;
  isolation: isolate;
  font-family: "Sora", "Noto Sans JP", sans-serif;
  color: var(--text-main);
  background: linear-gradient(100deg, var(--bg-1) 0%, var(--bg-2) 42%, var(--bg-3) 100%);
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

body::before {
  background: radial-gradient(42% 72% at 22% 72%, rgba(210, 141, 51, 0.2), transparent 66%),
    linear-gradient(90deg, rgba(246, 167, 72, 0.09) 0%, transparent 30%);
}

body::after {
  background: radial-gradient(40% 42% at 56% 14%, rgba(84, 188, 255, 0.11), transparent 70%);
}

body.performance-mode .stage-card,
body.performance-mode .control-card,
body.performance-mode .speed-card {
  backdrop-filter: none;
}

body.performance-mode .btn {
  transition: none;
}

.app-shell {
  width: 94vw;
  max-width: 1500px;
  height: 92vh;
  margin: 4vh auto;
  padding: 0;
  display: grid;
  gap: 16px;
  grid-template-columns: 1.3fr 1fr;
  align-items: start;
  overflow: hidden;
}

@media (min-width: 1024px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 420px;
    justify-items: stretch;
    align-items: start;
  }

  .stage-card {
    max-width: 100%;
  }

  .stage-canvas-wrap {
    width: 100%;
    max-width: 100%;
  }

  .control-card {
    width: 100%;
    max-width: 100%;
  }
}

.stage-card,
.control-card,
.speed-card {
  backdrop-filter: blur(15px);
  background: linear-gradient(155deg, rgba(6, 18, 34, 0.82), rgba(5, 13, 25, 0.64));
  border: 1px solid var(--glass-line);
  border-radius: 26px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.36);
}

.stage-card {
  position: relative;
  width: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  /* ウィンドウの境がわかるように背景と境界線を追加 */
  background: rgba(6, 18, 34, 0.4);
  border: 1px solid var(--glass-line);
  border-radius: 26px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.speed-card {
  width: 100%;
  max-width: min(100%, calc(84vh + 40px));
  margin-inline: auto;
}

.control-card {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 16px !important;
}

.stage-layout {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  height: 100%;
}

.stage-canvas-wrap {
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  width: 100%;
  flex: 1;
  margin: 0 auto;
}

.stage-card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.08), transparent 42%);
  pointer-events: none;
}

#pendulumCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(44, 93, 129, 0.2), rgba(3, 10, 20, 0.94));
  transition: filter 0.2s ease;
}

#pendulumCanvas.is-paused {
  filter: brightness(0.78) saturate(0.9);
}

.pause-indicator {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(226, 245, 255, 0.45);
  background: rgba(6, 20, 31, 0.7);
  color: #eef8ff;
  font-size: 0.86rem;
  letter-spacing: 0.03em;
  font-weight: 600;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 24px rgba(2, 9, 14, 0.42);
  pointer-events: none;
  z-index: 3;
}

.language-box {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: #93aac2;
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: normal;
}

.language-box::before,
.language-box::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 6px;
  height: 2px;
  border-radius: 999px;
  background: #d8eaff;
  pointer-events: none;
  opacity: 0.96;
}

.language-box::before {
  right: 18px;
  transform: translateY(-50%) rotate(38deg);
}

.language-box::after {
  right: 14px;
  transform: translateY(-50%) rotate(-38deg);
}

.language-box select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  border: 1px solid rgba(106, 166, 213, 0.32);
  background-color: rgba(9, 23, 40, 0.9);
  color: #d8eaff;
  border-radius: 12px;
  padding: 6px 30px 6px 10px;
  font-size: 0.76rem;
  cursor: pointer;
}

.language-box select:focus {
  outline: 2px solid rgba(146, 203, 248, 0.45);
  outline-offset: 1px;
}

.language-box select::-ms-expand {
  display: none;
}

.stage-badge {
  position: relative;
  padding: 4px 32px;
  max-width: 900px; /* 横に伸ばす */
  width: fit-content;
  margin: 8px auto;
  background: rgba(6, 18, 34, 0.6);
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  text-align: center; /* 真ん中に配置 */
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: none;
}

.badge-kicker {
  margin-bottom: 0;
  margin: 0;
  color: var(--accent);
  letter-spacing: normal;
  font-size: 0.68rem;
  font-weight: 600;
}

.stage-badge h1 {
  margin: 0;
  font-family: "Playfair Display", "Noto Serif JP", serif;
  font-size: clamp(1.4rem, 2.4vw, 2rem);
  line-height: 1.1; /* 行の幅を少し狭める */
  letter-spacing: 0.02em;
  font-weight: 700;
}

.stage-badge p {
  margin: 2px 0 0 0;
  color: var(--text-sub);
  font-size: 0.82rem;
  line-height: 1.5;
}

.bob-speed-panel {
  position: static;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px 14px 12px;
  border-radius: 15px;
  border: 1px solid rgba(130, 182, 220, 0.24);
  background: rgba(4, 14, 26, 0.62);
  backdrop-filter: blur(4px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.33);
  gap: 2px; /* 行間を最小限に */
  padding: 4px 0;
  border-radius: 0;
  border: none; /* 二重ベゼルを削除 */
  background: none;
  backdrop-filter: none;
  box-shadow: none;
  z-index: 3;
}

.bob-speed-title {
  margin: 0;
  color: #e3f3ff;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: none;
}

.bob-speed-range-labels {
  display: grid;
  grid-template-columns: repeat(21, 1fr);
  align-items: center;
  font-size: 0.64rem;
  color: #9fc6ea;
  letter-spacing: 0.02em;
  position: relative;
  height: 16px;
  padding: 0;
  width: 100%;
  margin-bottom: 2px;
  margin-bottom: -4px;
}

.bob-speed-range-labels span {
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.bob-speed-range-labels::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -2px;
  height: 6px;
  box-shadow:
    0% 0 0 1px rgba(159, 198, 234, 0.4),
    25% 0 0 1px rgba(159, 198, 234, 0.4),
    50% 0 0 1px rgba(159, 198, 234, 0.4),
    75% 0 0 1px rgba(159, 198, 234, 0.4),
    100% 0 0 1px rgba(159, 198, 234, 0.4);
  pointer-events: none;
}

.bob-speed-range-labels span {
  text-align: center;
}

.bob-speed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.bob-speed-scale {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.bob-speed-scale-value {
  color: #cfe3f3;
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bob-speed-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  grid-template-columns: 1fr !important; /* 横に長く伸ばす */
  gap: 2px;
}

body.three-bob-mode .bob-speed-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.bob-speed-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  gap: 12px;
}

.bob-speed-label {
  color: #b7d3e9;
  font-size: 0.67rem;
  white-space: nowrap;
}

.bob-speed-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: black;
  box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  width: 100%;
}

.bob-speed-track::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    hsl(0, 100%, 58%) 0%,
    hsl(40, 95%, 63%) 25%,
    hsl(100, 92%, 66%) 50%,
    hsl(240, 90%, 70%) 75%,
    hsl(280, 100%, 60%) 100%
  );
  border-radius: 999px;
  pointer-events: none;
}

.bob-speed-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 0;
  width: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.8), 0 0 8px rgba(255, 255, 255, 0.4);
  transform: translateX(-50%);
  z-index: 2;
}

.bob-speed-value {
  color: #f2d4ac;
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.control-card {
  padding: clamp(16px, 1.7vw, 22px);
  display: grid;
  align-content: start;
  gap: 14px;
  animation: rise 1.05s ease;
}

.control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.control-card h2 {
  margin: 0;
  font-family: "Playfair Display", "Noto Serif JP", serif;
  letter-spacing: 0.03em;
  font-size: 1.35rem;
}

.control-note {
  margin: -4px 0 0;
  color: #89aeca;
  font-size: 0.73rem;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mode-tab {
  border: 1px solid rgba(117, 172, 212, 0.28);
  background: rgba(8, 22, 38, 0.64);
  color: #aac6de;
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease;
}

.mode-tab:hover {
  border-color: rgba(227, 173, 98, 0.54);
  color: #dceeff;
}

.mode-tab.is-active {
  color: #fff;
  border-color: rgba(237, 175, 91, 0.7);
  background: linear-gradient(140deg, rgba(32, 56, 83, 0.9), rgba(14, 30, 48, 0.96));
  box-shadow: inset 0 0 14px rgba(250, 189, 106, 0.17);
}

.tab-panel {
  display: grid;
  gap: 14px;
}

.guide-panel {
  padding: 10px 4px 2px;
}

.guide-panel h3 {
  margin: 0;
  font-size: 1rem;
  color: #edf8ff;
  font-family: "Playfair Display", "Noto Serif JP", serif;
}

.guide-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 7px;
  color: #9dc0db;
  font-size: 0.8rem;
  line-height: 1.45;
}

.guide-window-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 10, 17, 0.62);
  backdrop-filter: blur(4px);
  display: none; /* 起動時に表示されないよう初期状態を非表示に修正 */
  place-items: center;
  padding: 18px;
  z-index: 12;
}

.guide-window {
  width: min(560px, 96vw);
  border-radius: 16px;
  border: 1px solid rgba(113, 167, 207, 0.28);
  background: linear-gradient(155deg, rgba(8, 22, 38, 0.96), rgba(6, 16, 29, 0.95));
  box-shadow: 0 24px 56px rgba(0, 0, 0, 0.48);
  padding: 14px 16px 16px;
  display: grid;
  gap: 12px;
}

.guide-window-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.guide-window-head h3 {
  margin: 0;
  font-size: 1.06rem;
  color: #edf8ff;
  font-family: "Playfair Display", "Noto Serif JP", serif;
}

.guide-close {
  border: 1px solid rgba(221, 173, 95, 0.46);
  background: rgba(14, 33, 54, 0.86);
  color: #f6cc91;
  border-radius: 9px;
  font-size: 0.74rem;
  padding: 5px 10px;
  cursor: pointer;
}

.guide-close:hover {
  border-color: rgba(244, 202, 150, 0.68);
}

.control-grid {
  display: grid;
  gap: 10px;
}

.control-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 7px 10px;
  align-items: center;
  color: var(--text-sub);
  font-size: 0.8rem;
  padding: 7px 8px 9px;
  background: var(--glass);
  border: 1px solid rgba(116, 174, 214, 0.2);
  border-radius: 11px;
}

.mode3-only {
  display: none;
}

body.three-bob-mode .mode3-only {
  display: grid;
}

.control-item span {
  color: #d7eafb;
  font-weight: 500;
}

.control-item output {
  color: #fff;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  justify-self: end;
}

.param-reset {
  border: 1px solid rgba(230, 178, 116, 0.34);
  background: linear-gradient(150deg, rgba(18, 36, 59, 0.82), rgba(8, 20, 35, 0.94));
  color: #f4c98d;
  border-radius: 8px;
  font-size: 0.67rem;
  padding: 4px 8px;
  cursor: pointer;
  line-height: 1;
}

.param-reset:hover {
  border-color: rgba(244, 202, 150, 0.65);
  background: linear-gradient(150deg, rgba(23, 47, 77, 0.88), rgba(11, 27, 48, 0.96));
}

.control-help {
  grid-column: 1 / -1;
  color: #7698b2;
  font-size: 0.68rem;
  line-height: 1.35;
}

.control-item input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
  accent-color: var(--control-accent);
}

.control-item select {
  grid-column: 1 / -1;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  border: 1px solid rgba(106, 166, 213, 0.34);
  background:
    linear-gradient(45deg, transparent 50%, #d8eaff 50%),
    linear-gradient(135deg, #d8eaff 50%, transparent 50%),
    rgba(9, 23, 40, 0.9);
  background-repeat: no-repeat;
  background-position:
    right 12px center,
    right 7px center,
    0 0;
  background-size:
    5px 5px,
    5px 5px,
    auto;
  color: #d8eaff;
  border-radius: 10px;
  padding: 7px 30px 7px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}

.control-item select:focus {
  outline: 2px solid rgba(146, 203, 248, 0.45);
  outline-offset: 1px;
}

.control-item select::-ms-expand {
  display: none;
}

.toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.speed-meter-card {
  display: grid;
  gap: 8px;
  padding: 10px 11px;
  border-radius: 12px;
  border: 1px solid rgba(118, 174, 214, 0.24);
  background: rgba(7, 20, 34, 0.64);
}

.speed-meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #d5e8f8;
  font-size: 0.76rem;
}

.speed-meter-current {
  color: #f4d4a5;
  font-variant-numeric: tabular-nums;
}

.speed-meter-bar {
  position: relative;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(132, 182, 218, 0.38);
  background: linear-gradient(
    90deg,
    hsl(0 90% 58%) 0%,
    hsl(44 95% 58%) 26%,
    hsl(120 72% 52%) 50%,
    hsl(200 87% 56%) 74%,
    hsl(280 78% 58%) 100%
  );
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.15);
  overflow: hidden;
}

.speed-meter-needle {
  position: absolute;
  left: 0;
  top: -3px;
  bottom: -3px;
  width: 2px;
  border-radius: 999px;
  background: rgba(246, 251, 255, 0.98);
  box-shadow: 0 0 10px rgba(198, 235, 255, 0.7);
  transform: translateX(-50%);
  transition: left 0.12s ease;
}

.speed-meter-scale {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #8caec8;
  font-size: 0.69rem;
  line-height: 1.4;
}

.speed-meter-scale span {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.speed-meter-scale strong {
  color: #bdd8ed;
  font-weight: 600;
}

.speed-meter-hint {
  color: #6f97b4;
  font-size: 0.67rem;
  line-height: 1.35;
}

.speed-meter-card.is-disabled {
  opacity: 0.68;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.79rem;
  color: var(--text-sub);
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid rgba(114, 170, 209, 0.24);
  background: rgba(8, 22, 38, 0.64);
}

.switch input {
  margin: 0;
  accent-color: #69aac8;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.hidden-input {
  display: none;
}

.btn {
  border: 1px solid rgba(106, 164, 208, 0.32);
  border-radius: 11px;
  padding: 10px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-main);
  background: linear-gradient(150deg, rgba(16, 35, 56, 0.85), rgba(8, 22, 38, 0.94));
  transition: transform 0.17s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(141, 198, 241, 0.56);
  box-shadow: 0 10px 22px rgba(7, 18, 31, 0.44);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  color: #2d1b0d;
  border-color: rgba(246, 191, 122, 0.8);
  background: linear-gradient(120deg, #f39c3a, #f5b256 62%, #f8ca82);
}

.btn.ghost {
  border-style: dashed;
}

.stats {
  margin: 2px 0 0;
  padding: 0;
  display: grid;
  gap: 7px;
}

.stats > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(6, 17, 27, 0.55);
  border: 1px solid rgba(151, 208, 232, 0.15);
  border-radius: 10px;
  padding: 9px 11px;
}

.stats dt {
  color: var(--text-sub);
  font-size: 0.76rem;
}

.stats dd {
  margin: 0;
  font-size: 0.84rem;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

@keyframes drift {
  from {
    transform: translate3d(-1.2vmax, 0, 0) scale(1);
  }
  to {
    transform: translate3d(1.2vmax, -1vmax, 0) scale(1.08);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  #pendulumCanvas {
    height: min(68vh, 620px);
  }

  .bob-speed-panel {
    width: min(760px, calc(100% - 18px));
    bottom: 8px;
    padding: 7px 8px 8px;
  }

  .bob-speed-grid {
    gap: 6px;
  }

  .bob-speed-item {
    gap: 5px;
  }

  .bob-speed-label,
  .bob-speed-value {
    font-size: 0.62rem;
  }
}

@media (max-width: 640px) {
  .mode-tabs {
    grid-template-columns: 1fr;
  }

  .language-box {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
    font-size: 0.62rem;
    gap: 6px;
  }

  .language-box select {
    font-size: 0.7rem;
    padding: 5px 26px 5px 8px;
  }

  .language-box::before {
    right: 15px;
    width: 5px;
  }

  .language-box::after {
    right: 11px;
    width: 5px;
  }

  .bob-speed-panel {
    width: min(94%, calc(100% - 14px));
    bottom: 6px;
    padding: 6px 6px 7px;
    gap: 5px;
  }

  .bob-speed-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .bob-speed-scale {
    gap: 7px;
  }

  .bob-speed-scale-value {
    font-size: 0.56rem;
  }

  .bob-speed-title {
    font-size: 0.58rem;
  }

  .bob-speed-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }

  body.three-bob-mode .bob-speed-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bob-speed-label,
  .bob-speed-value {
    font-size: 0.57rem;
  }

  .bob-speed-track {
    height: 8px;
  }

  .stage-badge {
    max-width: 90%;
  }

  .stage-badge p {
    display: none;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .toggle-row {
    grid-template-columns: 1fr;
  }
}
