:root {
  color-scheme: dark;
  --night: #121b3d;
  --indigo: #263561;
  --violet: #514978;
  --pink: #ec91b0;
  --pink-light: #ffcadc;
  --gold: #efc669;
  --ivory: #fff8ee;
  --cyan: #8fd5eb;
  --text-shadow: 0 2px 10px rgba(5, 9, 26, .65);
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  color: var(--ivory);
  font-family: "Microsoft YaHei UI", "Noto Sans CJK SC", "Yu Gothic UI", sans-serif;
  background:
    radial-gradient(circle at 50% 10%, rgba(120, 93, 148, .28), transparent 42%),
    linear-gradient(145deg, #080d21, #161735 58%, #2d203e);
}

button, input { font: inherit; }
button { color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

#app {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px 18px 38px;
}

#game-shell {
  width: min(calc(100vw - 36px), calc((100vh - 76px) * 16 / 9));
  aspect-ratio: 16 / 9;
  filter: drop-shadow(0 30px 45px rgba(0, 0, 0, .48));
}

#game {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  outline: none;
  border: 1px solid rgba(255, 226, 235, .4);
  border-radius: clamp(8px, 1vw, 18px);
  background: #11182f;
  user-select: none;
}

.outside-hint {
  position: fixed;
  bottom: 8px;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: rgba(255, 238, 241, .62);
  font-size: 12px;
  letter-spacing: .08em;
  white-space: nowrap;
}

#background-layer,
#background-layer img,
.sun-wash,
.vignette,
#ambient-layer,
#character-stage,
.screen-layer,
#ripple-layer {
  position: absolute;
  inset: 0;
}

#background-layer { z-index: -5; background: #11182f; }

#background-layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.025);
  transition: opacity 1.1s ease, transform 8s ease;
}

#background-layer img.visible { opacity: 1; transform: scale(1); }

.sun-wash {
  pointer-events: none;
  opacity: .16;
  mix-blend-mode: screen;
  background: linear-gradient(118deg, rgba(255, 235, 185, .85), transparent 42%, rgba(244, 147, 182, .2));
}

.vignette {
  pointer-events: none;
  box-shadow: inset 0 0 11vw rgba(7, 9, 28, .48);
  background: linear-gradient(to bottom, rgba(9, 12, 35, .16), transparent 22%, transparent 68%, rgba(8, 10, 30, .28));
}

#ambient-layer { z-index: -2; overflow: hidden; pointer-events: none; }

.petal {
  position: absolute;
  top: -8%;
  width: clamp(6px, .8vw, 15px);
  height: clamp(9px, 1.1vw, 21px);
  border-radius: 85% 15% 80% 20%;
  opacity: 0;
  background: linear-gradient(145deg, #fff0f4, #ef9db9 68%);
  filter: drop-shadow(0 2px 2px rgba(72, 41, 70, .18));
  animation: petal-fall var(--duration) linear var(--delay) infinite;
}

.petal-strong .petal { opacity: .8; }
.petals .petal { opacity: .48; }

@keyframes petal-fall {
  0% { transform: translate3d(0, -8vh, 0) rotate(0deg) scale(var(--scale)); }
  35% { transform: translate3d(var(--sway), 34vh, 0) rotate(170deg) scale(var(--scale)); }
  70% { transform: translate3d(calc(var(--sway) * -.4), 72vh, 0) rotate(380deg) scale(var(--scale)); }
  100% { transform: translate3d(var(--drift), 115vh, 0) rotate(620deg) scale(var(--scale)); }
}

.dust {
  position: absolute;
  width: clamp(2px, .22vw, 4px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: #ffe7a6;
  opacity: .65;
  box-shadow: 0 0 9px #ffd889;
  animation: dust-float var(--duration) ease-in-out var(--delay) infinite alternate;
}

@keyframes dust-float {
  from { transform: translate3d(-1vw, 2vh, 0) scale(.6); opacity: .15; }
  to { transform: translate3d(2vw, -7vh, 0) scale(1.4); opacity: .85; }
}

#character-stage { z-index: 2; pointer-events: none; }

.character-slot {
  position: absolute;
  bottom: -3.5%;
  width: 48%;
  height: 101%;
  opacity: .8;
  transform: translateY(0) scale(.97);
  filter: brightness(.72) saturate(.78) drop-shadow(0 22px 20px rgba(20, 13, 36, .32));
  transition: opacity .48s ease, filter .42s ease, transform .48s cubic-bezier(.2,.8,.2,1);
}

.character-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 100%;
}

.character-rin { left: -1.8%; }
.character-hiyori { right: -1.5%; }
.character-slot.active {
  z-index: 2;
  opacity: 1;
  transform: translateY(-1.2%) scale(1.015);
  filter: brightness(1.02) saturate(1.03) drop-shadow(0 25px 24px rgba(20, 13, 36, .4));
}

.character-slot.hidden {
  display: block !important;
  opacity: 0;
  transform: translateY(7%) scale(.94);
}

.character-rin.entering { animation: enter-left .72s cubic-bezier(.18,.85,.22,1) both; }
.character-hiyori.entering { animation: enter-right .72s cubic-bezier(.18,.85,.22,1) both; }

@keyframes enter-left { from { opacity: 0; transform: translateX(-8%) translateY(4%) scale(.94); } }
@keyframes enter-right { from { opacity: 0; transform: translateX(8%) translateY(4%) scale(.94); } }

.hud-element { position: absolute; z-index: 9; }

#chapter-badge {
  top: 3.4%;
  left: 3.2%;
  display: flex;
  align-items: baseline;
  gap: .9em;
  padding: .45em 1em;
  border-left: 3px solid var(--gold);
  text-shadow: var(--text-shadow);
  background: linear-gradient(90deg, rgba(15, 23, 59, .58), transparent);
  backdrop-filter: blur(4px);
}

