:root {
  color-scheme: light;
  --paper: #e8d8bd;
  --paper-pale: #f2e7d3;
  --ink: #292820;
  --ink-muted: #70695e;
  --night: #172a43;
  --night-soft: #30465e;
  --gold: #a97d45;
  --line: rgba(45, 42, 35, 0.5);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --hand: "Kaiti SC", "STKaiti", "KaiTi", serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: #0d1218;
  overscroll-behavior: none;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 8%, #34465a 0, #18232e 36rem, #0d1218 85%),
    #0d1218;
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

button {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid #e9c98c;
  outline-offset: 3px;
}

.game {
  position: relative;
  width: min(100%, 430px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.48);
  isolation: isolate;
}

.game::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0.13;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.45'/%3E%3C/svg%3E");
}

.prologue {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: end stretch;
  color: #f3e7d1;
  background: #101b27;
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.prologue[hidden] {
  display: none;
}

.prologue.is-leaving {
  opacity: 0;
  transform: scale(1.025);
}

.prologue-backdrop {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(8, 14, 21, 0.12) 0 30%, rgba(8, 14, 21, 0.94) 76%),
    url("./assets/station-choice.jpg") center top / auto 67% no-repeat,
    #101b27;
  filter: saturate(0.74) contrast(1.05);
}

.prologue-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.13;
  background-image: repeating-linear-gradient(
    101deg,
    transparent 0 18px,
    rgba(226, 237, 240, 0.72) 19px,
    transparent 20px 38px
  );
  animation: rain 2.3s linear infinite;
}

.prologue-card {
  position: relative;
  z-index: 1;
  padding: 0 28px max(28px, env(safe-area-inset-bottom));
}

.prologue-series {
  margin: 0;
  letter-spacing: 0.14em;
}

.prologue-series {
  color: #d4b47f;
  font-size: 10px;
}

.prologue h1 {
  margin: 14px 0 16px;
  font-size: clamp(38px, 11vw, 48px);
  font-weight: 400;
  letter-spacing: 0.08em;
}

.prologue-copy {
  font-size: 15px;
  line-height: 1.75;
}

.prologue-copy p {
  margin: 0 0 8px;
}

.prologue-copy blockquote {
  margin: 10px 0 0;
  border-left: 1px solid rgba(212, 180, 127, 0.62);
  padding-left: 12px;
  color: #d9bc8b;
  font-family: var(--hand);
  line-height: 1.7;
}

.prologue-start {
  width: 100%;
  margin-top: 20px;
  min-height: 56px;
  border: 1px solid rgba(232, 211, 175, 0.72);
  color: #172a43;
  background: #ead9bb;
  font-size: 16px;
  letter-spacing: 0.12em;
  cursor: pointer;
}

.scene-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: var(--paper);
}

.scene-image {
  position: absolute;
  inset: 0 0 auto;
  display: block;
  width: 100%;
  height: auto;
  filter: saturate(0.94) contrast(1.01);
  transform: scale(1.004);
  transform-origin: 50% 24%;
  transition: opacity 0.38s ease, filter 0.7s ease, transform 8s ease;
}

.game.is-settled .scene-image {
  transform: scale(1.025);
}

.scene-vignette {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(9, 16, 23, 0.12), transparent 24%),
    radial-gradient(ellipse at center 30%, transparent 48%, rgba(20, 15, 11, 0.16) 100%);
  pointer-events: none;
}

.scene-vignette::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 50%;
  background: linear-gradient(to bottom, transparent, rgba(232, 216, 189, 0.2) 28%, var(--paper) 90%);
}

.rain-layer {
  position: absolute;
  inset: 0;
  opacity: 0.13;
  pointer-events: none;
  mask-image: linear-gradient(to bottom, black 0 58%, transparent 76%);
  background-image: repeating-linear-gradient(
    101deg,
    transparent 0 16px,
    rgba(230, 239, 242, 0.7) 17px,
    transparent 18px 34px
  );
  animation: rain 2.3s linear infinite;
}

.game[data-scene="crossroads"] .rain-layer,
.game[data-scene="result"] .rain-layer {
  opacity: 0.04;
}

