/* Stapu chrome.
 *
 * Almost all of the colour in this game is in the canvas — the street is the
 * artwork. So the chrome here is deliberately the quietest of the three
 * games: no glass, no gloss, no cards. Everything floats over a live scene,
 * which per DESIGN.md means opaque-enough surfaces and no blur-everything.
 * The one place it's allowed to be expressive is the Devanagari, which leads
 * every emotional line with English sitting underneath it in a whisper. */

:root {
  --dusk: #1c1410;
  --ink: #f6ece0;
  --ink-mid: rgba(246, 236, 224, 0.72);
  --ink-dim: rgba(246, 236, 224, 0.5);
  --panel: rgba(28, 20, 16, 0.62);
  --line: rgba(255, 226, 186, 0.2);
  --chalk: #f2ead9;
  --gold: oklch(80% 0.14 82);
  --font-latin: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-hi: 'Noto Sans Devanagari', 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--dusk);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  font-family: var(--font-latin);
}

#stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

#world3d,
#scene,
#character3d,
#foreground {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

#world3d {
  z-index: 0;
  pointer-events: none;
  background: #87949c;
}

#scene {
  z-index: 2;
  touch-action: none;
  cursor: crosshair;
  filter: saturate(0.92) sepia(0.035);
}

#character3d {
  z-index: 3;
  pointer-events: none;
}

#foreground {
  z-index: 4;
  pointer-events: none;
}

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

/* Late-afternoon grade. Warm, but nowhere near a sepia filter — the PRD is
 * specific that the nostalgia has to come from the objects, not a brown wash
 * over everything. This is about 6% of a colour cast. */
#grade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  mix-blend-mode: soft-light;
  background: linear-gradient(160deg, rgba(255, 190, 110, 0.28) 0%, rgba(255, 190, 110, 0) 46%, rgba(60, 40, 90, 0.24) 100%);
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  background:
    radial-gradient(ellipse at 50% 62%, rgba(255, 216, 156, 0.06) 0%, rgba(255, 216, 156, 0) 42%),
    radial-gradient(ellipse at 50% 55%, transparent 44%, rgba(28, 14, 6, 0.16) 76%, rgba(16, 8, 4, 0.48) 100%);
}

/* --- Opening ------------------------------------------------------------ */

#intro {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #0b0806;
  transition: opacity 2.2s ease;
}

#intro.fading { opacity: 0; }
#intro.gone { display: none; }

#intro .clock {
  font-family: var(--font-hi);
  font-size: clamp(28px, 5.4vw, 48px);
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.5px;
  opacity: 0;
  animation: clockIn 3.4s ease forwards 0.7s;
}

#intro .clockEn {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  opacity: 0;
  animation: clockIn 3.4s ease forwards 1.5s;
}

@keyframes clockIn {
  0% { opacity: 0; }
  30%, 74% { opacity: 1; }
  100% { opacity: 0.9; }
}

/* --- Speech + callouts -------------------------------------------------- */

#speech, #callout {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8;
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(20, 8, 2, 0.75);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

#speech { bottom: 9%; }
#callout { top: 22%; }

#speech b, #callout b {
  display: block;
  font-family: var(--font-hi);
  font-weight: 600;
  color: var(--ink);
}

#speech b { font-size: clamp(20px, 3vw, 30px); }
#callout b { font-size: clamp(22px, 3.4vw, 34px); }

#speech i, #callout i {
  display: block;
  margin-top: 4px;
  font-style: normal;
  font-size: 12.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

#speech.hidden, #callout.hidden { opacity: 0; transform: translateX(-50%) translateY(6px); }

/* --- Progress: eight chalk pips ---------------------------------------- */

#progress {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  opacity: 0;
  transition: opacity 0.6s ease;
}

#progress.show { opacity: 1; }

