:root {
  color-scheme: dark;
  --ink: #f7f1e8;
  --ink-strong: #fffaf2;
  --muted: rgba(247, 241, 232, 0.72);
  --soft: rgba(247, 241, 232, 0.48);
  --line: rgba(255, 250, 242, 0.18);
  --panel: rgba(13, 14, 22, 0.78);
  --panel-strong: rgba(8, 9, 15, 0.9);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.48);
  --red: #d84b5f;
  --gold: #e6b85b;
  --cyan: #5cb7d4;
  --green: #62ba8e;
  --violet: #a98be8;
  --radius: 8px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dialogue-text-align: left;
  --sprite-slot-width: clamp(150px, 20vw, 300px);
  --sprite-slot-height: min(62vh, 620px);
  --sprite-content-scale: 1;
  --dialogue-panel-reserved-height: 232px;
  --choice-panel-gap: 20px;
  --dialogue-panel-clearance: calc(max(22px, env(safe-area-inset-bottom)) + var(--dialogue-panel-reserved-height));
  --lower-ui-clearance: calc(max(22px, env(safe-area-inset-bottom)) + var(--dialogue-panel-reserved-height) + var(--choice-panel-gap));
  --scene-bg-landscape: url("./public/images/visual-novel/narration_bg_birth_opening_landscape.webp");
  --scene-bg-portrait: url("./public/images/visual-novel/narration_bg_birth_opening_landscape.webp");
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: rgba(230, 184, 91, 0.18);
}

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

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family:
    Inter, "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", ui-sans-serif,
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 12%, rgba(216, 75, 95, 0.2), transparent 28%),
    radial-gradient(circle at 78% 18%, rgba(92, 183, 212, 0.16), transparent 30%),
    #080911;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 44px 44px;
  mix-blend-mode: screen;
  opacity: 0.5;
}

button {
  font: inherit;
  touch-action: manipulation;
}

button:focus-visible,
[tabindex]:focus-visible,
a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 20;
  padding: 9px 12px;
  color: #101018;
  font-weight: 900;
  background: var(--gold);
  border-radius: 6px;
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.game-shell {
  position: relative;
  z-index: 1;
  width: 100vw;
  height: 100svh;
  min-height: 620px;
  overflow: hidden;
  background: #070812;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#stage,
.stage {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: inherit;
  overflow: hidden;
  isolation: isolate;
  background: #0b0d16;
}

#sceneVeil {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
  background:
    radial-gradient(ellipse at center, transparent 34%, rgba(0, 0, 0, 0) 100%),
    linear-gradient(180deg, rgba(5, 6, 13, 0), rgba(5, 6, 13, 0));
  transition: background 380ms var(--ease);
}

#sceneBackdrop {
  position: absolute;
  inset: 0;
  z-index: -4;
  background:
    linear-gradient(to bottom, rgba(7, 8, 18, 0.04), rgba(7, 8, 18, 0.2) 48%, rgba(7, 8, 18, 0.82)),
    radial-gradient(circle at 26% 20%, rgba(230, 184, 91, 0.12), transparent 30%),
    radial-gradient(circle at 74% 38%, rgba(92, 183, 212, 0.1), transparent 34%),
    var(--scene-bg-landscape),
    linear-gradient(145deg, #272536, #0d101d 62%, #080911);
  background-position: center;
  background-size: cover;
  transform: scale(1.02);
  transition:
    filter 380ms var(--ease),
    opacity 380ms var(--ease);
}

#sceneBackdrop::before,
#sceneBackdrop::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
}

#sceneBackdrop::before {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 76px 76px;
  mask-image: linear-gradient(to bottom, transparent, #000 12%, #000 66%, transparent);
  opacity: 0.16;
}

#sceneBackdrop::after {
  background:
    radial-gradient(ellipse at center, transparent 42%, rgba(0, 0, 0, 0.48) 100%),
    linear-gradient(to top, rgba(0, 0, 0, 0.78), transparent 50%),
    linear-gradient(to right, rgba(0, 0, 0, 0.36), transparent 24%, transparent 76%, rgba(0, 0, 0, 0.36));
}

#fxLayer {
  position: absolute;
  inset: 0;
  z-index: -2;
  display: none;
  pointer-events: none;
  overflow: hidden;
}

#fxLayer::before,
#fxLayer::after {
  content: none;
}

#stage[data-mood] #fxLayer::before,
#stage[data-mood] #fxLayer::after,
#stage[data-bg] #fxLayer::before,
#stage[data-bg] #fxLayer::after {
  opacity: 0;
}

