:root {
  --bg: #06080d;
  --bg2: #0f141d;
  --panel: rgba(10, 14, 22, 0.82);
  --panel-strong: rgba(9, 12, 18, 0.92);
  --panel-soft: rgba(12, 15, 22, 0.66);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 248, 232, 0.16);
  --ink: #eee8de;
  --muted: rgba(238, 232, 222, 0.7);
  --gold: #d9b36a;
  --cinematic-gold: rgba(255, 221, 160, 0.22);
  --jade: #73d0a5;
  --red: #ef6f80;
  --shadow: 0 28px 84px rgba(0, 0, 0, 0.36);
  --top-gap: max(16px, env(safe-area-inset-top));
  --side-gap: max(16px, env(safe-area-inset-left));
  --side-gap-right: max(16px, env(safe-area-inset-right));
  --bottom-gap: max(16px, env(safe-area-inset-bottom));
  --joystick-size: 160px;
  --joystick-thumb: 62px;
  --action-size: 52px;
  --mobile-left-safe: calc(var(--joystick-size) + 36px);
  --mobile-right-safe: calc(var(--joystick-size) + var(--action-size) + 46px);
  --safe-center: calc(50% + (var(--mobile-left-safe) - var(--mobile-right-safe)) / 2);
  --transcript-height: 152px;
  --transcript-width: min(540px, calc(100% - 48px));
}
*,
*:before,
*:after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  width: 100%;
  height: 100%;
}
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  background:
    radial-gradient(
      circle at 82% 18%,
      rgba(255, 222, 162, 0.12),
      transparent 20%
    ),
    radial-gradient(
      circle at 14% 84%,
      rgba(74, 92, 138, 0.14),
      transparent 28%
    ),
    linear-gradient(180deg, #0c1118, #080b10 56%, #05070a);
  color: var(--ink);
  font-family:
    Noto Sans TC,
    sans-serif;
  overflow: hidden;
}
[hidden] {
  display: none !important;
}
button,
a {
  color: inherit;
  font: inherit;
}
button {
  cursor: pointer;
}
a {
  text-decoration: none;
}
:focus-visible {
  outline: 2px solid rgba(115, 208, 165, 0.72);
  outline-offset: 3px;
}
.lm402-page:before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.88' numOctaves='3'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
  opacity: 0.26;
  mix-blend-mode: soft-light;
}
.rotate-lock {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #030508eb;
}
.rotate-card {
  width: min(420px, 100%);
  padding: 26px 24px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, #0c1018f5, #080a10eb);
  box-shadow: var(--shadow);
}
.rotate-kicker,
.hud-overline,
.dock-kicker,
.objective-kicker,
.panel-kicker,
.dialogue-eyebrow,
.ending-kicker,
.debug-kicker {
  font:
    500 11px DM Mono,
    monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.56);
}
.rotate-card h1 {
  margin: 12px 0 10px;
  font:
    600 46px/1 Cormorant Garamond,
    serif;
}
.rotate-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.72;
}
.hud {
  position: fixed;
  top: var(--top-gap);
  left: var(--side-gap);
  right: var(--side-gap-right);
  z-index: 28;
  pointer-events: none;
}
.hud-toggle,
.hud-body {
  pointer-events: auto;
}
.hud-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: none;
  border-radius: 999px;
  background: #080c12c7;
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: 0 16px 38px #0000003d;
}
.hud-toggle-label {
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.hud-toggle-icon {
  font-size: 20px;
  line-height: 1;
}
.hud-body {
  width: min(920px, 100%);
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) auto;
  gap: 16px;
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: linear-gradient(180deg, #0a0e16eb, #080a10d1);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}
.hud.collapsed .hud-body {
  opacity: 0;
  transform: translateY(-12px);
  pointer-events: none;
}
.hud-title {
  margin-top: 8px;
  font:
    600 48px/1 Cormorant Garamond,
    serif;
  letter-spacing: 0.05em;
}
.hud-copy {
  margin-top: 8px;
  max-width: 58ch;
  color: var(--muted);
  line-height: 1.68;
}
.hud-meta,
.hud-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-content: flex-start;
}
.hud-pill,
.hud-link {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff08;
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.hud-link-button {
  appearance: none;
  cursor: pointer;
}
.hud-link:hover {
  border-color: #73d0a542;
  color: var(--jade);
}
#back-story-btn {
  border-color: rgba(115, 208, 165, 0.4);
  background: rgba(115, 208, 165, 0.08);
  color: var(--jade);
}
#back-story-btn:hover {
  border-color: rgba(115, 208, 165, 0.65);
  background: rgba(115, 208, 165, 0.16);
  box-shadow: 0 0 16px rgba(115, 208, 165, 0.12);
}
#back-story-side-btn {
  border-color: rgba(115, 208, 165, 0.4);
  background: rgba(115, 208, 165, 0.08);
  color: var(--jade);
}
#back-story-side-btn:hover {
  border-color: rgba(115, 208, 165, 0.65);
  background: rgba(115, 208, 165, 0.16);
}
.game-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(296px, 336px);
  gap: 18px;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100vw;
  min-width: 0;
  padding: 20px var(--side-gap-right) 20px var(--side-gap);
  overflow: hidden;
  align-items: stretch;
}
.stage {
  position: relative;
  min-width: 0;
  min-height: calc(100vh - 40px);
  min-height: calc(100dvh - 40px);
  height: calc(100vh - 40px);
  height: calc(100dvh - 40px);
  width: 100%;
  max-width: 100%;
  border-radius: 38px;
  overflow: hidden;
  contain: layout paint size;
  background: linear-gradient(180deg, #dfe9f2, #cfd9e5 58%, #bccad6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: var(--shadow);
}
#scene-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  background: linear-gradient(180deg, #dfe9f2, #cfd9e5 58%, #bccad6);
}
.stage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(
      circle at 82% 22%,
      rgba(255, 230, 172, 0.20),
      transparent 24%
    ),
    radial-gradient(
      circle at 18% 78%,
      rgba(255, 220, 160, 0.08),
      transparent 20%
    ),
    linear-gradient(180deg, #07090e14, #07090e42),
    radial-gradient(circle at 50% 52%, transparent 56%, rgba(4, 5, 8, 0.32));
  z-index: 1;
  transition: background 0.5s ease;
}
body[data-ui-preset="ending"] .stage-vignette {
  background:
    radial-gradient(
      circle at 66% 48%,
      rgba(255, 239, 202, 0.22),
      transparent 18%
    ),
    radial-gradient(
      circle at 66% 48%,
      rgba(255, 213, 136, 0.16),
      transparent 30%
    ),
    linear-gradient(180deg, rgba(6, 8, 12, 0.1), rgba(5, 7, 10, 0.46)),
    radial-gradient(circle at 50% 54%, transparent 48%, rgba(3, 5, 8, 0.5));
}
/* 結局時 canvas 韓劇柔焦光暈效果 */
body[data-ui-preset="ending"] #scene-canvas {
  filter: contrast(1.06) saturate(1.14) brightness(1.03);
}
.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 1px solid rgba(255, 247, 232, 0.26);
  opacity: 0;
  transition: opacity 0.16s ease;
  z-index: 12;
  pointer-events: none;
}
#scene-canvas.pointer-locked ~ .crosshair {
  opacity: 1;
}
.crosshair:before,
.crosshair:after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff7e870;
}
.crosshair:before {
  width: 8px;
  height: 1px;
}
.crosshair:after {
  width: 1px;
  height: 8px;
}
.pointer-pill,
.objective-prompt,
.hint-pill,
.focus-prompt,
.debug-panel {
  position: absolute;
  z-index: 12;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.speed-widget,
.audio-widget,
.font-widget,
.quality-widget {
  position: absolute;
  z-index: 12;
}
.pointer-pill {
  top: 18px;
  right: 18px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #070a10bd;
  font:
    500 11px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #fff4e6d1;
}
.pointer-pill.locked {
  border-color: #73d0a538;
  color: var(--jade);
}
.speed-widget {
  top: 18px;
  left: 18px;
  display: grid;
  gap: 10px;
  justify-items: start;
}
.audio-widget {
  top: 162px;
  left: 18px;
}
.song-selector {
  margin-top: 8px;
  display: grid;
  gap: 4px;
  min-width: 200px;
}
.song-selector[hidden] { display: none; }
.song-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border: none;
  background: transparent;
  color: #eee8de;
  font: 500 13px/1.3 "DM Sans", sans-serif;
  cursor: pointer;
  transition: background 0.15s;
}
.song-row:hover:not(:disabled) { background: #ffffff0a; }
.song-row.active { color: var(--jade); }
.song-row.locked { opacity: 0.5; cursor: not-allowed; }
.song-lock { font-size: 14px; }
.song-label { font-weight: 600; color: var(--jade); min-width: 32px; }
.song-name { color: #eee8ded1; }
.time-watch {
  position: absolute;
  top: 12px;
  left: 50%;
  right: auto;
  transform: translate(-50%);
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 16px 8px;
  background: var(--panel);
  border: 1px solid rgba(0, 220, 255, 0.25);
  border-radius: 12px;
  pointer-events: none;
  user-select: none;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  box-shadow:
    0 0 12px #00dcff26,
    inset 0 0 8px #00dcff0d;
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}
.time-watch:after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 220, 255, 0.03) 2px,
    rgba(0, 220, 255, 0.03) 4px
  );
  animation: scanLines 4s linear infinite;
  pointer-events: none;
}
@keyframes scanLines {
  0% {
    transform: translateY(0);
  }
  to {
    transform: translateY(4px);
  }
}
.time-watch.pulse {
  box-shadow:
    0 0 20px #00dcff66,
    inset 0 0 12px #00dcff1f;
}
.time-watch-label {
  font:
    500 8px DM Mono,
    monospace;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold);
}
.time-watch-display {
  font:
    500 22px DM Mono,
    monospace;
  letter-spacing: 0.15em;
  color: #00e5ff;
  text-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
  animation: watchPulse 3s ease-in-out infinite;
}
.time-watch.frozen .time-watch-display {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(217, 179, 106, 0.5);
  animation: none;
}
@keyframes watchPulse {
  0%,
  to {
    text-shadow: 0 0 8px rgba(0, 229, 255, 0.2);
  }
  50% {
    text-shadow: 0 0 14px rgba(0, 229, 255, 0.5);
  }
}
.music-prompt {
  position: absolute;
  right: 18px;
  left: auto;
  top: 68px;
  z-index: 22;
  width: min(220px, calc(100% - 40px));
  padding: 8px 10px 10px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  opacity: 0;
  transform: translateY(10px) scale(0.985);
  transition:
    opacity 0.42s ease,
    transform 0.42s ease;
}
.music-prompt.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}
.music-prompt.intro-mode {
  width: min(196px, calc(100% - 40px));
  padding: 7px 9px 9px;
  background: transparent;
}
.music-prompt-kicker {
  font:
    500 9px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.music-prompt-copy {
  margin-top: 4px;
  color: rgba(238, 232, 222, 0.78);
  line-height: 1.4;
  font-size: 12px;
}
.music-prompt.intro-mode .music-prompt-copy {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}
.music-prompt-button {
  margin-top: 8px;
  width: 100%;
  min-height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(115, 208, 165, 0.28);
  background: #73d0a51f;
  color: var(--jade);
}
.music-prompt-close {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition:
    color 0.2s ease,
    border-color 0.2s ease;
}
.music-prompt-close:hover {
  color: var(--jade, #73d0a5);
  border-color: rgba(115, 208, 165, 0.28);
}
.speed-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
  box-shadow: none;
}
.speed-toggle-label,
.speed-panel-kicker,
.speed-slider-label {
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.speed-toggle-label {
  color: var(--gold);
}
.speed-toggle-value {
  color: #fff4e6e6;
  font-size: 12px;
}
.speed-panel {
  min-width: 250px;
  padding: 14px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #080c12eb, #080b10cc);
  box-shadow: 0 18px 36px #0000003d;
}
.speed-presets {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}
.speed-preset {
  padding: 10px 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: #ffffff0a;
}
.speed-preset.active {
  border-color: #73d0a547;
  background: #73d0a51f;
  color: var(--jade);
}
.speed-slider {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.speed-slider input {
  width: 100%;
}
.speed-range-value {
  color: var(--muted);
  font:
    500 11px DM Mono,
    monospace;
  letter-spacing: 0.08em;
}
.audio-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
  box-shadow: none;
}
.audio-toggle-label {
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.audio-toggle-value {
  color: #fff4e6e6;
  font-size: 12px;
}
.audio-toggle[aria-pressed="true"] {
  border: none;
}
.audio-toggle[aria-pressed="true"] .audio-toggle-value {
  color: var(--jade);
}
.font-widget {
  top: 74px;
  left: 18px;
}
.quality-widget {
  top: 118px;
  left: 18px;
}
.font-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
}
.font-toggle-label {
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.font-toggle-value {
  color: #fff4e6e6;
  font-size: 12px;
}
.quality-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
}
.quality-toggle-label {
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.quality-toggle-value {
  color: #fff4e6e6;
  font-size: 12px;
}
.dock-copy,
.objective-copy,
.hint-pill,
.focus-prompt,
.transcript-text,
.dialogue-copy,
.dialogue-choice {
  font-size: calc(1em * var(--game-font-scale, 1));
}
.objective-kicker,
.music-prompt-kicker,
.subtitle-box .dock-kicker,
.cinematic-subtitle-source,
.hint-pill,
.focus-prompt,
.music-prompt-copy,
.objective-copy,
.dock-copy,
.cinematic-subtitle-text {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.72), 0 0 8px rgba(0, 0, 0, 0.3);
}
.objective-prompt {
  left: 50%;
  top: 20px;
  transform: translate(-50%) translateY(10px) scale(0.985);
  width: min(620px, calc(100% - 40px));
  padding: 16px 18px 18px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  opacity: 0;
  transition:
    transform 0.22s ease,
    width 0.22s ease,
    padding 0.22s ease,
    border-radius 0.22s ease,
    background 0.22s ease,
    opacity 0.42s ease;
}
.objective-prompt.show {
  opacity: 1;
  transform: translate(-50%) translateY(0) scale(1);
}
.objective-title {
  margin-top: 8px;
  font:
    600 34px/1 Cormorant Garamond,
    serif;
}
.objective-copy {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.62;
}
.objective-prompt.compact {
  width: auto;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: transparent;
}
.objective-prompt.compact .objective-title {
  margin-top: 0;
  font:
    500 12px/1 DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.objective-prompt.compact .objective-copy,
.objective-prompt.compact .objective-kicker {
  display: none;
}
.hint-pill {
  left: 50%;
  top: 110px;
  transform: translate(-50%) translateY(10px) scale(0.985);
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 10, 14, 0.82);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0;
  transition:
    opacity 0.42s ease,
    transform 0.42s ease;
}
.hint-pill.show {
  opacity: 1;
  transform: translate(-50%) translateY(0) scale(1);
}
.focus-prompt {
  left: 50%;
  bottom: calc(134px + var(--bottom-gap));
  transform: translate(-50%) translateY(10px) scale(0.985);
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 10, 14, 0.86);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0;
  transition:
    opacity 0.42s ease,
    transform 0.42s ease;
}
.focus-prompt.show {
  opacity: 1;
  transform: translate(-50%) translateY(0) scale(1);
}
.bottom-dock {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: calc(var(--transcript-height) + 16px + var(--bottom-gap));
  z-index: 13;
  display: grid;
  gap: 10px;
  width: auto;
}
.bottom-dock.above-blackout {
  z-index: 58;
}
.ambience-chip {
  display: none;
}
.dock-box {
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #080b10d6, #080a0ebd);
  box-shadow: 0 16px 40px #0003;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.ambience-box {
  padding: 12px 16px 13px;
}
.subtitle-box {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 15px 18px;
  min-height: 70px;
  border-color: #fff1d62e;
  background: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
.dock-copy {
  margin-top: 8px;
  color: #eee8ded1;
  line-height: 1.7;
}
.subtitle-box .dock-copy {
  margin-top: 0;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease,
    max-height 0.18s ease;
}
.bottom-dock.compact-subtitle .subtitle-box {
  min-height: 60px;
  padding-top: 11px;
  padding-bottom: 11px;
}
.bottom-dock.compact-subtitle .subtitle-box .dock-copy {
  opacity: 0.74;
  transform: translateY(2px);
}
.bottom-dock.hidden-subtitle .subtitle-box {
  min-height: 18px;
  padding: 0 10px;
  width: min(180px, 58vw);
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  opacity: 0.04;
  pointer-events: none;
}
.bottom-dock.hidden-subtitle .subtitle-box .dock-copy {
  opacity: 0;
  max-height: 0;
  margin: 0;
  overflow: hidden;
}
.bottom-dock.hidden-subtitle .subtitle-box .dock-kicker {
  opacity: 0;
}
.cinematic-subtitle-layer {
  position: fixed;
  inset: 0;
  z-index: 58;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding:
    24px 24px calc(24px + max(env(safe-area-inset-bottom), 0px));
  pointer-events: none;
}
.cinematic-subtitle-layer.centered {
  align-items: center;
  padding-top: 8vh;
}
.cinematic-subtitle-layer.center-low {
  align-items: center;
  padding-top: 22vh;
}
.cinematic-subtitle-layer[hidden] {
  display: none;
}
.cinematic-subtitle-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: min(940px, calc(100vw - 40px));
  padding: 14px 22px 16px;
  border-radius: 24px;
  border: 1px solid rgba(255, 245, 218, 0.22);
  background: transparent;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  text-align: center;
  pointer-events: auto;
}
.cinematic-subtitle-source {
  color: rgba(238, 232, 222, 0.72);
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}
.cinematic-subtitle-text {
  color: #fff3df;
  font:
    500 clamp(21px, 2.3vw, 34px) / 1.45 Cormorant Garamond,
    serif;
  letter-spacing: 0.02em;
  text-wrap: balance;
}
.transcript-dock {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: calc(18px + var(--bottom-gap));
  z-index: 13;
  display: grid;
  gap: 10px;
  width: auto;
  max-width: var(--transcript-width);
  pointer-events: auto;
}
.transcript-dock-bar,
.transcript-resize-handle {
  display: none;
}
.transcript-dock.ui-panel-managed {
  padding: 0;
  overflow: visible;
  gap: 8px;
  grid-template-rows: auto auto minmax(0, 1fr);
}
.transcript-dock.ui-panel-managed .transcript-dock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.transcript-dock.ui-panel-managed.ui-dragging .transcript-dock-bar {
  cursor: grabbing;
}
.transcript-dock.ui-panel-managed .transcript-resize-handle {
  display: block;
  pointer-events: auto;
}
.transcript-dock.ui-panel-managed .transcript-box {
  min-height: 0;
  max-height: none;
  overflow: hidden;
}
.transcript-dock.ui-panel-managed .transcript-list {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  flex: 1 1 auto;
}
.transcript-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, #080b10d6, #080a0ec2);
  box-shadow: 0 16px 34px #00000038;
  text-align: left;
}
.transcript-status {
  color: #eee8deb8;
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.transcript-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 132px;
  max-height: var(--transcript-height);
  padding: 14px 16px 12px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, #080b10e6, #080a0ed1);
  box-shadow: 0 18px 40px #0000003d;
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.transcript-dock.maximized {
  position: absolute;
  inset: 12px;
  bottom: 12px;
  z-index: 20;
  max-width: none;
}
.transcript-dock.maximized .transcript-box {
  max-height: none;
  flex: 1;
  min-height: 0;
}
.transcript-head {
  display: flex;
  flex-shrink: 0;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.transcript-copy {
  margin-top: 6px;
  color: #eee8de9e;
  line-height: 1.55;
  font-size: 12px;
}
.transcript-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: rgba(217, 179, 106, 0.42) rgba(255, 255, 255, 0.06);
}
.transcript-list::-webkit-scrollbar {
  width: 10px;
}
.transcript-list::-webkit-scrollbar-track {
  background: #ffffff0a;
  border-radius: 999px;
}
.transcript-list::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #d9b36a8a, #fff4e638);
  border-radius: 999px;
  border: 2px solid rgba(8, 10, 14, 0.72);
}
.transcript-item {
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: #ffffff08;
}
.transcript-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.transcript-source {
  color: var(--gold);
  font:
    500 9px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.transcript-time {
  color: #eee8de6b;
  font:
    500 9px DM Mono,
    monospace;
  letter-spacing: 0.08em;
}
.transcript-text {
  margin-top: 6px;
  color: #eee8ded6;
  line-height: 1.65;
  white-space: pre-wrap;
}
.debug-panel {
  right: 18px;
  bottom: calc(108px + var(--bottom-gap));
  width: min(280px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: #080c12d1;
  box-shadow: 0 14px 36px #0000003d;
}
.debug-text {
  margin: 10px 0 0;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  font:
    12px/1.5 DM Mono,
    monospace;
  color: #eee8decc;
}
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-top: 96px;
  padding-bottom: calc(28px + var(--bottom-gap));
  min-width: 0;
  min-height: 0;
  max-height: calc(100vh - 20px);
  max-height: calc(100dvh - 20px);
  overflow: auto;
  padding-right: 6px;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(217, 179, 106, 0.42) rgba(255, 255, 255, 0.06);
}
.side-panel::-webkit-scrollbar {
  width: 12px;
}
.side-panel::-webkit-scrollbar-track {
  background: #ffffff0a;
  border-radius: 999px;
}
.side-panel::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #d9b36a8f, #fff4e633);
  border-radius: 999px;
  border: 2px solid rgba(8, 10, 14, 0.72);
}
.side-panel::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, #d9b36ab8, #fff4e652);
}
.panel-card {
  padding: 18px 18px 20px;
  border-radius: 28px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #0a0e16eb, #080b11d1);
  box-shadow: var(--shadow);
}
.panel-title {
  margin-top: 8px;
  font:
    600 34px/1 Cormorant Garamond,
    serif;
}
.panel-objective {
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.68;
}
.phase-strip,
.memory-list,
.tip-list,
.ending-legend {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}
.panel-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.panel-action {
  text-align: center;
}
.phase-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: #ffffff08;
}
.phase-row.active {
  border-color: #73d0a538;
  background: #73d0a514;
}
.phase-index {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.12em;
}
.phase-row.active .phase-index {
  color: var(--jade);
  border-color: #73d0a53d;
}
.phase-copy strong,
.memory-title {
  display: block;
  font-weight: 500;
  line-height: 1.5;
}
.phase-copy span,
.memory-copy,
.tip-copy,
.ending-row {
  display: block;
  margin-top: 4px;
  color: #eee8dead;
  line-height: 1.62;
}
/* C3: memory progress dots */
.memory-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 8px 0 4px;
}
.memory-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: 1.5px solid rgba(255,255,255,0.22);
  transition: background 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
}
.memory-dot.collected {
  background: #d4af37;
  border-color: #d4af37;
  box-shadow: 0 0 6px rgba(212,175,55,0.5);
}
.memory-item {
  padding: 12px 14px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: #ffffff08;
}
.memory-kicker,
.tip-key {
  font:
    500 9px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #eee8de7a;
}
.tip-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.tip-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: #ffffff08;
}
.ending-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 0;
}
.ending-dot {
  width: 12px;
  height: 12px;
  margin-top: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.ending-dot.canon {
  background: #e4c171;
}
.ending-dot.memory {
  background: #d98ba5;
}
.ending-dot.perfect {
  background: #ffd700;
}
.ending-dot.missed {
  background: #8ea7dc;
}
.mobile-controls {
  position: absolute;
  inset: 0;
  display: none;
  z-index: 14;
  pointer-events: none;
}
.control-cluster {
  position: absolute;
  bottom: calc(18px + var(--bottom-gap));
  pointer-events: auto;
}
.control-cluster.left {
  left: max(14px, env(safe-area-inset-left));
}
.control-cluster.right {
  right: max(14px, env(safe-area-inset-right));
}
.joystick-shell {
  position: relative;
  width: var(--joystick-size);
  height: var(--joystick-size);
}
.joystick-label {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translate(-50%);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: #080b10b8;
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.joystick {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  touch-action: none;
}
.joystick-ring {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: radial-gradient(
    circle at center,
    #ffffff0f,
    #ffffff05 58%,
    #00000029
  );
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--joystick-thumb);
  height: var(--joystick-thumb);
  margin-left: calc(var(--joystick-thumb) / -2);
  margin-top: calc(var(--joystick-thumb) / -2);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(180deg, #ffffff29, #ffffff0a);
  box-shadow: 0 14px 28px #0000003d;
}
.action-glyph {
  position: absolute;
  width: var(--action-size);
  height: var(--action-size);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, #0c121ceb, #080c12d1);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 30px #0000003d;
  color: #fff4e6f5;
  display: grid;
  place-items: center;
  padding: 0;
  font:
    600 13px/1 "Noto Serif TC",
    serif;
  text-align: center;
  white-space: nowrap;
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}
.action-glyph:hover,
.action-glyph:active {
  transform: scale(1.04);
  background: #121924eb;
  border-color: #ffffff29;
}
.action-glyph.north {
  left: calc(50% - var(--action-size) / 2);
  top: calc(var(--action-size) * -0.36);
}
.action-glyph.south {
  left: calc(50% - var(--action-size) / 2);
  bottom: calc(var(--action-size) * -0.28);
}
.action-glyph.west {
  left: calc(var(--action-size) * -0.28);
  top: calc(50% - var(--action-size) / 2);
}
.action-glyph.east {
  right: calc(var(--action-size) * -0.28);
  top: calc(50% - var(--action-size) / 2);
}
.ending-blackout {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: #000;
  opacity: 0;
  transition: opacity 1.5s ease-in;
  pointer-events: none;
}
.ending-whiteout {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: #fff;
  opacity: 0;
  transition: opacity 2s ease-in;
  pointer-events: none;
}
.ending-whiteout.sky {
  background: linear-gradient(to bottom, #87ceeb 0%, #b3e0ff 50%, #e8f5ff 100%);
}
.ending-whiteout.sky::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    108deg,
    transparent 18%,
    rgba(255, 80, 80, 0.20) 28%,
    rgba(255, 165, 0, 0.17) 32%,
    rgba(255, 240, 0, 0.15) 36%,
    rgba(50, 200, 80, 0.15) 40%,
    rgba(30, 140, 255, 0.18) 44%,
    rgba(160, 60, 230, 0.17) 48%,
    transparent 58%
  );
  pointer-events: none;
}
.dialogue-sheet,
.ending-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
}
.dialogue-scrim {
  position: absolute;
  inset: 0;
  background: #03050899;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.dialogue-card,
.ending-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 32px));
  border-radius: 28px;
  padding: 22px 20px 20px;
  border: 1px solid var(--line-strong);
  background: #0a0e16;
  box-shadow: var(--shadow);
  cursor: grab;
}
.dialogue-card:active,
.ending-card:active {
  cursor: grabbing;
}
.dialogue-card.dragging,
.ending-card.dragging {
  cursor: grabbing;
  user-select: none;
}
.dialogue-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #ffffff0f;
}
.dialogue-title,
.ending-title {
  margin-top: 8px;
  font:
    600 42px/1 Cormorant Garamond,
    serif;
}
.dialogue-copy {
  margin-top: 14px;
  display: grid;
  gap: 10px;
  color: #eee8ded1;
  line-height: 1.8;
}
.dialogue-copy p {
  margin: 0;
}
.dialogue-choices,
.ending-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}
.dialogue-choice,
.ending-button {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #ffffff0a;
  text-align: center;
}
.dialogue-choice strong,
.ending-button {
  font-weight: 500;
}
.dialogue-choice span {
  display: block;
  margin-top: 6px;
  color: #eee8dea8;
  line-height: 1.6;
}
.ending-overlay {
  background:
    radial-gradient(
      circle at 64% 42%,
      rgba(255, 229, 172, 0.12),
      transparent 18%
    ),
    radial-gradient(
      circle at 50% 56%,
      rgba(255, 255, 255, 0.04),
      transparent 24%
    ),
    rgba(3, 5, 8, 0.72);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.ending-scroll-control {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 61;
  display: none;
  align-items: center;
  gap: 10px;
  width: min(360px, calc(100vw - 40px));
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(8, 10, 16, 0.82);
  color: rgba(238, 232, 222, 0.72);
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.26);
}
.ending-scroll-control input[type="range"] {
  flex: 1;
  accent-color: #d9b36a;
}
.ending-card {
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(860px, calc(100vw - 40px));
  padding: 28px 28px 24px;
  border-color: rgba(255, 238, 214, 0.14);
  background:
    radial-gradient(
      circle at 76% 24%,
      rgba(255, 231, 182, 0.1),
      transparent 24%
    ),
    linear-gradient(180deg, rgba(12, 15, 22, 0.96), rgba(8, 10, 16, 0.94));
  box-shadow:
    0 42px 120px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.ending-copy {
  margin-top: 14px;
  color: var(--muted);
  line-height: 1.86;
  font-size: calc(15px * var(--game-font-scale, 1));
}
.ending-title {
  font-size: clamp(42px, 5.4vw, 58px);
  letter-spacing: 0.04em;
}
.ending-kicker {
  color: #f0c989;
}
.ending-button.primary {
  background: #73d0a51f;
  border-color: #73d0a53d;
  color: var(--jade);
}
body.dialogue-open .mobile-controls,
body.ending-open .mobile-controls {
  pointer-events: none;
}
body.landscape-prompt .hud,
body.landscape-prompt .speed-widget,
body.landscape-prompt .audio-widget,
body.landscape-prompt .font-widget,
body.landscape-prompt .quality-widget,
body.landscape-prompt .time-watch,
body.landscape-prompt .objective-prompt,
body.landscape-prompt .hint-pill,
body.landscape-prompt .focus-prompt,
body.landscape-prompt .pointer-pill,
body.landscape-prompt .bottom-dock,
body.landscape-prompt .mobile-controls,
body.landscape-prompt .debug-panel {
  opacity: 0;
  pointer-events: none;
}
@media (max-width: 1380px) {
  .game-shell {
    grid-template-columns: minmax(0, 1fr) minmax(268px, 304px);
    gap: 14px;
  }
  .panel-card {
    padding: 16px 16px 18px;
    border-radius: 24px;
  }
  .panel-title {
    font-size: 30px;
  }
}
@media (max-width: 1080px) {
  .game-shell {
    position: fixed;
    inset: 0;
    grid-template-columns: 1fr;
    padding: 0;
    width: 100dvw;
    min-width: 100dvw;
    max-width: 100dvw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }
  .stage {
    min-height: 100vh;
    min-height: 100dvh;
    width: 100dvw;
    min-width: 100dvw;
    height: 100vh;
    height: 100dvh;
    max-width: 100dvw;
    border-radius: 0;
    border: none;
  }
  #scene-canvas {
    width: 100dvw !important;
    min-width: 100dvw;
    height: 100dvh !important;
  }
  .side-panel {
    display: none;
  }
  .mobile-controls {
    display: block;
  }
  .pointer-pill,
  .crosshair {
    display: none;
  }
  .font-widget {
    top: max(8px, env(safe-area-inset-top));
    left: calc(max(8px, env(safe-area-inset-left)) + 100px);
    z-index: 20;
  }
  .speed-widget {
    top: max(8px, env(safe-area-inset-top));
    left: calc(max(8px, env(safe-area-inset-left)) + 155px);
    z-index: 20;
  }
  .quality-widget {
    top: max(8px, env(safe-area-inset-top));
    left: auto;
    right: calc(max(8px, env(safe-area-inset-right)) + 210px);
    z-index: 20;
  }
  .audio-widget {
    top: max(8px, env(safe-area-inset-top));
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    z-index: 20;
  }
  .time-watch {
    top: max(8px, env(safe-area-inset-top));
    left: 50%;
    right: auto;
    transform: translate(-50%);
  }
  .music-prompt {
    left: max(8px, env(safe-area-inset-left));
    top: max(54px, calc(env(safe-area-inset-top) + 46px));
  }
  .objective-prompt {
    position: fixed;
    top: auto;
    bottom: calc(var(--controls-clearance) + 56px + var(--bottom-gap));
    left: var(--safe-center);
    transform: translate(-50%);
    width: min(
      420px,
      calc(100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px)
    );
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px
    );
    max-height: 40vh;
    overflow-y: auto;
    padding: 10px 14px 12px;
    word-break: break-word;
  }
  .objective-prompt.compact {
    width: auto;
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px
    );
    top: auto;
    bottom: calc(var(--controls-clearance) + 56px + var(--bottom-gap));
    left: var(--safe-center);
    transform: translate(-50%);
  }
  .hint-pill {
    top: auto;
    bottom: calc(var(--controls-clearance) + 56px + var(--bottom-gap));
    left: var(--safe-center);
    transform: translate(-50%);
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 20px
    );
    text-align: center;
  }
  .focus-prompt {
    position: fixed;
    top: auto;
    bottom: calc(var(--controls-clearance) + 160px + var(--bottom-gap));
    left: var(--safe-center);
    transform: translate(-50%);
    padding: 8px 14px;
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px
    );
    text-align: center;
    overflow-wrap: break-word;
    word-break: break-word;
  }
  .bottom-dock {
    position: fixed;
    left: calc(
      var(--safe-center) -
      min(
        164px,
        (min(var(--stage-width), 100dvw) - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px) / 2
      )
    );
    right: auto;
    bottom: calc(var(--controls-clearance) + 102px + var(--bottom-gap));
    width: min(
      328px,
      calc(
        min(var(--stage-width), 100dvw) - var(--mobile-left-safe) -
          var(--mobile-right-safe) - 16px
      )
    );
    max-width: calc(
      min(var(--stage-width), 100dvw) - var(--mobile-left-safe) -
        var(--mobile-right-safe) - 16px
    );
    gap: 6px;
    z-index: 16;
  }
  .ambience-chip {
    display: none !important;
  }
  .ambience-box {
    position: fixed !important;
    bottom: calc(var(--controls-clearance) + 102px + var(--bottom-gap) + 58px) !important;
    left: var(--safe-center) !important;
    transform: translate(-50%);
    width: min(380px, calc(100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 24px)) !important;
    max-height: 22vh;
    overflow-y: auto;
    padding: 7px 12px 8px;
    font-size: calc(9px * var(--game-font-scale, 1));
    line-height: 1.45;
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(8,11,16,.68), rgba(8,10,14,.48)) !important;
    box-shadow: 0 6px 18px #00000030;
    z-index: 9998;
    pointer-events: auto;
    word-break: break-word;
  }
  .subtitle-box {
    position: fixed !important;
    top: auto !important;
    bottom: calc(
      var(--controls-clearance) + 102px + var(--bottom-gap) + 6px
    ) !important;
    left: var(--safe-center) !important;
    transform: translate(-50%);
    width: min(
      420px,
      calc(100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px)
    ) !important;
    min-height: max(48px, calc(var(--rail-min-height) + 2px));
    max-height: 30vh;
    overflow-y: auto;
    grid-template-columns: 1fr;
    padding: 8px max(12px, env(safe-area-inset-right)) 9px
      max(12px, env(safe-area-inset-left));
    gap: 4px;
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px
    );
    box-shadow: 0 8px 24px #00000038;
    background: linear-gradient(180deg, #080b10c7, #080a0e94);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border-radius: 14px;
    z-index: 9999;
    pointer-events: auto;
    word-break: break-word;
  }
  .subtitle-box .dock-kicker {
    font-size: 9px;
  }
  .subtitle-box .dock-copy {
    display: block;
    overflow: hidden;
    font-size: calc(10px * var(--game-font-scale, 1));
    line-height: 1.4;
    max-height: 5.8em;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .bottom-dock.hidden-subtitle .subtitle-box {
    min-height: 0;
    width: 0;
    opacity: 0;
    pointer-events: none;
    overflow: hidden;
  }
  .transcript-dock {
    position: fixed;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    bottom: calc(var(--controls-clearance) + var(--joystick-size) + 8px + var(--bottom-gap));
    top: auto;
    width: min(
      420px,
      calc(
        min(var(--stage-width), 100dvw) - var(--mobile-left-safe) -
          var(--mobile-right-safe) - 12px
      )
    );
    max-width: calc(
      min(var(--stage-width), 100dvw) - var(--mobile-left-safe) -
        var(--mobile-right-safe) - 12px
    );
    gap: 6px;
    z-index: 17;
  }
  .transcript-dock.ui-panel-managed,
  .transcript-dock.mobile-freeform {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(
      420px,
      calc(
        min(var(--stage-width), 100dvw) - var(--mobile-left-safe) -
          var(--mobile-right-safe) - 12px
      )
    );
    max-width: none;
    max-height: none;
    gap: 8px;
    padding: 0;
    overflow: visible;
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  .transcript-dock.ui-panel-managed .transcript-dock-bar,
  .transcript-dock.mobile-freeform .transcript-dock-bar {
    display: flex;
  }
  .transcript-dock.ui-panel-managed.ui-dragging .transcript-dock-bar,
  .transcript-dock.mobile-freeform.ui-dragging .transcript-dock-bar {
    cursor: grabbing;
  }
  .transcript-dock-grip {
    width: 30px;
    height: 10px;
    flex: 0 0 auto;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.08),
      rgba(255, 255, 255, 0.16)
    );
  }
  .transcript-dock-hint {
    flex: 1 1 auto;
    font:
      500 9px DM Mono,
      monospace;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .transcript-dock-reset {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    background: transparent;
    color: var(--ink);
  }
  .transcript-toggle {
    min-height: 36px;
    padding: 7px 11px;
    border-radius: 16px;
  }
  .transcript-status {
    font-size: 9px;
  }
  .transcript-box {
    min-height: 88px;
    max-height: 50vh;
    overflow-y: auto;
    padding: 8px 10px;
    border-radius: 18px;
  }
  .transcript-dock.ui-panel-managed .transcript-box,
  .transcript-dock.mobile-freeform .transcript-box {
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }
  .transcript-dock.ui-panel-managed .transcript-list,
  .transcript-dock.mobile-freeform .transcript-list {
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    flex: 1 1 auto;
  }
  .transcript-resize-handle {
    display: block;
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 30px;
    height: 30px;
    border-radius: 0 0 16px 0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background:
      linear-gradient(135deg, transparent 0 46%, rgba(255, 255, 255, 0.16) 46% 52%, transparent 52% 100%),
      transparent;
    cursor: nwse-resize;
    touch-action: none;
  }
  .transcript-dock.ui-panel-managed .transcript-resize-handle,
  .transcript-dock.mobile-freeform .transcript-resize-handle {
    pointer-events: auto;
  }
  .transcript-copy {
    font-size: 9px;
    line-height: 1.38;
    max-width: 34ch;
  }
  .transcript-list {
    gap: 6px;
  }
  .transcript-item {
    padding: 8px 10px;
    border-radius: 14px;
  }
  .transcript-text {
    margin-top: 5px;
    font-size: calc(10px * var(--game-font-scale, 1));
    line-height: 1.4;
    text-align: center;
  }
  .transcript-item-head {
    justify-content: center;
  }
  .control-cluster {
    position: fixed;
    bottom: calc(10px + var(--bottom-gap));
  }
  .control-cluster.left {
    left: max(10px, env(safe-area-inset-left));
  }
  .control-cluster.right {
    right: max(10px, env(safe-area-inset-right));
  }
  .action-glyph {
    box-shadow: 0 10px 22px #0000003d;
    font-size: 11px;
    letter-spacing: 0.04em;
  }
  .debug-panel {
    position: fixed;
    right: 10px;
    bottom: calc(80px + var(--bottom-gap));
    width: min(240px, 34vw);
  }
  .dialogue-card {
    max-height: 85vh;
    overflow-y: auto;
  }
  .ending-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding:
      max(12px, env(safe-area-inset-top)) 12px
      calc(18px + max(env(safe-area-inset-bottom), 0px));
    -webkit-overflow-scrolling: touch;
  }
  .ending-card {
    position: relative;
    top: auto;
    bottom: auto;
    transform: none;
    width: min(860px, calc(100vw - 24px));
    max-height: calc(100dvh - 36px - env(safe-area-inset-top));
    overflow-y: auto;
    margin: 0 auto;
    padding-bottom: 54px;
    animation: ending-card-rise-mobile 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }
  .ending-scroll-control {
    display: flex;
  }
  .dock-copy {
    word-break: break-word;
    overflow-wrap: break-word;
  }
}
@media (max-width: 1080px) and (orientation: portrait) {
  .debug-panel {
    display: none;
  }
  .subtitle-box {
    max-height: 30vh;
    overflow-y: auto;
    word-break: break-word;
  }
  .subtitle-box .dock-copy {
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .objective-prompt {
    max-height: 40vh;
    overflow-y: auto;
    word-break: break-word;
  }
  .hint-pill {
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 20px
    );
    text-align: center;
  }
  .focus-prompt {
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 16px
    );
    overflow-wrap: break-word;
    word-break: break-word;
  }
  .dialogue-card {
    max-height: 85vh;
    overflow-y: auto;
  }
  .transcript-box {
    max-height: 50vh;
    overflow-y: auto;
  }
  .dock-copy {
    word-break: break-word;
    overflow-wrap: break-word;
  }
}
@media (max-width: 479px) and (orientation: portrait) {
  /* 窄手機：quality-widget 在右側（時空手錶與音樂之間） */
  .quality-widget {
    top: max(8px, env(safe-area-inset-top));
    left: auto;
    right: calc(max(8px, env(safe-area-inset-right)) + 210px);
    z-index: 20;
  }
}
@media (max-width: 1080px) and (orientation: landscape) {
  .ending-hook,
  .ending-tracker,
  #ending-tracker-summary {
    display: none;
  }
  .ending-card {
    max-height: none;
    overflow-y: visible;
  }
  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
  }
  .hud-body {
    width: min(520px, calc(100vw - 16px));
    grid-template-columns: 1fr;
    padding: 14px 16px 16px;
  }
  .hud-title {
    font-size: 34px;
  }
  .hud-copy {
    font-size: 14px;
    line-height: 1.55;
  }
  .hud-meta,
  .hud-links {
    justify-content: flex-start;
  }
  .time-watch {
    top: 12px;
    left: 50%;
    right: auto;
    transform: translate(-50%);
    padding: 4px 12px 6px;
    border-radius: 10px;
  }
  .time-watch-display {
    font-size: 16px;
  }
  .objective-prompt {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    transform: none;
    width: min(246px, 36vw);
    padding: 8px 12px 10px;
    bottom: calc(
      var(--controls-clearance) + var(--joystick-size) + 24px +
        var(--bottom-gap)
    );
  }
  .objective-title {
    font-size: 22px;
  }
  .objective-copy {
    font-size: calc(12px * var(--game-font-scale, 1));
    line-height: 1.44;
    word-break: break-word;
  }
  .objective-prompt.compact {
    width: auto;
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    transform: none;
    bottom: calc(
      var(--controls-clearance) + var(--joystick-size) + 24px +
        var(--bottom-gap)
    );
  }
  .font-widget {
    top: max(8px, env(safe-area-inset-top));
    left: calc(max(8px, env(safe-area-inset-left)) + 100px);
  }
  .speed-widget {
    top: max(8px, env(safe-area-inset-top));
    left: calc(max(8px, env(safe-area-inset-left)) + 155px);
  }
  .quality-widget {
    top: max(8px, env(safe-area-inset-top));
    left: auto;
    right: calc(max(8px, env(safe-area-inset-right)) + 210px);
  }
  .audio-widget {
    top: max(8px, env(safe-area-inset-top));
    left: auto;
    right: max(8px, env(safe-area-inset-right));
  }
  .music-prompt {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    top: max(50px, calc(env(safe-area-inset-top) + 40px));
    width: auto;
    max-width: calc(100vw - 18px);
    min-width: 0;
    padding: 6px 8px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 4px;
  }
  .music-prompt-kicker,
  .music-prompt-copy {
    display: none;
  }
  .music-prompt-button {
    min-height: 30px;
    margin-top: 0;
    padding: 0 14px;
    font-size: 11px;
    white-space: nowrap;
  }
  .music-prompt-close {
    position: static;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    font-size: 12px;
  }
  .audio-toggle {
    min-height: 38px;
    padding: 8px 12px;
  }
  .audio-toggle-label {
    display: none;
  }
  .speed-toggle {
    min-height: 38px;
    padding: 8px 12px;
  }
  .speed-toggle-label {
    display: none;
  }
  .font-toggle {
    min-height: 38px;
    padding: 8px 12px;
  }
  .font-toggle-label {
    display: none;
  }
  .speed-panel {
    min-width: 220px;
    padding: 12px;
  }
  .hint-pill {
    max-width: calc(
      100vw - var(--mobile-left-safe) - var(--mobile-right-safe) - 20px
    );
  }
  .focus-prompt {
    left: auto;
    right: max(8px, env(safe-area-inset-right));
    transform: none;
    max-width: 35vw;
    text-align: right;
    bottom: calc(
      var(--controls-clearance) + var(--joystick-size) + 24px +
        var(--bottom-gap)
    );
  }
  .transcript-dock {
    left: var(--safe-center);
    right: auto;
    transform: translate(-50%);
    width: min(
      320px,
      calc(
        min(var(--stage-width), 100dvw) - var(--mobile-left-safe) -
          var(--mobile-right-safe) - 12px
      )
    );
    max-width: calc(
      min(var(--stage-width), 100dvw) - var(--mobile-left-safe) -
        var(--mobile-right-safe) - 12px
    );
  }
  .transcript-box {
    max-height: 40vh;
  }
}
.intro-skip-btn {
  position: fixed;
  bottom: calc(28px + var(--bottom-gap));
  right: calc(28px + var(--side-gap-right));
  z-index: 200;
  padding: 10px 20px;
  font:
    500 10px DM Mono,
    monospace;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #eee8deb8;
  background: #080a10b8;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 40px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition:
    opacity 0.3s,
    background 0.2s,
    border-color 0.2s,
    color 0.2s;
  animation: skipFadeIn 1.2s 3s both;
}
.intro-skip-btn:hover {
  background: #0e121ae0;
  border-color: #ffffff52;
  color: #eee8de;
}
@keyframes skipFadeIn {
  0% {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.intro-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  overflow: hidden;
  background:
    radial-gradient(
      circle at 50% 50%,
      rgba(255, 224, 182, 0.12),
      transparent 32%
    ),
    radial-gradient(
      circle at 50% 50%,
      rgba(255, 104, 144, 0.08),
      transparent 58%
    );
  transition: opacity 1.4s ease;
}
.intro-fx-active {
  opacity: 1;
  animation: introFxPulse 4.2s ease-in-out infinite alternate;
}
.intro-fx-done {
  opacity: 0 !important;
  transition: opacity 1.8s ease !important;
}
.intro-fx:before {
  content: "";
  position: absolute;
  inset: -20%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(255, 220, 160, 0.04) 3deg,
    transparent 6deg,
    rgba(200, 230, 255, 0.03) 12deg,
    transparent 15deg,
    rgba(255, 200, 180, 0.04) 24deg,
    transparent 27deg,
    rgba(180, 210, 255, 0.03) 36deg,
    transparent 39deg,
    rgba(255, 220, 180, 0.04) 60deg,
    transparent 63deg,
    rgba(200, 225, 255, 0.03) 90deg,
    transparent 93deg,
    rgba(255, 215, 165, 0.04) 120deg,
    transparent 123deg,
    rgba(195, 220, 255, 0.03) 150deg,
    transparent 153deg,
    rgba(255, 220, 160, 0.04) 180deg,
    transparent 183deg,
    rgba(200, 230, 255, 0.03) 240deg,
    transparent 243deg,
    rgba(255, 220, 160, 0.04) 300deg,
    transparent 303deg,
    rgba(200, 220, 255, 0.03) 330deg,
    transparent 333deg
  );
  animation: introSpeedSpin 3.2s linear infinite;
  mix-blend-mode: screen;
}
.intro-fx:after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 80% 80% at 50% 50%,
    transparent 40%,
    rgba(255, 40, 60, 0.05) 70%,
    rgba(40, 80, 255, 0.08) 100%
  );
  animation: introChromatic 2.8s ease-in-out infinite alternate;
  mix-blend-mode: screen;
}
.intro-fx-thread,
.intro-fx-runner,
.intro-fx-flare {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.intro-fx-thread {
  width: 180vmax;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    #ff668400,
    #ff66841f 12%,
    #ff7692d1 48%,
    #ffddaae6,
    #ff7692d1 60%,
    #ff66841f 88%,
    #ff668400
  );
  box-shadow:
    0 0 18px #ff74926b,
    0 0 58px #ffa67e2e;
  transform: translate(-50%, -50%) rotate(-18deg) scaleX(0.92);
}
.intro-fx-runner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 40% 40%,
    #fffffffa,
    #ffe7c0eb 40%,
    #ff8098b3 72%,
    #ff809800
  );
  box-shadow:
    0 0 16px #ffffff6b,
    0 0 54px #ff859c52,
    0 0 96px #ffd69638;
  animation: introRunnerFly 3.6s cubic-bezier(0.22, 0.7, 0.18, 1) infinite;
}
.intro-fx-flare {
  width: 44vmin;
  height: 44vmin;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 50%,
    #fff7e938,
    #ffd7a514 34%,
    #ff60820f 56%,
    #ff608200
  );
  mix-blend-mode: screen;
  animation: introFlareBreathe 2.8s ease-in-out infinite;
}
.intro-fx-done .intro-fx-thread,
.intro-fx-done .intro-fx-runner,
.intro-fx-done .intro-fx-flare {
  opacity: 0;
}
@keyframes introSpeedSpin {
  0% {
    transform: rotate(0) scale(1.4);
  }
  to {
    transform: rotate(360deg) scale(1.4);
  }
}
@keyframes introChromatic {
  0% {
    transform: scale(1) translate(0);
    opacity: 0.6;
  }
  50% {
    transform: scale(1.04) translate(-1px, 0.5px);
    opacity: 1;
  }
  to {
    transform: scale(1) translate(1px, -0.5px);
    opacity: 0.7;
  }
}
@keyframes introFxPulse {
  0% {
    opacity: 0.5;
  }
  40% {
    opacity: 0.9;
  }
  60% {
    opacity: 0.7;
  }
  to {
    opacity: 0.6;
  }
}
@keyframes introRunnerFly {
  0% {
    transform: translate(calc(-50% - 48vw), calc(-50% + 16vh)) scale(0.64);
    opacity: 0.22;
  }
  18% {
    opacity: 0.9;
  }
  45% {
    transform: translate(calc(-50% - 8vw), calc(-50% + 2vh)) scale(1);
  }
  72% {
    transform: translate(calc(-50% + 16vw), calc(-50% - 10vh)) scale(0.9);
  }
  to {
    transform: translate(calc(-50% + 46vw), calc(-50% - 22vh)) scale(0.4);
    opacity: 0.18;
  }
}
@keyframes introFlareBreathe {
  0%,
  to {
    transform: translate(-50%, -50%) scale(0.88);
    opacity: 0.42;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.04);
    opacity: 0.88;
  }
}
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto !important;
  }
  *,
  *:before,
  *:after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .intro-fx,
  .intro-fx:before,
  .intro-fx:after {
    animation: none !important;
    opacity: 0 !important;
  }
  .stage-vignette {
    animation: none;
  }
}
/* Draggable UI System */
.ui-drag-handle {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.ui-drag-handle:active {
  cursor: grabbing;
}
.ui-dragging {
  opacity: 0.92;
  z-index: 70 !important;
  transition: none !important;
}
.ui-draggable {
  transition: box-shadow 0.2s;
}
.ui-draggable:hover {
  box-shadow: 0 0 0 1px rgba(115, 208, 165, 0.15);
}

/* Resizable transcript */
.transcript-dock.ui-resizable {
  resize: none;
  overflow: visible;
}
.transcript-dock.ui-resizable .transcript-box {
  overflow-y: auto;
}
.transcript-dock.ui-resizable .transcript-list {
  overflow-y: auto;
}
.ui-resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  z-index: 2;
}
.ui-resize-handle-tr {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}
.ui-resize-handle-br {
  bottom: -4px;
  right: -4px;
  cursor: nwse-resize;
}
.ui-resize-handle-tl {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}
.ui-resize-handle::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 2px;
  background: rgba(115, 208, 165, 0.25);
  opacity: 0;
  transition: opacity 0.15s;
}
.ui-resize-handle:hover::after {
  opacity: 1;
}