#progress .pip {
  width: 15px;
  height: 15px;
  border-radius: 3px;
  border: 1.4px solid rgba(242, 234, 217, 0.34);
  font: 500 9px/13px var(--font-latin);
  text-align: center;
  color: var(--ink-dim);
}

#progress .pip.done {
  background: var(--chalk);
  border-color: var(--chalk);
  color: #2a1c12;
}

/* Never colour alone — the square he's on is also the only one that's
 * outlined heavier and lifted. */
#progress .pip.now {
  border-color: var(--gold);
  border-width: 2px;
  color: var(--gold);
  transform: translateY(-2px);
}

/* --- Hint line ---------------------------------------------------------- */

#hint {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  padding: 7px 14px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink-mid);
  font-size: 12.5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#hint.show { opacity: 1; }

/* --- HUD ---------------------------------------------------------------- */

#hud {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  display: flex;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#hud.show { opacity: 1; pointer-events: auto; }

#hud button {
  width: 38px;
  height: 38px;
  font-size: 16px;
  line-height: 1;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

#hud svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#hud svg path:first-child { fill: currentColor; stroke: none; }
#hud #resetBtn svg path:first-child,
#hud #helpBtn svg path:first-child,
#hud #characterBtn svg path:first-child { fill: none; stroke: currentColor; }
.soundOff, #muteBtn.muted .soundOn { display: none; }
#muteBtn.muted .soundOff { display: inline-block; }

#hud button:hover { border-color: rgba(255, 226, 186, 0.42); }
#hud button:active { transform: scale(0.94); }
#hud button:focus-visible,
#againBtn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* --- Who's playing ------------------------------------------------------ */

#chooser {
  position: absolute;
  inset: 0;
  z-index: 23;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11, 8, 6, 0.72);
  transition: opacity 0.35s ease;
}
#chooser.hidden { opacity: 0; pointer-events: none; }
.chooserInner {
  width: min(620px, 100%);
  padding: 24px 26px 18px;
  border-radius: 14px;
  background: rgba(28, 20, 16, 0.94);
  border: 1px solid var(--line);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.chooserHi { display: block; font-family: var(--font-hi); font-weight: 600; font-size: 26px; line-height: 1.2; }
.chooserEn { display: block; font-style: normal; color: var(--ink-dim); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; margin: 4px 0 18px; }
.chooserGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chooserCard {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 12px 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 226, 186, 0.04);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.15s ease, background 0.2s ease;
}
.chooserCard:hover { border-color: rgba(255, 226, 186, 0.42); background: rgba(255, 226, 186, 0.08); transform: translateY(-2px); }
.chooserCard.chosen { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.chooserCard:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.chooserCard img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 9px; background: #1c1410; }
.chooserName { font-family: var(--font-hi); font-weight: 600; font-size: 18px; line-height: 1.2; }
.chooserName small { display: block; font-family: var(--font-latin); font-weight: 400; font-size: 11.5px; color: var(--ink-mid); margin-top: 3px; }
.chooserNote { margin-top: 14px; font-size: 12px; color: var(--ink-dim); }
body.coarse .chooserNote kbd { display: none; }
@media (max-width: 720px) {
  .chooserInner { padding: 16px; }
  .chooserGrid { gap: 10px; }
  .chooserName { font-size: 15px; }
}

/* --- How to play -------------------------------------------------------- */

#controls {
  position: absolute;
  inset: 0;
  z-index: 21;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11, 8, 6, 0.55);
  transition: opacity 0.35s ease;
}
#controls.hidden { opacity: 0; pointer-events: none; }
#controls .controlsInner {
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 22px 26px 18px;
  border-radius: 14px;
  background: rgba(28, 20, 16, 0.92);
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.controlsHi { display: block; font-family: var(--font-hi); font-weight: 600; font-size: 24px; line-height: 1.2; }
.controlsEn { display: block; font-style: normal; color: var(--ink-dim); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; margin: 4px 0 12px; }
.controlsIntro { margin: 0 0 14px; font-family: var(--font-latin); font-size: 13px; line-height: 1.45; color: var(--ink-mid); }
.controlsList { display: grid; grid-template-columns: 92px 1fr; gap: 10px 14px; margin: 0; }
.controlsList dt { color: var(--gold); font-weight: 600; font-size: 13px; padding-top: 2px; }
.controlsList dd { margin: 0; font-size: 13px; line-height: 1.45; color: var(--ink-mid); }
.controlsList dd .keys { display: block; color: var(--ink); margin-bottom: 2px; font-size: 12.5px; }
.controlsList dd em { font-style: normal; display: block; }
.controlsList dd.split { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: start; }
.splitFig { width: 120px; height: 56px; }
.splitFig rect, .splitFig line { fill: none; stroke: var(--chalk); stroke-width: 2.2; stroke-linecap: round; opacity: 0.9; }
.splitFig text { fill: var(--chalk); font-family: var(--font-latin); font-size: 13px; font-weight: 600; opacity: 0.9; }
.splitFig .foot { fill: none; stroke: var(--gold); stroke-width: 1.8; }
kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  background: rgba(255, 226, 186, 0.08);
  font-family: var(--font-latin);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink);
}
.controlsKeys { margin-top: 16px; font-size: 12px; color: var(--ink-dim); }
.controlsGo { margin-top: 12px; font-size: 12.5px; color: var(--ink-mid); }
body.coarse .keysDesktop { display: none !important; }
body:not(.coarse) .keysTouch { display: none !important; }
@media (max-width: 720px) {
  .controlsList { grid-template-columns: 76px 1fr; gap: 8px 10px; }
  .controlsList dd.split { grid-template-columns: 90px 1fr; }
  .splitFig { width: 90px; height: 42px; }
}