#chapter-badge span { color: var(--gold); font: 600 clamp(9px, .74vw, 14px)/1 "Segoe UI", sans-serif; letter-spacing: .18em; }
#chapter-badge strong { font-size: clamp(12px, 1.1vw, 21px); letter-spacing: .14em; }

.screen-layer {
  z-index: 20;
  display: grid;
  place-items: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .65s ease, visibility .65s;
}

.screen-layer.active { opacity: 1; visibility: visible; pointer-events: auto; }

#title-screen {
  background:
    linear-gradient(90deg, rgba(10, 15, 42, .86) 0%, rgba(16, 20, 50, .56) 42%, rgba(22, 15, 42, .1) 69%),
    linear-gradient(to top, rgba(8, 10, 31, .7), transparent 45%);
}

.title-glow {
  position: absolute;
  left: 8%;
  top: 12%;
  width: 34%;
  aspect-ratio: 1;
  border-radius: 50%;
  opacity: .26;
  background: radial-gradient(circle, rgba(255, 193, 199, .7), transparent 67%);
  filter: blur(18px);
  animation: title-breathe 4.5s ease-in-out infinite alternate;
}

@keyframes title-breathe { to { transform: scale(1.08); opacity: .38; } }

.title-copy {
  position: absolute;
  left: 8%;
  top: 16%;
  width: 44%;
  text-align: center;
  text-shadow: 0 4px 18px rgba(13, 9, 37, .72);
}

.title-kicker {
  margin: 0 0 .8em;
  color: var(--gold);
  font: 600 clamp(10px, .9vw, 17px)/1.2 "Segoe UI", sans-serif;
  letter-spacing: .38em;
}

.title-copy h1 { margin: 0; font-family: "Yu Mincho", "Noto Serif CJK SC", "STSong", serif; font-weight: 500; }
.title-copy h1 span { display: block; font-size: clamp(42px, 5.2vw, 100px); letter-spacing: .11em; }
.title-copy h1 small { display: block; margin-top: .12em; color: var(--pink-light); font-size: clamp(19px, 2vw, 38px); letter-spacing: .4em; }
.title-rule { display: flex; align-items: center; justify-content: center; gap: 1em; margin: 1.2em auto; width: 74%; color: var(--gold); }
.title-rule i { height: 1px; flex: 1; background: linear-gradient(90deg, transparent, var(--gold)); }
.title-rule i:last-child { transform: scaleX(-1); }
.title-subtitle { margin: 0 auto; max-width: 35em; color: rgba(255,248,238,.84); font-size: clamp(11px, 1vw, 19px); line-height: 1.85; letter-spacing: .08em; }