/* Maximize/minimize button */
.ui-maximize-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(238, 232, 222, 0.6);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.ui-maximize-btn:hover {
  background: rgba(115, 208, 165, 0.12);
  border-color: rgba(115, 208, 165, 0.25);
  color: #73d0a5;
}

/* Panel position memory indicator */
.ui-position-reset {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(238, 232, 222, 0.35);
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3;
}
.ui-has-custom-pos .ui-position-reset {
  display: flex;
}
.et-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
  opacity: 0.45;
  transition: opacity 0.2s;
}
.et-item.done {
  opacity: 1;
  border-color: rgba(115, 208, 165, 0.18);
  background: rgba(115, 208, 165, 0.04);
}
.et-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.et-dot.perfect {
  background: linear-gradient(135deg, #f5d78e, #e8b84e);
}
.et-dot.canon {
  background: #e4c171;
}
.et-dot.memory {
  background: #d98ba5;
}
.et-dot.missed {
  background: #8ea7dc;
}
.et-lbl {
  flex: 1;
  color: rgba(238, 232, 222, 0.7);
}
.et-chk {
  font-size: 11px;
  color: #73d0a5;
  font-weight: 600;
}
.et-item:not(.done) .et-chk {
  color: rgba(238, 232, 222, 0.25);
}
.ui-drag-handle {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.ui-drag-handle:active {
  cursor: grabbing;
}
.ui-dragging {
  opacity: 0.92 !important;
  z-index: 70 !important;
  transition: none !important;
}
.ui-draggable {
  transition: box-shadow 0.2s;
}
.ui-draggable:hover {
  box-shadow: 0 0 0 1px rgba(115, 208, 165, 0.12);
}
.ui-resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  bottom: -5px;
  right: -5px;
  z-index: 3;
}
.ui-resize-handle::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 2px;
  border-right: 2px solid rgba(115, 208, 165, 0.3);
  border-bottom: 2px solid rgba(115, 208, 165, 0.3);
  opacity: 0;
  transition: opacity 0.15s;
}
.ui-resize-handle:hover::after {
  opacity: 1;
}
.ui-max-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(238, 232, 222, 0.5);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.ui-max-btn:hover {
  background: rgba(115, 208, 165, 0.1);
  border-color: rgba(115, 208, 165, 0.2);
  color: #73d0a5;
}
.ui-reset-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.02);
  color: rgba(238, 232, 222, 0.3);
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 3;
}
.ui-has-pos .ui-reset-btn {
  display: flex;
}

