:root {
  /* Nepal flag + prayer flag palette */
  --crimson: #dc143c;
  --blue: #003893;
  --flag-blue: #1f6fd1;
  --flag-red: #e23b3b;
  --flag-green: #2e9e5b;
  --flag-yellow: #f5c518;
  --marigold: #f39a1e;
  --cream: #fff8ec;
  --ink: #2a1a14;
  --muted: #7a6457;
  --font: "Nirmala UI", "Noto Sans Devanagari", "Kohinoor Devanagari", Mangal, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: #3a8ee0;
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas { position: fixed; inset: 0; display: block; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  overflow-y: auto;
  padding: 16px;
  background: linear-gradient(rgba(0, 25, 70, 0.2), rgba(0, 25, 70, 0.5));
  transition: opacity 0.3s ease;
  touch-action: pan-y;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.card {
  margin: auto;
  width: min(440px, 100%);
  background: var(--cream);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  text-align: center;
}
.card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: clamp(16px, 4vw, 26px) clamp(16px, 5vw, 30px);
}

/* Dhaka-weave inspired band */
.dhaka {
  height: 14px;
  background:
    linear-gradient(45deg, transparent 35%, var(--crimson) 35% 65%, transparent 65%) 0 0 / 14px 14px,
    linear-gradient(-45deg, transparent 35%, #1b1b1b 35% 65%, transparent 65%) 0 0 / 14px 14px,
    var(--marigold);
}

.kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);
}
h1 {
  font-size: clamp(48px, 14vw, 74px);
  font-weight: 800;
  line-height: 1.15;
  color: var(--crimson);
  text-shadow: 0 3px 0 var(--blue);
}
.latin { font-size: 13px; font-weight: 800; letter-spacing: 0.4em; color: var(--blue); margin-top: -6px; }
.tag { font-size: 15px; line-height: 1.5; color: var(--ink); max-width: 34ch; }

.how { list-style: none; display: grid; gap: 8px; width: 100%; margin: 4px 0 6px; }
.how li { display: flex; align-items: center; gap: 10px; text-align: left; font-size: 14px; line-height: 1.35; color: var(--ink); }
.how .num {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  background: var(--flag-blue);
}
.how li:nth-child(2) .num { background: #1f7a45; }
.how li:nth-child(3) .num { background: var(--marigold); color: var(--ink); }

.meta { font-size: 14px; font-weight: 700; letter-spacing: 0.08em; color: var(--muted); }
.meta b { color: var(--crimson); font-size: 18px; margin-left: 4px; }

.btn {
  font: inherit;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 0.06em;
  color: #fff;
  background: var(--crimson);
  border: 0;
  border-radius: 999px;
  padding: 13px 38px;
  min-width: 160px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--blue);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--blue); }
.btn.ghost { background: transparent; color: var(--blue); box-shadow: inset 0 0 0 2px var(--blue); }
.btn.ghost:active { transform: translateY(1px); }
.btn:focus-visible, .link:focus-visible, #mute:focus-visible { outline: 3px solid var(--flag-yellow); outline-offset: 3px; }

.link {
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--blue);
  background: none;
  border: 0;
  padding: 6px 10px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* Game over */
.big-ne { font-size: clamp(46px, 13vw, 66px); font-weight: 800; line-height: 1.15; color: var(--crimson); text-shadow: 0 3px 0 var(--blue); }
.sub { font-size: 16px; color: var(--muted); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; margin: 6px 0; }
.stats div { background: rgba(0, 56, 147, 0.06); border-radius: 12px; padding: 10px 6px; display: flex; flex-direction: column; gap: 2px; }
.stats b { font-size: 34px; line-height: 1.1; color: var(--ink); }
.stats span { font-size: 13px; color: var(--muted); }
.badge {
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  background: var(--flag-yellow);
  padding: 5px 14px;
  border-radius: 999px;
}
.badge.hidden { display: none; }
.row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }

/* Sound button */
#mute {
  position: fixed;
  z-index: 2;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: rgba(255, 248, 236, 0.9);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
#mute svg { width: 22px; height: 22px; fill: currentColor; }
#mute .off { display: none; }
#mute.muted .on { display: none; }
#mute.muted .off { display: block; }

/* Devanagari joins letters, so never space them apart */
:lang(ne) .kicker, :lang(ne) .meta, :lang(ne) .btn { letter-spacing: 0; }
:lang(ne) .kicker { font-size: 14px; }