.title-menu {
  position: absolute;
  left: 13%;
  bottom: 10%;
  display: grid;
  gap: clamp(7px, .7vw, 14px);
  width: 22%;
  min-width: 210px;
}

.title-button {
  position: relative;
  height: clamp(46px, 4.9vw, 94px);
  padding: 0 16% 0 12%;
  border: 0;
  text-align: left;
  cursor: pointer;
  background: center / 100% 100% no-repeat url("assets/ui/buttons/ui_title_button_idle.png");
  transition: transform .18s ease, filter .18s ease;
}

.title-button:hover,
.title-button:focus-visible {
  outline: none;
  transform: translateX(2.2%);
  background-image: url("assets/ui/buttons/ui_title_button_hover.png");
  filter: drop-shadow(0 0 10px rgba(239, 198, 105, .32));
}

.title-button:active { transform: translateX(2.2%) translateY(3px); background-image: url("assets/ui/buttons/ui_title_button_pressed.png"); }
.title-button span { display: block; font-size: clamp(14px, 1.35vw, 26px); letter-spacing: .16em; }
.title-button small { position: absolute; right: 10%; top: 50%; transform: translateY(-50%); color: var(--gold); font: 600 clamp(7px, .58vw, 11px)/1 "Segoe UI", sans-serif; letter-spacing: .13em; }
.title-button:disabled { opacity: .42; cursor: not-allowed; filter: grayscale(.5); }

.title-hint { position: absolute; left: 0; right: 0; bottom: 2.7%; margin: 0; text-align: center; color: rgba(255,248,238,.56); font-size: clamp(8px, .7vw, 13px); letter-spacing: .15em; }

#chapter-card { z-index: 24; background: rgba(9, 13, 37, .82); backdrop-filter: blur(8px); }
.chapter-card-inner { width: 55%; text-align: center; text-shadow: var(--text-shadow); }
.chapter-card-inner span { color: var(--gold); font-size: clamp(12px, 1vw, 19px); letter-spacing: .5em; }
.chapter-card-inner h2 { margin: .35em 0 .3em; font: 500 clamp(38px, 5vw, 96px)/1.3 "Yu Mincho", "STSong", serif; letter-spacing: .2em; }
.chapter-card-inner i { display: block; width: 34%; height: 1px; margin: 0 auto 1.3em; background: linear-gradient(90deg, transparent, var(--pink), transparent); }
.chapter-card-inner p { margin: 0; color: rgba(255,248,238,.7); font-size: clamp(11px, 1vw, 19px); letter-spacing: .18em; }

#dialogue-layer { position: absolute; z-index: 8; left: 5.7%; right: 5.7%; bottom: 1.5%; height: 30.2%; }
#dialogue-hit-area { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; border: 0; cursor: pointer; background: transparent; }
#dialogue-box { position: absolute; inset: 0; padding: 7.4% 8.2% 4.5% 6%; background: center / 100% 100% no-repeat url("assets/ui/panels/ui_dialogue_box_1700x320.png"); filter: drop-shadow(0 10px 9px rgba(9, 10, 29, .35)); }
#dialogue-text { position: relative; z-index: 3; margin: 0; max-width: 91%; color: var(--ivory); font-size: clamp(17px, 1.75vw, 34px); line-height: 1.82; letter-spacing: .035em; text-shadow: var(--text-shadow); pointer-events: none; }
#dialogue-text.narration { color: #fff0e4; font-family: "Yu Mincho", "Noto Serif CJK SC", "STSong", serif; font-style: italic; letter-spacing: .06em; }

#nameplate {
  position: absolute;
  z-index: 5;
  left: 4%;
  top: -10.5%;
  width: 25%;
  height: 28.8%;
  display: flex;
  align-items: center;
  padding-left: 4.6%;
  background: center / 100% 100% no-repeat;
  filter: drop-shadow(0 7px 5px rgba(9, 10, 29, .32));
  pointer-events: none;
}

#nameplate span { font-size: clamp(13px, 1.3vw, 25px); font-weight: 700; letter-spacing: .17em; text-shadow: var(--text-shadow); }