/* Transparent-bottom UI surface pass */
.hud-toggle,
.hud-body,
.time-watch,
.speed-toggle,
.speed-panel,
.audio-toggle,
.font-toggle,
.pointer-pill,
.objective-prompt,
.hint-pill,
.focus-prompt,
.dock-box,
.subtitle-box,
.transcript-toggle,
.transcript-box,
.debug-panel,
.panel-card,
.memory-item,
.phase-row,
.tip-key,
.dialogue-card,
.dialogue-choice,
.ending-card,
.ending-button,
.ending-scroll-control,
.ui-maximize-btn,
.ui-position-reset,
.ui-max-btn,
.ui-reset-btn,
.music-prompt {
  background:
    linear-gradient(
      180deg,
      rgba(8, 11, 16, 0.24) 0%,
      rgba(8, 11, 16, 0.12) 64%,
      rgba(8, 11, 16, 0) 100%
    );
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  box-shadow: none;
}

.hud-body,
.time-watch,
.speed-panel,
.audio-toggle,
.font-toggle,
.objective-prompt,
.hint-pill,
.focus-prompt,
.dock-box,
.subtitle-box,
.transcript-toggle,
.transcript-box,
.debug-panel,
.panel-card,
.memory-item,
.phase-row,
.tip-key,
.dialogue-card,
.dialogue-choice,
.ending-card,
.ending-button,
.ending-scroll-control,
.music-prompt {
  border-color: rgba(255, 255, 255, 0.1);
}

