@charset "utf-8";

:root {
  color-scheme: dark;
  --ink: #f0eadf;
  --muted: #bbb6a8;
  --paper: #1b2224;
  --panel: rgba(25, 31, 32, .96);
  --panel-soft: rgba(25, 31, 32, .82);
  --accent: #e2b66f;
  --accent-dark: #78572d;
  --line: rgba(239, 231, 213, .2);
  --danger: #e0a09a;
  --text-size: 1.16rem;
  --measure: 74ch;
  font-family: system-ui, "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: #101516; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: #101516;
  color: var(--ink);
  line-height: 1.65;
}
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #f0c982;
  outline-offset: 3px;
}
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }
.skip-link {
  position: fixed; z-index: 20; left: 1rem; top: -5rem;
  padding: .65rem .9rem; background: var(--ink); color: #101516; border-radius: .4rem;
}
.skip-link:focus { top: 1rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.app-shell { min-height: 100vh; }

/* Title screen */
.title-screen {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(20rem, .95fr);
  align-items: center;
  gap: clamp(2rem, 6vw, 6rem);
  width: min(100% - 3rem, 76rem);
  min-height: 100vh;
  margin-inline: auto;
  padding-block: 3rem;
}
.title-art {
  position: relative;
  min-height: min(68vh, 38rem);
  overflow: hidden;
  border: 1px solid rgba(226, 182, 111, .32);
  border-radius: 1.25rem;
  background:
    radial-gradient(ellipse at 70% 25%, rgba(231, 192, 127, .25), transparent 25%),
    linear-gradient(160deg, #37494a 0%, #1e2b2d 50%, #121819 100%);
  box-shadow: 0 1.6rem 5rem rgba(0, 0, 0, .34);
}
.title-art::before, .title-art::after {
  position: absolute; content: ""; left: 0; right: 0; bottom: 0;
}
.title-art::before {
  height: 48%;
  background: linear-gradient(165deg, transparent 0 30%, rgba(10, 15, 16, .3) 30% 31%, #121819 31% 100%);
  clip-path: polygon(0 43%, 20% 16%, 36% 46%, 62% 8%, 82% 36%, 100% 17%, 100% 100%, 0 100%);
}
.title-art::after {
  height: 36%;
  background: linear-gradient(90deg, transparent 0 35%, rgba(226, 182, 111, .55) 35% 36%, transparent 36% 62%, rgba(226, 182, 111, .3) 62% 63%, transparent 63%),
              linear-gradient(0deg, #0c1112, rgba(12, 17, 18, .82));
  clip-path: polygon(0 70%, 100% 18%, 100% 100%, 0 100%);
}
.title-road {
  position: absolute; left: 46%; bottom: -7%; width: 55%; height: 58%;
  border-left: 1px solid rgba(226, 182, 111, .42);
  transform: rotate(-19deg); transform-origin: bottom left;
}
.title-light {
  position: absolute; right: 16%; top: 23%; width: 5rem; height: 5rem;
  border-radius: 50%; background: rgba(226, 182, 111, .2);
  box-shadow: 0 0 4rem 2rem rgba(226, 182, 111, .14);
}
.title-battery {
  position: absolute; right: 1.5rem; bottom: 1.5rem;
  display: grid; place-items: center; width: 2.6rem; height: 4.2rem;
  border: 2px solid rgba(240, 234, 223, .65); border-radius: .4rem;
  color: var(--accent); font-size: 1.3rem; font-weight: 700;
}
.title-battery::before { content: ""; position: absolute; top: -.45rem; width: .8rem; height: .35rem; background: rgba(240, 234, 223, .65); border-radius: .2rem .2rem 0 0; }
.title-copy { max-width: 36rem; }
.eyebrow { margin: 0 0 .75rem; color: var(--accent); font-size: .82rem; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
.title-copy h1 { margin-bottom: .8rem; font-size: clamp(2.7rem, 7vw, 5.1rem); line-height: 1.08; letter-spacing: .06em; }
.title-description { color: var(--muted); font-size: 1.08rem; }
.startup-message { min-height: 1.5em; color: var(--muted); font-size: .9rem; }
.title-actions { display: grid; gap: .7rem; max-width: 24rem; margin-top: 1.8rem; }
.button, .icon-button, .toolbar-button {
  border: 1px solid var(--line); border-radius: .5rem; background: rgba(255, 255, 255, .045);
  cursor: pointer; transition: background-color .15s ease, border-color .15s ease, transform .15s ease;
}
.button { min-height: 2.8rem; padding: .58rem 1rem; }
.button:hover:not(:disabled), .icon-button:hover:not(:disabled), .toolbar-button:hover:not(:disabled) { background: rgba(255, 255, 255, .11); border-color: rgba(226, 182, 111, .65); }
.button:active:not(:disabled), .icon-button:active:not(:disabled), .toolbar-button:active:not(:disabled) { transform: translateY(1px); }
.button-primary { border-color: var(--accent); background: var(--accent); color: #1b1b16; font-weight: 700; }
.button-primary:hover:not(:disabled) { background: #f0c982; }
.keyboard-hint { margin-top: 1.8rem; color: #9e9d93; font-size: .82rem; }

/* In-game header and scene */
.play-screen { min-height: 100vh; padding-bottom: 1.5rem; }
.game-topbar {
  position: sticky; z-index: 5; top: 0;
  display: grid; grid-template-columns: auto minmax(8rem, 1fr) auto; align-items: center; gap: 1rem;
  padding: .7rem clamp(.8rem, 3vw, 2.5rem);
  background: rgba(16, 21, 22, .94); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.icon-button { min-height: 2.4rem; padding: .42rem .8rem; }
.progress-info { display: grid; grid-template-columns: auto auto; align-items: center; gap: .1rem .9rem; color: var(--muted); font-size: .84rem; }
#chapter-label { color: var(--ink); font-weight: 700; }
#scene-label { text-align: right; }
progress { grid-column: 1 / -1; width: 100%; height: .3rem; border: 0; border-radius: 1rem; overflow: hidden; accent-color: var(--accent); }
progress::-webkit-progress-bar { background: #343b3b; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
.scene-stage {
  position: relative; display: grid; place-items: center; min-height: clamp(15rem, 38vh, 26rem);
  overflow: hidden; isolation: isolate; background: #293233;
}
.scene-stage::before, .scene-stage::after { position: absolute; z-index: -1; content: ""; inset: 0; }
.scene-stage::before {
  background:
    radial-gradient(ellipse at 76% 29%, rgba(240, 198, 132, .35), transparent 17%),
    linear-gradient(180deg, #536465 0%, #303d3e 54%, #1b2425 100%);
  transition: background .25s ease;
}
.scene-stage::after {
  background: linear-gradient(180deg, transparent 43%, rgba(10, 13, 14, .8) 100%);
}
.scene-stage[data-background="room"]::before { background: radial-gradient(ellipse at 65% 30%, rgba(231, 185, 113, .22), transparent 18%), linear-gradient(135deg, #594e42, #332f2a 55%, #1d2323); }
.scene-stage[data-background="station"]::before { background: radial-gradient(ellipse at 75% 25%, rgba(244, 193, 112, .33), transparent 16%), linear-gradient(155deg, #455759, #253335 62%, #172122); }
.scene-stage[data-background="shop"]::before { background: radial-gradient(ellipse at 24% 32%, rgba(223, 181, 111, .25), transparent 17%), linear-gradient(145deg, #6b5b43, #3f3930 58%, #1f2524); }
.scene-stage[data-background="street"]::before { background: radial-gradient(ellipse at 78% 22%, rgba(233, 198, 132, .35), transparent 18%), linear-gradient(170deg, #56656a, #2b373a 63%, #151b1d); }
.scene-stage[data-background="rain"]::before { background: repeating-linear-gradient(105deg, transparent 0 24px, rgba(200, 218, 222, .06) 25px 27px), linear-gradient(160deg, #52616a, #303b43 55%, #172126); }
.scene-stage[data-background="office"]::before { background: radial-gradient(ellipse at 70% 26%, rgba(242, 209, 153, .25), transparent 14%), linear-gradient(145deg, #68706d, #414947 52%, #242c2b); }
.scene-stage[data-background="home"]::before { background: radial-gradient(ellipse at 36% 28%, rgba(240, 195, 130, .22), transparent 16%), linear-gradient(145deg, #5c5548, #36332c 55%, #202523); }
.scene-stage[data-background="night"]::before { background: radial-gradient(ellipse at 78% 24%, rgba(229, 190, 127, .28), transparent 13%), linear-gradient(160deg, #35454c, #1d292f 58%, #101619); }
.background-image { position: absolute; z-index: -1; width: 100%; height: 100%; object-fit: cover; opacity: .72; }
.stage-wash { position: absolute; z-index: -1; inset: 0; background: linear-gradient(90deg, rgba(10, 13, 14, .12), transparent 45%, rgba(10, 13, 14, .25)); }
.scene-location { position: absolute; right: clamp(1rem, 4vw, 3rem); top: 1.4rem; color: rgba(245, 238, 224, .78); font-size: .85rem; letter-spacing: .12em; text-shadow: 0 1px 8px #101516; }
.portrait-frame { position: absolute; left: clamp(1rem, 5vw, 4rem); bottom: 0; display: grid; place-items: center; width: clamp(7rem, 17vw, 13rem); height: clamp(10rem, 28vw, 19rem); overflow: hidden; border: 1px solid rgba(240, 234, 223, .22); border-bottom: 0; border-radius: .8rem .8rem 0 0; background: linear-gradient(180deg, rgba(240, 234, 223, .12), rgba(16, 21, 22, .72)); box-shadow: 0 0 3rem rgba(0, 0, 0, .3); }
.portrait-image { width: 100%; height: 100%; object-fit: contain; object-position: bottom; }
.portrait-fallback { display: grid; place-items: center; width: 4.5rem; height: 4.5rem; border: 1px solid rgba(226, 182, 111, .7); border-radius: 50%; color: var(--accent); font-size: 1.35rem; }

/* Reading panel */
.narrative-panel { width: min(100% - 1.5rem, 76rem); margin: -1.1rem auto 0; position: relative; z-index: 2; padding: clamp(1.2rem, 3vw, 2rem); border: 1px solid var(--line); border-radius: .9rem; background: var(--panel); box-shadow: 0 1.2rem 4rem rgba(0, 0, 0, .32); }
.scene-heading { max-width: var(--measure); margin-inline: auto; }
.scene-heading .eyebrow { margin-bottom: .3rem; font-size: .75rem; }
.scene-heading h1 { margin-bottom: 1.25rem; font-size: clamp(1.35rem, 3vw, 1.8rem); line-height: 1.35; }
.text-content { max-width: var(--measure); min-height: 5.5rem; margin-inline: auto; font-size: var(--text-size); line-height: 1.95; }
.text-content p { margin: 0 0 1.05rem; white-space: pre-wrap; }
.text-content p:last-child { margin-bottom: .4rem; }
.speaker-label { color: var(--accent); font-size: .9rem; }
.advance-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: var(--measure); margin: 1.1rem auto 0; padding-top: .9rem; border-top: 1px solid var(--line); }
.choice-panel { max-width: var(--measure); margin: 1.3rem auto .2rem; padding: 1rem; border: 1px solid rgba(226, 182, 111, .35); border-radius: .65rem; background: rgba(226, 182, 111, .055); }
.choice-prompt { margin-bottom: .8rem; color: var(--accent); font-weight: 700; }
.choice-options { display: grid; gap: .6rem; }
.choice-option { width: 100%; text-align: left; border-color: rgba(226, 182, 111, .42); }
.game-toolbar { display: flex; flex-wrap: wrap; justify-content: center; gap: .55rem; width: min(100% - 1.5rem, 76rem); margin: .85rem auto 1.5rem; }
.toolbar-button { min-height: 2.35rem; padding: .42rem .72rem; color: var(--muted); font-size: .86rem; }
.toolbar-button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-dark); }

/* Modal and controls */
.modal { width: min(92vw, 44rem); max-height: min(86vh, 52rem); padding: 0; overflow: hidden; border: 1px solid rgba(226, 182, 111, .4); border-radius: .85rem; background: #202829; color: var(--ink); box-shadow: 0 2rem 6rem rgba(0, 0, 0, .65); }
.modal::backdrop { background: rgba(6, 9, 10, .78); backdrop-filter: blur(4px); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-content { max-height: calc(min(86vh, 52rem) - 4rem); overflow: auto; padding: 1.2rem; }
.modal-content p { color: var(--muted); }
.modal-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.modal-list { display: grid; gap: .55rem; }
.modal-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .65rem; padding: .8rem; border: 1px solid var(--line); border-radius: .55rem; }
.modal-row p { margin: .15rem 0 0; font-size: .84rem; }
.modal-row .button { min-height: 2.3rem; padding: .35rem .65rem; }
.setting-row { display: grid; grid-template-columns: minmax(8rem, 1fr) minmax(9rem, 1.2fr) auto; align-items: center; gap: .8rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
.setting-row label { color: var(--ink); }
.setting-row input[type="range"] { width: 100%; accent-color: var(--accent); }
.setting-value { min-width: 3.5rem; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.history-list { display: grid; gap: .7rem; }
.history-entry { padding: .7rem .8rem; border-left: 2px solid var(--accent-dark); background: rgba(255, 255, 255, .035); }
.history-entry strong { display: block; margin-bottom: .25rem; color: var(--accent); font-size: .84rem; }
.history-entry p { margin: 0; color: var(--ink); white-space: pre-wrap; }
.chapter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
.status-message { min-height: 1.5em; color: var(--accent); font-size: .9rem; }
.status-error { color: var(--danger); }

@media (max-width: 58rem) {
  .title-screen { grid-template-columns: 1fr; width: min(100% - 2rem, 42rem); gap: 1.5rem; padding-block: 1.5rem; }
  .title-art { min-height: 30vh; max-height: 20rem; }
  .title-copy h1 { font-size: clamp(2.7rem, 13vw, 4.2rem); }
}
@media (max-width: 40rem) {
  .game-topbar { gap: .5rem; padding-inline: .65rem; }
  .progress-info { gap: .1rem .4rem; font-size: .76rem; }
  .scene-stage { min-height: 17rem; }
  .narrative-panel { width: calc(100% - 1rem); padding: 1rem; }
  .setting-row { grid-template-columns: 1fr auto; }
  .setting-row input[type="range"] { grid-column: 1 / -1; grid-row: 2; }
  .chapter-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