#continue-indicator {
  position: absolute;
  z-index: 4;
  right: 4.2%;
  bottom: 9%;
  width: 3.8%;
  opacity: 0;
  animation: continue-bounce .9s ease-in-out infinite alternate;
}

#continue-indicator.visible { opacity: 1; }
@keyframes continue-bounce { to { transform: translateY(24%); } }

#quick-menu {
  position: absolute;
  z-index: 12;
  right: 8.2%;
  bottom: 4.1%;
  display: flex;
  gap: clamp(4px, .45vw, 9px);
}

.quick-button {
  width: clamp(34px, 3.8vw, 73px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  cursor: pointer;
  border-radius: 22%;
  background: center / 100% 100% no-repeat;
  transition: transform .16s ease, filter .16s ease;
}
.quick-button:hover, .quick-button:focus-visible, .quick-button.active { outline: none; transform: translateY(-6%); filter: drop-shadow(0 0 8px rgba(239,198,105,.4)); }
.quick-auto { background-image: url("assets/ui/icons/ui_quick_auto_idle.png"); }.quick-auto:hover,.quick-auto.active { background-image: url("assets/ui/icons/ui_quick_auto_hover.png"); }
.quick-skip { background-image: url("assets/ui/icons/ui_quick_skip_idle.png"); }.quick-skip:hover,.quick-skip.active { background-image: url("assets/ui/icons/ui_quick_skip_hover.png"); }
.quick-history { background-image: url("assets/ui/icons/ui_quick_history_idle.png"); }.quick-history:hover { background-image: url("assets/ui/icons/ui_quick_history_hover.png"); }
.quick-save { background-image: url("assets/ui/icons/ui_quick_save_idle.png"); }.quick-save:hover { background-image: url("assets/ui/icons/ui_quick_save_hover.png"); }
.quick-load { background-image: url("assets/ui/icons/ui_quick_load_idle.png"); }.quick-load:hover { background-image: url("assets/ui/icons/ui_quick_load_hover.png"); }
.quick-config { background-image: url("assets/ui/icons/ui_quick_config_idle.png"); }.quick-config:hover { background-image: url("assets/ui/icons/ui_quick_config_hover.png"); }
.quick-hide { background-image: url("assets/ui/icons/ui_quick_hide_idle.png"); }.quick-hide:hover { background-image: url("assets/ui/icons/ui_quick_hide_hover.png"); }

#choice-layer {
  position: absolute;
  z-index: 14;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4%;
  padding-bottom: 4%;
  background: radial-gradient(circle at 50% 48%, rgba(28, 29, 68, .26), rgba(8, 10, 29, .58));
  backdrop-filter: blur(2px);
}

.choice-heading { text-align: center; text-shadow: var(--text-shadow); animation: choice-enter .55s ease both; }
.choice-heading span { display: block; margin-bottom: .5em; color: var(--gold); font: 700 clamp(9px, .8vw, 15px)/1 "Segoe UI", sans-serif; letter-spacing: .3em; }
.choice-heading strong { font: 500 clamp(24px, 2.4vw, 46px)/1.3 "Yu Mincho", "STSong", serif; letter-spacing: .12em; }
#choice-list { display: grid; gap: clamp(10px, 1.1vw, 21px); width: 48%; min-width: 430px; }
.choice-button {
  position: relative;
  width: 100%;
  min-height: clamp(64px, 6.2vw, 119px);
  padding: 1.3% 10% 1.3% 8%;
  border: 0;
  cursor: pointer;
  text-align: left;
  background: center / 100% 100% no-repeat url("assets/ui/buttons/ui_choice_button_idle.png");
  animation: choice-enter .55s cubic-bezier(.18,.84,.24,1) both;
  animation-delay: var(--delay);
  transition: transform .16s ease, filter .16s ease;
}
.choice-button:hover,.choice-button:focus-visible { outline: none; transform: translateX(1.8%); background-image: url("assets/ui/buttons/ui_choice_button_hover.png"); filter: drop-shadow(0 0 14px rgba(239,198,105,.4)); }
.choice-button:active { transform: translateX(1.8%) translateY(3px); background-image: url("assets/ui/buttons/ui_choice_button_pressed.png"); }
.choice-button strong { display: block; color: var(--ivory); font-size: clamp(13px, 1.25vw, 24px); font-weight: 500; letter-spacing: .04em; }
.choice-button small { display: block; margin-top: .45em; color: var(--gold); font-size: clamp(8px, .68vw, 13px); letter-spacing: .12em; }
@keyframes choice-enter { from { opacity: 0; transform: translateY(25%); } }

