:root {
  --bg: #0d1117;
  --panel: rgba(16, 21, 28, 0.72);
  --panel-2: rgba(28, 36, 48, 0.85);
  --line: rgba(120, 140, 165, 0.25);
  --ink: #e6edf3;
  --ink-dim: #aeb9c6;
  --accent: #f2a649;
  --accent-2: #6ea8fe;
  --good: #4ec97a;
  --bad: #e5604d;
  --mid: #d6a94e;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Full-bleed stage ───────────────────────────────── */
.layout {
  position: fixed;
  inset: 0;
  overflow: hidden;
}
.scene-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}
.scene-bg.bg-in { animation: bgfade 0.6s ease; }
@keyframes bgfade { from { opacity: 0; } to { opacity: 1; } }

/* Speaking-character cut-out, anchored bottom-left, behind the text panel. */
.sprite {
  --flip: 1; /* 1 = normal, -1 = mirrored (set by .right) */
  position: absolute;
  left: clamp(8px, 3vw, 60px);
  right: auto;
  bottom: 0;
  height: min(82vh, 760px);
  width: auto;
  max-width: 42vw;
  object-fit: contain;
  object-position: bottom;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.55));
  transform: scaleX(var(--flip));
  transition: opacity 0.25s ease, transform 0.25s ease;
}
/* Kitchen: stand on the right, mirrored to face into the scene. */
.sprite.right,
.sprite.winner {
  --flip: -1;
  left: auto;
  right: clamp(8px, 3vw, 60px);
}
.sprite.hidden { opacity: 0; transform: translateY(28px) scaleX(var(--flip)); }
.sprite.pop { animation: spritePop 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.3); }
@keyframes spritePop {
  0% { opacity: 0; transform: translateY(48px) scale(0.96) scaleX(var(--flip)); }
  100% { opacity: 1; transform: translateY(0) scale(1) scaleX(var(--flip)); }
}

/* Darkening gradients so overlay text stays readable over any art. */
.vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(7, 10, 14, 0.45) 0%, rgba(7, 10, 14, 0) 14%, rgba(7, 10, 14, 0) 100%);
}

/* ── HUD top strip (no bar — floats over art) ───────── */
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 22px;
}
.brand {
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--accent);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  font-size: 15px;
}
.day-label {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9);
  font-weight: 600;
}
.controls { display: flex; gap: 8px; margin-left: auto; }
.controls button {
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  backdrop-filter: blur(8px);
}
.controls button:hover { border-color: var(--accent); }
.controls button.toggle.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(242, 166, 73, 0.16);
}

/* Transparent Restart button, bottom-right. */
.restart-btn {
  position: absolute;
  z-index: 5;
  right: 18px;
  bottom: 16px;
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid rgba(120, 140, 165, 0.35);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.restart-btn:hover {
  color: var(--ink);
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
}

/* ── Overlay panels ─────────────────────────────────── */
/* All panels share one slot at the top-right; only one is open at a time. */
.panel {
  position: absolute;
  z-index: 4;
  top: 60px;
  right: 18px;
  left: auto;
  width: min(320px, calc(100vw - 36px));
  max-height: calc(100vh - 80px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow-y: auto;
  scrollbar-width: thin;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

/* Hidden state: slide off to the right and disable interaction. */
.panel.hidden { opacity: 0; pointer-events: none; transform: translateX(115%); }
.panel h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--ink-dim);
}

/* ── Center stage content ───────────────────────────── */
.stage {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(740px, calc(100vw - 48px));
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  scrollbar-width: thin;
}
.scene-body { padding: 22px 26px 24px; }
.scene-body h2 { margin: 6px 0 14px; font-size: 26px; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); }
.scene-body p { margin: 0 0 12px; color: #e3eaf2; }

/* Speaker nameplate above a spoken line. */
.nameplate {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin: 2px 0 8px;
  padding: 4px 12px;
  background: var(--accent);
  color: #1a1300;
  border-radius: 8px;
}
.nameplate b { font-size: 15px; }
.nameplate i { font-size: 12px; font-style: normal; opacity: 0.8; }

/* Dialogue lines. */
.line { margin: 0 0 12px; }
.line.narration { color: #cdd7e2; font-style: italic; }
.line.spoken {
  color: #fff;
  font-size: 18px;
  line-height: 1.55;
  border-left: 3px solid var(--accent);
  padding-left: 12px;
}

/* ── Choices ────────────────────────────────────────── */
.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 15px;
  transition: transform 0.06s ease, border-color 0.12s ease, background 0.12s ease;
}
.choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(40, 52, 68, 0.95);
  transform: translateY(-1px);
}
.choice .num {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--accent);
  margin-top: 1px;
}
.ctext { display: flex; flex-direction: column; gap: 2px; }
.hint { font-style: italic; color: var(--ink-dim); font-size: 13px; }
.choice.continue { justify-content: center; font-weight: 600; color: var(--accent); }
.choice.locked { opacity: 0.55; cursor: not-allowed; }
.lock { font-size: 12px; color: var(--accent); }