/* --- Ending ------------------------------------------------------------- */

#endCard {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 8, 6, 0.86);
  transition: opacity 1.2s ease;
}

#endCard.hidden { opacity: 0; pointer-events: none; }

.endInner { text-align: center; padding: 0 24px; }

.endHi {
  display: block;
  font-family: var(--font-hi);
  font-size: clamp(26px, 4.2vw, 40px);
  font-weight: 600;
  color: var(--ink);
}

.endEn {
  display: block;
  margin-top: 6px;
  font-style: normal;
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.endStats {
  margin: 22px auto 26px;
  max-width: 420px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--ink-mid);
}

#againBtn {
  font-family: var(--font-hi);
  font-size: 17px;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: 999px;
  border: 1px solid rgba(255, 226, 186, 0.35);
  background: linear-gradient(180deg, rgba(255, 216, 156, 0.22), rgba(255, 186, 110, 0.1));
  color: var(--ink);
  cursor: pointer;
}

#againBtn .lat {
  font-family: var(--font-latin);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-left: 8px;
}

#againBtn:hover { border-color: var(--gold); }

/* --- Rotate gate -------------------------------------------------------- */

#rotateGate {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 32px;
  text-align: center;
  color: var(--ink);
  background: linear-gradient(180deg, #3a2718, #140d08);
}

#rotateGate b { font-family: var(--font-hi); font-size: 24px; font-weight: 600; }
#rotateGate i { font-style: normal; font-size: 13.5px; color: var(--ink-dim); max-width: 300px; }

@media (hover: none) and (pointer: coarse) and (orientation: portrait) and (max-width: 560px) {
  #rotateGate { display: flex; }
}

/* Bigger targets where there's no mouse; the whole HUD is icon-only anyway. */
@media (hover: none) {
  #hud button { width: 44px; height: 44px; }
  #hint { font-size: 11.5px; bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  #intro .clock, #intro .clockEn { animation-duration: 0.01ms; opacity: 1; }
  #speech, #callout, #progress, #hint, #hud, #endCard, #intro { transition-duration: 0.01ms; }
}