@media (max-height: 520px) {
  .how, .tag { display: none; }
  h1 { font-size: 44px; }
  .card-body { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay, .btn { transition: none; }
}

/* ---------- Bato Harayo: night theme ---------- */
html, body { background: #04060f; }
.overlay { background: linear-gradient(rgba(2, 4, 15, 0.35), rgba(2, 4, 15, 0.75)); }
h1 { font-size: clamp(44px, 12vw, 66px); white-space: nowrap; }

/* HUD */
#hud {
  position: fixed; z-index: 2;
  top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: 68px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start;
}
#hud.hidden, #panel.hidden { display: none; }
.pill {
  font: inherit; font-weight: 800; font-size: 15px; color: #fff3d6;
  background: rgba(10, 14, 35, 0.75); border: 1px solid rgba(255, 220, 160, 0.25);
  border-radius: 999px; padding: 9px 16px;
}
.meters { display: grid; gap: 6px; background: rgba(10, 14, 35, 0.75); border: 1px solid rgba(255, 220, 160, 0.18); padding: 8px 12px; border-radius: 14px; }
.meter { display: grid; grid-template-columns: 56px 96px; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: #e9e2d0; }
.meter i { display: block; height: 8px; background: rgba(255, 255, 255, 0.15); border-radius: 4px; overflow: hidden; }
.meter b { display: block; height: 100%; width: 100%; background: #2e9e5b; transition: width 0.5s ease, background 0.5s; }
.meter.fear b { background: #e23b3b; }
#memBtn { cursor: pointer; }
#memBtn:focus-visible { outline: 3px solid var(--flag-yellow); outline-offset: 3px; }
#mute { background: rgba(10, 14, 35, 0.75); color: #fff3d6; border: 1px solid rgba(255, 220, 160, 0.25); }

/* Story panel */
#panel {
  position: fixed; z-index: 3; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(680px, 100%); max-height: 54vh;
  display: flex; flex-direction: column;
  background: linear-gradient(rgba(12, 14, 32, 0.9), rgba(6, 8, 20, 0.97));
  color: #f3ecdf; border-radius: 18px 18px 0 0;
  border-top: 1px solid rgba(255, 220, 160, 0.25);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}
#place { font-size: 14px; font-weight: 800; color: var(--marigold); margin-bottom: 8px; }
#lines { flex: 1 1 auto; min-height: 60px; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; padding-right: 4px; }
.line { font-size: 15.5px; line-height: 1.6; }
.line.say b { display: block; font-size: 13px; color: #ffcf7a; }
.line.thought {
  font-style: italic; color: #d4dcff;
  background: rgba(120, 140, 255, 0.1); border-left: 3px solid #8fa3ff;
  padding: 10px 14px; border-radius: 0 10px 10px 0;
}
.line.thought::before { content: attr(data-label); display: block; font-style: normal; font-size: 11px; font-weight: 800; color: #a9b8ff; }
.line.event { color: #ffb38a; font-weight: 700; }
.line.sys { font-size: 13px; color: #b3ab9b; }
#choices { display: flex; flex-wrap: wrap; gap: 6px 8px; margin-top: 10px; }
.choices-label { width: 100%; font-size: 12px; font-weight: 800; color: #b3ab9b; margin-top: 2px; }
.choice {
  font: inherit; font-size: 14.5px; font-weight: 700; line-height: 1.3; text-align: left;
  color: #fff3d6; background: rgba(255, 248, 236, 0.08);
  border: 1px solid rgba(255, 220, 160, 0.35); border-radius: 12px;
  padding: 8px 12px; cursor: pointer; transition: background 0.15s;
}
.choice.path { border-color: rgba(143, 163, 255, 0.55); background: rgba(143, 163, 255, 0.1); }
.choice:hover { background: rgba(255, 248, 236, 0.16); }
.choice:focus-visible { outline: 3px solid var(--flag-yellow); outline-offset: 2px; }
.choice:disabled { opacity: 0.45; cursor: default; }
.choice small { font-weight: 600; color: #b3ab9b; }

/* Walking fade */
#fade {
  position: fixed; inset: 0; z-index: 5; display: grid; place-items: center;
  background: #000; color: #cfc6b0; font-size: 18px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.45s ease;
}
#fade.on { opacity: 1; pointer-events: auto; }

/* Memory sheet + ending */
#memory h2 { font-size: 22px; color: var(--crimson); }
#memList { list-style: none; display: grid; gap: 8px; width: 100%; text-align: left; max-height: 50vh; overflow-y: auto; }
#memList li { font-size: 14px; line-height: 1.5; background: rgba(0, 56, 147, 0.06); border-radius: 10px; padding: 10px 12px; }
#memList li b { color: var(--blue); }
.stars { font-size: 34px; letter-spacing: 6px; color: #e0a800; line-height: 1; }
.stars .off { color: #d8cfc0; }
.over-thought { font-style: italic; color: #33408a; background: rgba(0, 56, 147, 0.07); border-left: 3px solid #5b6fd6; border-radius: 0 10px 10px 0; padding: 8px 12px; text-align: left; font-size: 15px; line-height: 1.5; }
.sub { line-height: 1.55; }

@media (prefers-reduced-motion: reduce) { #fade, .meter b { transition: none; } }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stats.three div { padding: 12px 10px; }
.stats.three b { font-size: clamp(16px, 4.8vw, 22px); white-space: nowrap; }
.stats.three span { font-size: 12px; }
.badge { padding: 6px 16px; }

/* ---------- Voices + conversation bubbles ---------- */
#voiceBtn {
  position: fixed; z-index: 4;
  top: max(14px, env(safe-area-inset-top)); right: calc(max(14px, env(safe-area-inset-right)) + 54px);
  width: 44px; height: 44px; display: grid; place-items: center; cursor: pointer;
  color: #fff3d6; background: rgba(10, 14, 35, 0.75); border: 1px solid rgba(255, 220, 160, 0.25); border-radius: 50%;
}
#voiceBtn svg { width: 22px; height: 22px; }
#voiceBtn .off { display: none; }
#voiceBtn.muted .on { display: none; }
#voiceBtn.muted .off { display: block; }
#voiceBtn:focus-visible { outline: 3px solid var(--flag-yellow); outline-offset: 3px; }
#mute { z-index: 4; }
#hud { right: 124px; }

.line.say, .line.me { max-width: 88%; padding: 8px 12px; border-radius: 14px; }
.line.say { align-self: flex-start; background: rgba(255, 255, 255, 0.07); border-bottom-left-radius: 4px; }
.line.me { align-self: flex-end; background: rgba(255, 207, 122, 0.16); border-bottom-right-radius: 4px; }
.line.me b { display: block; font-size: 13px; color: #9fd3ff; }
.line.thought { align-self: stretch; }
#lines { gap: 8px; }
#place { margin-bottom: 6px; }

/* Wide screens: story column on the right, scene fills the rest (no empty band under a small box) */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  #panel {
    left: auto; right: 0; top: 0; bottom: 0; transform: none;
    width: min(440px, 36vw); max-height: none;
    border-radius: 0; border-top: 0; border-left: 1px solid rgba(255, 220, 160, 0.2);
    padding: 74px 20px calc(18px + env(safe-area-inset-bottom));
    background: linear-gradient(rgba(10, 12, 28, 0.97), rgba(6, 8, 20, 0.99));
  }
  #place { font-size: 16px; }
  .line { font-size: 16px; }
  #choices { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .choice { width: 100%; }
  .choices-label { grid-column: 1 / -1; }
  .choices-label { margin-top: 4px; }
}

/* Panel header: place name + memory button (keeps the top bar to one row) */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.panel-head #place { margin: 0; }
.mini {
  font: inherit; font-size: 13px; font-weight: 800; color: #fff3d6; cursor: pointer;
  background: rgba(255, 248, 236, 0.08); border: 1px solid rgba(255, 220, 160, 0.3);
  border-radius: 999px; padding: 6px 14px; flex: none;
}
.mini:hover { background: rgba(255, 248, 236, 0.16); }
.mini:focus-visible { outline: 3px solid var(--flag-yellow); outline-offset: 2px; }
@media (max-width: 520px) {
  .pill { font-size: 14px; padding: 8px 12px; }
  .meters { padding: 7px 10px; gap: 5px; }
  .meter { grid-template-columns: 40px 64px; gap: 6px; }
}

/* Phone battery + badges */
.meter.batt b { background: #4aa3ff; width: 0; }
.badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 100%; }
.badges:empty { display: none; }
.badges-title { width: 100%; font-size: 13px; font-weight: 800; color: var(--muted); }
.chip { font-size: 12px; font-weight: 700; line-height: 1.3; padding: 5px 10px; border-radius: 999px; color: var(--muted); border: 1px dashed rgba(122, 100, 87, 0.55); }
.chip.on { color: var(--ink); background: var(--flag-yellow); border: 1px solid #d9a800; }