/* ── Inbox ──────────────────────────────────────────── */
.mail {
  border-left: 3px solid var(--accent-2);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.mail-from { font-size: 12px; color: var(--accent-2); font-weight: 600; }
.mail-subj { font-weight: 600; font-size: 14px; }
.mail-prev { font-size: 12px; color: var(--ink-dim); }
.mail.empty { border-left-color: var(--line); color: var(--ink-dim); font-size: 13px; }

/* ── Stats ──────────────────────────────────────────── */
.stat { margin-bottom: 12px; }
.stat-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.stat-val { font-variant-numeric: tabular-nums; color: var(--ink-dim); }
.bar { height: 8px; background: rgba(0, 0, 0, 0.45); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.fill { height: 100%; background: var(--accent-2); transition: width 0.4s ease; }
.stat.good .fill { background: var(--good); }
.stat.bad .fill { background: var(--bad); }
.stat.mid .fill { background: var(--accent); }

.recap-box { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 10px; }
.recap-box h4 { margin: 0 0 6px; font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; }
.recap-box ul { margin: 0; padding-left: 18px; font-size: 13px; }
.recap-box li.up { color: var(--good); }
.recap-box li.down { color: var(--bad); }

/* ── Relationships ──────────────────────────────────── */
.rel { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.rel img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.rel-info { display: flex; flex-direction: column; line-height: 1.2; }
.rel-info b { font-size: 14px; }
.rel-mood { font-size: 12px; }
.m-good { color: var(--good); }
.m-bad { color: var(--bad); }
.m-mid { color: var(--ink-dim); }

/* ── Ending ─────────────────────────────────────────── */
.ending-tag {
  display: inline-block;
  background: var(--accent);
  color: #1a1300;
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
}
.final-stats {
  margin: 14px 0;
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

/* ── Toasts ─────────────────────────────────────────── */
.toast-wrap {
  position: fixed;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  pointer-events: none;
  z-index: 60;
}
.toast {
  background: rgba(13, 17, 23, 0.88);
  border: 2px solid var(--line);
  padding: 14px 30px;
  border-radius: 99px;
  font-size: clamp(20px, 3vw, 30px);
  font-weight: 800;
  letter-spacing: 0.3px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(12px);
  white-space: nowrap;
  opacity: 0;
  transform-origin: center;
  animation: toastPop 1.9s cubic-bezier(0.18, 0.9, 0.32, 1.4) both;
}
.toast.up {
  color: var(--good);
  border-color: var(--good);
  text-shadow: 0 0 22px rgba(78, 201, 122, 0.6);
}
.toast.down {
  color: var(--bad);
  border-color: var(--bad);
  text-shadow: 0 0 22px rgba(229, 96, 77, 0.6);
}
@keyframes toastPop {
  0% { opacity: 0; transform: scale(0.4) translateY(14px) rotate(-8deg); }
  16% { opacity: 1; transform: scale(1.18) translateY(0) rotate(5deg); }
  28% { transform: scale(0.96) rotate(-3deg); }
  38% { transform: scale(1.04) rotate(2deg); }
  48% { transform: scale(1) rotate(0deg); }
  72% { opacity: 1; transform: scale(1) translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: scale(1.05) translateY(-70px) rotate(3deg); }
}

/* Animate the inner content only — never the .stage itself, which uses
   translateX(-50%) to stay centered; animating its transform makes it jump
   sideways. The content does a quick, smooth fade + rise. */
.stage.fade-in .scene-body {
  animation: beatIn 0.18s cubic-bezier(0.22, 0.61, 0.36, 1) both;
  will-change: opacity, transform;
}
@keyframes beatIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 1100px) {
  .stage { width: min(620px, calc(100vw - 40px)); }
  .panel { width: 240px; opacity: 0.96; }
}
@media (max-width: 820px) {
  html, body { overflow: auto; }
  .layout { position: relative; min-height: 100vh; }
  .panel, .stage {
    position: static;
    transform: none;
    width: auto;
    margin: 12px;
    max-height: none;
    bottom: auto;
  }
  .hud-top { position: sticky; background: rgba(7, 10, 14, 0.6); backdrop-filter: blur(8px); flex-wrap: wrap; }
  .scene-bg, .vignette { position: fixed; }
  .panel.hidden { display: none; }
}