.hud-body,
.speed-panel,
.transcript-box,
.panel-card,
.dialogue-card,
.ending-card {
  box-shadow:
    0 12px 30px rgba(0, 0, 0, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.hud-toggle,
.hud-body,
.time-watch,
.speed-toggle,
.speed-panel,
.audio-toggle,
.font-toggle,
.pointer-pill,
.objective-prompt,
.hint-pill,
.focus-prompt,
.music-prompt,
.transcript-toggle,
.transcript-box,
.debug-panel,
.panel-card,
.memory-item,
.phase-row,
.tip-key,
.dialogue-card,
.dialogue-choice,
.ending-card,
.ending-button,
.ending-scroll-control {
  color: var(--ink);
}

.hud-copy,
.hud-link,
.objective-copy,
.hint-pill,
.focus-prompt,
.music-prompt-copy,
.dock-copy,
.transcript-copy,
.transcript-text,
.dialogue-copy,
.dialogue-choice,
.panel-objective,
.memory-copy,
.tip-copy,
.ending-copy,
.phase-copy span,
.et-lbl,
.et-item,
.time-watch-label,
.time-watch-display {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.52);
}

.dialogue-scrim {
  background: rgba(3, 5, 8, 0.42);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.ending-overlay {
  background:
    radial-gradient(
      circle at 64% 42%,
      rgba(255, 229, 172, 0.09),
      transparent 18%
    ),
    radial-gradient(
      circle at 50% 56%,
      rgba(255, 255, 255, 0.03),
      transparent 24%
    ),
    rgba(3, 5, 8, 0.58);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.ending-card {
  background:
    radial-gradient(
      circle at 76% 24%,
      rgba(255, 231, 182, 0.08),
      transparent 24%
    ),
    linear-gradient(
      180deg,
      rgba(12, 15, 22, 0.22),
      rgba(8, 10, 16, 0.12) 70%,
      rgba(8, 10, 16, 0)
    );
}

.dialogue-card {
  background: #0a0e16;
}

.panel-card,
.transcript-box,
.speed-panel {
  background:
    linear-gradient(
      180deg,
      rgba(10, 14, 22, 0.2),
      rgba(8, 11, 16, 0.1) 68%,
      rgba(8, 10, 16, 0)
    );
}

.dock-box,
.subtitle-box,
.objective-prompt,
.hint-pill,
.focus-prompt,
.music-prompt,
.transcript-toggle,
.debug-panel {
  background:
    linear-gradient(
      180deg,
      rgba(8, 11, 16, 0.16),
      rgba(8, 10, 16, 0.08) 72%,
      rgba(8, 10, 16, 0)
    );
}

.dialogue-choice,
.ending-button,
.phase-row,
.memory-item,
.tip-key,
.audio-toggle,
.font-toggle,
.speed-toggle,
.pointer-pill,
.ui-maximize-btn,
.ui-position-reset,
.ui-max-btn,
.ui-reset-btn {
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.05),
      rgba(255, 255, 255, 0.03) 70%,
      rgba(255, 255, 255, 0)
    );
}

.dialogue-choice:hover,
.ending-button:hover,
.audio-toggle:hover,
.font-toggle:hover,
.speed-toggle:hover,
.music-prompt-button:hover,
.music-prompt-close:hover,
.ui-maximize-btn:hover,
.ui-max-btn:hover {
  border-color: rgba(115, 208, 165, 0.28);
  color: #9cf0c9;
}

.dialogue-choice:focus-visible,
.ending-button:focus-visible,
.audio-toggle:focus-visible,
.font-toggle:focus-visible,
.speed-toggle:focus-visible,
.music-prompt-button:focus-visible,
.transcript-toggle:focus-visible,
.ui-maximize-btn:focus-visible,
.ui-position-reset:focus-visible,
.ui-max-btn:focus-visible,
.ui-reset-btn:focus-visible,
.speed-preset:focus-visible,
.hud-toggle:focus-visible,
.hud-link:focus-visible,
.action-glyph:focus-visible,
.intro-skip-btn:focus-visible,
.transcript-resize-handle:focus-visible,
.ending-scroll-control input[type="range"]:focus-visible {
  outline: 2px solid rgba(115, 208, 165, 0.88);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px rgba(115, 208, 165, 0.14);
}

@media (max-width: 1080px) {
  .speed-widget,
  .audio-widget,
  .font-widget,
  .quality-widget,
  .objective-prompt,
  .hint-pill,
  .focus-prompt,
  .debug-panel,
  .music-prompt,
  .subtitle-box,
  .transcript-box,
  .dialogue-card,
  .ending-card,
  .ending-scroll-control,
  .transcript-toggle {
    background:
      linear-gradient(
        180deg,
        rgba(8, 11, 16, 0.18),
        rgba(8, 10, 16, 0.08) 72%,
        rgba(8, 10, 16, 0)
      );
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  .subtitle-box {
    border-color: rgba(255, 241, 214, 0.16);
  }

  .dialogue-card,
  .ending-card {
    max-width: calc(100vw - 24px);
  }
}

/* ═══════════════════════════════════════════
   E3: 電影式字幕動畫 — typewriter + 角色字重
   ═══════════════════════════════════════════ */
.cinematic-subtitle-text.typewriter {
  overflow: hidden;
  white-space: nowrap;
  border-right: 2px solid rgba(255, 243, 223, 0.6);
  animation: typewriter-reveal 2.4s steps(20, end) forwards,
             typewriter-blink 0.6s step-end 3;
  width: 0;
  display: inline-block;
}
.cinematic-subtitle-text.typewriter.done {
  width: auto;
  white-space: normal;
  border-right: none;
  animation: none;
}
@keyframes typewriter-reveal {
  from { width: 0; }
  to { width: 100%; }
}
@keyframes typewriter-blink {
  50% { border-color: transparent; }
}

.cinematic-subtitle-source {
  font-weight: 600;
  letter-spacing: 0.28em;
}

/* ═══════════════════════════════════════════
   C4: 結局成就動畫
   ═══════════════════════════════════════════ */
.ending-overlay {
  transition: opacity 0.6s ease;
}
.ending-card {
  animation: ending-card-rise 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes ending-card-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -44%) scale(0.94);
    filter: blur(8px);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    filter: blur(0);
  }
}
@keyframes ending-card-rise-mobile {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
    filter: blur(6px);
  }
  100% {
    opacity: 1;
    transform: none;
    filter: blur(0);
  }
}
@media (max-width: 1080px) {
  .ending-card {
    animation: ending-card-rise-mobile 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }
}

