/* ==========================================================================
   Super Kerala – UI styles
   Canvas fills the screen; menus are DOM overlays styled after a Kerala
   kasavu sari (cream + gold borders) on a sunset-plum backdrop.
   ========================================================================== */

:root {
  --gold: #f6c453;
  --gold-deep: #c98a2b;
  --cream: #fff4de;
  --ink: #26131f;
  --plum: #2a1747;
  --panel: rgba(34, 16, 38, 0.82);
  --line: rgba(246, 196, 83, 0.55);
  --muted: rgba(255, 244, 222, 0.72);
  --radius: 18px;
  --font: "Baloo Chettan 2", "Noto Sans Malayalam", "Malayalam Sangam MN", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--plum);
  color: var(--cream);
  font-family: var(--font);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none; /* taps go straight to the game, no scroll/zoom */
}

#vignette,
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none; /* input still lands on #game */
}
#hud { display: block; width: 100%; height: 100%; }
#vignette {
  background: radial-gradient(farthest-corner circle at 50% 50%,
    rgba(14, 8, 28, 0) 45%, rgba(14, 8, 28, 0.18) 78%, rgba(14, 8, 28, 0.55) 100%);
}

/* ?fps frame-time meter (game.js Perf) */
#fps-meter {
  position: fixed;
  left: calc(env(safe-area-inset-left) + 6px);
  bottom: calc(env(safe-area-inset-bottom) + 6px);
  z-index: 9999;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #9dffa8;
  font: 600 11px/1.3 ui-monospace, Menlo, monospace;
  pointer-events: none;
}
#fps-meter.slow { color: #ffb36b; }

/* Used by JS to read safe-area insets for the canvas HUD */
#safe-probe {
  position: fixed;
  inset: 0;
  pointer-events: none;
  visibility: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.hidden { display: none !important; }

/* ---------- overlay screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at center, rgba(20, 8, 24, 0.15) 0%, rgba(20, 8, 24, 0.6) 100%);
  overflow-y: auto;
  z-index: 6;
  animation: fade-in 0.25s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.panel {
  position: relative;
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 26px 22px 20px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1.5px solid var(--line);
  box-shadow:
    0 0 0 5px rgba(255, 244, 222, 0.05),
    0 20px 60px rgba(10, 0, 20, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.3s cubic-bezier(.2, .8, .2, 1);
}

/* kasavu stripe along the top edge */
.panel::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 8px;
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--gold) 12%, var(--cream) 50%, var(--gold) 88%, transparent);
  opacity: 0.8;
}

@keyframes rise {
  from { transform: translateY(14px) scale(0.98); opacity: 0; }
  to { transform: none; opacity: 1; }
}

h2 {
  margin: 4px 0 0;
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 800;
  color: var(--gold);
  text-align: center;
  line-height: 1.2;
}

/* ---------- title ---------- */
.title-block { text-align: center; }

.title-ml {
  font-size: clamp(46px, 13vw, 78px);
  font-weight: 800;
  line-height: 1.1;
  background: linear-gradient(180deg, #fff1b8 0%, var(--gold) 45%, var(--gold-deep) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(60, 20, 30, 0.6));
  padding-top: 6px;
}

.title-en {
  margin: 0;
  font-size: clamp(16px, 4vw, 20px);
  font-weight: 700;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--cream);
}

.subtitle {
  margin: 2px 0 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--gold);
}