#modal-layer {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(7, 9, 27, .65);
  backdrop-filter: blur(8px);
}

#modal-panel {
  width: 69%;
  height: 70%;
  padding: 4% 5%;
  background: center / 100% 100% no-repeat url("assets/ui/panels/ui_system_panel_1320x760.png");
  filter: drop-shadow(0 20px 35px rgba(0,0,0,.42));
  animation: modal-in .26s ease both;
}
@keyframes modal-in { from { opacity: 0; transform: scale(.96) translateY(2%); } }
#modal-panel header { display: flex; align-items: center; justify-content: space-between; height: 13%; border-bottom: 1px solid rgba(236,145,176,.34); }
#modal-kicker { color: var(--gold); font: 700 clamp(8px, .7vw, 13px)/1 "Segoe UI", sans-serif; letter-spacing: .28em; }
#modal-title { display: inline-block; margin: 0 0 0 .7em; font-size: clamp(17px, 1.6vw, 31px); letter-spacing: .12em; }
#modal-close { width: clamp(32px, 3vw, 58px); aspect-ratio: 1; border: 1px solid var(--pink); border-radius: 50%; cursor: pointer; color: var(--ivory); font-size: clamp(20px, 2vw, 38px); background: rgba(30,39,78,.7); transition: .18s ease; }
#modal-close:hover { color: var(--gold); border-color: var(--gold); transform: rotate(8deg); }
#modal-content { height: 80%; overflow-y: auto; padding: 3% 1%; scrollbar-color: var(--pink) rgba(18,27,61,.6); }
.history-list { display: grid; gap: 1em; }
.history-entry { padding: .8em 1em; border-left: 3px solid var(--pink); background: rgba(15,24,57,.52); }
.history-entry strong { display: block; margin-bottom: .3em; color: var(--gold); font-size: clamp(10px, .9vw, 17px); }
.history-entry p { margin: 0; font-size: clamp(11px, 1vw, 19px); line-height: 1.7; }
.empty-state { display: grid; height: 100%; place-items: center; color: rgba(255,248,238,.58); letter-spacing: .12em; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7% 8%; padding: 2%; }
.setting { display: grid; gap: .9em; }
.setting label { display: flex; justify-content: space-between; color: var(--ivory); font-size: clamp(11px, 1.05vw, 20px); }
.setting output { color: var(--gold); }
.setting input[type="range"] { width: 100%; accent-color: var(--pink); }
.setting-wide { grid-column: 1 / -1; }
.config-actions { display: flex; gap: 1em; margin-top: 1em; }
.system-button { padding: .75em 1.6em; border: 1px solid var(--pink); border-radius: 999px; cursor: pointer; color: var(--ivory); background: rgba(37,48,94,.75); transition: .18s ease; }
.system-button:hover { border-color: var(--gold); background: rgba(78,68,122,.8); }

#ending-card { z-index: 30; background: rgba(8, 11, 32, .68); backdrop-filter: blur(7px); }
.ending-panel { width: 52%; min-height: 48%; padding: 6% 7%; text-align: center; background: center / 100% 100% no-repeat url("assets/ui/panels/ui_confirm_panel_820x420.png"); filter: drop-shadow(0 20px 34px rgba(0,0,0,.45)); }
#ending-kicker { color: var(--gold); font: 700 clamp(9px, .8vw, 15px)/1 "Segoe UI", sans-serif; letter-spacing: .28em; }
#ending-title { margin: .55em 0 .7em; font: 500 clamp(25px, 2.5vw, 48px)/1.3 "Yu Mincho", "STSong", serif; letter-spacing: .12em; }
#ending-summary { min-height: 3.5em; margin: 0 auto 1.6em; font-size: clamp(11px, 1vw, 19px); line-height: 1.8; color: rgba(255,248,238,.82); }
.ending-actions { display: flex; justify-content: center; gap: 1em; }
.title-button.compact { width: 42%; min-width: 150px; }