.ending-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(from 180deg,
    rgba(217, 179, 106, 0.4),
    rgba(115, 208, 165, 0.3),
    rgba(239, 111, 128, 0.3),
    rgba(217, 179, 106, 0.4));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0;
  animation: ending-glow-in 1.2s 0.4s ease forwards;
}
@keyframes ending-glow-in {
  to { opacity: 1; }
}

/* 結局色調差異 */
.ending-card[data-ending="perfect"] { --ending-accent: #d9b36a; }
.ending-card[data-ending="canon"] { --ending-accent: #73d0a5; }
.ending-card[data-ending="memory"] { --ending-accent: #8bb4e8; }
.ending-card[data-ending="missed"] { --ending-accent: #8c8a88; }

.ending-card[data-ending]::after {
  content: "";
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 60%;
  height: 2px;
  background: var(--ending-accent, #d9b36a);
  border-radius: 0 0 2px 2px;
  opacity: 0.7;
}

/* ═══════════════════════════════════════════
   C5: 電影寬銀幕黑邊 + 結局強化
   ═══════════════════════════════════════════ */

/* Letterboxing bars — 2.39:1 cinematic ratio */
.letterbox-bar {
  position: fixed;
  left: 0; right: 0;
  z-index: 55;
  height: 0;
  background: #000;
  pointer-events: none;
  transition: height 1.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.letterbox-bar--top { top: 0; }
.letterbox-bar--bottom { bottom: 0; }
body.cinematic-mode .letterbox-bar {
  height: max(4vh, 28px);
}

/* Ending overlay — deeper atmospheric background */
.ending-overlay {
  background:
    radial-gradient(ellipse 50% 50% at 50% 40%, rgba(255,229,172,0.08), transparent 60%),
    radial-gradient(circle at 50% 56%, rgba(255,255,255,0.03), transparent 28%),
    rgba(3, 5, 8, 0.82);
  -webkit-backdrop-filter: blur(14px) saturate(0.7);
  backdrop-filter: blur(14px) saturate(0.7);
}

/* Ending title — staggered letter reveal feel */
.ending-title {
  opacity: 0;
  animation: ending-title-reveal 1.6s 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes ending-title-reveal {
  0% { opacity: 0; transform: translateY(12px); letter-spacing: 0.12em; filter: blur(4px); }
  60% { opacity: 1; filter: blur(0); }
  100% { opacity: 1; transform: translateY(0); letter-spacing: 0.04em; filter: blur(0); }
}

/* Ending buttons — cinematic staggered entrance */
/* 按鈕入場由 btn-glow-pulse 接管，不再額外設 opacity: 0 避免衝突 */

/* Ending card light beam effect */
.ending-card::after {
  background: linear-gradient(90deg, transparent, var(--ending-accent, #d9b36a), transparent);
  box-shadow: 0 0 20px color-mix(in srgb, var(--ending-accent, #d9b36a) 40%, transparent);
  animation: ending-beam-pulse 3s 1.5s ease-in-out infinite alternate;
}
@keyframes ending-beam-pulse {
  0% { opacity: 0.5; width: 40%; }
  100% { opacity: 0.9; width: 70%; }
}

/* Enhanced cinematic vignette during gameplay */
.cinematic-vignette {
  background:
    radial-gradient(ellipse 75% 75% at 50% 50%, transparent 45%, rgba(0,0,0,0.55) 100%),
    linear-gradient(0deg, rgba(0,0,0,0.18) 0%, transparent 8%, transparent 92%, rgba(0,0,0,0.12) 100%);
}

/* Intro thread — add shimmer highlight traveling along */
@keyframes introThreadShimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}
.intro-fx-active .intro-fx-thread {
  background-size: 200% 100%;
  animation: introThreadShimmer 2.4s linear infinite;
  background-image: linear-gradient(
    90deg,
    #ff668400 0%,
    #ff66841f 10%,
    #ff7692d1 30%,
    #ffffffcc 50%,
    #ff7692d1 70%,
    #ff66841f 90%,
    #ff668400 100%
  );
}

/* ═══════════════════════════════════════════
   C6: 載入畫面
   ═══════════════════════════════════════════ */
.lm402-loader {
  position: fixed;
  inset: 0;
  z-index: 999;
  background:
    radial-gradient(ellipse 60% 60% at 50% 42%, rgba(20,16,30,0.9), transparent 60%),
    radial-gradient(circle at 30% 80%, rgba(255,72,88,0.03), transparent 40%),
    #06080d;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 1.2s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: auto;
}
.loader-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 0 24px;
  opacity: 0;
  animation: loader-content-in 1.2s 0.3s ease forwards;
}
@keyframes loader-content-in {
  0% { opacity: 0; transform: translateY(12px); filter: blur(4px); }
  100% { opacity: 1; transform: translateY(0); filter: blur(0); }
}
.lm402-loader.fade-out {
  opacity: 0;
  pointer-events: none;
}
.lm402-loader-title {
  font: 300 clamp(18px, 2.5vw, 28px) / 1.4 "Cormorant Garamond", Georgia, "Times New Roman", serif;
  color: rgba(238, 232, 222, 0.8);
  letter-spacing: 0.1em;
  text-align: center;
  text-shadow: 0 0 40px rgba(217,179,106,0.08);
  /* CLS 穩定：固定最小高度避免 fallback → webfont 切換造成 layout shift */
  min-height: calc(1.4em * 2);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}
.lm402-loader-quote {
  font: 300 clamp(12px, 1.6vw, 16px) / 1.8 "Noto Serif TC", "PingFang TC", serif;
  color: rgba(238, 232, 222, 0.4);
  max-width: 320px;
  text-align: center;
  opacity: 0;
  animation: loader-quote-in 1s 0.8s ease forwards;
  /* CLS 穩定：明確 fallback 到系統字體 */
  font-synthesis: none;
}
@keyframes loader-quote-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}
.lm402-loader-bar {
  width: min(240px, 60vw);
  height: 2px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 1px;
  overflow: hidden;
  position: relative;
}
/* Ambient shimmer on the bar track */
.lm402-loader-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(217,179,106,0.1) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: loader-bar-shimmer 2s ease-in-out infinite;
}
@keyframes loader-bar-shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}
.lm402-loader-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #d9b36a, #ef6f80, #73d0a5);
  background-size: 200% 100%;
  border-radius: 1px;
  transition: width 0.3s ease;
  box-shadow: 0 0 8px rgba(217,179,106,0.3);
  animation: loader-fill-glow 2s ease-in-out infinite alternate;
}
@keyframes loader-fill-glow {
  0% { box-shadow: 0 0 6px rgba(217,179,106,0.2); }
  100% { box-shadow: 0 0 14px rgba(217,179,106,0.5), 0 0 28px rgba(239,111,128,0.15); }
}
.lm402-loader-pct {
  font: 400 10px "DM Mono", monospace;
  color: rgba(238, 232, 222, 0.35);
  letter-spacing: 0.2em;
}
.lm402-loader-tip {
  font: 300 11px/1.7 "Noto Sans TC", sans-serif;
  color: rgba(238, 232, 222, 0.28);
  text-align: center;
  max-width: 280px;
  margin-top: 12px;
  min-height: 2.4em;
  transition: opacity 0.5s ease;
}

/* ═══════════════════════════════════════════
   C2: 互動物件 hotspot glow（CSS 層面的提示）
   ═══════════════════════════════════════════ */
.hotspot-indicator {
  position: fixed;
  pointer-events: none;
  z-index: 14;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217, 179, 106, 0.9), rgba(239,111,128,0.3) 60%, transparent 72%);
  box-shadow: 0 0 16px 6px rgba(217, 179, 106, 0.35), 0 0 40px rgba(239,111,128,0.12);
  animation: hotspot-pulse 2.4s ease-in-out infinite;
}
/* Outer ring for better visibility */
.hotspot-indicator::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px solid rgba(217, 179, 106, 0.2);
  animation: hotspot-ring 2.4s ease-in-out infinite;
}
@keyframes hotspot-pulse {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.4); opacity: 0.35; }
}
@keyframes hotspot-ring {
  0%, 100% { transform: scale(1); opacity: 0.4; }
  50% { transform: scale(1.8); opacity: 0; }
}