.topbar {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  z-index: 8;
  width: min(220px, calc(100vw - 32px));
  pointer-events: none;
}

.progress-card {
  width: 100%;
  padding: 9px 10px;
  background: rgba(5, 6, 12, 0.34);
  border: 1px solid rgba(255, 250, 242, 0.12);
  border-radius: var(--radius);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
}

.chapter-label {
  display: block;
  max-width: 100%;
  margin-bottom: 8px;
  overflow: hidden;
  color: var(--ink-strong);
  font-size: 0.7rem;
  font-weight: 900;
  line-height: 1.25;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.62);
}

.progress-track {
  width: 100%;
  height: 3px;
  overflow: hidden;
  background: rgba(255, 250, 242, 0.12);
  border-radius: 999px;
}

#progressFill {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--cyan));
  border-radius: inherit;
  box-shadow: 0 0 18px rgba(230, 184, 91, 0.42);
  transition: width 420ms var(--ease);
}

.progress-pips {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 5px;
  margin-top: 8px;
}

.progress-pip {
  display: block;
  aspect-ratio: 1;
  background: rgba(255, 250, 242, 0.14);
  border: 1px solid rgba(255, 250, 242, 0.1);
  border-radius: 2px;
}

.progress-pip.is-active {
  background: linear-gradient(135deg, var(--gold), var(--cyan));
  border-color: rgba(255, 250, 242, 0.36);
  box-shadow: 0 0 14px rgba(230, 184, 91, 0.32);
}

.admin-panel {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 12;
  width: min(320px, calc(100vw - 32px));
  color: var(--ink);
  font-size: 12px;
  cursor: default;
}

.admin-toggle {
  display: block;
  width: max-content;
  margin-left: auto;
  padding: 8px 10px;
  color: var(--ink-strong);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  list-style: none;
  background: rgba(5, 6, 12, 0.58);
  border: 1px solid rgba(255, 250, 242, 0.22);
  border-radius: 6px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
  cursor: pointer;
  backdrop-filter: blur(16px);
}

.admin-toggle::-webkit-details-marker {
  display: none;
}

.admin-controls {
  display: grid;
  gap: 10px;
  margin-top: 8px;
  padding: 10px;
  background: rgba(5, 6, 12, 0.82);
  border: 1px solid rgba(255, 250, 242, 0.18);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
}

.admin-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 800;
}

.admin-select {
  width: 100%;
  min-height: 34px;
  color: var(--ink-strong);
  font: inherit;
  background: rgba(255, 250, 242, 0.1);
  border: 1px solid rgba(255, 250, 242, 0.2);
  border-radius: 6px;
}

.admin-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.admin-button {
  min-height: 32px;
  padding: 7px 8px;
  color: var(--ink-strong);
  font-size: 11px;
  font-weight: 900;
  background: rgba(230, 184, 91, 0.16);
  border: 1px solid rgba(230, 184, 91, 0.28);
  border-radius: 6px;
  cursor: pointer;
}

.admin-button:hover,
.admin-button:focus-visible {
  background: rgba(230, 184, 91, 0.28);
}

#characterLayer {
  position: absolute;
  inset: 96px 4vw 220px;
  z-index: 2;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: clamp(16px, 4vw, 58px);
  pointer-events: none;
  transition:
    filter 240ms var(--ease),
    opacity 240ms var(--ease),
    transform 240ms var(--ease);
}

.sprite-wrap {
  position: relative;
  display: grid;
  flex: 0 0 var(--sprite-slot-width);
  width: var(--sprite-slot-width);
  height: var(--sprite-slot-height);
  min-height: 300px;
  place-items: end center;
  opacity: 0.78;
  filter: saturate(0.82) brightness(0.78);
  transform-origin: center bottom;
  animation: sprite-breathe 4.8s var(--ease) infinite;
  transition:
    filter 240ms var(--ease),
    opacity 240ms var(--ease),
    transform 240ms var(--ease);
}

.sprite-wrap:nth-child(2) {
  animation-delay: -1.4s;
}

.sprite-wrap:nth-child(3) {
  animation-delay: -2.6s;
}

.sprite-wrap[data-active="true"],
.sprite-wrap.is-active {
  opacity: 1;
  filter: saturate(1.08) brightness(1.08) drop-shadow(0 0 26px rgba(230, 184, 91, 0.3));
  transform: translateY(-6px);
}

.sprite-wrap.has-image,
.sprite-wrap.has-image.is-support,
.sprite-wrap.has-image.is-active {
  opacity: 1;
  filter: saturate(1) brightness(1);
}