#toast, #status-pill {
  position: absolute;
  z-index: 60;
  left: 50%;
  transform: translateX(-50%);
  padding: .7em 1.5em;
  border: 1px solid rgba(239,198,105,.6);
  border-radius: 999px;
  color: var(--ivory);
  font-size: clamp(9px, .8vw, 15px);
  letter-spacing: .1em;
  background: rgba(17,25,58,.88);
  box-shadow: 0 9px 20px rgba(0,0,0,.24);
  backdrop-filter: blur(8px);
}
#toast { top: 7%; animation: toast-in .28s ease both; }
#status-pill { top: 3.5%; left: auto; right: 3.2%; transform: none; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -30%); } }

#ripple-layer { z-index: 70; pointer-events: none; }
.ripple { position: absolute; width: 12px; aspect-ratio: 1; border: 2px solid rgba(255,238,229,.8); border-radius: 50%; transform: translate(-50%, -50%); animation: ripple .55s ease-out forwards; }
@keyframes ripple { to { width: 80px; opacity: 0; } }

#restore-ui-button {
  position: absolute;
  z-index: 50;
  right: 3%;
  bottom: 4%;
  padding: .7em 1.2em;
  border: 1px solid var(--pink);
  border-radius: 999px;
  cursor: pointer;
  color: var(--ivory);
  background: rgba(17,25,58,.72);
  backdrop-filter: blur(7px);
}

.hidden { display: none !important; }
.ui-fade { transition: opacity .25s ease; }
.ui-hidden #dialogue-layer, .ui-hidden #quick-menu, .ui-hidden #chapter-badge { opacity: 0; pointer-events: none; }

@media (max-width: 760px), (max-height: 520px) {
  #app { padding: 0; }
  #game-shell { width: min(100vw, calc(100vh * 16 / 9)); }
  #game { border: 0; border-radius: 0; }
  .outside-hint { display: none; }
  .title-menu { left: 8%; bottom: 7%; width: 28%; min-width: 160px; }
  #choice-list { width: 64%; min-width: 300px; }
}