/* ═══════════════════════════════════════════
   D3: 手機版電影色調（CSS filter 近似）
   ═══════════════════════════════════════════ */
@media (max-width: 1080px) {
  #scene-canvas {
    filter: sepia(0.08) saturate(1.1) contrast(1.04) brightness(0.98);
  }
}

/* ═══════════════════════════════════════════
   E2: 完美結局 vignette + grain overlay
   ═══════════════════════════════════════════ */
.cinematic-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 57;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.5) 100%);
  opacity: 0;
  transition: opacity 1.2s ease;
}
.cinematic-vignette.active {
  opacity: 1;
}
.cinematic-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 57;
  opacity: 0;
  transition: opacity 0.8s ease;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)' opacity='0.4'/%3E%3C/svg%3E");
  background-size: 128px 128px;
  mix-blend-mode: overlay;
}
.cinematic-grain.active {
  opacity: 0.15;
}

/* ═══════════════════════════════════════════
   P1: 對話面板可拖曳 / 可縮放
   ═══════════════════════════════════════════ */
.dialogue-card.ui-has-pos {
  position: fixed !important;
  left: var(--ui-x) !important;
  top: var(--ui-y) !important;
  transform: none !important;
  margin: 0 !important;
}
.dialogue-card.ui-has-size {
  width: var(--ui-w) !important;
  height: var(--ui-h) !important;
  max-width: none !important;
  max-height: none !important;
  overflow-y: auto;
}
.dialogue-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 20px;
  height: 20px;
  cursor: nwse-resize;
  opacity: 0.3;
  transition: opacity 0.2s;
  background:
    linear-gradient(135deg, transparent 50%, rgba(255,241,214,0.28) 50%);
  border-radius: 0 0 var(--card-radius, 14px) 0;
  z-index: 2;
}
.dialogue-resize-handle:hover {
  opacity: 0.6;
}