.tagline {
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 0;
  min-height: 52px;
  padding: 10px 18px;
  border-radius: 14px;
  font: 700 18px/1.15 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:active { transform: translateY(2px) scale(0.98); }

.btn:focus-visible,
.segmented button:focus-visible,
.village-card:focus-visible,
.icon-btn:focus-visible,
.menu-card:focus-visible,
.mini-card:focus-visible,
.link-btn:focus-visible,
.text-input:focus-visible {
  outline: 3px solid var(--cream);
  outline-offset: 2px;
}

.btn-primary {
  color: var(--ink);
  background: linear-gradient(180deg, #ffe08f 0%, var(--gold) 50%, var(--gold-deep) 100%);
  box-shadow: 0 4px 0 #8a5a1a, 0 8px 22px rgba(246, 196, 83, 0.28);
}

.btn-primary:hover { box-shadow: 0 4px 0 #8a5a1a, 0 10px 28px rgba(246, 196, 83, 0.45); }
.btn-primary:active { box-shadow: 0 2px 0 #8a5a1a; }

.btn-xl {
  min-height: 62px;
  font-size: 24px;
  font-weight: 800;
}

.btn-secondary {
  color: var(--cream);
  background: rgba(255, 244, 222, 0.08);
  border: 1.5px solid var(--line);
}

.btn-secondary:hover { background: rgba(255, 244, 222, 0.15); }

.btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
  flex: none;
}

/* ---------- popup close (×) ----------
   First child of a .panel: sticky, so it stays in the corner while a long panel scrolls,
   and its negative margins keep it out of the flow so the title stays centred. */
.panel-close {
  position: sticky;
  top: 0;
  z-index: 3;
  align-self: flex-end;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  margin: -14px -8px -58px 0;   /* -58 = its own 44px + the panel's 14px gap */
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid rgba(246, 196, 83, 0.45);
  background: rgba(20, 8, 24, 0.55);
  color: var(--cream);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
.panel-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.panel-close:hover { background: var(--gold); border-color: var(--gold); color: var(--ink); transform: rotate(90deg); }
.panel-close:active { transform: scale(0.92); }
.panel-close:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
/* keep titles clear of the × */
.panel > .panel-close:not(.hidden) ~ h2,
.panel > .panel-close:not(.hidden) ~ .panel-head,
.panel > .panel-close:not(.hidden) ~ .online-view > h2 { padding-inline: 44px; }
.panel > .panel-close:not(.hidden) ~ .online-view > h2 + .hint { padding-inline: 44px; }
@media (prefers-reduced-motion: reduce) { .panel-close:hover { transform: none; } }

/* × on the newspaper / letter sheet: ink on paper */
.paper-x {
  position: sticky;
  top: 0;
  float: right;
  z-index: 2;
  width: 40px;
  height: 40px;
  margin: -10px -10px 0 8px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid rgba(43, 33, 24, 0.35);
  background: rgba(255, 250, 238, 0.85);
  color: #2b2118;
  cursor: pointer;
  touch-action: manipulation;
}
.paper-x svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.paper-x:hover { background: #2b2118; color: #f3ead6; }
.paper-x:focus-visible { outline: 3px solid #2b2118; outline-offset: 2px; }

/* popup header: small kicker over the title */
.panel-head { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.panel-head h2 { margin: 0; }
.panel-head .hint { margin: 2px 0 0; max-width: 46ch; }
.panel-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  border: 1px solid rgba(246, 196, 83, 0.4);
  background: rgba(246, 196, 83, 0.1);
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.panel-kicker:empty { display: none; }

/* sticky action bar at the bottom of a popup */
.panel-foot {
  display: flex;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid rgba(246, 196, 83, 0.2);
}
.panel-foot .btn { flex: 1; }
.panel-foot .btn-primary { flex: 2; }

.row {
  display: flex;
  gap: 10px;
}

.row > .btn { flex: 1; }

/* ---------- fields & segmented controls ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.lang-ml .field-label { text-transform: none; letter-spacing: 0; font-size: 14px; }

.segmented {
  display: flex;
  padding: 4px;
  gap: 4px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(246, 196, 83, 0.3);
}

.segmented button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--cream);
  font: 700 16px/1.1 var(--font);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented button:hover { background: rgba(255, 244, 222, 0.08); }

.segmented button[aria-checked="true"] {
  background: var(--gold);
  color: var(--ink);
}

.text-input {
  min-height: 50px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--cream);
  font: 600 18px var(--font);
  -webkit-user-select: text;
  user-select: text;
}

.text-input::placeholder { color: rgba(255, 244, 222, 0.4); }

.credit,
.hint {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.credit { font-size: 12px; opacity: 0.75; }

/* ---------- village select ---------- */
.village-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.village-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px 10px;
  min-height: 110px;
  border-radius: 14px;
  border: 2px solid rgba(255, 244, 222, 0.15);
  background: linear-gradient(180deg, rgba(255, 244, 222, 0.06), rgba(0, 0, 0, 0.2));
  color: var(--cream);
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.village-card:hover { transform: translateY(-2px); }

.village-card[aria-checked="true"] {
  border-color: var(--team);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--team) 35%, transparent), 0 8px 22px rgba(0, 0, 0, 0.35);
  background: linear-gradient(180deg, color-mix(in srgb, var(--team) 26%, transparent), rgba(0, 0, 0, 0.2));
}

.village-card[aria-checked="true"]::after {
  content: "✓";
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--team);
  color: #fff;
  font-size: 14px;
  line-height: 22px;
  font-weight: 800;
}

.village-boat {
  width: 100%;
  max-width: 170px;
}

.village-boat svg,
.podium-boat svg {
  display: block;
  width: 100%;
  height: auto;
}

.village-name {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
}

.village-sub {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- how to play ---------- */
.panel-howto { width: min(600px, 100%); }

.howto-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.howto-sec h3 {
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}

.howto-sec ul {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 15px;
  line-height: 1.45;
}

.howto-sec li::marker { color: var(--gold); }

/* ---------- pause ---------- */
.panel-pause { width: min(360px, 100%); }

/* ---------- in-race buttons ---------- */
body.map-open .hud-controls { display: none; }

.hud-controls {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  gap: 10px;
  z-index: 5;
}

.icon-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid rgba(246, 196, 83, 0.7);
  background: rgba(30, 14, 32, 0.72);
  color: var(--cream);
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.icon-btn:active { transform: scale(0.94); }

/* ---------- results ---------- */
.panel-results { width: min(600px, 100%); }

.result-headline {
  margin: -4px 0 0;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--cream);
}

.result-headline.win {
  color: var(--gold);
  font-size: 22px;
  animation: glow 1.4s ease-in-out infinite alternate;
}

@keyframes glow {
  from { text-shadow: 0 0 0 rgba(246, 196, 83, 0); }
  to { text-shadow: 0 0 18px rgba(246, 196, 83, 0.8); }
}

.results-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: end;
  gap: 8px;
}

.podium-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
}

.podium-boat {
  width: 100%;
  max-width: 120px;
  margin-bottom: 2px;
}

.podium-name {
  max-width: 100%;
  font-size: clamp(11px, 3.1vw, 15px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
}

.podium-who {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
  overflow-wrap: anywhere;
}

.podium-time {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 4px;
}

.podium-block {
  width: 100%;
  border-radius: 10px 10px 4px 4px;
  background: linear-gradient(180deg, var(--team), color-mix(in srgb, var(--team) 55%, #000));
  display: flex;
  justify-content: center;
  padding-top: 6px;
  font-size: 26px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  border-top: 3px solid rgba(255, 255, 255, 0.35);
}

.podium-col.p1 .podium-block { height: 92px; }
.podium-col.p2 .podium-block { height: 66px; }
.podium-col.p3 .podium-block { height: 48px; }

.podium-col.me .podium-block { box-shadow: 0 0 0 3px var(--gold), 0 0 20px rgba(246, 196, 83, 0.5); }

.fourth {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 14px;
}

.fourth:empty { display: none; }
.fourth-place { font-weight: 800; color: var(--muted); }
.fourth-time { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 244, 222, 0.06);
  border: 1px solid rgba(246, 196, 83, 0.25);
}

.stat-k {
  font-size: 12px;
  color: var(--muted);
}

.stat-v {
  font-size: 20px;
  font-weight: 800;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

.stat-v em {
  display: block;
  font-style: normal;
  font-size: 12px;
  color: var(--gold);
}

/* ---------- menu extras ---------- */
.event-line,
.result-prize {
  margin: -6px 0 0;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
}

/* ---------- open world overlays ---------- */
.world-ui {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.toast-wrap {
  position: absolute;
  left: 50%;
  bottom: max(92px, calc(env(safe-area-inset-bottom) + 92px));
  transform: translateX(-50%);
  width: min(460px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast {
  padding: 8px 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  color: var(--cream);
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 8px 24px rgba(10, 0, 20, 0.4);
  animation: toast-in 0.3s cubic-bezier(.2, .8, .2, 1);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.toast-big {
  font-size: 19px;
  font-weight: 800;
  color: var(--gold);
  border-color: var(--gold);
}

.toast.out { opacity: 0; transform: translateY(-8px); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.action-btn {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  max-width: min(60vw, 280px);
  min-height: 56px;
  padding: 10px 20px;
  border: 0;
  border-radius: 28px;
  pointer-events: auto;
  color: var(--ink);
  background: linear-gradient(180deg, #ffe08f 0%, var(--gold) 50%, var(--gold-deep) 100%);
  box-shadow: 0 4px 0 #8a5a1a, 0 8px 22px rgba(246, 196, 83, 0.35);
  font: 800 16px/1.15 var(--font);
  cursor: pointer;
  touch-action: manipulation;
  animation: toast-in 0.2s ease-out;
}

.action-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #8a5a1a; }

.world-fade {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: #0b0716;
  opacity: 0;
  transition: opacity 0.6s ease;
}

.world-fade.show { opacity: 1; }

@keyframes nudge {
  from { transform: translateY(0); }
  to { transform: translateY(3px); }
}
@keyframes story-fade { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
   KADHA COMICS (comic.js): the story as a motion comic
   Ink-black outlines, paper-white balloons, yellow captions, hard offset
   shadows. Layers inside #world-ui, bottom to top: the illustrated panel,
   the letterbox, balloons and choices, toasts, the reader's buttons, SFX,
   travel captions, mission cards, covers and newspapers, the log.
   ========================================================================== */
:root {
  --cx-ink: #141017;
  --cx-paper: #fffbf1;
  --cx-cap: #ffe25a;
  --cx-red: #e23a3a;
  --cx-bar: clamp(16px, 7.5vh, 64px);
  /* Kalam letters any English; Malayalam falls through to Noto Sans Malayalam */
  --cx-letter: "Kalam", "Noto Sans Malayalam", "Malayalam Sangam MN", var(--font);
  --cx-display: "Bangers", "Noto Sans Malayalam", "Malayalam Sangam MN", var(--font);
  --cx-ml: "Noto Sans Malayalam", "Malayalam Sangam MN", var(--font);
  /* a solid ink outline for big lettering (text-stroke would eat into Malayalam glyphs) */
  --cx-outline: 3px 0 0 var(--cx-ink), -3px 0 0 var(--cx-ink), 0 3px 0 var(--cx-ink), 0 -3px 0 var(--cx-ink),
    2px 2px 0 var(--cx-ink), -2px -2px 0 var(--cx-ink), 2px -2px 0 var(--cx-ink), -2px 2px 0 var(--cx-ink);
}
.toast-wrap { z-index: 6; }
#hud { transition: opacity 0.4s ease; }
.cx-cinema #hud { opacity: 0; }

/* ---------- the illustrated panel: blurred art behind an inked comic panel ---------- */
.cx-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: #0d0a14;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  cursor: pointer;
  transition: opacity 0.45s ease, visibility 0s linear 0.45s;
}
.cx-stage.show { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity 0.45s ease; }
.cx-stage-bg {
  position: absolute;
  inset: -8%;
  background: #0d0a14 center / cover no-repeat;
  filter: blur(28px) saturate(1.3) brightness(0.36);
  will-change: transform;
}
.cx-stage-bg.move-in { animation: cx-bg-in 18s ease-out forwards; }
.cx-stage-bg.move-out { animation: cx-bg-out 18s ease-out forwards; }
.cx-stage-bg.move-left { animation: cx-bg-left 18s ease-out forwards; }
.cx-stage-bg.move-right { animation: cx-bg-right 18s ease-out forwards; }
@keyframes cx-bg-in { from { transform: scale(1); } to { transform: scale(1.08); } }
@keyframes cx-bg-out { from { transform: scale(1.08); } to { transform: scale(1); } }
@keyframes cx-bg-left { from { transform: translateX(3%); } to { transform: translateX(-3%); } }
@keyframes cx-bg-right { from { transform: translateX(-3%); } to { transform: translateX(3%); } }
/* big halftone dots fading in toward the edges, like a printed page */
.cx-stage-dots {
  position: absolute;
  inset: 0;
  background: radial-gradient(rgba(255, 244, 222, 0.11) 1.3px, transparent 1.8px) 0 0 / 10px 10px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 45%, transparent 30%, #000 90%);
  mask-image: radial-gradient(ellipse at 50% 45%, transparent 30%, #000 90%);
}
.cx-panel {
  position: absolute;
  z-index: 1;
  overflow: hidden;
  background: #0d0a14;
  border: 4px solid var(--cx-ink);
  box-shadow: 0 0 0 5px var(--cx-paper), 0 0 0 8px var(--cx-ink), 14px 16px 0 8px rgba(0, 0, 0, 0.55);
  transform: rotate(-0.4deg);
  transition: left 0.35s ease, top 0.35s ease, width 0.35s ease, height 0.35s ease;
}
.cx-art {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  transition: transform 1.7s cubic-bezier(0.3, 0.05, 0.2, 1);
  will-change: transform;
}
.cx-art.still { transition: none; }
.cx-art img { display: block; width: 100%; height: 100%; -webkit-user-drag: none; user-select: none; }
/* fine print dots and a soft inner shade over the art */
.cx-panel-ink {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(rgba(20, 16, 23, 0.22) 0.9px, transparent 1.3px) 0 0 / 5px 5px;
  mix-blend-mode: multiply;
  box-shadow: inset 0 0 70px rgba(10, 5, 15, 0.45);
}
.cx-panel-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.cx-panel.enter { animation: cx-slam 0.62s cubic-bezier(0.2, 0.9, 0.25, 1.15) both; }
.cx-panel.swap { animation: cx-wipe-panel 0.55s cubic-bezier(0.3, 0.8, 0.2, 1) both; }
.cx-panel.enter .cx-panel-flash,
.cx-panel.swap .cx-panel-flash { animation: cx-flash 0.5s ease-out; }
@keyframes cx-slam {
  0% { opacity: 0; transform: translate(-24px, 34px) rotate(-4deg) scale(0.92); }
  60% { opacity: 1; transform: rotate(0.6deg) scale(1.015); }
  100% { transform: rotate(-0.4deg); }
}
@keyframes cx-wipe-panel { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes cx-flash { from { opacity: 0.8; } to { opacity: 0; } }
/* a clue you can tap: a soft glint, easy to miss */
.cx-clue {
  position: absolute;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 236, 170, 0.55) 0%, rgba(246, 196, 83, 0.18) 40%, transparent 70%);
  cursor: pointer;
  touch-action: manipulation;
  animation: cx-glint 2.6s ease-in-out infinite;
}
.cx-clue::after {
  content: '';
  position: absolute;
  inset: 14px;
  border: 2px solid rgba(255, 244, 222, 0.7);
  border-radius: 50%;
  animation: cx-ring 2.6s ease-out infinite;
}
.cx-clue.found { animation: cx-found 0.7s ease-out forwards; pointer-events: none; }
@keyframes cx-glint { 0%, 100% { opacity: 0.4; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1.05); } }
@keyframes cx-ring { 0% { transform: scale(0.5); opacity: 0.9; } 100% { transform: scale(1.6); opacity: 0; } }
@keyframes cx-found { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(2.4); } }

/* ---------- the letterbox ---------- */
.cx-bars { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.cx-bars i {
  position: absolute;
  left: 0;
  right: 0;
  height: var(--cx-bar);
  background: #000;
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.cx-bars i:first-child { top: 0; transform: translateY(-100%); }
.cx-bars i:last-child { bottom: 0; transform: translateY(100%); }
.cx-bars.on i { transform: none; }

/* ---------- balloons ---------- */
.cx-talk { position: absolute; inset: 0; z-index: 5; pointer-events: none; }
.cx-balloon,
.cx-caption,
.cx-choices { position: absolute; left: 0; top: 0; pointer-events: auto; }
.cx-balloon { width: max-content; max-width: 420px; color: var(--cx-ink); cursor: pointer; will-change: transform; }
.cx-bin { position: relative; padding: 20px 24px 16px; }
.cx-balloon.is-shout .cx-bin { padding: 22px 28px 18px; }
.cx-balloon.is-phone .cx-bin { padding: 20px 22px 15px; }
.cx-shape { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; filter: drop-shadow(4px 5px 0 rgba(0, 0, 0, 0.38)); }
/* two passes: an ink outline under a paper fill, so only the outer edge of balloon + tail shows */
.cx-shape .o { fill: var(--cx-ink); stroke: var(--cx-ink); stroke-width: 6; stroke-linejoin: round; }
.cx-shape .f { fill: var(--cx-paper); }
.is-whisper .cx-shape .o { fill: none; stroke-dasharray: 10 7; }
.is-phone .cx-shape .f { fill: #eaf6ff; }
.cx-balloon .cx-text { color: var(--cx-ink); }
.is-whisper .cx-text { color: #3a3340; }
.is-shout .cx-text { font-size: 19px; }
.cx-text {
  position: relative;
  margin: 0;
  font: 700 17px/1.5 var(--cx-letter);
  -webkit-user-select: none;
  user-select: none;
}
/* word-by-word lettering: comic.js sets --i on each word and --per on the line */
.cx-text .w {
  display: inline-block;
  opacity: 0;
  animation: cx-word 0.22s ease-out forwards;
  animation-delay: calc(var(--i) * var(--per, 40ms));
}
.cx-text.done .w { animation: none; opacity: 1; transform: none; }
.cx-text .em { color: var(--cx-red); font-family: "Bangers", var(--cx-letter); font-weight: 400; font-size: 1.14em; letter-spacing: 0.04em; }
@keyframes cx-word { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.cx-balloon.pop .cx-bin { animation: cx-pop 0.3s cubic-bezier(0.2, 1.45, 0.4, 1) both; }
@keyframes cx-pop { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: none; } }
.cx-balloon.out,
.cx-caption.out,
.cx-choices.out { opacity: 0; transition: opacity 0.12s ease; }
/* the speaker's name tag, with their portrait chip over the world */
.cx-tag {
  position: absolute;
  left: 16px;
  top: 0;
  z-index: 1;
  max-width: calc(100% - 24px);
  display: flex;
  align-items: center;
  padding: 3px 12px 3px 10px;
  border: 3px solid var(--cx-ink);
  border-radius: 4px;
  background: var(--hue, #26131f);
  color: #fff;
  box-shadow: 3px 3px 0 var(--cx-ink);
  font: 800 14px/1.2 var(--font);
  white-space: nowrap;
  transform: translateY(-62%) rotate(-2.5deg);
}
.cx-who { overflow: hidden; text-overflow: ellipsis; }
.cx-tag.has-face { padding-left: 48px; }
.cx-face {
  display: none;
  position: absolute;
  left: -8px;
  top: 50%;
  width: 50px;
  height: 50px;
  margin-top: -27px;
  border: 3px solid var(--cx-ink);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #fff6dc 0%, #f6c453 100%);
}
.cx-tag.has-face .cx-face { display: block; }
.cx-balloon.is-phone .cx-tag { background: var(--cx-ink); color: var(--cx-cap); }
/* ▼ once the line is all there */
.cx-more {
  position: absolute;
  right: 16px;
  bottom: 7px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--cx-ink);
  opacity: 0;
}
.cx-text.done ~ .cx-more { opacity: 1; animation: nudge 0.9s ease-in-out infinite alternate; }
.has-choices .cx-more { display: none; }

/* narration: the yellow caption box */
.cx-caption {
  max-width: 560px;
  padding: 10px 18px 12px;
  border: 3px solid var(--cx-ink);
  border-radius: 2px;
  background: var(--cx-cap);
  color: var(--cx-ink);
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.5);
  cursor: pointer;
  will-change: transform;
}
.cx-caption .cx-text { font: 600 16px/1.55 var(--cx-ml); }
.cx-caption.pop { animation: cx-cap-in 0.35s cubic-bezier(0.3, 0.8, 0.2, 1) both; }
@keyframes cx-cap-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(-12px -12px -12px -12px); } }
.cx-caption .cx-more { right: 10px; bottom: 5px; }
.cx-cap-who { display: block; margin-bottom: 2px; font: 800 12px/1.2 var(--font); opacity: 0.7; }
.cx-caption.is-journal {
  background: repeating-linear-gradient(180deg, #fdf8ea 0 26px, #c9dbf2 26px 27px);
  border-left-width: 10px;
  border-left-color: #c94a4a;
}
.cx-caption.is-journal .cx-text { font-family: "Chilanka", var(--cx-ml); font-size: 18px; line-height: 27px; }

/* ---------- decision cards ---------- */
.cx-choices { display: flex; flex-direction: column; gap: 9px; }
.cx-choices.two { display: grid; grid-template-columns: 1fr 1fr; }
.cx-choices-head {
  align-self: flex-start;
  justify-self: start;
  grid-column: 1 / -1;
  padding: 3px 14px 2px;
  background: var(--cx-ink);
  color: var(--cx-cap);
  font: 400 19px/1.3 var(--cx-display);
  letter-spacing: 0.06em;
  transform: rotate(-2deg);
}
.cx-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 16px 8px 10px;
  border: 3px solid var(--cx-ink);
  border-radius: 6px;
  background: var(--cx-paper);
  color: var(--cx-ink);
  box-shadow: 5px 5px 0 var(--cx-ink);
  font: 700 16px/1.35 var(--cx-letter);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transform: rotate(0.5deg);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
  animation: cx-card 0.36s cubic-bezier(0.2, 1.25, 0.4, 1) backwards;
  animation-delay: calc(var(--k) * 70ms);
}
.cx-choice:nth-of-type(even) { transform: rotate(-0.5deg); }
.cx-choice:hover:not(:disabled),
.cx-choice:focus-visible {
  outline: none;
  background: var(--cx-cap);
  transform: translate(-2px, -2px) rotate(0);
  box-shadow: 7px 7px 0 var(--cx-ink);
}
.cx-choice:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--cx-ink); }
.cx-choice:disabled { opacity: 0.5; cursor: not-allowed; }
.cx-key {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--cx-ink);
  border-radius: 50%;
  background: var(--cx-red);
  color: #fff;
  font: 400 18px/1 var(--cx-display);
}
@keyframes cx-card { from { opacity: 0; transform: translateY(18px) rotate(-3deg) scale(0.96); } }

/* ---------- the reader's buttons: AUTO, SKIP, LOG ---------- */
.cx-tools {
  position: absolute;
  z-index: 7;
  left: max(12px, env(safe-area-inset-left));
  top: calc(env(safe-area-inset-top) + 10px);
  display: flex;
  gap: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.cx-tools.on { opacity: 1; pointer-events: auto; transform: none; }
.cx-tools button {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 11px;
  border: 2px solid rgba(255, 244, 222, 0.45);
  border-radius: 16px;
  background: rgba(10, 6, 16, 0.6);
  color: var(--cream);
  font: 400 16px/1 var(--cx-display);
  letter-spacing: 0.08em;
  cursor: pointer;
  touch-action: manipulation;
}
.cx-tools button b { font-weight: 400; }
.cx-tools button:hover { border-color: var(--cx-cap); }
.cx-tools button:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
.cx-tools button.on { background: var(--cx-cap); border-color: var(--cx-ink); color: var(--cx-ink); }
.cx-tools button.on b { animation: cx-blink 1s steps(2) infinite; }
.cx-tools kbd { padding: 2px 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.16); font: 700 10px/1 var(--font); letter-spacing: 0; }
.cx-tools button.on kbd { background: rgba(0, 0, 0, 0.12); }
@keyframes cx-blink { 50% { opacity: 0.55; } }

/* ---------- SFX lettering ---------- */
.cx-sfx { position: absolute; inset: 0; z-index: 9; overflow: hidden; pointer-events: none; }
.cx-pow {
  position: absolute;
  width: 0;
  height: 0;
  transform: rotate(var(--r)) scale(var(--s));
  animation: cx-pow 1.25s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
.cx-pow svg { position: absolute; left: -110px; top: -80px; width: 220px; height: 160px; overflow: visible; }
.cx-pow .b2 { fill: var(--cx-ink); }
.cx-pow .b1 { fill: var(--cx-cap); }
.cx-pow span {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -52%);
  color: var(--cx-red);
  font: 400 46px/1 var(--cx-display);
  letter-spacing: 0.03em;
  white-space: nowrap;
  text-shadow: var(--cx-outline), 4px 5px 0 var(--cx-ink);
}
@keyframes cx-pow {
  0% { opacity: 0; transform: rotate(var(--r)) scale(calc(var(--s) * 0.2)); }
  18% { opacity: 1; transform: rotate(var(--r)) scale(calc(var(--s) * 1.15)); }
  32% { transform: rotate(var(--r)) scale(var(--s)); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: rotate(var(--r)) scale(calc(var(--s) * 1.06)); }
}

/* ---------- "Later…": a story jump ---------- */
.cx-travel {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #07050c;
  opacity: 0;
  pointer-events: auto;
  transition: opacity 0.55s ease;
}
.cx-travel.show { opacity: 1; }
.cx-travel.show.out { opacity: 0; transition-duration: 0.6s; }
.cx-travel-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 560px;
  padding: 14px 24px 16px;
  border: 3px solid var(--cx-ink);
  background: var(--cx-cap);
  color: var(--cx-ink);
  box-shadow: 0 0 0 3px var(--cx-cap), 10px 10px 0 3px rgba(255, 226, 90, 0.16);
  opacity: 0;
  transform: rotate(-1.5deg);
}
.cx-travel.show .cx-travel-box { animation: cx-travel-in 0.45s 0.35s cubic-bezier(0.3, 0.8, 0.2, 1) forwards; }
.cx-travel .k { font: 700 15px/1.2 var(--cx-ml); opacity: 0.75; }
.cx-travel .p { font: 800 clamp(20px, 4.4vw, 30px)/1.25 var(--cx-ml); }
.cx-travel .t { font: 400 22px/1.1 var(--cx-display); letter-spacing: 0.06em; color: var(--cx-red); }
@keyframes cx-travel-in {
  from { opacity: 0; clip-path: inset(0 100% 0 0); }
  to { opacity: 1; clip-path: inset(-20px -20px -20px -20px); }
}

/* ---------- mission title (GTA style) ---------- */
.cx-title,
.cx-passed {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  pointer-events: auto;
  animation: story-fade 0.3s ease-out;
}
.cx-title { background: linear-gradient(180deg, transparent 14%, rgba(5, 2, 10, 0.72) 32%, rgba(5, 2, 10, 0.72) 68%, transparent 86%); }
.cx-title-in { max-width: 920px; text-align: center; animation: cx-wipe-in 0.6s 0.1s cubic-bezier(0.3, 0.8, 0.2, 1) both; }
.cx-title .kick {
  display: inline-block;
  padding: 3px 14px;
  background: var(--cx-ink);
  color: var(--cx-cap);
  font: 800 clamp(13px, 2.2vw, 17px)/1.3 var(--cx-ml);
  transform: rotate(-2deg);
  box-shadow: 0 0 0 2px var(--cx-cap);
}
.cx-title h2 {
  margin: 12px 0 0;
  color: #fff;
  font: 800 clamp(30px, 7vw, 68px)/1.18 var(--cx-ml);
  text-shadow: var(--cx-outline), 6px 7px 0 var(--cx-ink);
  transform: skewX(-6deg);
}
.cx-title .swash {
  display: block;
  width: min(520px, 80%);
  height: 8px;
  margin: 12px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold) 15%, #fff1b8 50%, var(--gold) 85%, transparent);
  transform-origin: left center;
  animation: cx-swash 0.7s 0.4s cubic-bezier(0.3, 0.8, 0.2, 1) both;
}
.cx-title.out { opacity: 0; transition: opacity 0.42s ease; }
.cx-title.out .cx-title-in { animation: cx-wipe-out 0.42s ease-in forwards; }
@keyframes cx-wipe-in { from { clip-path: inset(-30% 100% -30% -5%); } to { clip-path: inset(-30% -5% -30% -5%); } }
@keyframes cx-wipe-out { from { clip-path: inset(-30% -5% -30% -5%); } to { clip-path: inset(-30% -5% -30% 100%); } }
@keyframes cx-swash { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- MISSION PASSED ---------- */
.cx-passed-band {
  position: relative;
  width: 100%;
  padding: 26px 16px 24px;
  text-align: center;
  background: linear-gradient(180deg, transparent, rgba(5, 2, 10, 0.8) 18%, rgba(5, 2, 10, 0.8) 82%, transparent);
}
.cx-passed-band::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(rgba(255, 210, 63, 0.16) 1.4px, transparent 1.9px) 0 0 / 11px 11px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 10%, transparent 70%);
  mask-image: radial-gradient(ellipse at center, #000 10%, transparent 70%);
  pointer-events: none;
}
.cx-passed-big {
  position: relative;
  color: #ffcf3a;
  font: 400 clamp(40px, 8.6vw, 104px)/1 var(--cx-display);
  letter-spacing: 0.04em;
  text-shadow: var(--cx-outline), 6px 7px 0 var(--cx-ink), 0 0 40px rgba(255, 207, 58, 0.45);
  animation: cx-stamp 0.55s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.cx-passed-sub { position: relative; margin-top: 8px; color: #fff; font: 800 clamp(16px, 3vw, 22px)/1.3 var(--cx-ml); text-shadow: 2px 2px 0 var(--cx-ink); }
.cx-passed-name { position: relative; margin-top: 2px; color: var(--muted); font: 700 clamp(14px, 2.4vw, 17px)/1.3 var(--cx-ml); }
.cx-passed-loot { position: relative; }
.cx-passed-loot span {
  display: inline-block;
  margin: 12px 6px 0;
  padding: 4px 14px;
  border: 2.5px solid var(--cx-ink);
  background: var(--cx-cap);
  color: var(--cx-ink);
  box-shadow: 3px 3px 0 #000;
  font: 800 16px/1.25 var(--cx-ml);
  transform: rotate(-2deg);
  animation: cx-card 0.4s 0.55s cubic-bezier(0.2, 1.25, 0.4, 1) backwards;
}
.cx-passed-loot span + span { transform: rotate(1.5deg); }
.cx-passed.out { opacity: 0; transition: opacity 0.42s ease; }
@keyframes cx-stamp { 0% { opacity: 0; transform: scale(2.4); filter: blur(6px); } 100% { opacity: 1; transform: none; filter: none; } }

/* ---------- chapter covers: each chapter is a new issue ---------- */
.cx-cover {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  overflow: hidden;
  background-color: #07050c;
  background-image: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--hue) 55%, #07050c) 0%, #07050c 72%);
  cursor: pointer;
  pointer-events: auto;
  perspective: 1400px;
  animation: story-fade 0.4s ease-out;
}
.cx-cover-rays {
  position: absolute;
  inset: -60%;
  background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 244, 222, 0.08) 0deg 6deg, transparent 6deg 15deg);
  -webkit-mask-image: radial-gradient(circle, #000 15%, transparent 60%);
  mask-image: radial-gradient(circle, #000 15%, transparent 60%);
  animation: cx-spin 80s linear infinite;
}
@keyframes cx-spin { to { transform: rotate(360deg); } }
.cx-cover-book {
  position: relative;
  container-type: inline-size;
  width: min(88vw, 52vh, 430px);
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 5px solid var(--cx-ink);
  background: #120d18;
  box-shadow: 0 0 0 4px var(--cx-paper), 0 0 0 7px var(--cx-ink), 18px 20px 0 7px rgba(0, 0, 0, 0.55);
  transform: rotate(-1.5deg);
  transform-origin: left center;
  animation: cx-cover-in 0.85s cubic-bezier(0.2, 0.9, 0.25, 1.1) both;
}
.cx-cover-art { position: absolute; inset: 0; }
.cx-cover-art img { width: 100%; height: 100%; object-fit: cover; animation: cx-cover-zoom 8s ease-out both; }
.cx-cover-art::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(rgba(20, 16, 23, 0.25) 0.9px, transparent 1.3px) 0 0 / 5px 5px;
  mix-blend-mode: multiply;
}
@keyframes cx-cover-zoom { from { transform: scale(1.14); } to { transform: scale(1); } }
.cx-cover-mast {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 3cqi;
  padding: 4cqi 4.5cqi 9cqi;
  background: linear-gradient(180deg, rgba(5, 2, 10, 0.92) 55%, transparent);
}
.cx-cover-mast .logo { color: var(--cx-cap); font: 400 12.5cqi/0.92 var(--cx-display); letter-spacing: 0.02em; text-shadow: var(--cx-outline), 4px 4px 0 var(--cx-red); }
.cx-cover-mast .series { grid-column: 1; margin-top: 1.5cqi; color: #fff; font: 700 3.8cqi/1.3 var(--cx-ml); }
.cx-cover-mast .issue {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: start;
  min-width: 15cqi;
  padding: 1cqi 2cqi 1.4cqi;
  border: 3px solid var(--cx-ink);
  background: var(--cx-paper);
  color: var(--cx-ink);
  text-align: center;
  transform: rotate(3deg);
}
.cx-cover-mast .issue small { display: block; font: 800 3.2cqi/1.2 var(--cx-ml); }
.cx-cover-mast .issue b { display: block; font: 400 11cqi/0.95 var(--cx-display); }
.cx-cover-price {
  position: absolute;
  left: 4.5cqi;
  top: 34cqi;
  width: 15cqi;
  height: 15cqi;
  display: grid;
  place-items: center;
  border: 3px solid var(--cx-ink);
  border-radius: 50%;
  background: var(--cx-red);
  color: #fff;
  font: 400 6cqi/1 var(--cx-display);
  font-style: normal;
  transform: rotate(-12deg);
}
.cx-cover-code {
  position: absolute;
  right: 4.5cqi;
  top: 34cqi;
  width: 10cqi;
  height: 15cqi;
  border: 1.4cqi solid #fff;
  background: #fff repeating-linear-gradient(90deg, #111 0 1px, transparent 1px 3px, #111 3px 5px, transparent 5px 6px, #111 6px 7px, transparent 7px 9px);
}
.cx-cover-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22cqi 5cqi 6cqi;
  background: linear-gradient(180deg, transparent, rgba(5, 2, 10, 0.9) 45%);
}
.cx-cover-foot .kick {
  display: inline-block;
  padding: 0.6cqi 3cqi;
  border: 3px solid var(--cx-ink);
  background: var(--hue);
  color: #fff;
  box-shadow: 3px 3px 0 var(--cx-ink);
  font: 800 4.2cqi/1.3 var(--cx-ml);
  transform: rotate(-3deg);
}
.cx-cover-foot h2 {
  margin: 3cqi 0 1.5cqi;
  color: #fff;
  font: 800 10.5cqi/1.14 var(--cx-ml);
  text-shadow: var(--cx-outline), 5px 6px 0 var(--hue);
  animation: cx-stamp 0.55s 0.5s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
.cx-cover-foot .sub { color: var(--cx-cap); font: 400 5.6cqi/1.05 var(--cx-display); letter-spacing: 0.04em; }
.cx-cover.is-end .cx-cover-foot h2 { font-size: 9cqi; }
.cx-cover-tap {
  position: relative;
  color: var(--cream);
  font: 400 19px/1 var(--cx-display);
  letter-spacing: 0.12em;
  opacity: 0;
  animation: cx-tap 1.2s 1.3s ease-in-out infinite alternate;
}
@keyframes cx-tap { from { opacity: 0.25; } to { opacity: 0.9; } }
@keyframes cx-cover-in {
  0% { opacity: 0; transform: translateY(48px) rotate(-9deg) scale(0.88); }
  70% { opacity: 1; transform: rotate(1deg) scale(1.01); }
  100% { transform: rotate(-1.5deg); }
}
.cx-cover.out { opacity: 0; transition: opacity 0.6s ease-in; }
.cx-cover.out .cx-cover-book { animation: cx-turn 0.6s cubic-bezier(0.5, 0, 0.75, 0) forwards; }
.cx-cover.out .cx-cover-tap { display: none; }
@keyframes cx-turn { from { transform: rotate(-1.5deg); } to { transform: rotateY(-105deg); opacity: 0.3; } }

/* ---------- the log: the story so far ---------- */
.cx-log {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(7, 5, 12, 0.8);
  pointer-events: auto;
  animation: story-fade 0.25s ease-out;
}
.cx-log-sheet {
  width: min(640px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border: 4px solid var(--cx-ink);
  background: var(--cx-paper);
  color: var(--cx-ink);
  box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.6);
  animation: rise 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.cx-log-sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px 8px 16px;
  border-bottom: 3px solid var(--cx-ink);
  background: var(--cx-cap);
}
.cx-log-sheet h2 { margin: 0; color: var(--cx-ink); font: 800 19px/1.3 var(--cx-ml); text-align: left; }
.cx-log-x {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--cx-ink);
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
}
.cx-log-x svg { width: 18px; height: 18px; fill: none; stroke: var(--cx-ink); stroke-width: 3; stroke-linecap: round; }
.cx-log ol {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 16px;
  list-style: none;
  overflow-y: auto;
  -webkit-user-select: text;
  user-select: text;
}
.cx-log li b {
  display: inline-block;
  padding: 1px 9px;
  border: 2px solid var(--cx-ink);
  background: var(--hue);
  color: #fff;
  font: 800 13px/1.3 var(--font);
  transform: rotate(-1.5deg);
}
.cx-log li p { margin: 4px 0 0; padding: 8px 13px; border: 2.5px solid var(--cx-ink); border-radius: 16px; background: #fff; font: 600 15px/1.55 var(--cx-letter); }
.cx-log li.is-caption p { margin: 0; border-radius: 2px; background: var(--cx-cap); font-family: var(--cx-ml); }
.cx-log li.is-choice { align-self: flex-end; }
.cx-log li.is-choice span { display: inline-block; padding: 5px 12px; border-radius: 4px; background: var(--cx-ink); color: var(--cx-cap); font: 700 14px/1.4 var(--cx-letter); }

/* ---------- newspapers and letters ---------- */
.story-paper {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: center;
  /* clear of the map / pause / mute buttons at the top */
  padding: calc(env(safe-area-inset-top) + 68px) 16px max(16px, env(safe-area-inset-bottom));
  background: radial-gradient(ellipse at center, rgba(30, 18, 40, 0.75), rgba(7, 5, 12, 0.9));
  pointer-events: auto;
  overflow-y: auto;
  perspective: 1200px;
  animation: story-fade 0.35s ease-out;
}
.story-paper-sheet {
  position: relative;
  width: 100%;
  max-width: 580px;
  max-height: 100%;
  overflow-y: auto;
  padding: 22px 22px 18px;
  border-radius: 3px;
  color: #2b2118;
  box-shadow: 12px 14px 0 rgba(0, 0, 0, 0.45), 0 24px 70px rgba(0, 0, 0, 0.55);
}
/* a newspaper spins in, like the front page in an old film */
.is-paper .story-paper-sheet {
  background:
    radial-gradient(rgba(60, 40, 20, 0.06) 1px, transparent 1.4px) 0 0 / 6px 6px,
    linear-gradient(180deg, #f4ecd8, #e4d6b6);
  transform: rotate(-0.8deg);
  animation: cx-paper-spin 0.95s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
@keyframes cx-paper-spin {
  0% { opacity: 0; transform: rotate(-700deg) scale(0.06); }
  70% { opacity: 1; transform: rotate(5deg) scale(1.04); }
  100% { transform: rotate(-0.8deg); }
}
/* a letter unfolds */
.is-letter .story-paper-sheet {
  background: repeating-linear-gradient(180deg, #e9f0f9 0 27px, #cddcef 27px 28px);
  border: 6px solid #9fb8d8;
  border-style: dashed solid;
  transform: rotate(0.5deg);
  transform-origin: 50% 0;
  animation: cx-unfold 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes cx-unfold { from { opacity: 0; transform: rotateX(-80deg) scaleY(0.5); } to { opacity: 1; transform: rotate(0.5deg); } }
.story-paper.out { opacity: 0; transition: opacity 0.3s ease; }
.story-paper.out .story-paper-sheet { animation: cx-paper-out 0.3s ease-in forwards; }
@keyframes cx-paper-out { to { opacity: 0; transform: translateY(40px) rotate(4deg) scale(0.96); } }
.story-paper-mast {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}
.is-paper .story-paper-mast {
  padding: 2px 0 8px;
  border-bottom: 4px double #2b2118;
  font-family: Georgia, "Times New Roman", var(--cx-ml);
  letter-spacing: 0.02em;
}
.is-letter .story-paper-mast { font-size: 14px; text-transform: uppercase; color: #3a5a8a; text-align: left; }   /* no letter-spacing: it pulls Malayalam conjuncts apart */
.story-paper-date { margin: 6px 0 12px; padding-bottom: 6px; border-bottom: 1px solid rgba(43, 33, 24, 0.35); font-size: 13px; font-weight: 700; opacity: 0.75; text-align: center; }
.is-letter .story-paper-date { border: 0; text-align: right; }
.story-paper-title { margin: 0 0 12px; font-size: 22px; line-height: 1.15; color: #2b2118; }
.is-paper .story-paper-title { font: 800 clamp(22px, 4.6vw, 30px)/1.15 var(--cx-ml); text-align: center; }
.story-paper-photo { position: relative; margin: 0 0 14px; overflow: hidden; aspect-ratio: 16 / 9; border: 2px solid #2b2118; background: #b9ae96; }
.story-paper-photo img { display: block; width: 100%; height: 100%; object-fit: cover; filter: grayscale(1) sepia(0.3) contrast(1.3) brightness(1.04); }
.story-paper-photo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(rgba(30, 20, 10, 0.4) 0.9px, transparent 1.3px) 0 0 / 4px 4px;
  mix-blend-mode: multiply;
}
.story-paper-body p { margin: 0 0 10px; font-size: 16px; line-height: 1.5; }
.is-paper .story-paper-body { columns: 2 16em; column-gap: 24px; column-rule: 1px solid rgba(43, 33, 24, 0.3); }
.is-letter .story-paper-body p { margin-bottom: 0; font: 400 18px/28px "Chilanka", var(--cx-ml); }
.story-paper-close { display: block; position: sticky; bottom: 0; margin: 16px auto 0; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
@media (max-width: 480px) {
  .story-paper-body p { font-size: 15px; }
  .is-letter .story-paper-body p { font-size: 17px; }
  .story-paper-sheet { padding: 18px 16px 14px; }
}

/* ---------- smaller screens ---------- */
@media (max-width: 560px), (max-height: 500px) {
  .cx-bin { padding: 17px 18px 13px; }
  .cx-text { font-size: 15px; line-height: 1.45; }
  .is-shout .cx-text { font-size: 16px; }
  .cx-caption { padding: 8px 14px 10px; }
  .cx-caption .cx-text { font-size: 14.5px; }
  .cx-tag { font-size: 13px; }
  .cx-choices { gap: 7px; }
  .cx-choice { min-height: 42px; padding: 6px 12px 6px 8px; font-size: 14.5px; box-shadow: 4px 4px 0 var(--cx-ink); }
  .cx-key { width: 26px; height: 26px; font-size: 16px; }
  .cx-choices-head { font-size: 16px; }
  .cx-tools button { height: 28px; padding: 0 9px; font-size: 14px; }
  .cx-pow span { font-size: 38px; }
}
@media (pointer: coarse) {
  .cx-tools kbd,
  .cx-key { display: none; }
}

.result-prize { white-space: pre-line; }
.result-prize.pass { color: #7ee8c8; }


/* ---------- shared world: who's online + emotes ---------- */
.presence {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 10px));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
.presence-pill {
  padding: 3px 10px 3px 8px;
  border-radius: 99px;
  background: rgba(30, 14, 32, 0.72);
  border: 1px solid rgba(246, 196, 83, 0.45);
  color: var(--cream);
  font-size: 12px;
  font-weight: 700;
}
.presence-pill::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #4ade80;
  vertical-align: 1px;
}
.hidden.presence-pill { display: none; }

/* ---------- online lobby ---------- */
.panel-online { width: min(580px, 100%); }
.online-view { display: flex; flex-direction: column; gap: 14px; }
.online-view.hidden { display: none; }

.btn-sm { min-height: 40px; padding: 6px 14px; font-size: 15px; }

.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.field-meta { font-size: 13px; font-weight: 700; color: var(--muted); }

/* identity row: avatar + name + reroll ----------------------------------- */
.id-card {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.id-field { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.id-avatar {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(160deg, color-mix(in srgb, var(--team, #f2a900) 85%, #fff 15%), var(--team, #f2a900));
  border: 2px solid rgba(255, 244, 222, 0.35);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.icon-btn {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  color: var(--cream);
  background: rgba(255, 244, 222, 0.08);
  border: 2px solid var(--line);
  transition: background 0.15s ease, transform 0.15s ease;
}
.icon-btn:hover { background: rgba(255, 244, 222, 0.16); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.icon-btn.rolling svg { animation: dice-roll 0.45s ease; }
@keyframes dice-roll {
  50% { transform: rotate(180deg) scale(0.8); }
  100% { transform: rotate(360deg); }
}

/* the two hero actions ---------------------------------------------------- */
.play-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.play-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  padding: 12px 14px;
  border-radius: 16px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--cream);
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}
.play-card:hover { background: rgba(255, 244, 222, 0.12); }
.play-card:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
.play-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.play-card-primary {
  color: var(--ink);
  background: linear-gradient(180deg, #ffd978, var(--gold));
  border-color: var(--gold-deep);
  box-shadow: 0 4px 0 #8a5a1a, 0 10px 24px rgba(246, 196, 83, 0.28);
}
.play-card-primary:hover { background: linear-gradient(180deg, #ffe08f, #ffc956); }
.play-card-primary:active { box-shadow: 0 1px 0 #8a5a1a; }
.pc-icon {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.2);
}
.play-card-primary .pc-icon { background: rgba(38, 19, 31, 0.16); }
.pc-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.play-card-primary .pc-icon svg { fill: none; }
.pc-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pc-title { font-size: 17px; font-weight: 800; line-height: 1.15; }
.pc-sub { font-size: 12.5px; font-weight: 600; line-height: 1.25; opacity: 0.78; }
.pc-spin { display: none; }
.play-card.busy { pointer-events: none; }
.play-card.busy .pc-icon { opacity: 0; }
.play-card.busy .pc-spin {
  display: block;
  position: absolute;
  left: 22px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid currentColor;
  border-top-color: transparent;
  opacity: 0.85;
  animation: pc-spin 0.7s linear infinite;
}
@keyframes pc-spin { to { transform: rotate(360deg); } }
.play-cards:has(.busy) .play-card:not(.busy) { opacity: 0.45; pointer-events: none; }

/* code entry -------------------------------------------------------------- */
.code-join { display: flex; flex-direction: column; gap: 6px; }
.code-row { display: flex; align-items: center; gap: 10px; }
.code-boxes { flex: 1; min-width: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.code-box {
  width: 100%;
  min-width: 0;
  height: 54px;
  padding: 0;
  text-align: center;
  text-transform: uppercase;
  font-family: inherit;
  font-size: 24px;
  font-weight: 800;
  color: var(--cream);
  caret-color: var(--gold);
  background: rgba(0, 0, 0, 0.32);
  border: 2px solid rgba(246, 196, 83, 0.3);
  border-radius: 12px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.code-box:focus {
  outline: none;
  border-color: var(--gold);
  background: rgba(0, 0, 0, 0.5);
  transform: translateY(-2px);
}
.code-box.filled { border-color: color-mix(in srgb, var(--gold) 70%, transparent); }
.code-boxes.shake { animation: code-shake 0.4s ease; }
.code-boxes.shake .code-box { border-color: #ff9a8a; }
@keyframes code-shake {
  20% { transform: translateX(-7px); }
  45% { transform: translateX(6px); }
  70% { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}
.code-row .btn { flex: none; min-width: 92px; }
.code-row .btn:disabled { opacity: 0.4; cursor: default; }

.online-status {
  margin: 0;
  min-height: 1.2em;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
}
.online-status:empty { display: none; }
.online-status.error { color: #ff9a8a; }

/* lobby header ------------------------------------------------------------ */
.room-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}
/* keep the header clear of the panel's floating close button */
.panel > .panel-close:not(.hidden) ~ .online-view .room-head { padding-inline-end: 46px; }
.room-id { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.room-head-side { display: flex; align-items: center; gap: 8px; }
.room-code {
  display: inline-flex;
  gap: 6px;
  padding: 2px 8px;
  margin-left: -8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.12em;
  color: var(--gold);
  transition: background 0.15s ease;
}
.room-code:hover { background: rgba(246, 196, 83, 0.12); }
.room-code:active { transform: scale(0.98); }
.net-pill {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: 99px;
  color: #bdf3c6;
  background: rgba(47, 162, 74, 0.22);
  border: 1.5px solid rgba(47, 162, 74, 0.5);
  white-space: nowrap;
}
.net-pill.warn { color: #ffe0a3; background: rgba(242, 169, 0, 0.2); border-color: rgba(242, 169, 0, 0.55); }
.net-pill.bad { color: #ffb3a7; background: rgba(215, 38, 61, 0.22); border-color: rgba(215, 38, 61, 0.55); }
.net-pill:empty { display: none; }

/* crew slots -------------------------------------------------------------- */
.crew-slots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.crew-slot {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 12px 8px 9px;
  border-radius: 13px;
  background: rgba(0, 0, 0, 0.28);
  border: 2px solid color-mix(in srgb, var(--team, var(--line)) 42%, transparent);
  animation: slot-in 0.25s ease;
}
@keyframes slot-in { from { opacity: 0; transform: translateY(-5px); } }
.crew-slot.me {
  background: color-mix(in srgb, var(--team) 16%, rgba(0, 0, 0, 0.28));
  border-color: color-mix(in srgb, var(--team) 80%, transparent);
}
.crew-slot.open {
  border-style: dashed;
  border-color: rgba(246, 196, 83, 0.3);
  background: rgba(0, 0, 0, 0.16);
}
.cs-badge {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  background: var(--team, rgba(255, 244, 222, 0.12));
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}
.crew-slot.open .cs-badge {
  color: var(--muted);
  background: rgba(255, 244, 222, 0.08);
  border: 1.5px dashed rgba(246, 196, 83, 0.35);
}
.cs-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.cs-name {
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crew-slot.open .cs-name { color: var(--muted); font-weight: 600; }
.cs-village { font-size: 12.5px; color: var(--muted); }
.cs-crown { color: var(--gold); margin-right: 3px; }
.cs-you {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px 6px;
  margin-left: 5px;
  border-radius: 99px;
  background: rgba(255, 244, 222, 0.18);
  color: var(--cream);
  vertical-align: 2px;
}
.cs-state {
  flex: none;
  font-size: 11.5px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 99px;
  background: rgba(255, 244, 222, 0.1);
  color: var(--muted);
}
.cs-state.on { background: #2fa24a; color: #fff; }
.cs-state.host { background: rgba(246, 196, 83, 0.2); color: var(--gold); }
.cs-dots { flex: none; display: inline-flex; gap: 4px; padding-right: 4px; }
.cs-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: cs-dot 1.1s ease-in-out infinite;
}
.cs-dots i:nth-child(2) { animation-delay: 0.15s; }
.cs-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes cs-dot { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ready progress ---------------------------------------------------------- */
.ready-track {
  height: 6px;
  border-radius: 99px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.ready-track.hidden { display: none; }
.ready-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #2fa24a, #7ee08c);
  transition: width 0.3s ease;
}

.village-grid-4 { grid-template-columns: repeat(4, 1fr); gap: 8px; }
.village-card-sm { min-height: 0; padding: 10px 4px; border-top: 5px solid var(--team); }
.village-card-sm .village-name { font-size: 14px; }
.village-card-sm .village-sub { font-size: 11px; }
.village-card-sm[aria-checked="true"]::after { top: 4px; right: 4px; width: 18px; height: 18px; line-height: 18px; font-size: 11px; }
.village-card:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.online-settings { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
.online-settings button:disabled { opacity: 0.6; cursor: default; }
.online-hint { color: var(--cream); font-weight: 600; }

@media (max-width: 520px) {
  .play-cards { grid-template-columns: 1fr; }
  .play-card { min-height: 66px; }
}
@media (max-width: 480px) {
  .village-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .online-settings { grid-template-columns: 1fr; }
  .room-head { flex-direction: column; align-items: stretch; }
  .room-head-side { justify-content: space-between; }
  .code-box { height: 48px; font-size: 21px; }
  .code-row .btn { min-width: 78px; }
}
@media (prefers-reduced-motion: reduce) {
  .crew-slot, .icon-btn.rolling svg, .code-boxes.shake, .cs-dots i { animation: none; }
}

/* ---------- login / guest (account.js) ---------- */
.panel-login { width: min(440px, 100%); }
.panel-login .title-ml { font-size: clamp(40px, 11vw, 62px); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form .btn:disabled { opacity: 0.6; cursor: progress; }
.or-line {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}
.or-line::before,
.or-line::after { content: ""; flex: 1; height: 1px; background: var(--line); opacity: 0.6; }
/* district → 18+ → Google / guest */
.login-steps { display: flex; flex-direction: column; gap: 14px; }
.panel-login.pw-mode .login-only { display: none; }
.select-wrap { position: relative; display: block; }
.select-input {
  width: 100%;
  padding-right: 44px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.select-input:invalid { color: rgba(255, 244, 222, 0.45); }
.select-input option { color: var(--cream); background: #2a1532; }
.select-caret {
  position: absolute; right: 14px; top: 50%;
  width: 22px; height: 22px; margin-top: -11px;
  fill: none; stroke: var(--gold); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
  pointer-events: none;
}
.check-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 0;
  cursor: pointer;
  color: var(--cream);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.check-row:hover .check-box { border-color: var(--gold); }
.check-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check-box {
  flex: none;
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.check-box svg {
  width: 18px; height: 18px;
  fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
  opacity: 0; transform: scale(0.6);
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.check-row input:checked + .check-box { background: var(--gold); border-color: var(--gold); }
.check-row input:checked + .check-box svg { opacity: 1; transform: none; }
.check-row input:focus-visible + .check-box { outline: 3px solid var(--cream); outline-offset: 2px; }
/* missing step: shake + red edge so the player sees what's left */
.field.needs .text-input,
.check-row.needs .check-box { border-color: #ff9a8a; }
.needs { animation: needs-shake 0.35s ease; }
@keyframes needs-shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.btn-google {
  gap: 12px;
  color: #1f1f1f;
  background: #fff;
  border: 0;
  box-shadow: 0 4px 0 #b9ab93, 0 8px 22px rgba(0, 0, 0, 0.3);
}
.btn-google:hover { background: #f7f3ea; }
.btn-google:active { box-shadow: 0 2px 0 #b9ab93; }
.btn-google .g-logo { width: 26px; height: 26px; }
.login-steps .btn.is-locked { opacity: 0.55; filter: saturate(0.6); }
.login-steps .btn.is-locked:hover { opacity: 0.7; }
.link-btn {
  align-self: center;
  border: 0;
  padding: 6px 10px;
  background: none;
  color: var(--gold);
  font: 600 14px var(--font);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
@media (prefers-reduced-motion: reduce) { .needs { animation: none; } }

.seg-compact { align-self: center; width: min(260px, 100%); }
.seg-compact button { min-height: 36px; font-size: 14px; }

/* ---------- home district picker ---------- */
.panel-district { width: min(780px, 100%); overflow: hidden; padding-bottom: 18px; }
.panel-district > *,
.panel-login > * { flex-shrink: 0; }
/* header and action bar stay put; only the map + list scrolls */
.panel-district > .district-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 -10px;
  padding: 4px 10px 6px;
  border-radius: 12px;
}
.district-body { display: flex; gap: 16px; align-items: flex-start; }
.district-map {
  flex: none;
  width: 160px;
  padding: 10px;
  border-radius: 14px;
  background: radial-gradient(ellipse at 60% 40%, rgba(80, 160, 200, 0.18), rgba(0, 0, 0, 0.25));
  border: 1px solid rgba(246, 196, 83, 0.2);
  box-sizing: content-box;
  height: auto;
  image-rendering: pixelated;
  cursor: pointer;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.45));
  position: sticky;
  top: 0;
}
.district-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.district-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  min-height: 58px;
  border-radius: 12px;
  border: 2px solid rgba(255, 244, 222, 0.14);
  border-left: 5px solid var(--team);
  background: linear-gradient(180deg, rgba(255, 244, 222, 0.06), rgba(0, 0, 0, 0.2));
  color: var(--cream);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.district-card:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--team) 60%, transparent); }
.district-card:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
.district-card[aria-checked="true"] {
  border-color: var(--team);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--team) 35%, transparent), 0 6px 18px rgba(0, 0, 0, 0.35);
  background: linear-gradient(180deg, color-mix(in srgb, var(--team) 28%, transparent), rgba(0, 0, 0, 0.2));
}
.district-icon { font-size: 24px; line-height: 1; flex: none; }
.district-text { display: flex; flex-direction: column; min-width: 0; }
.district-name { font-size: 16px; font-weight: 800; line-height: 1.15; }
.district-sub { font-size: 12px; line-height: 1.25; color: var(--muted); }
.district-text { flex: 1; }
.district-card { padding-right: 34px; }
/* tick on the picked card */
.district-check {
  position: absolute;
  top: 50%;
  right: 10px;
  width: 20px;
  height: 20px;
  margin-top: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 244, 222, 0.25);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.district-card[aria-checked="true"] .district-check {
  border-color: var(--team);
  background: var(--team) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 10.5l3.2 3L15 7' fill='none' stroke='%2326131f' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
}
/* "Home" tag on the district you live in now */
.district-badge {
  display: none;
  position: absolute;
  top: -8px;
  right: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 16px;
}
.district-card.is-home .district-badge { display: block; }
#btn-district-go:disabled { opacity: 0.55; cursor: default; box-shadow: none; }

/* ---------- profile button + popover on the main menu ---------- */
.profile-wrap { position: relative; min-width: 0; }
.profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 260px;
  padding: 4px 14px 4px 4px;
  border-radius: 999px;
  border: 1.5px solid rgba(246, 196, 83, 0.7);
  background: rgba(30, 14, 32, 0.72);
  color: var(--cream);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.profile-btn:hover,
.profile-btn[aria-expanded="true"] { background: rgba(60, 28, 58, 0.9); border-color: var(--gold); }
.profile-btn:focus-visible { outline: 3px solid var(--cream); outline-offset: 2px; }
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(160deg, #ffe08f, var(--gold) 50%, var(--gold-deep));
  color: var(--ink);
  font: 800 20px/1 var(--font);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}
.avatar-lg { width: 56px; height: 56px; font-size: 28px; }
.profile-btn-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.profile-btn-name { font-size: 15px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-btn-sub { font-size: 12px; font-weight: 600; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-btn-sub:empty { display: none; }

.profile-pop {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 20;
  width: min(340px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius);
  border: 1.5px solid var(--line);
  background: rgba(34, 16, 38, 0.97);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  transform-origin: top left;
  animation: pop-in 0.16s cubic-bezier(.2, .8, .2, 1);
}
.profile-pop.hidden { display: none; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-6px) scale(0.97); } }
.profile-head { display: flex; align-items: center; gap: 12px; padding-right: 36px; }
.profile-head .panel-close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; margin: 0; }
.profile-id { display: flex; flex-direction: column; min-width: 0; }
.profile-name { font-size: 20px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-tag { font-size: 13px; font-weight: 600; color: var(--muted); }
.profile-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(246, 196, 83, 0.25);
}
.stat-icon { font-size: 18px; line-height: 1; }
.stat-num { font-size: 20px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; line-height: 1.1; }
.profile-travel { display: flex; flex-direction: column; gap: 8px; }
.travel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.travel-total { font-size: 13px; font-weight: 700; color: var(--gold); }
.travel-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.trip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 8px 2px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(246, 196, 83, 0.18);
}
.trip-icon { font-size: 16px; line-height: 1.1; }
.trip-num { font-size: 17px; font-weight: 800; color: var(--cream); font-variant-numeric: tabular-nums; }
.trip-label { font-size: 11px; font-weight: 600; color: var(--muted); text-align: center; line-height: 1.05; }
.profile-options:empty { display: none; }
.profile-pop .btn { min-height: 46px; font-size: 16px; }
.profile-pop .hint.hidden { display: none; }

/* guest name step on the login panel */
.panel-login.name-mode .login-steps { display: none; }
.guest-form { display: flex; flex-direction: column; gap: 14px; }
.guest-form.hidden { display: none; }
.guest-head { text-align: center; }
.guest-head h2 { margin: 0 0 4px; font-size: 24px; }

@media (max-width: 560px) {
  .district-map { display: none; }
  .panel-district { padding: 22px 14px 14px; }
  .panel-district .panel-head .hint { font-size: 13px; }
}
@media (max-width: 380px) {
  .district-grid { grid-template-columns: 1fr; }
}

/* ---------- main menu (home): title, story card and mode tiles over the attract race ---------- */
.screen-home {
  align-items: stretch;
  background: linear-gradient(90deg, rgba(20, 8, 24, 0.78) 0%, rgba(20, 8, 24, 0.35) 55%, rgba(20, 8, 24, 0.12) 100%);
}

.home {
  width: 100%;
  max-width: 1180px;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.3s cubic-bezier(.2, .8, .2, 1);
}

.home-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}


.home-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.home-tools .seg-compact { width: auto; padding: 3px; border-radius: 12px; background: rgba(30, 14, 32, 0.72); }
.home-tools .seg-compact button { flex: none; padding: 0 12px; }

.home-tools .icon-btn { width: 44px; height: 44px; font: 800 20px/1 var(--font); }
.home-tools #btn-sound span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.home-title { text-align: left; }
.home-title .title-ml { font-size: clamp(44px, 8vw, 84px); }

.home-stats {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.home-stats:empty { display: none; }

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 10px;
}

/* ---------- the four-way main menu ---------- */

.menu-grid {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.menu-card {
  appearance: none;
  position: relative;
  min-height: 112px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 48px 16px 16px;
  border: 1.5px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--cream);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
}

.menu-card:hover {
  background: rgba(60, 28, 58, 0.92);
  border-color: var(--gold);
  transform: translateY(-3px);
  box-shadow: 0 10px 28px rgba(10, 0, 20, 0.45);
}

.menu-card:active { transform: translateY(0) scale(0.99); }

/* the first way in reads as the primary action: a gold plaque, not a glass panel */
.menu-card-hero {
  grid-column: 1 / -1;
  border-color: var(--gold);
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 6px 0 #8a5a1a, 0 18px 40px rgba(10, 0, 20, 0.5);
}

.menu-card-hero:hover {
  background: #fff6e4;
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #8a5a1a, 0 22px 46px rgba(10, 0, 20, 0.5);
}

.menu-card-hero:active {
  transform: translateY(3px) scale(1);
  box-shadow: 0 3px 0 #8a5a1a, 0 10px 24px rgba(10, 0, 20, 0.5);
}

.menu-card-icon {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(201, 138, 43, 0.16);
}

.menu-card-hero .menu-card-icon { background: rgba(138, 90, 26, 0.14); }

.menu-card-icon svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-card-hero .menu-card-icon svg { stroke: #8a5a1a; }

.menu-card-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.menu-card-name {
  font-size: 19px;
  font-weight: 800;
  line-height: 1.15;
}

.menu-card-hero .menu-card-name { font-size: 22px; }

.menu-card-sub {
  font-size: 13px;
  line-height: 1.35;
  color: var(--muted);
}

.menu-card-sub:empty { display: none; }
.menu-card-hero .menu-card-sub { color: #7a4a2a; }

/* the chevron in the corner: present on every card, gold disc on the hero */
.menu-card-go {
  position: absolute;
  top: 50%;
  right: 16px;
  width: 11px;
  height: 11px;
  border-right: 2.5px solid var(--gold);
  border-bottom: 2.5px solid var(--gold);
  transform: translateY(-50%) rotate(-45deg);
  transition: right 0.15s ease;
}

.menu-card:hover .menu-card-go { right: 12px; }

.menu-card-hero .menu-card-go {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: var(--gold-deep);
  transform: translateY(-50%);
  right: 14px;
}

.menu-card-hero .menu-card-go::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 54%;
  border-left: 13px solid var(--cream);
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  transform: translate(-50%, -50%);
}

.menu-card-hero:hover .menu-card-go { right: 14px; }

.home-main-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 22px;
}

.link-btn {
  appearance: none;
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font: 600 14px var(--font);
  text-decoration: underline;
  cursor: pointer;
}

.home-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
}

.home-foot .credit { text-align: left; }

/* ---------- mini-games picker ---------- */
.panel-mini { width: min(680px, 100%); }

.mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.mini-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 1.5px solid rgba(246, 196, 83, 0.35);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--cream);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.mini-card:hover { background: rgba(255, 244, 222, 0.08); border-color: var(--gold); }
.mini-icon { font-size: 28px; line-height: 1.2; }
.mini-name { font-size: 17px; font-weight: 700; line-height: 1.2; }
.mini-where { font-size: 13px; color: var(--muted); }
.mini-stats { margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--gold); }

/* phones in portrait: stack everything, darken the whole scene */
@media (max-width: 720px) {
  .screen-home { background: linear-gradient(180deg, rgba(20, 8, 24, 0.7) 0%, rgba(20, 8, 24, 0.25) 45%, rgba(20, 8, 24, 0.7) 100%); }
  .home-top { align-items: center; gap: 8px; }
  .profile-btn { max-width: 200px; }
  .home-title { text-align: center; }
  .home-stats { text-align: center; }
  .home-main { align-items: stretch; }
  .menu-grid { width: 100%; grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .menu-card { min-height: 0; align-items: center; padding: 12px 44px 12px 14px; }
  .menu-card:hover { transform: none; }
  .menu-card-hero:hover { transform: none; }
  .menu-card-icon { width: 40px; height: 40px; }
  .menu-card-hero .menu-card-name { font-size: 20px; }
  .home-main-foot { justify-content: center; }
  .home-foot { justify-content: center; }
  .home-foot .credit { display: none; }
}

/* ---------- short landscape screens (phones on their side) ---------- */
@media (max-height: 560px) and (orientation: landscape) {
  .panel { padding: 18px 18px 14px; gap: 10px; }
  .panel::before { top: 6px; }

  .title-ml { font-size: clamp(40px, 9vw, 64px); }

  .home { gap: 10px; }
  .home-title .title-ml { font-size: clamp(32px, 7vw, 48px); padding-top: 0; }
  .home-title .subtitle,
  .home-foot { display: none; }
  .menu-grid { gap: 8px; }
  .menu-card { min-height: 0; align-items: center; padding: 10px 42px 10px 12px; }
  .menu-card-icon { width: 36px; height: 36px; border-radius: 10px; }
  .menu-card-icon svg { width: 22px; height: 22px; }
  .menu-card-name { font-size: 17px; }
  .menu-card-hero .menu-card-name { font-size: 18px; }
  .menu-card-sub { display: none; }
  .menu-card-hero .menu-card-go { width: 32px; height: 32px; }
  .menu-card-hero .menu-card-go::after { border-left-width: 11px; border-top-width: 7px; border-bottom-width: 7px; }
  .mini-grid { grid-template-columns: repeat(3, 1fr); }

  .btn { min-height: 46px; font-size: 16px; }
  .btn-xl { min-height: 52px; font-size: 20px; }

  .toast-wrap { bottom: 72px; }
  .toast { padding: 5px 12px; font-size: 13px; }
  .toast-big { font-size: 16px; }
  .segmented button { min-height: 38px; }

  .panel-select { width: min(820px, 100%); }
  .district-grid { grid-template-columns: repeat(3, 1fr); }
  .district-map { display: none; }
  .panel-login .title-block { display: none; }
  .village-grid { grid-template-columns: repeat(4, 1fr); }
  .village-card { min-height: 92px; }
  .village-name { font-size: 15px; }

  .panel-results { width: min(820px, 100%); }
  .results-body { flex-direction: row; align-items: flex-end; }
  .results-body > * { flex: 1; }
  .podium-col.p1 .podium-block { height: 64px; }
  .podium-col.p2 .podium-block { height: 46px; }
  .podium-col.p3 .podium-block { height: 34px; }
  .podium-boat { max-width: 90px; }
  .stat-v { font-size: 17px; }
}

@media (max-width: 380px) {
  .btn { font-size: 16px; }
  .village-name { font-size: 15px; }
  .podium-name { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .panel,
  .toast,
  .cx-panel,
  .cx-stage-bg,
  .cx-balloon.pop .cx-bin,
  .cx-caption.pop,
  .cx-text .w,
  .cx-more,
  .cx-choice,
  .cx-cover-book,
  .cx-cover-art img,
  .cx-cover-rays,
  .cx-cover-foot h2,
  .cx-title-in,
  .cx-title .swash,
  .cx-passed-big,
  .cx-pow,
  .story-paper-sheet,
  .result-headline.win { animation: none !important; }
  .cx-text .w { opacity: 1; }
  .cx-art { transition: none; }
}

/* ==========================================================================
   PLAY WITH FRIENDS – the group: its pill, its panel and the live scoreboard
   ========================================================================== */
.party-pill {
  padding: 4px 12px 4px 9px;
  border-radius: 99px;
  background: linear-gradient(180deg, rgba(246, 196, 83, 0.95), rgba(236, 170, 51, 0.95));
  border: 1px solid rgba(60, 30, 12, 0.35);
  color: #2a1747;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(120, 72, 16, 0.6);
}
.party-pill::before { content: "👥"; margin-right: 6px; }
.party-pill:active { transform: translateY(2px); box-shadow: none; }
.party-pill.hidden { display: none; }

.party-panel {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  background: rgba(14, 7, 20, 0.62);
  backdrop-filter: blur(3px);
}
.party-panel.hidden { display: none; }
.party-sheet {
  width: min(620px, 100%);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: 20px;
  background: linear-gradient(180deg, #3a2159, #2a1747);
  border: 2px solid rgba(246, 196, 83, 0.5);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: slot-in 0.2s ease;
}
.party-head h2 { margin: 0; font-size: 22px; }
.party-head .hint { margin: 3px 0 0; }
.party-cols { display: grid; grid-template-columns: minmax(150px, 0.8fr) 1.4fr; gap: 14px; }
.party-col { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.party-who { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; }
.party-who-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.26);
  font-size: 13.5px;
}
.party-who-row .pw-dot {
  flex: none; width: 7px; height: 7px; border-radius: 50%; background: #4ade80;
}
.party-who-row.away { opacity: 0.55; }
.party-who-row.away .pw-dot { background: var(--muted); }
.pw-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pw-where { font-size: 11px; color: var(--muted); }

.party-games { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.party-game {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: 13px;
  text-align: left;
  color: var(--cream);
  font-family: inherit;
  background: rgba(255, 244, 222, 0.08);
  border: 1.5px solid rgba(246, 196, 83, 0.28);
  cursor: pointer;
}
.party-game:hover:not(:disabled) { background: rgba(255, 244, 222, 0.14); }
.party-game:active:not(:disabled) { transform: translateY(2px); }
.party-game:disabled { opacity: 0.45; cursor: default; }
.party-game-hero {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, rgba(246, 196, 83, 0.95), rgba(236, 170, 51, 0.92));
  color: #2a1747;
  border-color: rgba(60, 30, 12, 0.35);
}
.pg-icon { flex: none; font-size: 22px; }
.pg-text { display: flex; flex-direction: column; min-width: 0; }
.pg-name { font-weight: 800; font-size: 14.5px; }
.pg-sub { font-size: 11.5px; opacity: 0.75; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.party-board {
  position: absolute;
  top: max(58px, calc(env(safe-area-inset-top) + 54px));
  right: max(10px, env(safe-area-inset-right));
  z-index: 8;
  width: min(230px, 46vw);
  padding: 10px 11px;
  border-radius: 14px;
  background: rgba(22, 11, 30, 0.86);
  border: 1.5px solid rgba(246, 196, 83, 0.45);
  color: var(--cream);
  animation: slot-in 0.25s ease;
}
.party-board.hidden { display: none; }
/* the result stays in its corner: a game's own result card owns the middle */
.party-board.final {
  width: min(280px, 60vw);
  padding: 13px 13px 11px;
  border-width: 2px;
  border-color: var(--gold);
  background: rgba(22, 11, 30, 0.95);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.55);
}
.party-board h3 { margin: 0 0 7px; font-size: 14px; letter-spacing: 0.02em; }
.party-board.final h3 { font-size: 15.5px; margin-bottom: 9px; color: var(--gold); }
.pb-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.pb-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 7px;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.28);
  font-size: 13px;
}
.pb-row.me { background: rgba(246, 196, 83, 0.18); }
.pb-row.pending { opacity: 0.6; }
.pb-place { flex: none; width: 20px; text-align: center; }
.pb-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pb-score { font-weight: 800; color: var(--gold); }
.pb-foot { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); text-align: center; }
.party-board.final .pb-foot { font-size: 15px; font-weight: 800; color: var(--cream); }
.party-board .btn { width: 100%; margin-top: 9px; }

@media (max-width: 560px) {
  .party-cols { grid-template-columns: 1fr; }
  .party-games { grid-template-columns: 1fr; }
  .party-board { width: min(200px, 52vw); font-size: 12px; }
}

/* ---------- brand logo (art/brand) ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.title-logo {
  display: block;
  width: clamp(200px, 26vw, 340px);
  height: auto;
  margin: 0 auto;
  filter: drop-shadow(0 10px 24px rgba(10, 4, 14, 0.55));
  animation: logo-in 0.5s cubic-bezier(.2, 1.3, .4, 1) both;
}

.home-title .title-logo { margin: -6px 0 -2px -10px; }
.panel-login .title-logo { width: clamp(150px, 40vw, 210px); margin-top: -8px; }

@keyframes logo-in {
  from { opacity: 0; transform: scale(0.88); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .title-logo { animation: none; }
}

@media (max-width: 720px) {
  .home-title .title-logo { width: clamp(160px, 52vw, 220px); margin: -4px auto 0; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .home-title .title-logo { width: clamp(110px, 22vh, 150px); margin: 0 0 -4px; }
}

/* ---------- in-game toolbar: map · sound · pause in one bar, the minimap sits under it ---------- */
.hud-controls {
  align-items: center;
  gap: 2px;
  height: 48px;
  min-width: var(--mm-w, 0px);   /* world.js sets this so the bar and the minimap share one width */
  padding: 4px;
  box-sizing: border-box;
  border-radius: 14px;
  border: 1px solid rgba(246, 196, 83, 0.45);
  background: linear-gradient(180deg, rgba(48, 24, 50, 0.88), rgba(26, 12, 28, 0.88));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 244, 222, 0.08);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.hud-controls .icon-btn {
  flex: 1 1 0;
  width: auto;
  min-width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--cream);
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.12s ease;
}
.hud-controls .icon-btn svg { width: 21px; height: 21px; stroke-width: 1.9; }
.hud-controls .icon-btn:hover { background: rgba(255, 244, 222, 0.1); color: #fff; }
.hud-controls .icon-btn:active { background: rgba(246, 196, 83, 0.18); }
.hud-controls .icon-btn.hidden { display: none; }
/* ---------- in-game profile pill, top-left: the menu's profile button, a touch smaller ---------- */
.hud-me {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  z-index: 5;
}
.hud-me.hidden,
body.map-open .hud-me { display: none; }
.cx-cinema .hud-me { opacity: 0; pointer-events: none; }
.hud-me .profile-btn {
  max-width: min(240px, calc(100vw - var(--mm-w, 110px) - 48px));
  padding: 3px 14px 3px 3px;
  gap: 9px;
  background: linear-gradient(180deg, rgba(48, 24, 50, 0.88), rgba(26, 12, 28, 0.88));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 244, 222, 0.08);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.hud-me .profile-btn.hidden { display: none; }
.hud-me .profile-btn:active .avatar { transform: scale(0.94); }
.hud-me .avatar { width: 38px; height: 38px; font-size: 18px; transition: transform 0.12s ease; }
/* opened from the game: the popover hangs under the pill */
.hud-me .profile-pop {
  top: calc(100% + 8px);
  left: 0;
  max-height: calc(100vh - 80px - env(safe-area-inset-top));
  max-height: calc(100dvh - 80px - env(safe-area-inset-top));
  overflow-y: auto;
  transform-origin: top left;
}
/* just after the full map closes, the toolbar ignores the tap that closed it (world.js closeMap) */
body.hud-guard .hud-controls,
body.hud-guard .hud-me { pointer-events: none; }
@media (max-width: 599px) {
  .hud-controls { height: 44px; padding: 3px; border-radius: 12px; }
  .hud-controls .icon-btn { min-width: 34px; height: 36px; }
  .hud-controls .icon-btn svg { width: 19px; height: 19px; }
  .hud-me .profile-btn { padding-right: 12px; gap: 8px; }
  .hud-me .avatar { width: 34px; height: 34px; font-size: 16px; }
  .hud-me .profile-btn-name { font-size: 14px; }
  .hud-me .profile-btn-sub { font-size: 11px; }
  /* the minimap opens the map on a tap, so the bar drops its own map button here */
  .hud-controls #btn-map { display: none; }
}
