:root {
  color-scheme: dark;
  --ink: #f4eadc;
  --muted: #bcae9e;
  --wine: #6d2638;
  --wine-bright: #a43f58;
  --gold: #d2b06e;
  --night: #100a0e;
  --panel: rgba(18, 11, 15, .91);
  --font-size: 21px;
}

* { box-sizing: border-box; }

html, body { width: 100%; min-height: 100%; margin: 0; }

body {
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: Manrope, Arial, sans-serif;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
[hidden] { display: none !important; }

.novel { min-height: 100svh; background: #100a0e; }

.title-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(180deg, rgba(9, 7, 11, .28), rgba(12, 6, 9, .86)),
    url("assets/backgrounds/BG-01D.webp") center/cover;
}

.title-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle at 50% 39%, transparent 5%, rgba(7, 4, 6, .56) 76%);
}

.curtain {
  position: absolute;
  inset-block: 0;
  width: 25vw;
  min-width: 170px;
  z-index: -1;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 8%, rgba(0,0,0,.16) 9% 16%),
    linear-gradient(90deg, #240b13, #651d30 45%, #2b0b16);
  box-shadow: 0 0 70px #080406;
}
.curtain-left { left: 0; clip-path: polygon(0 0, 100% 0, 77% 100%, 0 100%); }
.curtain-right { right: 0; transform: scaleX(-1); clip-path: polygon(0 0, 100% 0, 77% 100%, 0 100%); }

.title-glow {
  position: absolute;
  width: 56vw;
  height: 56vw;
  border-radius: 50%;
  background: rgba(232, 213, 174, .1);
  filter: blur(60px);
  z-index: -1;
}