/* ═══════════════════════════════════════════
   P2: 字幕 / 氛圍拖曳游標
   ═══════════════════════════════════════════ */
.subtitle-box .ui-drag-handle,
.ambience-box .ui-drag-handle {
  cursor: grab;
}
.subtitle-box .ui-drag-handle:active,
.ambience-box .ui-drag-handle:active {
  cursor: grabbing;
}

/* ═══════════════════════════════════════════
   P3: 字幕自動偵測背景亮度 — 動態底色
   ═══════════════════════════════════════════ */
.subtitle-box,
.ambience-box,
.cinematic-subtitle-card {
  --subtitle-adaptive-bg: rgba(8, 10, 14, 0.62);
  background: var(--subtitle-adaptive-bg) !important;
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  transition: background 0.4s ease;
}

/* ═══════════════════════════════════════════
   P4: 手機 transcript 位置微調
   ═══════════════════════════════════════════ */
@media (max-width: 799px) {
  .transcript-dock.ui-has-pos {
    max-width: 52% !important;
  }
}

/* ═══════════════════════════════════════════
   D2: 可互動按鈕亮光脈動特效
   ═══════════════════════════════════════════ */
@keyframes btn-glow-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(180,220,255,0), 0 0 8px 2px rgba(140,200,255,0.18); }
  50%  { box-shadow: 0 0 0 5px rgba(140,200,255,0.10), 0 0 18px 6px rgba(140,200,255,0.28); }
  100% { box-shadow: 0 0 0 0 rgba(180,220,255,0), 0 0 8px 2px rgba(140,200,255,0.18); }
}
@keyframes btn-glow-pulse-primary {
  0%   { box-shadow: 0 0 0 0 rgba(217,179,106,0), 0 0 8px 2px rgba(217,179,106,0.22); }
  50%  { box-shadow: 0 0 0 6px rgba(217,179,106,0.12), 0 0 22px 8px rgba(217,179,106,0.32); }
  100% { box-shadow: 0 0 0 0 rgba(217,179,106,0), 0 0 8px 2px rgba(217,179,106,0.22); }
}

/* 未點擊過的主要按鈕 — 金色脈動 */
.ending-button.primary:not(.glow-off) {
  animation: btn-glow-pulse-primary 2.4s ease-in-out infinite;
}
/* 未點擊過的普通互動按鈕 */
.ending-button:not(.primary):not(.glow-off),
.panel-action:not(.primary):not(.glow-off),
.action-glyph:not(.glow-off) {
  animation: btn-glow-pulse 2.8s ease-in-out infinite;
}
/* 已點擊：停止發光 */
.ending-button.glow-off,
.panel-action.glow-off,
.action-glyph.glow-off {
  animation: none !important;
}

/* ═══════════════════════════════════════════
   D2: 視角搖桿標籤位置上移，避免與 action-glyph 重疊
   ═══════════════════════════════════════════ */
.control-cluster.right .joystick-label {
  top: -44px;
}

/* ═══════════════════════════════════════════
   D2: 可拖移 UI 面板 — side-panel、speed-panel 浮動版
   ═══════════════════════════════════════════ */
.side-panel.ui-float {
  position: fixed !important;
  top: 60px;
  right: 12px;
  left: auto !important;
  bottom: auto !important;
  width: 300px;
  max-height: 88vh;
  /* C9: ui-float 模式下，top:60px 已經避開頂部 HUD，原本的 96px padding 變雙重偏移 */
  padding-top: 14px;
  padding-bottom: 20px;
  overflow-y: auto;
  border-radius: 12px;
  cursor: default;
  box-shadow: 0 8px 32px rgba(0,0,0,0.48), 0 0 0 1px rgba(255,255,255,0.06);
  z-index: 200;
  resize: none;
  transition: box-shadow 0.2s;
}
.side-panel.ui-float:hover {
  box-shadow: 0 8px 40px rgba(0,0,0,0.58), 0 0 0 1px rgba(140,200,255,0.14);
}
.side-panel.ui-float .panel-card:first-child {
  cursor: grab;
  user-select: none;
}
.side-panel.ui-float .panel-card:first-child:active {
  cursor: grabbing;
}
/* 拖移把手提示線 */
.ui-drag-handle-hint {
  display: block;
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.14);
  margin: 0 auto 6px;
}