@media (orientation: portrait) and (max-width: 1100px) {
  html,
  body,
  #app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
  }

  #app {
    display: block;
    padding: 0;
  }

  #game-shell {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    filter: none;
  }

  #game {
    border: 0;
    border-radius: 0;
  }

  .outside-hint { display: none; }

  #background-layer img {
    object-position: 52% 50%;
    transform: scale(1.04);
  }

  #background-layer img.visible { transform: scale(1); }

  .vignette {
    box-shadow: inset 0 0 22vw rgba(7, 9, 28, .45);
    background: linear-gradient(to bottom, rgba(9, 12, 35, .12), transparent 30%, transparent 58%, rgba(8, 10, 30, .48));
  }

  .character-slot {
    bottom: 16%;
    width: 72%;
    height: 76%;
  }

  .character-rin { left: -17%; }
  .character-hiyori { right: -15%; }

  .character-slot.active {
    transform: translateY(-1%) scale(1.035);
  }

  #chapter-badge {
    top: max(14px, env(safe-area-inset-top));
    left: 0;
    max-width: 86%;
    gap: .7em;
    padding: .7em 1em .7em 1.15em;
    border-left-width: 4px;
    background: linear-gradient(90deg, rgba(15, 23, 59, .78), rgba(15, 23, 59, .28) 78%, transparent);
  }

  #chapter-badge span { font-size: clamp(9px, 2.5vw, 13px); }
  #chapter-badge strong { font-size: clamp(14px, 3.8vw, 20px); }

  .title-glow {
    left: 8%;
    top: 5%;
    width: 84%;
  }

  .title-copy {
    left: 7%;
    top: max(8%, env(safe-area-inset-top));
    width: 86%;
  }

  .title-copy h1 span { font-size: clamp(42px, 13vw, 76px); }
  .title-copy h1 small { font-size: clamp(19px, 5.6vw, 32px); }
  .title-kicker { font-size: clamp(10px, 2.8vw, 15px); }
  .title-subtitle { font-size: clamp(12px, 3vw, 17px); }

  .title-menu {
    left: 10%;
    right: 10%;
    bottom: max(7%, calc(env(safe-area-inset-bottom) + 24px));
    width: auto;
    min-width: 0;
    gap: 10px;
  }

  .title-button {
    height: clamp(58px, 8.5vh, 76px);
    padding-left: 12%;
  }

  .title-button span { font-size: clamp(16px, 4.4vw, 23px); }
  .title-button small { font-size: clamp(8px, 2.2vw, 11px); }
  .title-hint { display: none; }

  .chapter-card-inner { width: 86%; }
  .chapter-card-inner h2 { font-size: clamp(42px, 13vw, 72px); }
  .chapter-card-inner span,
  .chapter-card-inner p { font-size: clamp(12px, 3.3vw, 18px); }

  #dialogue-layer {
    left: 2.5%;
    right: 2.5%;
    bottom: max(10px, env(safe-area-inset-bottom));
    height: clamp(210px, 25dvh, 300px);
  }

  #dialogue-box {
    padding: clamp(64px, 7.5vh, 88px) 6% 26px;
  }

  #dialogue-layer:has(#nameplate.hidden) #dialogue-box {
    padding-top: clamp(34px, 4.5vh, 54px);
  }

  #dialogue-text {
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
    font-size: clamp(17px, 4.2vw, 23px);
    line-height: 1.65;
    letter-spacing: .025em;
  }

  #nameplate {
    left: 4%;
    top: -28px;
    width: min(48%, 430px);
    height: 70px;
    padding-left: 8%;
  }

  #nameplate span { font-size: clamp(15px, 4vw, 21px); }

  #continue-indicator {
    right: 5%;
    bottom: 7%;
    width: clamp(22px, 6vw, 32px);
  }

  #quick-menu {
    right: 3%;
    bottom: calc(max(10px, env(safe-area-inset-bottom)) + clamp(210px, 25dvh, 300px) + 10px);
    gap: clamp(3px, 1vw, 8px);
  }

  .quick-button { width: clamp(38px, 10vw, 52px); }

  #choice-layer {
    gap: 4vh;
    padding: max(24px, env(safe-area-inset-top)) 4% max(24px, env(safe-area-inset-bottom));
  }

  .choice-heading span { font-size: clamp(10px, 2.8vw, 14px); }
  .choice-heading strong { font-size: clamp(26px, 7vw, 38px); }

  #choice-list {
    width: 94%;
    min-width: 0;
    gap: 14px;
  }

  .choice-button {
    min-height: clamp(76px, 11vh, 108px);
    padding: 3% 10% 3% 9%;
  }

  .choice-button strong { font-size: clamp(16px, 4vw, 21px); }
  .choice-button small { font-size: clamp(9px, 2.4vw, 12px); }

  #modal-panel {
    width: 94%;
    height: min(78%, 760px);
    padding: 7% 7%;
  }

  #modal-panel header { height: 12%; }
  #modal-kicker { font-size: clamp(8px, 2.2vw, 11px); }
  #modal-title { font-size: clamp(18px, 4.8vw, 25px); }
  #modal-close { width: 42px; font-size: 27px; }
  #modal-content { height: 84%; padding-top: 5%; }
  .history-entry strong { font-size: 13px; }
  .history-entry p { font-size: clamp(13px, 3.4vw, 17px); }
  .config-grid { grid-template-columns: 1fr; gap: 24px; }
  .setting-wide { grid-column: auto; }
  .setting label { font-size: clamp(13px, 3.5vw, 17px); }
  .config-actions { flex-wrap: wrap; }

  .ending-panel {
    width: 92%;
    min-height: 46%;
    padding: 13% 9%;
  }

  #ending-kicker { font-size: clamp(10px, 2.7vw, 14px); }
  #ending-title { font-size: clamp(29px, 7.4vw, 42px); }
  #ending-summary { font-size: clamp(13px, 3.5vw, 17px); }
  .ending-actions { gap: 8px; }
  .title-button.compact { width: 50%; min-width: 0; }

  #toast {
    top: max(14px, env(safe-area-inset-top));
    max-width: 86%;
    white-space: nowrap;
  }

  #status-pill {
    top: max(14px, env(safe-area-inset-top));
    right: 3%;
  }

  #restore-ui-button {
    right: 4%;
    bottom: max(18px, env(safe-area-inset-bottom));
  }
}

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