.light-sweep {
  position: absolute;
  top: 0;
  left: -55%;
  width: 42%;
  height: 58%;
  opacity: 0;
  transform: skewX(-18deg);
  background: linear-gradient(90deg, transparent, rgba(240, 211, 158, 0.13), transparent);
  pointer-events: none;
}

.game[data-scene="phone"] .light-sweep,
.game[data-scene="call"] .light-sweep {
  opacity: 1;
  animation: passing-light 6s ease-in-out infinite;
}

@keyframes rain {
  from { background-position: 0 -54px; }
  to { background-position: 0 54px; }
}

@keyframes passing-light {
  0%, 42% { left: -55%; }
  70%, 100% { left: 120%; }
}

.hud {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 14px;
  left: 14px;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  color: rgba(246, 237, 221, 0.92);
}

.chapter-stamp {
  display: flex;
  height: 35px;
  align-items: center;
  border: 1px solid rgba(241, 225, 198, 0.3);
  background: rgba(13, 23, 34, 0.48);
  backdrop-filter: blur(7px);
}

.chapter-stamp span {
  padding: 0 9px;
  font-size: 9px;
  letter-spacing: 0.15em;
}

.chapter-stamp b {
  display: grid;
  width: 32px;
  align-self: stretch;
  place-items: center;
  border-left: 1px solid rgba(241, 225, 198, 0.3);
  font-size: 12px;
  font-weight: 400;
}

.sound-toggle {
  display: flex;
  min-height: 35px;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(241, 225, 198, 0.3);
  border-radius: 999px;
  padding: 0 11px;
  color: inherit;
  background: rgba(13, 23, 34, 0.48);
  backdrop-filter: blur(7px);
  cursor: pointer;
}

.sound-label {
  font-size: 9px;
  letter-spacing: 0.12em;
}

