:root {
  --ink: #f2eadc;
  --muted: #bcae99;
  --panel: rgba(18, 15, 13, 0.83);
  --panel-strong: rgba(12, 10, 9, 0.94);
  --line: rgba(242, 234, 220, 0.18);
  --rust: #b46a35;
  --acid: #8aa06c;
  --cyan: #63a8b7;
  --danger: #ba493f;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: #080706;
  color: var(--ink);
  font-family: "Segoe UI", "Arial", sans-serif;
}

button {
  font: inherit;
}

.vn-shell {
  width: 100%;
  min-height: 100%;
  background: #080706;
}

.stage {
  --dialogue-edge: max(18px, calc((100vw - 1120px) / 2));
  --dialogue-width: min(1120px, calc(100vw - 36px));
  --sprite-height: min(74vh, 650px);
  --stage-image: none;
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 620px;
  overflow: hidden;
  isolation: isolate;
  background: #080706;
}

.stage::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 0;
  background: #080706;
  pointer-events: none;
}

.stage.illustration-mode::before {
  background-image: var(--stage-image);
  background-size: cover;
  background-position: center center;
  filter: blur(18px) brightness(0.36) saturate(0.88);
  transform: scale(1.08);
}

.layer,
.overlay-layer img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  pointer-events: none;
}

.bg {
  z-index: 1;
  filter: saturate(0.92) contrast(1.03);
}

.cg {
  z-index: 2;
}

.illustration-mode .bg,
.illustration-mode .cg {
  object-fit: contain;
  object-position: center center;
}

.overlay-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.overlay-layer img {
  opacity: var(--opacity, 0.55);
  mix-blend-mode: screen;
}

.sprite-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.sprite {
  --slot-flip: 1;
  --slot-shift: 0%;
  position: absolute;
  bottom: 0px;
  height: var(--sprite-height);
  width: auto;
  max-width: min(37vw, 430px);
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 26px 32px rgba(0, 0, 0, 0.72));
  transform-origin: bottom center;
  transform: translateX(var(--slot-shift)) scaleX(var(--slot-flip));
}

.sprite.mirror {
  --slot-flip: -1;
}

.sprite.left {
  left: calc(var(--dialogue-edge) + 18px);
}

.sprite.center {
  left: 50%;
  max-width: min(42vw, 520px);
  --slot-shift: -50%;
}

.sprite.right {
  right: calc(var(--dialogue-edge) + 18px);
  --slot-shift: -8%;
}

.sprite.small {
  opacity: 0.96;
}

.topbar {
  position: absolute;
  z-index: 8;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0));
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.brand-title {
  font-size: 22px;
  font-weight: 750;
  letter-spacing: 0;
}

.scene-badge {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tools button,
.choice-box button,
.ending-card button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(15, 13, 11, 0.72);
  color: var(--ink);
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.tools button:hover,
.choice-box button:hover,
.ending-card button:hover {
  border-color: rgba(242, 234, 220, 0.42);
  background: rgba(48, 38, 30, 0.82);
}

.tools button:active,
.choice-box button:active,
.ending-card button:active {
  transform: translateY(1px);
}

.stat-panel {
  position: absolute;
  z-index: 7;
  right: 18px;
  top: 74px;
  width: 220px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(10, 9, 8, 0.58);
  backdrop-filter: blur(8px);
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  color: var(--muted);
  font-size: 13px;
}

.stat-row b {
  color: var(--ink);
  min-width: 24px;
  text-align: right;
}

.dialogue {
  position: absolute;
  z-index: 9;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: var(--dialogue-width);
  min-height: 156px;
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.42);
}

.dialogue-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
}

.speaker {
  color: #f7d4a7;
  font-weight: 740;
  font-size: 15px;
}

.progress {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.text {
  margin: 0;
  font-size: 21px;
  line-height: 1.45;
  text-wrap: pretty;
}

.choice-box {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.choice-box button {
  min-height: 52px;
  text-align: left;
  color: #f7ead6;
  background: rgba(35, 28, 22, 0.84);
}

.choice-effects {
  display: block;
  color: var(--acid);
  font-size: 12px;
  margin-top: 5px;
}

.next-hit {
  position: absolute;
  z-index: 5;
  inset: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.scene-drawer {
  position: absolute;
  z-index: 10;
  top: 72px;
  left: 18px;
  width: min(420px, calc(100vw - 36px));
  max-height: calc(100vh - 260px);
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  padding: 10px;
}

.scene-drawer button {
  display: block;
  width: 100%;
  min-height: 38px;
  text-align: left;
  border: 0;
  border-bottom: 1px solid rgba(242, 234, 220, 0.08);
  background: transparent;
  color: var(--muted);
  padding: 8px 6px;
  cursor: pointer;
}

.scene-drawer button.current {
  color: var(--ink);
  background: rgba(180, 106, 53, 0.18);
}

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--ink);
}

.ending-modal {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
}

.ending-card {
  width: min(620px, 100%);
  border: 1px solid rgba(186, 73, 63, 0.54);
  background: rgba(16, 12, 10, 0.96);
  padding: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.ending-kicker {
  margin: 0 0 8px;
  color: var(--danger);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
}

.ending-card h2 {
  margin: 0 0 12px;
  font-size: 28px;
}

.ending-card p {
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .stage {
    --dialogue-edge: 10px;
    --sprite-height: min(50vh, 430px);
    min-height: 700px;
  }

  .stage.illustration-mode {
    background: #050403;
  }

  .stage.illustration-mode .bg,
  .stage.illustration-mode .cg {
    height: 100%;
    object-position: center center;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px;
  }

  .brand {
    flex-direction: column;
    gap: 3px;
  }

  .brand-title {
    font-size: 18px;
  }

  .tools {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 2px;
  }

  .tools button {
    flex: 0 0 auto;
    padding: 8px 9px;
    font-size: 13px;
  }

  .stat-panel {
    display: none;
  }

  .sprite {
    bottom: 0px;
    max-width: 54vw;
  }

  .sprite.left {
    left: -6px;
  }

  .sprite.right {
    right: 8px;
    --slot-shift: -18%;
  }

  .dialogue {
    left: 10px;
    right: 10px;
    transform: none;
    bottom: 10px;
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    min-height: 188px;
    padding: 14px;
    overflow: hidden;
  }

  .text {
    font-size: 18px;
    width: 100%;
    max-width: calc(100vw - 84px);
    overflow-wrap: anywhere;
  }

  .choice-box {
    grid-template-columns: 1fr;
    max-width: calc(100vw - 48px);
    min-width: 0;
  }

  .choice-box button,
  .speaker,
  .scene-meta {
    min-width: 0;
    overflow-wrap: anywhere;
  }
}