.sprite-wrap.has-image.is-active {
  filter: saturate(1.08) brightness(1.08) drop-shadow(0 0 26px rgba(230, 184, 91, 0.3));
}

.sprite-wrap.has-image.is-support {
  filter: saturate(1) brightness(1);
}

.sprite-wrap::before {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 76%;
  height: 18%;
  content: "";
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.48), transparent 68%);
  transform: translateX(-50%);
  filter: blur(2px);
}

.sprite-wrap::after {
  position: relative;
  display: grid;
  width: 72%;
  height: 88%;
  place-items: center;
  color: rgba(255, 250, 242, 0.72);
  font-size: clamp(1.5rem, 3.2vw, 3rem);
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
  content: "H";
  background:
    radial-gradient(circle at 50% 15%, rgba(255, 237, 216, 0.98) 0 12%, transparent 12.5%),
    linear-gradient(130deg, transparent 0 21%, rgba(255, 250, 242, 0.62) 21% 30%, transparent 31%),
    linear-gradient(170deg, transparent 0 18%, rgba(25, 26, 36, 0.94) 18% 47%, rgba(84, 69, 87, 0.96) 47% 100%);
  border-radius: 44% 44% 12% 12% / 16% 16% 8% 8%;
  box-shadow:
    inset 0 0 0 1px rgba(255, 250, 242, 0.16),
    0 22px 54px rgba(0, 0, 0, 0.44);
  clip-path: polygon(31% 0, 69% 0, 83% 20%, 91% 100%, 10% 100%, 18% 20%);
}

.sprite-wrap.has-image::after {
  display: none;
}

.sprite-image {
  position: relative;
  z-index: 1;
  display: block;
  width: 118%;
  height: 95%;
  object-fit: contain;
  object-position: center bottom;
  opacity: 1;
  transform: scale(var(--sprite-content-scale));
  transform-origin: center bottom;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 26px 34px rgba(0, 0, 0, 0.48));
}

.sprite-wrap.is-support .sprite-image {
  opacity: 1;
  filter: drop-shadow(0 22px 30px rgba(0, 0, 0, 0.42));
}

.sprite-card {
  display: none;
}