/* ═══════════════════════════════════════════
   C9: side-panel 收合切換（手動隱藏）
   ═══════════════════════════════════════════ */
/* 收合按鈕：貼在第一張卡片右上角 */
.side-panel-collapse {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(217, 179, 106, 0.28);
  border-radius: 8px;
  background: rgba(10, 14, 22, 0.78);
  color: rgba(217, 179, 106, 0.82);
  font: 600 14px/1 "Noto Sans TC", system-ui, sans-serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease, transform 180ms ease;
  z-index: 3;
}
.side-panel-collapse:hover {
  background: rgba(217, 179, 106, 0.14);
  color: #ffe8b8;
  border-color: rgba(217, 179, 106, 0.6);
}
.side-panel-collapse:focus-visible {
  outline: 2px solid rgba(217, 179, 106, 0.6);
  outline-offset: 2px;
}
/* 收合後的面板狀態 — 用 transform 滑出避免 CLS、避免影響 canvas resize */
.side-panel.ui-float.is-collapsed {
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
  transition: transform 360ms cubic-bezier(0.4, 0.0, 0.2, 1), opacity 300ms ease;
}
.side-panel.ui-float {
  transition: transform 360ms cubic-bezier(0.4, 0.0, 0.2, 1), opacity 300ms ease, box-shadow 200ms ease;
}
/* 收合後的叫回把手 — 預設隱藏，面板收起時才顯示 */
#side-panel-reveal {
  position: fixed;
  top: 96px;
  right: 0;
  width: 28px;
  height: 72px;
  padding: 0;
  border: 1px solid rgba(217, 179, 106, 0.32);
  border-right: none;
  border-radius: 10px 0 0 10px;
  background: linear-gradient(270deg, rgba(22, 18, 28, 0.92), rgba(10, 14, 22, 0.78));
  color: rgba(217, 179, 106, 0.88);
  font: 500 10px/1.2 "Noto Sans TC", system-ui, sans-serif;
  letter-spacing: 0.12em;
  writing-mode: vertical-rl;
  cursor: pointer;
  z-index: 201;
  opacity: 0;
  transform: translateX(100%);
  pointer-events: none;
  transition: transform 360ms cubic-bezier(0.4, 0.0, 0.2, 1) 60ms, opacity 240ms ease 60ms, background 180ms ease, border-color 180ms ease;
  box-shadow: -4px 2px 16px rgba(0, 0, 0, 0.42);
}
#side-panel-reveal.is-visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}
#side-panel-reveal:hover {
  background: linear-gradient(270deg, rgba(32, 26, 40, 0.96), rgba(18, 22, 32, 0.88));
  border-color: rgba(217, 179, 106, 0.6);
  color: #ffe8b8;
}
#side-panel-reveal:focus-visible {
  outline: 2px solid rgba(217, 179, 106, 0.6);
  outline-offset: 2px;
}
/* 手機／窄螢幕不顯示收合按鈕（面板已經被 display:none） */
@media (max-width: 768px) {
  .side-panel-collapse,
  #side-panel-reveal {
    display: none !important;
  }
}
@media (prefers-reduced-motion: reduce) {
  .side-panel.ui-float,
  .side-panel.ui-float.is-collapsed,
  #side-panel-reveal {
    transition-duration: 80ms;
  }
}
/* 收合時 stage 應該撐滿 — 用 :has() 與 class 雙保險 */
.game-shell:has(> .side-panel.ui-float.is-collapsed),
body.side-panel-collapsed .game-shell {
  grid-template-columns: minmax(0, 1fr) 0 !important;
  gap: 0 !important;
  padding-right: 0 !important;
}

/* ═══════════════════════════════════════════
   D2: 一眼瞬間結局文字全螢幕疊加
   ═══════════════════════════════════════════ */
#one-gaze-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.8s ease;
}
#one-gaze-overlay.show {
  opacity: 1;
}
#one-gaze-overlay .one-gaze-text {
  font: 400 26px/1.6 'Cormorant Garamond', serif;
  letter-spacing: 0.12em;
  color: rgba(238,232,222,0.96);
  text-align: center;
  text-shadow: 0 0 40px rgba(180,200,255,0.5), 0 2px 8px rgba(0,0,0,0.8);
  padding: 24px 40px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 4px;
  background: rgba(4,6,12,0.72);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

/* ═══════════════════════════════════════════
   C9: Cinematic Gate（韓劇導演風·點擊進入）
   — 黑幕、呼吸光暈、字體柔邊、淡入淡出
   — 解除瀏覽器自動播放限制 + 延後載入 Three.js
   ═══════════════════════════════════════════ */
.cinematic-gate {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(
      ellipse 70% 60% at 50% 46%,
      rgba(22, 18, 28, 0.98),
      rgba(6, 8, 13, 0.99) 70%
    ),
    radial-gradient(circle at 22% 78%, rgba(217, 179, 106, 0.06), transparent 42%),
    radial-gradient(circle at 78% 22%, rgba(239, 111, 128, 0.045), transparent 40%),
    #06080d;
  opacity: 0;
  animation: cinematic-gate-in 1.4s 0.05s ease forwards;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  contain: layout paint size;
}
@keyframes cinematic-gate-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.cinematic-gate.gate-exiting {
  animation: cinematic-gate-out 1.1s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
  pointer-events: none;
}
@keyframes cinematic-gate-out {
  0% { opacity: 1; transform: scale(1); filter: blur(0); }
  100% { opacity: 0; transform: scale(1.025); filter: blur(3px); }
}
.cinematic-gate-grain {
  position: absolute;
  inset: 0;
  opacity: 0.35;
  mix-blend-mode: overlay;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    radial-gradient(circle at 70% 80%, rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    radial-gradient(circle at 40% 60%, rgba(255, 255, 255, 0.012) 1px, transparent 1px);
  background-size: 3px 3px, 4px 4px, 5px 5px;
}
.cinematic-gate-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse at center,
    transparent 42%,
    rgba(0, 0, 0, 0.55) 100%
  );
  pointer-events: none;
}
.cinematic-gate-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 0 24px;
  max-width: 640px;
  text-align: center;
  z-index: 2;
  opacity: 0;
  transform: translateY(14px);
  animation: cinematic-gate-inner-in 1.8s 0.55s cubic-bezier(0.22, 0.61, 0.36, 1)
    forwards;
}
@keyframes cinematic-gate-inner-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.cinematic-gate-kicker {
  font: 400 clamp(10px, 1vw, 12px) / 1.6 "DM Mono", "Noto Sans TC", monospace;
  color: rgba(217, 179, 106, 0.55);
  letter-spacing: 0.34em;
  text-transform: uppercase;
}
.cinematic-gate-quote {
  font: 300 clamp(15px, 1.85vw, 20px) / 1.95 "Noto Serif TC", serif;
  color: rgba(238, 232, 222, 0.7);
  max-width: 520px;
  letter-spacing: 0.04em;
}
.cinematic-gate-enter {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 22px 44px;
  margin-top: 12px;
  border: 1px solid rgba(217, 179, 106, 0.35);
  border-radius: 2px;
  background: linear-gradient(
    180deg,
    rgba(22, 18, 28, 0) 0%,
    rgba(217, 179, 106, 0.035) 100%
  );
  color: rgba(255, 244, 224, 0.95);
  font-family: "Cormorant Garamond", "Noto Serif TC", serif;
  font-weight: 300;
  font-size: clamp(17px, 2vw, 22px);
  line-height: 1.4;
  letter-spacing: 0.09em;
  cursor: pointer;
  overflow: hidden;
  transition:
    border-color 0.6s ease,
    color 0.6s ease,
    background 0.6s ease,
    transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
  animation: cinematic-gate-breath 4.5s 1.8s ease-in-out infinite;
}
@keyframes cinematic-gate-breath {
  0%, 100% {
    box-shadow:
      0 0 0 0 rgba(217, 179, 106, 0),
      inset 0 0 0 0 rgba(217, 179, 106, 0);
    border-color: rgba(217, 179, 106, 0.35);
  }
  50% {
    box-shadow:
      0 0 42px 2px rgba(217, 179, 106, 0.12),
      inset 0 0 24px 0 rgba(217, 179, 106, 0.04);
    border-color: rgba(217, 179, 106, 0.52);
  }
}
.cinematic-gate-enter:hover {
  border-color: rgba(217, 179, 106, 0.75) !important;
  color: #fff4e0;
  background: linear-gradient(
    180deg,
    rgba(22, 18, 28, 0) 0%,
    rgba(217, 179, 106, 0.08) 100%
  );
  transform: translateY(-1px);
}
.cinematic-gate-enter:focus-visible {
  outline: none;
  border-color: rgba(217, 179, 106, 0.9) !important;
  box-shadow: 0 0 0 3px rgba(217, 179, 106, 0.18) !important;
}
.cinematic-gate-enter:active {
  transform: translateY(0) scale(0.995);
}
.cinematic-gate-enter-halo {
  position: absolute;
  inset: -30%;
  background: radial-gradient(
    ellipse at center,
    rgba(217, 179, 106, 0.14),
    transparent 60%
  );
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}
.cinematic-gate-enter:hover .cinematic-gate-enter-halo {
  opacity: 1;
}
.cinematic-gate-enter-text {
  position: relative;
  z-index: 1;
  white-space: nowrap;
}
.cinematic-gate-enter-em {
  font-style: italic;
  letter-spacing: 0.03em;
  color: #d9b36a;
  margin-left: 0.15em;
}
.cinematic-gate-hint {
  font: 300 clamp(10px, 1vw, 12px) / 1.8 "Noto Sans TC", sans-serif;
  color: rgba(238, 232, 222, 0.34);
  letter-spacing: 0.08em;
  margin-top: 4px;
}
@media (max-width: 640px) {
  .cinematic-gate-inner {
    gap: 22px;
    padding: 0 20px;
  }
  .cinematic-gate-quote {
    font-size: 15px;
    line-height: 1.9;
  }
  .cinematic-gate-enter {
    padding: 18px 26px;
    font-size: 16px;
    letter-spacing: 0.06em;
  }
  .cinematic-gate-enter-text {
    white-space: normal;
  }
  .cinematic-gate-hint {
    font-size: 10.5px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .cinematic-gate { animation-duration: 0.3s; }
  .cinematic-gate-inner { animation-duration: 0.3s; animation-delay: 0.1s; }
  .cinematic-gate-enter { animation: none; }
  .cinematic-gate.gate-exiting { animation-duration: 0.3s; }
}
