:root {
  --bg: #07080a;
  --panel: rgba(14, 16, 20, 0.72);
  --line: rgba(255, 255, 255, 0.12);
  --ink: #f4f5f7;
  --dim: #9aa2ad;
  --amber: #ffb300;
  --amber-soft: rgba(255, 179, 0, 0.18);
  --cyan: #58d6ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 460px;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }

/* soft vignette on top of the render */
#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 32%, transparent 42%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(to top, rgba(4, 5, 7, 0.92) 0%, rgba(4, 5, 7, 0) 34%);
}

.hud {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) clamp(14px, 4vw, 28px) 0;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.hud-top {
  top: 0;
  justify-content: space-between;
  align-items: flex-start;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.mark {
  width: 10px;
  height: 26px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--amber), #b47400);
  box-shadow: 0 0 16px rgba(255, 179, 0, 0.5);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b {
  font-size: clamp(17px, 4.6vw, 21px);
  letter-spacing: 0.16em;
  font-weight: 700;
}
.brand-text i {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--dim);
  margin-top: 3px;
}

.views {
  display: flex;
  gap: 6px;
  padding: 5px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.vbtn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #b9c0c9;
  cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}
.vbtn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.vbtn:hover { color: #fff; background: rgba(255, 255, 255, 0.07); }
.vbtn:active { transform: scale(0.94); }
.vbtn.is-on {
  color: #1a1200;
  background: linear-gradient(180deg, #ffc23a, #e09a00);
  border-color: rgba(255, 214, 128, 0.7);
}
.vbtn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.hint {
  position: absolute;
  z-index: 3;
  right: clamp(14px, 4vw, 28px);
  top: calc(max(14px, env(safe-area-inset-top)) + 100px);
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.38);
  text-align: right;
  max-width: 40vw;
  pointer-events: none;
}

/* ------------------------------------------------------------- bottom panel */
.hud-bottom {
  bottom: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 14px clamp(14px, 4vw, 28px) max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(6, 7, 9, 0.94), rgba(6, 7, 9, 0.55) 70%, transparent);
}

.readout {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.state {
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--amber);
  font-weight: 700;
}
.stage-name {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--dim);
}
.stage-name::before {
  content: "//";
  margin-right: 6px;
  color: rgba(88, 214, 255, 0.6);
}

.track-wrap { display: flex; flex-direction: column; gap: 4px; }

.scrub {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 34px;
  background: transparent;
  cursor: pointer;
}
.scrub::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background:
    linear-gradient(90deg, var(--amber) var(--fill, 0%), rgba(255, 255, 255, 0.14) var(--fill, 0%));
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.scrub::-moz-range-track {
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
}
.scrub::-moz-range-progress {
  height: 6px;
  border-radius: 99px;
  background: var(--amber);
}
.scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  margin-top: -10px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, #ffcf5c 42%, #e79b00 100%);
  border: 2px solid #1a1300;
  box-shadow: 0 0 0 4px rgba(255, 179, 0, 0.16), 0 6px 14px rgba(0, 0, 0, 0.5);
}
.scrub::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff, #ffcf5c 42%, #e79b00 100%);
  border: 2px solid #1a1300;
}
.scrub:focus-visible { outline: 2px solid var(--cyan); outline-offset: 4px; border-radius: 8px; }

.ticks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: rgba(255, 255, 255, 0.3);
  padding: 0 2px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.primary, .ghost {
  min-height: 48px;
  border-radius: 14px;
  font-size: 15px;
  letter-spacing: 0.16em;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  transition: transform 0.16s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
}
.primary {
  border: 1px solid rgba(255, 214, 128, 0.55);
  color: #1a1200;
  background: linear-gradient(180deg, #ffcb52, #e79b00);
  box-shadow: 0 10px 30px rgba(255, 160, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.primary .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2a1c00;
  box-shadow: 0 0 0 3px rgba(42, 28, 0, 0.18);
}
.primary:active { transform: translateY(1px) scale(0.995); }
.primary:focus-visible, .ghost:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.ghost {
  border: 1px solid var(--line);
  color: #d7dbe0;
  background: rgba(255, 255, 255, 0.05);
  padding: 0 18px;
  font-weight: 600;
}
.ghost:hover { background: rgba(255, 255, 255, 0.1); }

/* ----------------------------------------------------------------- fallback */
.fallback {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 72px 20px 200px;
  background: radial-gradient(70% 60% at 50% 42%, #14171d, #06070a 100%);
}
.fallback[hidden] { display: none; }
.fallback img {
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  object-fit: contain;
  filter: drop-shadow(0 18px 26px rgba(0, 0, 0, 0.55));
}
.fallback-note {
  margin: 0;
  max-width: 34ch;
  text-align: center;
  font-size: 12px;
  line-height: 1.6;
  color: var(--dim);
}

/* ------------------------------------------------------------------ loading */
.loading {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  background: radial-gradient(60% 60% at 50% 45%, #12151a, #06070a 100%);
  transition: opacity 0.6s ease, visibility 0.6s ease;
}
.loading.is-done { opacity: 0; visibility: hidden; }
.loading-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--dim);
}
.loader {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 179, 0, 0.25);
  border-top-color: var(--amber);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 760px) {
  .hud-bottom {
    flex-direction: row;
    align-items: center;
    gap: 22px;
    padding-top: 18px;
  }
  .readout { flex-direction: column; gap: 4px; min-width: 148px; }
  .track-wrap { flex: 1; }
  .actions { grid-template-columns: auto auto; }
  .primary { padding: 0 26px; }
  .hint { top: auto; bottom: 130px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