.title-card { width: min(760px, 88vw); text-align: center; animation: title-in 1.1s both; }
.eyebrow, .modal-kicker { margin: 0; color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: .32em; text-transform: uppercase; }
.title-card h1 { margin: .08em 0 0; font: 600 clamp(68px, 11vw, 148px)/.78 "Cormorant Garamond", Georgia, serif; letter-spacing: -.055em; text-shadow: 0 5px 40px #080406; }
.subtitle { margin: 22px 0 0; font: italic 400 clamp(20px, 2.2vw, 30px)/1.2 "Cormorant Garamond", Georgia, serif; color: #e6d8c7; }
.title-rule { display: flex; align-items: center; justify-content: center; margin: 23px auto 17px; width: min(360px, 60vw); }
.title-rule::before, .title-rule::after { content: ""; height: 1px; flex: 1; background: linear-gradient(90deg, transparent, var(--gold)); }
.title-rule::after { transform: scaleX(-1); }
.title-rule span { width: 9px; height: 9px; margin: 0 13px; border: 1px solid var(--gold); transform: rotate(45deg); }
.author { margin: 0; color: var(--muted); font-size: 13px; letter-spacing: .17em; text-transform: uppercase; }
.title-actions { display: flex; justify-content: center; gap: 12px; margin-top: 40px; }
.button { min-width: 185px; border: 1px solid rgba(210,176,110,.5); padding: 14px 23px; border-radius: 2px; cursor: pointer; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; transition: .2s ease; }
.button-primary { color: #1a0d11; background: var(--gold); }
.button-primary:hover { background: #ead09a; transform: translateY(-2px); }
.button-quiet { background: rgba(22,11,16,.72); backdrop-filter: blur(8px); }
.button-quiet:hover { background: var(--wine); }
.edition { margin: 23px 0 0; color: rgba(244,234,220,.53); font-size: 11px; }
.corner-button { position: fixed; top: 20px; border: 0; background: transparent; cursor: pointer; color: rgba(255,255,255,.62); font-size: 12px; text-decoration: none; }
.title-settings { right: 22px; }
.title-back { left: 22px; }

.reader { width: 100vw; min-width: 0; height: 100svh; display: grid; grid-template-rows: 54px minmax(0, 1fr) 58px; overflow: hidden; background: #0d090c; }
.reader-bar { z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 0 max(14px, env(safe-area-inset-left)); border-bottom: 1px solid rgba(210,176,110,.16); background: rgba(16,10,14,.96); }
.bar-button { border: 0; background: transparent; cursor: pointer; }
.scene-button { justify-self: start; display: grid; padding: 4px 0; text-align: left; }
.scene-button span { color: var(--gold); font-size: 9px; letter-spacing: .16em; text-transform: uppercase; }
.scene-button strong { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 15px/1.2 "Cormorant Garamond", Georgia, serif; }
.reader-title { color: rgba(244,234,220,.55); font: 500 18px "Cormorant Garamond", Georgia, serif; letter-spacing: .11em; text-transform: uppercase; }
.bar-actions { justify-self: end; display: flex; align-items: center; gap: 18px; }
.icon-button { padding: 8px 0; color: var(--muted); font-size: 11px; }
.icon-button:hover { color: var(--ink); }
.shelf-link { text-decoration: none; }

.stage { position: relative; width: 100%; min-width: 0; min-height: 0; overflow: hidden; isolation: isolate; background: #1a1316; }
.background, .mass-layer { position: absolute; width: 100%; height: 100%; inset: 0; object-fit: cover; user-select: none; }
.background { z-index: -5; animation: bg-in .8s both; }
.mass-layer { z-index: -1; object-fit: contain; filter: drop-shadow(0 12px 14px rgba(0,0,0,.35)); animation: mass-in .65s both; }
.stage-wash { position: absolute; inset: 0; z-index: -4; pointer-events: none; background: linear-gradient(90deg, rgba(12,8,10,.18), transparent 30% 70%, rgba(12,8,10,.18)), linear-gradient(0deg, rgba(10,6,9,.65), transparent 40%); }
.grain { position: absolute; inset: 0; z-index: 7; pointer-events: none; opacity: .12; mix-blend-mode: soft-light; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 160 160' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E"); }

.sprite-slot { position: absolute; z-index: 1; bottom: 0; width: 47%; height: 94%; display: flex; align-items: flex-end; justify-content: center; pointer-events: none; transition: opacity .3s, filter .3s; }
.sprite-slot img { display: block; max-width: 100%; width: auto; height: 100%; object-fit: contain; object-position: center bottom; filter: drop-shadow(0 14px 15px rgba(0,0,0,.42)); animation: sprite-in .35s both; }
.sprite-left { left: 1%; }
.sprite-right { right: 1%; }
.sprite-single { left: 50%; transform: translateX(-50%); width: 48%; }
.sprite-slot.listener { filter: brightness(.72) saturate(.78); opacity: .82; }
.sprite-slot.active { filter: brightness(1.04); opacity: 1; z-index: 2; }
.stage.mass-mode .sprite-slot { opacity: 0; }

.dialogue-panel { position: absolute; z-index: 10; left: clamp(16px, 6vw, 96px); right: clamp(16px, 6vw, 96px); bottom: 19px; min-height: 154px; padding: 20px 61px 21px 27px; border: 1px solid rgba(210,176,110,.34); background: var(--panel); box-shadow: 0 18px 60px rgba(0,0,0,.46), inset 3px 0 0 var(--wine-bright); backdrop-filter: blur(16px) saturate(.8); }
.dialogue-panel::before { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(255,255,255,.045); pointer-events: none; }
.dialogue-panel.narration { background: rgba(30,22,22,.89); box-shadow: 0 18px 60px rgba(0,0,0,.46), inset 3px 0 0 var(--gold); }
.speaker-row { position: relative; display: flex; align-items: baseline; justify-content: space-between; gap: 15px; margin-bottom: 7px; }
.speaker-row h2 { margin: 0; color: #e3c37f; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; }
.speaker-row span { color: rgba(244,234,220,.38); font-size: 9px; }
.dialogue-text { position: relative; min-width: 0; min-height: 2.9em; max-height: 5.5em; overflow-y: auto; overflow-wrap: break-word; padding-right: 5px; font: 500 var(--font-size)/1.42 "Cormorant Garamond", Georgia, serif; letter-spacing: .003em; text-wrap: pretty; scrollbar-width: thin; }
.narration .dialogue-text { color: #ded0be; font-style: italic; }
.advance-hitbox { position: absolute; z-index: 2; right: 0; bottom: 0; width: 56px; height: 56px; border: 0; background: transparent; cursor: pointer; }
.continue-mark { position: absolute; z-index: 3; right: 27px; bottom: 24px; width: 9px; height: 9px; border-right: 2px solid var(--gold); border-bottom: 2px solid var(--gold); transform: rotate(45deg); animation: pulse-down 1.1s infinite; pointer-events: none; }
.scene-card { position: absolute; z-index: 12; left: 50%; top: 43%; transform: translate(-50%,-50%); width: min(580px, 76vw); padding: 25px; text-align: center; color: var(--ink); background: rgba(18,10,14,.84); border-block: 1px solid rgba(210,176,110,.5); backdrop-filter: blur(10px); animation: scene-card 2.4s both; }
.scene-card span { display: block; color: var(--gold); font-size: 10px; letter-spacing: .25em; text-transform: uppercase; }
.scene-card strong { display: block; margin-top: 8px; font: 500 clamp(28px,5vw,50px)/1 "Cormorant Garamond", Georgia, serif; }

.reader-controls { z-index: 20; width: 100%; min-width: 0; display: grid; grid-template-rows: 3px 1fr; background: rgba(16,10,14,.98); border-top: 1px solid rgba(210,176,110,.12); }
.progress-track { background: rgba(255,255,255,.06); }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--wine-bright), var(--gold)); transition: width .3s ease; }
.control-row { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 8px; padding: 6px max(14px, env(safe-area-inset-left)); }
.control-button { min-width: 72px; height: 36px; padding: 0 16px; border: 1px solid rgba(255,255,255,.12); border-radius: 2px; background: rgba(255,255,255,.035); cursor: pointer; color: var(--muted); font-size: 11px; font-weight: 600; }
.control-button:hover, .control-button[aria-pressed="true"] { color: var(--ink); border-color: rgba(210,176,110,.45); background: rgba(109,38,56,.35); }
.control-next { color: #1b1114; background: var(--gold); border-color: var(--gold); }
.control-next:hover { color: #1b1114; background: #ead09a; }
.hint { justify-self: center; margin: 0; color: rgba(244,234,220,.38); font-size: 10px; }

.modal { width: min(900px, calc(100vw - 28px)); max-height: min(82svh, 760px); padding: 0; overflow: hidden; color: var(--ink); border: 1px solid rgba(210,176,110,.34); background: #181015; box-shadow: 0 25px 100px rgba(0,0,0,.75); }
.modal::backdrop { background: rgba(8,5,7,.78); backdrop-filter: blur(7px); }
.modal-shell { max-height: inherit; display: grid; grid-template-rows: auto minmax(0,1fr); margin: 0; }
.modal-shell > header { display: flex; align-items: center; justify-content: space-between; padding: 20px 23px; border-bottom: 1px solid rgba(255,255,255,.08); }
.modal h2 { margin: 3px 0 0; font: 500 30px "Cormorant Garamond", Georgia, serif; }
.close-button { border: 0; padding: 8px; background: transparent; cursor: pointer; color: var(--muted); font-size: 11px; }
.scene-list, .history-list { overflow-y: auto; padding: 14px 22px 24px; }
.act-group h3 { position: sticky; top: -14px; z-index: 2; margin: 0 -8px 7px; padding: 14px 8px 7px; color: var(--gold); background: #181015; font-size: 10px; letter-spacing: .2em; text-transform: uppercase; }
.scene-item { width: 100%; display: grid; grid-template-columns: 50px 1fr auto; align-items: center; gap: 12px; padding: 12px 8px; color: var(--ink); text-align: left; border: 0; border-bottom: 1px solid rgba(255,255,255,.06); background: transparent; cursor: pointer; }
.scene-item:hover, .scene-item.current { background: rgba(210,176,110,.07); }
.scene-item span { color: var(--gold); font: 500 16px "Cormorant Garamond", Georgia, serif; }
.scene-item strong { font-size: 12px; font-weight: 500; }
.scene-item small { color: rgba(244,234,220,.38); font-size: 9px; }
.history-entry { display: grid; grid-template-columns: 120px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.history-entry strong { color: var(--gold); font-size: 10px; letter-spacing: .05em; text-transform: uppercase; }
.history-entry p { margin: 0; color: #dfd2c2; font: 18px/1.35 "Cormorant Garamond", Georgia, serif; }
.settings-shell { grid-template-rows: auto auto auto auto auto; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 18px 23px; border-bottom: 1px solid rgba(255,255,255,.06); }
.setting-row span { display: grid; gap: 4px; }
.setting-row strong { font-size: 12px; }
.setting-row small { color: var(--muted); font-size: 10px; }
.setting-row input[type="range"] { width: min(230px, 37vw); accent-color: var(--gold); }
.toggle-row input { width: 42px; height: 22px; accent-color: var(--wine-bright); }
.danger-button { justify-self: start; margin: 21px 23px; padding: 10px 14px; color: #dba4a4; border: 1px solid rgba(190,82,82,.35); background: transparent; cursor: pointer; font-size: 10px; }

.ending { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: linear-gradient(rgba(8,5,7,.72), rgba(8,5,7,.94)), url("assets/backgrounds/BG-04B.webp") center/cover; }
.ending-card { text-align: center; animation: title-in 1.5s both; }
.ending-card p { margin: 0; color: var(--gold); font-size: 10px; letter-spacing: .35em; text-transform: uppercase; }
.ending-card h2 { margin: 24px 0; font: italic 400 clamp(40px,7vw,84px)/.96 "Cormorant Garamond", Georgia, serif; }
.ending-card span { display: block; margin-bottom: 38px; color: var(--muted); font-size: 11px; letter-spacing: .15em; text-transform: uppercase; }
.toast { position: fixed; z-index: 200; top: 70px; left: 50%; transform: translateX(-50%); padding: 10px 16px; border: 1px solid rgba(210,176,110,.3); background: rgba(18,11,15,.94); color: var(--ink); font-size: 11px; }

@keyframes title-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes bg-in { from { opacity: .35; transform: scale(1.025); } to { opacity: 1; transform: scale(1); } }
@keyframes sprite-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes mass-in { from { opacity: 0; transform: scale(.985); } to { opacity: 1; transform: scale(1); } }
@keyframes scene-card { 0%,100% { opacity: 0; } 15%,78% { opacity: 1; } }
@keyframes pulse-down { 0%,100% { opacity: .25; transform: translateY(-2px) rotate(45deg); } 50% { opacity: 1; transform: translateY(3px) rotate(45deg); } }

@media (max-width: 760px) {
  .reader { grid-template-rows: 48px minmax(0,1fr) 55px; }
  .reader-title, .hint, #fullscreenButton { display: none; }
  .reader-bar { grid-template-columns: 1fr auto; }
  .scene-button { min-width: 0; }
  .bar-actions { min-width: 0; gap: 8px; }
  .icon-button { font-size: 9px; }
  .sprite-slot { width: 72%; height: 82%; }
  .sprite-left { left: -15%; }
  .sprite-right { right: -15%; }
  .sprite-single { width: 78%; }
  .dialogue-panel { left: 9px; right: 9px; bottom: 9px; min-height: 175px; padding: 17px 45px 18px 18px; }
  .dialogue-text { max-height: 6.8em; font-size: var(--font-size); }
  .continue-mark { right: 18px; bottom: 19px; }
  .control-row { grid-template-columns: auto auto 1fr auto; padding-inline: 8px; }
  .control-button { min-width: 58px; padding-inline: 10px; }
  .title-actions { flex-direction: column; align-items: center; }
  .title-card h1 { font-size: clamp(58px, 20vw, 92px); }
  .curtain { width: 18vw; min-width: 80px; }
  .history-entry { grid-template-columns: 90px 1fr; }
}

@media (max-height: 580px) and (orientation: landscape) {
  .reader { grid-template-rows: 42px minmax(0,1fr) 47px; }
  .dialogue-panel { bottom: 8px; min-height: 116px; padding-block: 12px; }
  .dialogue-text { max-height: 3em; }
  .sprite-slot { height: 104%; }
  .reader-title, .hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