.sound-bars {
  display: flex;
  width: 15px;
  height: 14px;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.sound-bars i {
  width: 2px;
  height: 4px;
  background: currentColor;
  animation: sound-bar 1.1s ease-in-out infinite;
}

.sound-bars i:nth-child(2) {
  height: 10px;
  animation-delay: -0.45s;
}

.sound-bars i:nth-child(3) {
  height: 7px;
  animation-delay: -0.2s;
}

.sound-toggle[aria-pressed="false"] {
  opacity: 0.55;
}

.sound-toggle[aria-pressed="false"] .sound-bars i {
  height: 2px;
  animation: none;
}

@keyframes sound-bar {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

.timeline {
  position: absolute;
  top: max(58px, calc(env(safe-area-inset-top) + 48px));
  right: 14px;
  left: 14px;
  z-index: 20;
  height: 2px;
  overflow: hidden;
  background: rgba(241, 229, 207, 0.22);
}

.timeline-fill {
  display: block;
  width: 12%;
  height: 100%;
  background: rgba(244, 232, 209, 0.88);
  transform-origin: left;
  transition: width 0.65s ease;
}

.scene-hotspots {
  position: absolute;
  inset: 76px 0 auto;
  z-index: 12;
  height: min(46vh, 390px);
  pointer-events: none;
}

.hotspot {
  position: absolute;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 1px solid rgba(245, 225, 188, 0.84);
  border-radius: 50%;
  padding: 0;
  color: #f5e1bc;
  background: rgba(20, 34, 48, 0.32);
  box-shadow: 0 0 0 7px rgba(235, 204, 150, 0.08);
  backdrop-filter: blur(2px);
  pointer-events: auto;
  cursor: pointer;
  animation: hotspot-breathe 2.1s ease-in-out infinite;
}

.hotspot::before,
.hotspot::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.hotspot::before {
  width: 12px;
  height: 1px;
}

.hotspot::after {
  width: 1px;
  height: 12px;
}

.hotspot.is-seen {
  color: #d6c6aa;
  background: rgba(20, 34, 48, 0.58);
  animation: none;
}

.hotspot.is-locked {
  opacity: 0.38;
}

.hotspot-label {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  width: max-content;
  max-width: 100px;
  padding: 4px 7px;
  color: #f3e5ce;
  background: rgba(13, 23, 34, 0.76);
  font-size: 9px;
  letter-spacing: 0.08em;
  transform: translateX(-50%);
}

@keyframes hotspot-breathe {
  0%, 100% { box-shadow: 0 0 0 6px rgba(235, 204, 150, 0.06); }
  50% { box-shadow: 0 0 0 13px rgba(235, 204, 150, 0.16); }
}

.story-panel {
  position: absolute;
  top: clamp(402px, 49.5dvh, 466px);
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 8px 24px max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, rgba(232, 216, 189, 0.9) 18px, var(--paper) 72px);
}

.scene-meta {
  display: flex;
  min-height: 24px;
  align-items: center;
  justify-content: space-between;
  color: var(--night);
}

.scene-index,
.scene-time {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.13em;
}

.scene-time {
  display: none;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.scene-time.is-visible {
  display: block;
}

.scene-title {
  margin: 8px 0 7px;
  font-size: clamp(21px, 6vw, 27px);
  font-weight: 400;
  line-height: 1.24;
  letter-spacing: 0.035em;
}

.scene-copy {
  color: #49453d;
  font-size: clamp(13px, 3.7vw, 15px);
  line-height: 1.65;
  letter-spacing: 0.025em;
}

.scene-copy p {
  margin: 0;
}

.scene-copy .dialogue {
  margin-top: 4px;
  color: var(--night);
  font-family: var(--hand);
  font-size: 1.08em;
}

.scene-copy .decision-context {
  display: block;
  margin-top: 5px;
  color: var(--night);
  font-family: var(--hand);
}

.interaction {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.action {
  position: relative;
  min-height: 52px;
  border: 1px solid rgba(45, 42, 35, 0.72);
  padding: 8px 14px;
  color: var(--ink);
  background: rgba(238, 225, 201, 0.58);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.action b {
  display: block;
  font-weight: 400;
}

.action:active {
  transform: translateY(2px);
}

.action.primary {
  border-color: var(--night);
  color: #f4e8d2;
  background: var(--night);
}

.action small {
  display: block;
  margin-top: 4px;
  opacity: 0.66;
  font-size: 8px;
  letter-spacing: 0.12em;
}

.action[disabled] {
  cursor: default;
  opacity: 0.4;
}

.scene-hint {
  display: none;
}

.swipe-control {
  position: relative;
  height: 92px;
  overflow: hidden;
  border: 1px solid rgba(37, 42, 42, 0.48);
  background:
    linear-gradient(to bottom, rgba(36, 69, 69, 0.12), transparent 42%, rgba(75, 53, 47, 0.1)),
    rgba(240, 228, 205, 0.45);
  touch-action: none;
  user-select: none;
}

.swipe-label {
  position: absolute;
  left: 14px;
  color: var(--ink-muted);
  font-size: 9px;
  letter-spacing: 0.12em;
}

.swipe-label.up { top: 10px; }
.swipe-label.down { bottom: 10px; }

.phone-drag {
  position: absolute;
  top: 50%;
  right: 14px;
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 1px solid rgba(231, 211, 175, 0.66);
  border-radius: 13px;
  color: #f3e7d0;
  background: #243242;
  box-shadow: 0 8px 18px rgba(28, 29, 27, 0.25);
  transform: translateY(-50%);
  transition: transform 0.18s ease;
  cursor: grab;
}

.phone-drag::before {
  content: "";
  width: 24px;
  height: 3px;
  border-top: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  opacity: 0.7;
}

.phone-drag.is-dragging {
  transition: none;
  cursor: grabbing;
}

.swipe-fallback {
  position: absolute;
  inset: 0 78px 0 0;
  display: grid;
  grid-template-rows: 1fr 1fr;
}

.swipe-fallback button {
  border: 0;
  color: transparent;
  background: transparent;
  cursor: pointer;
}

.ticket-choice {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 10px 15px;
  text-align: left;
  background:
    radial-gradient(circle at 0 50%, var(--paper) 0 5px, transparent 6px),
    radial-gradient(circle at 100% 50%, var(--paper) 0 5px, transparent 6px),
    rgba(242, 230, 207, 0.74);
}

.ticket-choice b {
  display: block;
  color: var(--night);
  font-family: var(--hand);
  font-size: 17px;
  font-weight: 400;
}

.ticket-choice small {
  color: var(--ink-muted);
}

.inventory {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.item {
  min-height: 62px;
  border: 1px solid rgba(47, 43, 36, 0.42);
  padding: 7px 3px;
  background: rgba(239, 225, 199, 0.58);
  font-size: 9px;
  cursor: grab;
  touch-action: none;
  transition: opacity 0.2s ease, transform 0.12s ease;
}

.item span {
  display: block;
  margin-bottom: 4px;
  color: var(--night);
  font-size: 18px;
}

.test-inventory {
  grid-template-columns: repeat(2, 1fr);
}

.test-inventory .item {
  min-height: 68px;
  cursor: pointer;
}

.item.is-collected {
  opacity: 0.38;
  text-decoration: line-through;
}

.pocket {
  display: grid;
  min-height: 54px;
  place-items: center;
  border: 1px dashed rgba(31, 46, 61, 0.62);
  color: var(--night);
  background: rgba(40, 61, 82, 0.06);
  font-size: 11px;
  letter-spacing: 0.08em;
  transition: background 0.2s ease, transform 0.2s ease;
}

.pocket.is-over {
  background: rgba(40, 61, 82, 0.18);
  transform: scale(1.015);
}

.explore-status {
  display: flex;
  gap: 7px;
}

.clue-tag {
  flex: 1;
  border-bottom: 1px solid rgba(48, 43, 35, 0.34);
  padding-bottom: 5px;
  color: var(--ink-muted);
  font-size: 9px;
  text-align: center;
}

.clue-tag.is-found {
  color: var(--night);
  border-color: var(--night);
}

.dial-control {
  position: relative;
  display: grid;
  height: 106px;
  place-items: center;
}

.dial-ring {
  position: absolute;
  width: 92px;
  height: 92px;
  border: 1px solid rgba(37, 53, 50, 0.44);
  border-radius: 50%;
  background: conic-gradient(var(--night) var(--dial-progress, 0deg), rgba(44, 54, 48, 0.1) 0);
  mask: radial-gradient(circle, transparent 54%, black 56%);
  transform: rotate(-90deg);
}

.dial-button {
  z-index: 1;
  display: grid;
  width: 67px;
  height: 67px;
  place-items: center;
  border: 1px solid rgba(30, 51, 48, 0.72);
  border-radius: 50%;
  color: #eee2ca;
  background: #263e3b;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.dial-button.is-holding {
  transform: scale(0.97);
}

.route-drag {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  touch-action: none;
}

.route-target {
  display: grid;
  min-height: 62px;
  place-items: center;
  border: 1px dashed rgba(48, 43, 35, 0.55);
  background: rgba(237, 223, 198, 0.54);
  font-size: 12px;
  cursor: pointer;
}

.route-target small {
  display: block;
  margin-top: 4px;
  color: var(--ink-muted);
  font-size: 8px;
}

.route-target.is-over {
  border-style: solid;
  color: #f4e8d2;
  background: var(--night);
}

.drag-ticket {
  grid-column: 1 / -1;
  justify-self: center;
  width: 126px;
  border: 1px solid var(--night);
  padding: 7px 12px;
  color: var(--night);
  background: var(--paper-pale);
  font-size: 10px;
  text-align: center;
  letter-spacing: 0.12em;
  cursor: grab;
  touch-action: none;
  z-index: 2;
}

.route-memory {
  position: absolute;
  top: 72px;
  right: 12px;
  bottom: auto;
  z-index: 22;
  display: flex;
  gap: 5px;
  pointer-events: none;
}

.memory-mark {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  border: 1px solid rgba(35, 41, 41, 0.34);
  border-radius: 50%;
  color: var(--night);
  background: rgba(236, 223, 199, 0.72);
  font-size: 11px;
}

.toast {
  position: absolute;
  top: 88px;
  left: 50%;
  z-index: 40;
  width: max-content;
  max-width: calc(100% - 48px);
  border: 1px solid rgba(237, 219, 188, 0.3);
  padding: 8px 13px;
  color: #f3e5ce;
  background: rgba(15, 27, 38, 0.82);
  font-size: 10px;
  letter-spacing: 0.07em;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.transition-curtain {
  position: absolute;
  inset: 0;
  z-index: 45;
  background: var(--night);
  opacity: 0;
  transform: translateX(-102%);
  pointer-events: none;
}

.game.is-transitioning .transition-curtain {
  animation: curtain 0.72s cubic-bezier(0.72, 0, 0.25, 1);
}

@keyframes curtain {
  0% { opacity: 0; transform: translateX(-102%); }
  42% { opacity: 1; transform: translateX(0); }
  58% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(102%); }
}

.result-panel {
  padding-top: 0;
}

.game[data-scene="result"] .story-panel {
  top: 318px;
  overflow-y: auto;
  background: linear-gradient(to bottom, transparent, rgba(232, 216, 189, 0.92) 18px, var(--paper) 62px);
}

.game[data-scene="result"] .scene-copy {
  font-size: 10px;
  line-height: 1.5;
}

.game[data-scene="result"] .interaction {
  padding-top: 8px;
}

.result-panel .scene-title {
  color: var(--night);
  font-size: clamp(28px, 8vw, 35px);
}

.result-panel .scene-title.is-long {
  max-width: 92%;
  font-size: clamp(23px, 6.5vw, 28px);
  text-wrap: balance;
}

.game[data-scene="result"] .route-memory {
  display: none;
}

.result-kicker {
  color: var(--gold);
  font-family: var(--hand);
  font-size: 14px;
}

.sentence-stack {
  display: grid;
  gap: 7px;
}

.sentence-stack .action {
  min-height: 45px;
  text-align: left;
}

.multi-choice {
  grid-template-columns: repeat(2, 1fr);
}

.multi-choice .action:nth-child(n + 3) {
  grid-column: auto;
}

.destination-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.destination-grid .action {
  min-height: 60px;
  text-align: left;
}

.choice-summary {
  border: 1px dashed rgba(31, 46, 61, 0.45);
  padding: 12px;
  color: var(--night);
  font-size: 10px;
  text-align: center;
  letter-spacing: 0.1em;
}

.trait-row {
  display: flex;
  gap: 5px;
  margin: 7px 0;
}

.trait-row span {
  border: 1px solid rgba(23, 42, 67, 0.36);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--night);
  font-size: 8px;
  letter-spacing: 0.08em;
}

.result-reading,
.result-shadow,
.result-advice {
  font-size: 10px;
  line-height: 1.55;
}

.result-shadow,
.result-advice {
  margin-top: 5px !important;
}

.result-shadow b,
.result-advice b {
  color: var(--night);
  font-weight: 400;
}

.result-quote {
  margin-top: 7px !important;
  color: var(--gold);
  font-family: var(--hand);
  font-size: 12px;
  line-height: 1.55;
}

.result-meaning {
  margin-top: 7px !important;
  color: #49453d;
  font-size: 11px;
  line-height: 1.6;
}

.result-meaning b,
.result-route b {
  color: var(--night);
  font-weight: 400;
}

.result-route {
  border-left: 1px solid var(--gold);
  padding-left: 10px;
  color: var(--ink-muted);
  font-size: 10px;
  line-height: 1.7;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.result-number {
  position: absolute;
  right: 20px;
  top: 60px;
  color: rgba(23, 42, 67, 0.1);
  font-size: 58px;
  font-style: italic;
  line-height: 1;
}

@media (max-height: 720px) {
  .story-panel {
    top: 350px;
  }

  .scene-title {
    margin-block: 4px;
    font-size: 20px;
  }

  .scene-copy {
    font-size: 12px;
    line-height: 1.45;
  }

  .interaction {
    padding-top: 7px;
  }

  .action {
    min-height: 46px;
  }
}

@media (min-width: 431px) {
  .game {
    min-height: min(900px, 100dvh);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
