:root {
  color-scheme: dark;
  --navy-950: #0b1220;
  --navy-900: #111c2f;
  --navy-800: #22314c;
  --navy-700: #304568;
  --cream: #fffaf0;
  --cream-soft: rgba(255, 250, 240, 0.9);
  --pink: #f2b8c7;
  --pink-strong: #e68aa5;
  --gold: #d2a853;
  --ink: #233049;
  --shadow: 0 24px 80px rgba(3, 10, 24, 0.42);
  --ease-spring: cubic-bezier(.2, .9, .2, 1.08);
  font-family: "Noto Sans SC", "Microsoft YaHei UI", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  background:
    radial-gradient(circle at 50% 15%, #405477 0, #111a2b 58%, #070c15 100%);
  color: var(--cream);
  user-select: none;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 4px; }

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.screen {
  position: absolute;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: scale(1.015);
  transition: opacity .55s ease, transform .7s var(--ease-spring), visibility 0s linear .7s;
  box-shadow: var(--shadow);
}

.screen.is-active {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  transition-delay: 0s;
}

.is-hidden { display: none !important; }

/* Title */
.title-screen {
  background:
    linear-gradient(110deg, rgba(255, 250, 240, .97) 0 48%, rgba(255, 250, 240, .68) 60%, rgba(20, 34, 55, .12) 100%),
    linear-gradient(160deg, #d9e5ee 0%, #edc6cf 56%, #566984 100%);
  color: var(--ink);
}

.title-sky { position: absolute; inset: 0; background: radial-gradient(circle at 85% 15%, rgba(255,255,255,.95), transparent 34%); }
.title-grid { position: absolute; inset: 0; opacity: .22; background-image: linear-gradient(rgba(34,49,76,.16) 1px, transparent 1px), linear-gradient(90deg, rgba(34,49,76,.16) 1px, transparent 1px); background-size: 42px 42px; mask-image: linear-gradient(90deg, #000, transparent 72%); }

.title-copy { position: absolute; z-index: 4; left: 8%; top: 18%; width: 43%; }
.eyebrow { margin: 0 0 1.1rem; color: var(--pink-strong); font: 700 clamp(.65rem, .85vw, 1rem)/1.2 ui-monospace, monospace; letter-spacing: .28em; }
.title-copy h1 { margin: 0; font: 800 clamp(3.8rem, 7vw, 8rem)/.86 "Yu Mincho", "Noto Serif SC", serif; letter-spacing: -.06em; color: var(--navy-800); text-shadow: 0 4px 0 rgba(255,255,255,.8); }
.title-copy h1 span { color: var(--pink-strong); }
.chapter-kicker { display: inline-block; margin: 1.25rem 0 .85rem; padding: .45rem .85rem; border-left: 4px solid var(--gold); background: rgba(255,255,255,.62); font-weight: 800; letter-spacing: .16em; }
.title-description { color: #58657b; font: 500 clamp(.8rem, 1.05vw, 1.15rem)/1.9 "Noto Serif SC", serif; }
.title-actions { display: flex; gap: 1rem; margin-top: 2.2rem; }

.menu-button {
  min-width: 11rem;
  min-height: 3.35rem;
  padding: .75rem 1.6rem;
  border: 1px solid rgba(34,49,76,.26);
  border-radius: 999px;
  background: rgba(255,255,255,.75);
  color: var(--navy-800);
  font-weight: 800;
  letter-spacing: .08em;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(34,49,76,.12);
  transition: transform .2s var(--ease-spring), box-shadow .2s, background .2s;
}
.menu-button:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 16px 30px rgba(34,49,76,.18); }
.menu-button:active:not(:disabled) { transform: translateY(1px) scale(.985); }
.menu-button.primary { color: #fff; border-color: var(--navy-800); background: linear-gradient(135deg, var(--navy-800), var(--navy-700)); }
.menu-button:disabled { opacity: .42; cursor: not-allowed; }
.audio-hint { margin-top: 1rem; color: #798397; font-size: .78rem; letter-spacing: .08em; }

.title-character { position: absolute; z-index: 3; right: -1%; bottom: -25%; width: 53%; height: 130%; pointer-events: none; }
.title-character::before { content: ""; position: absolute; width: 70%; aspect-ratio: 1; border-radius: 50%; right: 2%; top: 10%; background: rgba(255,255,255,.58); box-shadow: 0 0 0 1px rgba(34,49,76,.08), 0 0 0 35px rgba(255,255,255,.17); }
.title-character img { position: absolute; z-index: 2; right: 4%; bottom: 0; height: 100%; max-width: 100%; object-fit: contain; filter: drop-shadow(-18px 20px 20px rgba(20,30,48,.18)); }
.character-name-jp { position: absolute; z-index: 3; right: 2.6%; top: 18%; writing-mode: vertical-rl; color: rgba(34,49,76,.48); font: 800 1.1rem/1 ui-monospace, monospace; letter-spacing: .32em; }
.corner-settings { position: absolute; z-index: 10; top: 3%; right: 2.5%; border: 0; background: transparent; color: var(--navy-700); font-weight: 800; letter-spacing: .12em; cursor: pointer; }

.sakura-field i { position: absolute; z-index: 2; width: 16px; height: 11px; border-radius: 80% 20% 70% 30%; background: rgba(230,138,165,.46); animation: petal 9s linear infinite; }
.sakura-field i:nth-child(1) { left: 8%; top: -5%; animation-delay: -2s; }
.sakura-field i:nth-child(2) { left: 20%; top: -8%; animation-delay: -6s; transform: scale(.7); }
.sakura-field i:nth-child(3) { left: 40%; top: -3%; animation-delay: -4s; }
.sakura-field i:nth-child(4) { left: 58%; top: -9%; animation-delay: -8s; transform: scale(1.25); }
.sakura-field i:nth-child(5) { left: 73%; top: -6%; animation-delay: -1s; }
.sakura-field i:nth-child(6) { left: 85%; top: -4%; animation-delay: -5s; transform: scale(.8); }
.sakura-field i:nth-child(7) { left: 93%; top: -7%; animation-delay: -7s; }
.sakura-field i:nth-child(8) { left: 50%; top: -2%; animation-delay: -3s; transform: scale(.55); }
@keyframes petal { to { translate: 10vw 115vh; rotate: 620deg; } }

/* Game scene */
.game-screen { background: #19253a; }
.scene-backdrop { position: absolute; inset: 0; overflow: hidden; background: linear-gradient(112deg, rgba(255,248,229,.92) 0 34%, rgba(187,190,190,.92) 34.5% 51%, #7d8792 51.5% 100%); }
.scene-backdrop::before { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, transparent 0 46%, rgba(19,31,50,.28) 46.3% 47.2%, transparent 47.5%), repeating-linear-gradient(0deg, rgba(34,49,76,.06) 0 1px, transparent 1px 78px); }
.window-light { position: absolute; left: 4%; top: 5%; width: 35%; height: 72%; border: 18px solid #f5efe4; box-shadow: inset 0 0 0 3px #9aa8b4, 22px 30px 90px rgba(255,235,190,.75); background: linear-gradient(155deg, #c9e5f0 0, #f8d7dd 62%, #f7e7bc 100%); }
.window-light::before, .window-light::after { content: ""; position: absolute; background: #f5efe4; box-shadow: 0 0 0 2px #9aa8b4; }
.window-light::before { left: 48%; top: 0; width: 18px; height: 100%; }
.window-light::after { left: 0; top: 48%; width: 100%; height: 18px; }
.stair { position: absolute; right: -8%; width: 65%; height: 18%; background: repeating-linear-gradient(0deg, #8d96a1 0 21%, #707a87 22% 28%, #a8afb7 29% 49%); transform: skewY(-10deg); box-shadow: 0 -10px 22px rgba(13,24,40,.22); }
.stair-one { bottom: 4%; }
.stair-two { right: 28%; bottom: 31%; transform: skewY(11deg) scale(.82); opacity: .78; }
.railing { position: absolute; left: 36%; bottom: 17%; width: 52%; height: 8px; background: #3e4c5d; transform: rotate(-21deg); box-shadow: 0 0 0 2px rgba(255,255,255,.2), 10px 12px 14px rgba(15,25,40,.25); }
.railing::before, .railing::after { content: ""; position: absolute; width: 7px; height: 270px; background: #3e4c5d; transform-origin: top; transform: rotate(21deg); }
.railing::before { left: 8%; }.railing::after { right: 8%; }
.scene-backdrop::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(24,38,60,.06), rgba(10,18,31,.42)); box-shadow: inset 0 0 120px rgba(8,14,24,.3); }

.dust i { position: absolute; z-index: 2; width: 5px; aspect-ratio: 1; border-radius: 50%; background: #fff5cf; box-shadow: 0 0 12px #fff2bc; animation: dust 6s ease-in-out infinite alternate; }
.dust i:nth-child(1){left:15%;top:25%}.dust i:nth-child(2){left:29%;top:58%;animation-delay:-2s}.dust i:nth-child(3){left:47%;top:20%;animation-delay:-4s}.dust i:nth-child(4){left:62%;top:47%;animation-delay:-1s}.dust i:nth-child(5){left:78%;top:17%;animation-delay:-3s}.dust i:nth-child(6){left:89%;top:57%;animation-delay:-5s}
@keyframes dust { to { transform: translate(20px,-38px) scale(.55); opacity: .2; } }

.game-hud { position: absolute; z-index: 12; top: 3.2%; left: 3.2%; right: 3.2%; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
.chapter-badge, .state-badge { padding: .65rem .9rem; border-left: 3px solid var(--pink); background: linear-gradient(90deg, rgba(14,25,43,.72), transparent); text-shadow: 0 2px 8px #000; }
.chapter-badge span, .state-badge span { display: block; color: var(--pink); font: 700 clamp(.55rem,.7vw,.78rem)/1.2 ui-monospace,monospace; letter-spacing: .16em; }
.chapter-badge strong { font-size: clamp(.72rem,.95vw,1.05rem); letter-spacing: .08em; }
.state-badge { text-align: right; border-left: 0; border-right: 3px solid var(--gold); background: linear-gradient(270deg, rgba(14,25,43,.78), transparent); }
.state-badge strong { display: inline-block; margin: .1rem .35rem 0 0; color: var(--cream); font: 800 clamp(1.1rem,1.6vw,1.8rem)/1 ui-monospace,monospace; }
.state-badge i { color: #aed9c1; font: 700 .66rem/1 ui-monospace,monospace; letter-spacing: .1em; }
.state-badge i.is-locked { color: #ff9fae; }

.character-stage { position: absolute; z-index: 5; inset: 0; pointer-events: none; overflow: hidden; }
.character-aura { position: absolute; right: 2%; top: 3%; width: 50%; aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, rgba(255,239,209,.28), transparent 66%); filter: blur(12px); }
.character-rin { position: absolute; right: 4%; bottom: -29%; height: 127%; max-width: 65%; object-fit: contain; object-position: bottom right; transform-origin: bottom center; filter: drop-shadow(-22px 22px 18px rgba(10,18,31,.35)); transition: filter .2s, transform .35s var(--ease-spring), opacity .3s; }
.character-rin.is-speaking { filter: drop-shadow(-22px 22px 18px rgba(10,18,31,.35)) brightness(1.025); }
.character-rin.is-entering { animation: character-in .7s var(--ease-spring) both; }
@keyframes character-in { from { opacity: 0; transform: translateX(6%) scale(.985); } }

.dialogue-zone { position: absolute; z-index: 20; left: 4.5%; right: 4.5%; bottom: 2.8%; height: 30%; }
.dialogue-box { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; padding: 6.4% 7.5% 4%; border: 0; color: var(--ink); text-align: left; cursor: pointer; background: url('../assets/ui/dialogue/ui_dialogue_box.png') center/100% 100% no-repeat; filter: drop-shadow(0 18px 26px rgba(6,13,24,.35)); transition: transform .12s ease, filter .2s; }
.dialogue-box:active { transform: translateY(2px); filter: drop-shadow(0 10px 18px rgba(6,13,24,.3)); }
.dialogue-sheen { position: absolute; inset: 7% 5%; border-radius: 28px; overflow: hidden; pointer-events: none; }
.dialogue-sheen::after { content: ""; position: absolute; top: -120%; left: -30%; width: 20%; height: 320%; rotate: 18deg; background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent); animation: sheen 8s ease-in-out infinite; }
@keyframes sheen { 0%,70%{translate:0} 90%,100%{translate:900%} }
.nameplate { position: absolute; left: 6.7%; top: -9%; width: 21%; height: 28%; display: grid; place-items: center; padding-bottom: 1%; background: url('../assets/ui/dialogue/ui_nameplate.png') center/100% 100% no-repeat; color: var(--cream); text-shadow: 0 2px 5px rgba(0,0,0,.28); font-size: clamp(.76rem,1.2vw,1.35rem); font-weight: 800; letter-spacing: .13em; }
.dialogue-text { display: block; min-height: 3.7em; font: 600 clamp(.82rem,1.35vw,1.5rem)/1.85 "Noto Serif SC",serif; letter-spacing: .035em; text-shadow: 0 1px 0 #fff; }
.continue-indicator { position: absolute; right: 6.5%; bottom: 13%; color: var(--pink-strong); font-size: clamp(.65rem,.9vw,1rem); opacity: 0; animation: continue-bob 1s ease-in-out infinite; }
.continue-indicator.is-visible { opacity: 1; }
@keyframes continue-bob { 50% { transform: translateY(6px); } }

.quickbar { position: absolute; z-index: 3; right: 4.2%; top: -18%; width: min(48%, 840px); height: 23%; display: flex; align-items: center; justify-content: flex-end; gap: .7%; padding: .2% 2.2%; background: url('../assets/ui/quickbar/ui_quickbar_bg.png') center/100% 100% no-repeat; }
.quickbar button { position: relative; width: 12.4%; height: 82%; padding: 0; border: 0; background: transparent; cursor: pointer; opacity: .74; transition: opacity .2s, transform .2s var(--ease-spring), filter .2s; }
.quickbar button:hover, .quickbar button.is-active { opacity: 1; transform: translateY(-4px); filter: drop-shadow(0 4px 7px rgba(210,168,83,.45)); }
.quickbar button:active { transform: translateY(1px) scale(.94); }
.quickbar img { width: 42%; max-height: 56%; object-fit: contain; }
.quickbar span { display: block; color: var(--navy-800); font: 800 clamp(.38rem,.48vw,.58rem)/1 ui-monospace,monospace; letter-spacing: .05em; }

.choice-panel { position: absolute; z-index: 30; inset: 13% 19% 31%; display: flex; flex-direction: column; justify-content: center; filter: drop-shadow(0 24px 36px rgba(7,13,23,.35)); }
.choice-panel > p { margin: 0 auto 1.2%; padding: .55rem 1.4rem; border-radius: 999px; color: var(--cream); background: rgba(24,38,60,.86); font-weight: 800; letter-spacing: .12em; }
.choice-list { display: grid; gap: 3.5%; }
.choice-button { position: relative; width: 100%; min-height: clamp(54px,8.5vh,112px); padding: 1.1% 8%; border: 0; background: url('../assets/ui/dialogue/ui_choice_default.png') center/100% 100% no-repeat; color: var(--ink); cursor: pointer; font-size: clamp(.72rem,1.1vw,1.2rem); font-weight: 800; letter-spacing: .05em; opacity: 0; transform: translateY(18px) scale(.98); animation: choice-in .45s var(--ease-spring) forwards; transition: filter .18s, transform .18s; }
.choice-button:hover, .choice-button:focus-visible { background-image: url('../assets/ui/dialogue/ui_choice_hover.png'); transform: translateY(-2px) scale(1.012); filter: drop-shadow(0 8px 12px rgba(210,168,83,.26)); }
.choice-button:active { background-image: url('../assets/ui/dialogue/ui_choice_pressed.png'); transform: scale(.985); }
.choice-button::before { content: attr(data-key); position: absolute; left: 4%; top: 50%; translate: 0 -50%; color: var(--pink-strong); font: 900 1.15em/1 ui-monospace,monospace; }
@keyframes choice-in { to { opacity: 1; transform: none; } }

.ending-panel { position: absolute; z-index: 35; left: 20%; right: 20%; top: 18%; padding: 4.8% 7%; min-height: 48%; border-radius: 34px; color: var(--ink); text-align: center; background: url('../assets/ui/system/ui_modal_panel.png') center/100% 100% no-repeat; filter: drop-shadow(0 30px 50px rgba(6,13,24,.45)); animation: panel-in .5s var(--ease-spring); }
.ending-label { color: var(--pink-strong); font: 800 .7rem/1 ui-monospace,monospace; letter-spacing: .25em; }
.ending-panel h2 { color: var(--navy-800); font: 800 clamp(1.3rem,2.4vw,2.7rem)/1.2 "Noto Serif SC",serif; }
.ending-panel > p:not(.ending-label) { line-height: 1.8; }
.ending-state { display: inline-block; padding: .5rem 1rem; border: 1px solid rgba(34,49,76,.14); border-radius: 999px; background: rgba(242,184,199,.18); font-family: ui-monospace,monospace; }
.ending-actions { display: flex; justify-content: center; gap: 1rem; margin-top: 2rem; }
@keyframes panel-in { from { opacity: 0; transform: translateY(20px) scale(.96); } }

/* Modals */
.modal-layer { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 4vh 4vw; background: rgba(7,12,22,.68); backdrop-filter: blur(10px); }
.modal-card { position: relative; width: min(76vw, 1120px); height: min(72vh, 720px); padding: 4.5rem 5rem 4rem; color: var(--ink); background: url('../assets/ui/system/ui_modal_panel.png') center/100% 100% no-repeat; filter: drop-shadow(0 34px 60px rgba(0,0,0,.45)); animation: panel-in .35s var(--ease-spring); }
.modal-card header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 1.1rem; border-bottom: 1px solid rgba(34,49,76,.15); }
.modal-card header span { color: var(--pink-strong); font: 800 .7rem/1 ui-monospace,monospace; letter-spacing: .2em; }
.modal-card h2 { margin: .3rem 0 0; color: var(--navy-800); }
.modal-close { width: 48px; aspect-ratio: 1; border: 0; border-radius: 50%; color: var(--navy-800); background: rgba(242,184,199,.18); font-size: 1.8rem; cursor: pointer; }
.modal-close:hover { background: rgba(242,184,199,.4); rotate: 6deg; }
.log-content { height: calc(100% - 5rem); padding: 1rem .5rem 2rem 0; overflow-y: auto; user-select: text; }
.log-entry { padding: .8rem 1rem; border-left: 3px solid var(--pink); margin-bottom: .7rem; background: rgba(255,255,255,.45); }
.log-entry strong { display: block; color: var(--navy-700); font-size: .78rem; letter-spacing: .12em; }
.log-entry p { margin: .3rem 0 0; line-height: 1.7; }
.settings-grid { display: grid; gap: 1.4rem; margin-top: 2.2rem; }
.settings-grid label { display: grid; gap: .8rem; padding: 1.1rem 1.2rem; border-radius: 16px; background: rgba(255,255,255,.46); }
.settings-grid label > span { display: flex; justify-content: space-between; align-items: center; }
.settings-grid small { display: block; color: #7a8495; font-weight: 500; }
.settings-grid output { color: var(--pink-strong); font-family: ui-monospace,monospace; }
input[type="range"] { width: 100%; accent-color: var(--pink-strong); }
.toggle-row { grid-template-columns: 1fr auto !important; align-items: center; cursor: pointer; }
.toggle-row input { position: absolute; opacity: 0; }
.toggle-row i { width: 54px; height: 29px; padding: 3px; border-radius: 999px; background: #a8b0bb; transition: background .2s; }
.toggle-row i::before { content: ""; display: block; width: 23px; height: 23px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: translate .25s var(--ease-spring); }
.toggle-row input:checked + i { background: var(--pink-strong); }
.toggle-row input:checked + i::before { translate: 25px; }

.toast { position: fixed; z-index: 150; left: 50%; bottom: 4vh; translate: -50% 150%; padding: .75rem 1.3rem; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; color: #fff; background: rgba(20,32,52,.94); box-shadow: 0 12px 36px rgba(0,0,0,.28); opacity: 0; transition: translate .35s var(--ease-spring), opacity .3s; }
.toast.is-visible { translate: -50% 0; opacity: 1; }
.asset-error { position: fixed; z-index: 160; top: 1rem; left: 50%; translate: -50%; padding: .5rem 1rem; border-radius: 8px; background: #9a3348; color: #fff; }
noscript { position: fixed; inset: 0; z-index: 999; display: grid; place-items: center; color: #fff; background: #111c2f; }

@media (max-aspect-ratio: 16 / 9) {
  .screen { width: 100vw; height: auto; }
  .title-copy { left: 6%; }
  .dialogue-zone { left: 3%; right: 3%; }
}

@media (max-width: 600px) {
  .screen { width: 100vw; height: 100svh; aspect-ratio: auto; }
  .title-copy { left: 7%; right: 7%; top: 11%; width: auto; }
  .title-copy h1 { font-size: clamp(3.4rem, 19vw, 5.5rem); }
  .title-description { max-width: 75%; }
  .title-actions { flex-direction: column; width: 56%; }
  .menu-button { min-width: 0; width: 100%; }
  .title-character { right: -23%; bottom: -11%; width: 92%; height: 96%; opacity: .78; }
  .game-hud { top: 2%; left: 2%; right: 2%; }
  .character-rin { right: -14%; bottom: 8%; height: 83%; max-width: 90%; }
  .scene-backdrop .window-light { width: 62%; }
  .dialogue-zone { left: 1.5%; right: 1.5%; bottom: 1%; height: 31%; }
  .dialogue-box { padding: 10% 9% 5%; background-size: cover; border-radius: 18px; overflow: hidden; }
  .nameplate { top: -4%; width: 42%; height: 24%; }
  .dialogue-text { font-size: clamp(.82rem, 3.7vw, 1.05rem); line-height: 1.65; }
  .quickbar { left: 2%; right: 2%; top: -16%; width: 96%; height: 20%; }
  .quickbar span { display: none; }
  .quickbar img { width: 58%; max-height: 72%; }
  .choice-panel { inset: 17% 3% 32%; }
  .choice-list { gap: 2.2%; }
  .choice-button { min-height: 66px; padding-left: 14%; background-size: cover; border-radius: 14px; overflow: hidden; }
  .ending-panel { left: 4%; right: 4%; top: 18%; padding: 12% 8%; }
  .ending-actions { flex-direction: column; }
  .modal-card { width: 94vw; height: min(72vh, 720px); padding: 3.8rem 2rem 2rem; background-size: cover; border-radius: 24px; overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