.sprite-wrap[data-character="dahye_child"]::after {
  content: "D";
  background:
    radial-gradient(circle at 50% 14%, #ffe4cd 0 13%, transparent 13.5%),
    radial-gradient(circle at 31% 5%, #d84b5f 0 7%, transparent 7.5%),
    radial-gradient(circle at 69% 5%, #d84b5f 0 7%, transparent 7.5%),
    linear-gradient(165deg, transparent 0 20%, #f5c87d 20% 48%, #c95468 48% 100%);
}

.sprite-wrap[data-character="dahye_highschool"]::after {
  content: "D";
  background:
    radial-gradient(circle at 50% 13%, #ffe0c7 0 12%, transparent 12.5%),
    linear-gradient(105deg, transparent 0 24%, rgba(18, 18, 24, 0.96) 24% 34%, transparent 35%),
    linear-gradient(165deg, transparent 0 20%, #f4f1ea 20% 48%, #24324a 48% 100%);
}

.sprite-wrap[data-character="dahye_university"]::after {
  content: "D";
  background:
    radial-gradient(circle at 50% 13%, #f8d8c1 0 12%, transparent 12.5%),
    linear-gradient(180deg, #12131d 0 9%, transparent 9%),
    linear-gradient(160deg, transparent 0 19%, #1c1c27 19% 54%, #5cb7d4 54% 100%);
}

.sprite-wrap[data-character="heize_job"]::after {
  content: "H";
  background:
    radial-gradient(circle at 50% 13%, #f7d9bf 0 12%, transparent 12.5%),
    linear-gradient(180deg, #2d6ea6 0 8%, transparent 8%),
    linear-gradient(166deg, transparent 0 20%, #111722 20% 55%, #2a6f67 55% 100%);
}

.sprite-wrap[data-character="heize_battle"]::after {
  content: "H";
  background:
    radial-gradient(circle at 50% 13%, #f4d4bd 0 12%, transparent 12.5%),
    linear-gradient(180deg, #6e5232 0 9%, transparent 9%),
    linear-gradient(165deg, transparent 0 19%, #1c1721 19% 49%, #87d35f 49% 100%);
}

.sprite-wrap[data-character="professor"]::after {
  content: "P";
  background:
    radial-gradient(circle at 50% 13%, #f1d2bd 0 12%, transparent 12.5%),
    linear-gradient(160deg, transparent 0 20%, #323a46 20% 54%, #6f7a88 54% 100%);
}

.sprite-wrap[data-character="friend"]::after {
  content: "F";
  background:
    radial-gradient(circle at 50% 13%, #f3d7c4 0 12%, transparent 12.5%),
    linear-gradient(158deg, transparent 0 20%, #263c4a 20% 50%, #62ba8e 50% 100%);
}

.sprite-wrap[data-character="mother"]::after {
  width: 62%;
  height: 72%;
  content: "";
  background:
    radial-gradient(ellipse at 50% 12%, #3b2c2a 0 10%, transparent 10.5%),
    radial-gradient(ellipse at 50% 20%, #4b3735 0 15%, transparent 15.5%),
    linear-gradient(164deg, transparent 0 23%, #6d594d 23% 58%, #8d7768 58% 100%);
  border-radius: 48% 48% 12% 12% / 18% 18% 8% 8%;
  clip-path: polygon(34% 0, 66% 0, 79% 19%, 87% 100%, 13% 100%, 21% 19%);
  filter: brightness(0.74) drop-shadow(0 18px 24px rgba(0, 0, 0, 0.38));
}

.sprite-wrap[data-character="father"]::after {
  width: 64%;
  height: 74%;
  content: "";
  background:
    radial-gradient(ellipse at 50% 11%, #20242b 0 11%, transparent 11.5%),
    linear-gradient(180deg, #252a32 0 18%, transparent 18.5%),
    linear-gradient(164deg, transparent 0 22%, #1f2632 22% 56%, #343b47 56% 100%);
  border-radius: 46% 46% 12% 12% / 17% 17% 8% 8%;
  clip-path: polygon(33% 0, 67% 0, 80% 18%, 88% 100%, 12% 100%, 20% 18%);
  filter: brightness(0.72) drop-shadow(0 18px 24px rgba(0, 0, 0, 0.38));
}

.sprite-wrap[data-character="engineer"]::after {
  content: "E";
  background:
    radial-gradient(circle at 50% 13%, #efd2c0 0 12%, transparent 12.5%),
    linear-gradient(160deg, transparent 0 20%, #131721 20% 50%, #5cb7d4 50% 100%);
}

.sprite-wrap[data-character="brother_back"] {
  width: clamp(120px, 15vw, 210px);
}

.sprite-wrap[data-character="brother_back"]::after {
  width: 62%;
  height: 76%;
  content: "";
  background:
    radial-gradient(circle at 50% 10%, #11151c 0 11%, transparent 11.5%),
    linear-gradient(180deg, #141923 0 18%, transparent 18%),
    linear-gradient(164deg, transparent 0 19%, #1a202a 19% 54%, #283241 54% 100%);
  border-radius: 46% 46% 12% 12% / 16% 16% 8% 8%;
  clip-path: polygon(34% 0, 66% 0, 79% 17%, 86% 100%, 14% 100%, 21% 17%);
  filter: brightness(0.72) drop-shadow(0 18px 24px rgba(0, 0, 0, 0.38));
}

.sprite-wrap[data-character="host"]::after {
  content: "MC";
  background:
    radial-gradient(circle at 50% 13%, #ead0bd 0 12%, transparent 12.5%),
    linear-gradient(160deg, transparent 0 20%, #11131d 20% 50%, #d84b5f 50% 100%);
}

.sprite-wrap[data-character="rival"]::after {
  content: "R";
  background:
    radial-gradient(circle at 50% 13%, #f0d0bd 0 12%, transparent 12.5%),
    linear-gradient(160deg, transparent 0 20%, #201827 20% 50%, #a98be8 50% 100%);
}

.sprite-wrap[data-character="heize_ending"]::after {
  content: "H";
  background:
    radial-gradient(circle at 50% 13%, #f7d9c3 0 12%, transparent 12.5%),
    linear-gradient(155deg, transparent 0 19%, #f2f2f1 19% 42%, #d84b5f 42% 100%);
}

.dialogue-panel {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 9;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  grid-template-areas:
    "nameplate nameplate"
    "dialogue actions";
  gap: 12px 16px;
  max-width: 1080px;
  min-height: 168px;
  margin: 0 auto;
  padding: 28px 30px 24px;
  background:
    linear-gradient(180deg, rgba(18, 19, 29, 0.92), rgba(8, 9, 16, 0.91)),
    linear-gradient(90deg, rgba(230, 184, 91, 0.15), rgba(92, 183, 212, 0.11));
  border: 1px solid rgba(255, 250, 242, 0.18);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  cursor: pointer;
}

.dialogue-panel::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 250, 242, 0.16);
}

.nameplate {
  grid-area: nameplate;
}

#speaker {
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: min(100%, 280px);
  min-height: 28px;
  margin: -43px 0 0 2px;
  padding: 6px 12px;
  overflow: hidden;
  color: #101018;
  font-size: 0.82rem;
  font-weight: 900;
  background: linear-gradient(90deg, var(--gold), #fff3bc);
  border: 1px solid rgba(255, 250, 242, 0.42);
  border-radius: 999px;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 10px 30px rgba(230, 184, 91, 0.24);
}

#dialogue {
  grid-area: dialogue;
  min-width: 0;
  min-height: 5.1em;
  margin: 0;
  color: var(--ink-strong);
  font-size: clamp(1rem, 1.42vw, 1.18rem);
  font-weight: 650;
  line-height: 1.78;
  text-align: var(--dialogue-text-align);
  word-break: keep-all;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.game-shell[data-line-type="transition"] #characterLayer {
  opacity: 1;
  filter: saturate(1) brightness(1);
}

.game-shell[data-line-type="choice"] #characterLayer {
  opacity: 1;
  filter: saturate(1) brightness(1);
  transform: translateY(0);
}

.game-shell[data-line-type="response"] #characterLayer {
  opacity: 1;
  filter: saturate(1) brightness(1);
  transform: translateY(0);
}

.game-shell[data-line-type="transition"] #sceneBackdrop {
  transform: scale(1.045);
}

.game-shell[data-line-type="transition"] #sceneVeil {
  background:
    radial-gradient(ellipse at center, transparent 34%, rgba(0, 0, 0, 0.56) 100%),
    linear-gradient(180deg, rgba(5, 6, 13, 0.28), rgba(5, 6, 13, 0.58));
}

.game-shell[data-line-type="transition"] .dialogue-panel {
  max-width: 880px;
  min-height: 154px;
  overflow: hidden;
  text-align: var(--dialogue-text-align);
  background:
    linear-gradient(180deg, rgba(6, 7, 12, 0.9), rgba(10, 10, 16, 0.88)),
    linear-gradient(90deg, rgba(230, 184, 91, 0.16), rgba(216, 75, 95, 0.11));
  border-color: rgba(230, 184, 91, 0.28);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.62),
    inset 0 0 0 1px rgba(255, 250, 242, 0.08);
}

.game-shell[data-line-type="transition"] .dialogue-panel::after {
  position: absolute;
  top: 14px;
  right: 18px;
  padding: 4px 9px;
  color: rgba(255, 250, 242, 0.76);
  font-size: 0.62rem;
  font-weight: 950;
  line-height: 1;
  letter-spacing: 0;
  pointer-events: none;
  content: "CHAPTER";
  background: rgba(230, 184, 91, 0.14);
  border: 1px solid rgba(230, 184, 91, 0.32);
  border-radius: 999px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
}

.game-shell[data-line-type="transition"] .nameplate {
  justify-self: center;
}

.game-shell[data-line-type="transition"] #speaker {
  margin-left: 0;
}

.game-shell[data-line-type="transition"] #dialogue {
  min-height: 4.5em;
  text-align: var(--dialogue-text-align);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.72);
}

.game-shell[data-line-type="response"] .dialogue-panel {
  background:
    linear-gradient(180deg, rgba(18, 19, 29, 0.94), rgba(8, 9, 16, 0.92)),
    linear-gradient(90deg, rgba(230, 184, 91, 0.2), rgba(92, 183, 212, 0.09));
  border-color: rgba(230, 184, 91, 0.32);
  box-shadow:
    0 28px 90px rgba(0, 0, 0, 0.58),
    inset 0 1px 0 rgba(255, 250, 242, 0.14);
}

.dialogue-actions {
  grid-area: actions;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 8px;
}

.game-shell[data-line-type="transition"] .dialogue-actions {
  align-items: center;
}

.game-shell[data-line-type="resolved-ending"] .dialogue-panel {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "nameplate"
    "dialogue"
    "visual"
    "stats";
  max-width: 760px;
  min-height: 0;
  padding-bottom: 24px;
  background:
    linear-gradient(180deg, rgba(18, 19, 29, 0.9), rgba(8, 9, 16, 0.92)),
    linear-gradient(135deg, rgba(230, 184, 91, 0.2), rgba(216, 75, 95, 0.14), rgba(92, 183, 212, 0.12));
  box-shadow:
    0 30px 92px rgba(0, 0, 0, 0.66),
    inset 0 1px 0 rgba(255, 250, 242, 0.14);
}

.game-shell[data-line-type="resolved-ending"] .nameplate {
  justify-self: center;
}

.game-shell[data-line-type="resolved-ending"] .dialogue-actions {
  display: none;
}

.game-shell[data-line-type="resolved-ending"] #dialogue {
  min-height: 0;
  text-align: center;
}

.ending-visual {
  grid-area: visual;
  width: min(100%, 560px);
  margin: 0;
  overflow: hidden;
  justify-self: center;
  background: rgba(5, 6, 12, 0.46);
  border: 1px solid rgba(255, 250, 242, 0.18);
  border-radius: 8px;
  box-shadow:
    0 16px 46px rgba(0, 0, 0, 0.34),
    inset 0 1px 0 rgba(255, 250, 242, 0.1);
}

.ending-image {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  object-position: center;
}

.ending-stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 540px);
  padding: 4px;
  justify-self: center;
  background: linear-gradient(180deg, rgba(8, 9, 16, 0.92), rgba(8, 9, 16, 0.96));
  border-radius: 8px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.24);
}

.ending-stat {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  color: rgba(255, 250, 242, 0.86);
  background: rgba(5, 6, 12, 0.42);
  border: 1px solid rgba(255, 250, 242, 0.16);
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255, 250, 242, 0.08);
}

.ending-stat.is-dominant {
  color: var(--ink-strong);
  background: linear-gradient(135deg, rgba(230, 184, 91, 0.22), rgba(255, 250, 242, 0.08));
  border-color: rgba(230, 184, 91, 0.58);
}

.ending-stat-label {
  min-width: 0;
  overflow: hidden;
  font-size: 0.76rem;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ending-stat-value {
  color: var(--gold);
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
  font-weight: 950;
}

#nextButton {
  position: relative;
  display: inline-flex;
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: visible;
  color: var(--ink-strong);
  font-weight: 900;
  background: rgba(255, 250, 242, 0.08);
  border: 1px solid rgba(255, 250, 242, 0.2);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.72;
  box-shadow:
    0 0 0 1px rgba(255, 250, 242, 0.18),
    0 10px 24px rgba(0, 0, 0, 0.26);
  transition:
    background 180ms var(--ease),
    border-color 180ms var(--ease),
    transform 180ms var(--ease);
}

#nextButton::before {
  position: relative;
  z-index: 1;
  width: 9px;
  height: 9px;
  content: "";
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-1px, -1px);
}

#nextButton::after {
  position: absolute;
  inset: -6px;
  pointer-events: none;
  content: "";
  border: 1px solid rgba(230, 184, 91, 0.42);
  border-radius: 50%;
  opacity: 0.2;
  transform: scale(0.92);
  animation: next-cue-pulse 1800ms var(--ease) infinite;
}

#nextButton[hidden] {
  display: inline-flex !important;
  visibility: hidden;
}

#nextButton:hover {
  background: rgba(255, 250, 242, 0.16);
  border-color: rgba(255, 250, 242, 0.34);
  transform: translateY(-1px);
}

#choices {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  right: max(18px, env(safe-area-inset-right));
  bottom: var(--lower-ui-clearance);
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 960px;
  margin: 0 auto;
  counter-reset: choice;
}

#choices:not(.has-choices) {
  display: none;
}

#choices.has-choices::before {
  grid-column: 1 / -1;
  width: max-content;
  max-width: 100%;
  padding: 5px 10px;
  overflow: hidden;
  color: rgba(255, 250, 242, 0.78);
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  content: "SELECT";
  background: rgba(5, 6, 12, 0.62);
  border: 1px solid rgba(255, 250, 242, 0.16);
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(14px);
}

.choice-button {
  position: relative;
  counter-increment: choice;
  min-height: 54px;
  padding: 12px 14px;
  padding-left: 46px;
  padding-right: 44px;
  overflow-wrap: anywhere;
  color: var(--ink-strong);
  font-size: 1rem;
  font-weight: 850;
  line-height: 1.32;
  text-align: left;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.72);
  background: linear-gradient(180deg, rgba(10, 11, 18, 0.82), rgba(8, 9, 15, 0.72));
  border: 1px solid rgba(255, 250, 242, 0.3);
  border-radius: var(--radius);
  box-shadow:
    0 18px 46px rgba(0, 0, 0, 0.46),
    inset 0 1px 0 rgba(255, 250, 242, 0.1);
  cursor: pointer;
  animation: choice-in 420ms var(--ease) both;
  transition:
    background 180ms var(--ease),
    border-color 180ms var(--ease),
    box-shadow 180ms var(--ease),
    transform 180ms var(--ease);
  backdrop-filter: blur(16px);
}

.choice-button::before {
  position: absolute;
  top: 50%;
  left: 14px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  color: #101018;
  font-size: 0.68rem;
  font-weight: 950;
  line-height: 1;
  content: counter(choice, decimal-leading-zero);
  background: linear-gradient(135deg, var(--gold), #fff3bc);
  border-radius: 50%;
  box-shadow: 0 0 18px rgba(230, 184, 91, 0.28);
  transform: translateY(-50%);
}

.choice-label {
  display: block;
}

.choice-cursor {
  position: absolute;
  top: 50%;
  right: 16px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid var(--gold);
  opacity: 0;
  filter: drop-shadow(0 0 10px rgba(230, 184, 91, 0.5));
  transform: translateX(-6px) translateY(-50%);
  transition:
    opacity 180ms var(--ease),
    transform 180ms var(--ease);
}

.choice-button:nth-child(2) {
  animation-delay: 60ms;
}

.choice-button:nth-child(3) {
  animation-delay: 120ms;
}

.choice-button:nth-child(4) {
  animation-delay: 180ms;
}

.choice-button:hover,
.choice-button:focus-visible {
  background: linear-gradient(180deg, rgba(230, 184, 91, 0.28), rgba(216, 75, 95, 0.18));
  border-color: rgba(230, 184, 91, 0.58);
  box-shadow:
    0 20px 52px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(230, 184, 91, 0.26),
    inset 0 1px 0 rgba(255, 250, 242, 0.16);
  transform: translateY(-2px);
}

.choice-button:hover .choice-cursor,
.choice-button.is-focused .choice-cursor,
.choice-button:focus .choice-cursor,
.choice-button:focus-visible .choice-cursor {
  opacity: 1;
  transform: translateX(0) translateY(-50%);
}

.choice-cursor.is-visible {
  opacity: 1;
  transform: translateX(0) translateY(-50%);
}

.choice-button:disabled,
#nextButton:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

[hidden]:not(#nextButton) {
  display: none !important;
}

@keyframes sprite-breathe {
  0%,
  100% {
    translate: 0 0;
  }

  50% {
    translate: 0 -5px;
  }
}

@keyframes choice-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes next-cue-pulse {
  0%,
  100% {
    opacity: 0.2;
    transform: scale(0.92);
  }

  50% {
    opacity: 0.7;
    transform: scale(1.08);
  }
}

@media (max-width: 900px), (orientation: portrait) {
  :root {
    --sprite-slot-width: clamp(170px, 48vw, 280px);
    --sprite-slot-height: min(54svh, 560px);
    --dialogue-panel-reserved-height: min(31svh, 260px);
    --choice-panel-gap: 14px;
    --dialogue-panel-clearance: calc(max(10px, env(safe-area-inset-bottom)) + min(29svh, 232px) + 8px);
    --lower-ui-clearance: calc(max(10px, env(safe-area-inset-bottom)) + var(--dialogue-panel-reserved-height) + var(--choice-panel-gap));
  }

  body {
    overflow: hidden;
  }

  .game-shell {
    min-height: 100svh;
  }

  .topbar {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    width: min(240px, calc(100vw - 24px));
  }

  .progress-card {
    padding: 8px;
  }

  #characterLayer {
    top: 76px;
    right: 0;
    bottom: var(--dialogue-panel-clearance);
    left: 0;
    gap: 0;
    --sprite-slot-width: clamp(170px, 48vw, 280px);
    --sprite-slot-height: min(54svh, 560px);
  }

  .game-shell[data-line-type="choice"] #characterLayer {
    bottom: var(--lower-ui-clearance);
  }

  .sprite-wrap {
    min-height: 280px;
  }

  .sprite-wrap:nth-child(n + 3) {
    display: none;
  }

  #choices {
    bottom: var(--lower-ui-clearance);
    grid-template-columns: 1fr;
    gap: 8px;
    padding-bottom: 8px;
    max-height: none;
    overflow: visible;
    overscroll-behavior: contain;
    scrollbar-color: rgba(230, 184, 91, 0.72) rgba(5, 6, 12, 0.28);
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    box-shadow: inset 0 -18px 18px -18px rgba(230, 184, 91, 0.46);
  }

  #choices.has-choices::before {
    display: none;
  }

  .choice-button {
    min-height: 50px;
    padding: 10px 12px;
    padding-left: 44px;
    padding-right: 40px;
    font-size: 0.98rem;
    line-height: 1.3;
  }

  .dialogue-panel {
    grid-template-columns: minmax(0, 1fr) 34px;
    gap: 10px;
    min-height: 186px;
    padding: 24px 18px 17px;
  }

  .game-shell[data-line-type="choice"] .dialogue-panel {
    max-height: var(--dialogue-panel-reserved-height);
    overflow-y: auto;
  }

  .game-shell[data-line-type="resolved-ending"] .dialogue-panel {
    max-height: calc(100svh - 20px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  .ending-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    width: min(100%, 280px);
  }

  .ending-stat {
    gap: 5px;
    padding: 8px;
  }

  #speaker {
    margin-top: -30px;
  }

  #dialogue {
    min-height: 5.2em;
    font-size: clamp(1.02rem, 3.9vw, 1.12rem);
    line-height: 1.58;
  }

  .dialogue-actions {
    justify-content: center;
  }

  #nextButton {
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
  }

}

@media (max-width: 520px) {
  #characterLayer {
    --sprite-slot-width: max(174px, 58vw);
    top: 70px;
    right: -10vw;
    bottom: var(--dialogue-panel-clearance);
    left: -10vw;
  }

  .sprite-wrap {
    min-width: 174px;
  }

  #choices {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: var(--lower-ui-clearance);
  }

  .choice-button {
    min-height: 50px;
    font-size: 0.98rem;
  }

  .dialogue-panel {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    min-height: 188px;
    padding: 23px 15px 15px;
  }

  #dialogue {
    min-height: 5em;
    font-size: clamp(1.04rem, 4.4vw, 1.12rem);
  }
}

@media (max-width: 520px) and (max-height: 700px) {
  :root {
    --dialogue-panel-reserved-height: 220px;
    --choice-panel-gap: 8px;
    --lower-ui-clearance: calc(max(10px, env(safe-area-inset-bottom)) + var(--dialogue-panel-reserved-height) + var(--choice-panel-gap));
  }

  #choices {
    gap: 6px;
    max-height: none;
    padding-bottom: 6px;
  }

  .choice-button {
    min-height: 40px;
    padding: 8px 10px;
    padding-left: 38px;
    padding-right: 32px;
    font-size: 0.84rem;
    line-height: 1.22;
  }

  .choice-button::before {
    left: 10px;
    width: 20px;
    height: 20px;
    font-size: 0.62rem;
  }

  .choice-cursor {
    right: 11px;
  }

  .dialogue-panel {
    min-height: 208px;
    padding: 20px 14px 14px;
  }

  #dialogue {
    min-height: 4.6em;
    font-size: 0.92rem;
    line-height: 1.48;
  }
}

@media (max-height: 680px) and (orientation: landscape) {
  :root {
    --dialogue-panel-reserved-height: 168px;
    --choice-panel-gap: 16px;
    --lower-ui-clearance: calc(max(22px, env(safe-area-inset-bottom)) + var(--dialogue-panel-reserved-height) + var(--choice-panel-gap));
  }

  #characterLayer {
    top: 64px;
    right: 3vw;
    bottom: var(--lower-ui-clearance);
    left: 3vw;
    --sprite-slot-height: min(56vh, 430px);
  }

  .sprite-wrap {
    min-height: 230px;
  }

  #choices {
    bottom: var(--lower-ui-clearance);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 860px;
    max-height: min(42svh, 180px);
    padding-bottom: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-color: rgba(230, 184, 91, 0.72) rgba(5, 6, 12, 0.28);
    scrollbar-width: thin;
    box-shadow: inset 0 -16px 16px -16px rgba(230, 184, 91, 0.46);
  }

  .choice-button {
    min-height: 42px;
    padding: 9px 12px;
    font-size: 0.88rem;
  }

  .dialogue-panel {
    min-height: 132px;
    padding: 20px 22px 16px;
  }

  .game-shell[data-line-type="choice"] .dialogue-panel {
    max-height: var(--dialogue-panel-reserved-height);
    overflow-y: auto;
  }

  .game-shell[data-line-type="resolved-ending"] .dialogue-panel {
    max-height: calc(100svh - 16px);
    min-height: 0;
    overflow-y: auto;
  }

  .game-shell[data-line-type="resolved-ending"] .ending-stats {
    gap: 5px 8px;
    width: min(100%, 460px);
  }

  .game-shell[data-line-type="resolved-ending"] .ending-stat {
    padding: 6px 9px;
  }

  .game-shell[data-line-type="resolved-ending"] #dialogue {
    min-height: 3.4em;
    line-height: 1.48;
  }

  #speaker {
    margin-top: -27px;
  }

  #dialogue {
    min-height: 3.2em;
    font-size: 0.95rem;
    line-height: 1.55;
  }
}

@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;
  }
}
