/* Fonts, served from fonts/ so the game asks no other site for anything (SIL Open Font Licence: fonts/OFL-*.txt).
   Latin characters only. Nunito is one variable font, declared at the three weights the game uses. */
@font-face { font-family: 'Bungee'; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/bungee-latin.woff2?v=126eec706b) format('woff2'); }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/nunito-latin.woff2?v=ba344451ea) format('woff2'); }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 800; font-display: swap; src: url(fonts/nunito-latin.woff2?v=ba344451ea) format('woff2'); }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 900; font-display: swap; src: url(fonts/nunito-latin.woff2?v=ba344451ea) format('woff2'); }

:root {
  --ink: #fff7ea;
  --muted: #dcc6a3;
  --muted-light: #f0e2c8;                 /* the same sand colour, lighter: small text over the busy 3D desert */
  --gold: #ffcf5c;
  --orange: #ff8a1f;
  --panel: rgba(28, 16, 8, 0.78);
  --line: rgba(255, 220, 160, 0.2);
  --display: 'Bungee', Impact, 'Arial Black', sans-serif;
  /* Safe areas: notches, rounded corners and the home bar (game.js reads them too, for the HUD) */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;              /* no pull-to-refresh or bounce */
  background: #2a1a0e;
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 600;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;            /* no long-press menus */
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: none;
}
button:focus-visible, a:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: none; }
body.gfx3d canvas#gl { display: block; }

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: max(24px, var(--safe-t)) max(16px, var(--safe-r)) max(24px, var(--safe-b)) max(16px, var(--safe-l));
  text-align: center;
  overflow-y: auto;
  touch-action: pan-y;                    /* menus scroll, but no pinch or double-tap zoom */
  overscroll-behavior: contain;
}
.screen.active { display: flex; }
/* centre vertically but never clip the top when content is taller than the screen */
.screen > :first-child { margin-top: auto; }
.screen > :last-child { margin-bottom: auto; }

#screen-title, #screen-select, #screen-shop, #screen-rooms {
  background:
    radial-gradient(ellipse at 50% 115%, rgba(255, 140, 40, 0.35), transparent 60%),
    linear-gradient(180deg, rgba(24, 12, 34, 0.72), rgba(42, 22, 10, 0.8));
}
.overlay { background: rgba(15, 8, 4, 0.72); backdrop-filter: blur(3px); }

h2 { font-family: var(--display); font-size: clamp(26px, 5vw, 40px); font-weight: 400; color: var(--gold); text-shadow: 0 3px 0 #7c2d12; }
h2.shout { font-size: clamp(34px, 8vw, 64px); animation: pop 0.35s ease-out; }

.logo {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(56px, 13vw, 130px);
  line-height: 0.92;
  color: var(--gold);
  text-shadow: 0 4px 0 #c2410c, 0 8px 0 #7c2d12, 0 14px 30px rgba(0, 0, 0, 0.6);
  animation: float 3s ease-in-out infinite;
}
.tagline { font-size: clamp(16px, 2.6vw, 20px); color: var(--muted); font-weight: 800; }
.hint { font-size: 13px; color: var(--muted-light); }
.touch-only { display: none; }
body.is-touch .touch-only { display: block; }
body.is-touch .keys-only { display: none; }

.row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--display);
  font-size: 18px;
  padding: 12px 28px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--gold), var(--orange));
  color: #3a1a05;
  box-shadow: 0 5px 0 #a3420b, 0 10px 24px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a3420b; }
.btn.big { font-size: 24px; padding: 14px 46px; }
.btn.ghost { background: rgba(255, 255, 255, 0.06); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

/* ---------- hall of fame ---------- */
.hall {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 18px;
}
.hall h3 { font-family: var(--display); font-weight: 400; font-size: 16px; color: var(--gold); margin-bottom: 8px; letter-spacing: 1px; }
.hall ol { list-style: none; counter-reset: rank; display: grid; gap: 4px; }
.hall li { counter-increment: rank; display: grid; grid-template-columns: 26px 1fr auto auto; gap: 10px; align-items: baseline; text-align: left; font-size: 15px; }
.hall li::before { content: counter(rank); font-family: var(--display); color: var(--muted); }
.hall li:first-child::before { content: '👑'; }
.hall li.empty { display: block; text-align: center; color: var(--muted); }
.hall li.empty::before { content: none; }
.hall .hn { font-weight: 900; }
.hall .hs { font-weight: 900; font-variant-numeric: tabular-nums; }
.hall .hw { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.tab {
  font: 900 12px 'Nunito', sans-serif;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab.on { background: var(--d); border-color: transparent; color: #1a0d04; }

/* ---------- character select ---------- */
#screen-select { gap: 14px; }
#hero-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 7), minmax(0, 1fr));
  gap: 10px;
  width: min(940px, 100%);
}
.hero-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.hero-card canvas { width: 68px; height: 68px; }
.hero-card:hover { transform: translateY(-3px); background: rgba(255, 255, 255, 0.1); }
.hero-card.selected {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 22%, rgba(20, 10, 4, 0.6));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 40%, transparent), 0 12px 28px rgba(0, 0, 0, 0.4);
  transform: translateY(-4px) scale(1.03);
}
.hc-name { font-family: var(--display); font-size: 14px; }
.hc-title { font-size: 11px; color: var(--muted-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hc-best { font-size: 11px; color: #ffd27a; font-weight: 800; margin-top: 2px; }

#hero-detail {
  width: min(780px, 100%);
  display: grid;
  grid-template-columns: 1fr 230px;
  gap: 6px 22px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 6px solid var(--c);
  border-radius: 16px;
  text-align: left;
}
.d-main { display: flex; flex-direction: column; gap: 6px; }
.d-name { font-family: var(--display); font-size: 30px; line-height: 1; color: var(--c); }
.d-title { font-weight: 900; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; font-size: 13px; }
.d-quote { font-style: italic; font-size: 16px; }
.d-special { font-size: 14px; color: var(--muted); }
.d-special b { color: var(--gold); }
.d-stats { display: grid; gap: 7px; align-content: center; }
.stat { display: grid; grid-template-columns: 74px 1fr; align-items: center; font-size: 13px; font-weight: 800; }
.pips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.pips i { height: 10px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); }
.pips i.on { background: var(--c); }

.options { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.seg { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 4px; padding: 4px; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 14px; }
.seg-btn {
  font-family: var(--display);
  font-size: 14px;
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.on { background: var(--d); color: #1a0d04; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
.chip {
  font: 800 14px 'Nunito', sans-serif;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { background: rgba(255, 255, 255, 0.12); }
.diff-desc { margin-top: -6px; min-height: 1.3em; font-size: 14px; font-weight: 800; color: var(--muted); }

.seg-btn:disabled { cursor: default; opacity: 0.55; }
.seg-btn.on:disabled { opacity: 1; }
.btn.alt { background: linear-gradient(180deg, #7dd3fc, #38bdf8); color: #082f49; box-shadow: 0 5px 0 #0369a1, 0 10px 24px rgba(0, 0, 0, 0.35); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.hall-scope { font-family: 'Nunito', sans-serif; font-size: 12px; font-weight: 900; color: var(--muted); letter-spacing: 0; }
[hidden] { display: none !important; }

/* ---------- web edition: SCA CodeFest, credit, multiplayer note ---------- */
.cf-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 207, 92, 0.55);
  background: rgba(20, 12, 6, 0.6);
  color: var(--ink);
  font: 800 14px 'Nunito', sans-serif;
  text-decoration: none;
}
.cf-chip b { color: var(--gold); margin-left: 3px; }
.cf-chip:hover { background: rgba(40, 24, 10, 0.75); }
.fine { font-size: 12px; font-weight: 800; color: var(--muted-light); line-height: 1.5; }
.web-multi { align-items: center; text-align: center; font-size: 16px; font-weight: 800; }
.web-multi h3 { font-family: var(--display); font-weight: 400; color: var(--gold); font-size: 20px; }
.web-multi p { color: var(--ink); }
.cf-line { font-weight: 800; color: var(--muted); }
.cf-line a { color: var(--gold); font-weight: 900; }
.hall .hn small { color: var(--muted); font-weight: 800; }

/* ---------- coins & shop ---------- */
.shop-btn { background: linear-gradient(180deg, #fde68a, #f59e0b); }
.btn.story { background: linear-gradient(180deg, #fef3c7, #d97706); box-shadow: 0 5px 0 #92400e, 0 10px 24px rgba(0, 0, 0, 0.35); }
.wallet { font-family: var(--display); font-size: 22px; color: var(--gold); }
.shop-tabs { margin: 0; }
.shop-tabs .tab { font-size: 15px; padding: 8px 18px; --d: var(--gold); }
.shop-grid {
  width: min(900px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.shop-item {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  align-items: center;
  padding: 12px;
  text-align: left;
  background: var(--panel);
  border: 2px solid var(--tier, var(--line));
  border-radius: 14px;
}
.shop-item canvas { width: 64px; height: 64px; grid-row: span 3; }
.shop-item .icon { font-size: 34px; grid-row: span 3; width: 52px; text-align: center; }
.shop-item .nm { font-family: var(--display); font-size: 15px; }
.shop-item .sub { font-size: 12px; color: var(--muted); }
.shop-item .tier { font: 900 11px 'Nunito', sans-serif; letter-spacing: 1px; text-transform: uppercase; color: var(--tier); }
.shop-item .buy { grid-column: 1 / -1; margin-top: 6px; font-size: 14px; padding: 8px 12px; }
.shop-item.owned { opacity: 0.8; }
.shop-item.owned .buy { background: rgba(74, 222, 128, 0.18); color: #86efac; box-shadow: none; }
.shop-hint { max-width: 640px; }
.hero-card.locked canvas { filter: grayscale(0.85) brightness(0.7); }
.hero-card .hc-best.lock { color: #fecaca; }
.unlock-row { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.unlock-row .btn { font-size: 15px; padding: 9px 18px; }
.unlock-row span { color: var(--muted); font-weight: 800; font-size: 13px; }
.coins-earned { font-family: var(--display); font-size: 22px; color: var(--gold); }
.coins-earned small { display: block; font-family: 'Nunito', sans-serif; font-size: 13px; color: var(--muted); font-weight: 800; }

/* ---------- multiplayer ---------- */
.panel {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.panel.help { text-align: left; font-size: 14px; }
.panel.help h3 { font-family: var(--display); font-weight: 400; color: var(--gold); font-size: 16px; }
.panel.help ol { padding-left: 20px; display: grid; gap: 4px; }
.panel.help code { background: rgba(0, 0, 0, 0.35); padding: 1px 6px; border-radius: 6px; }
.rooms-status { color: var(--muted); font-weight: 800; }
.rooms-status b { color: var(--gold); user-select: all; }
.room-list { display: grid; gap: 8px; }
.room-list .empty { color: var(--muted); text-align: center; padding: 8px; }
.room-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  text-align: left;
}
.room-item .code { font-family: var(--display); font-size: 20px; color: var(--gold); letter-spacing: 2px; }
.room-item .who { font-size: 13px; color: var(--muted); }
.room-item .who b { color: var(--ink); }
.code-input {
  width: 110px;
  font-family: var(--display);
  font-size: 20px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 3px;
  padding: 8px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  user-select: text;
  -webkit-user-select: text;
}
.room-bar {
  display: none;
  width: min(780px, 100%);
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 14px;
}
.room-bar.on { display: flex; }
.room-bar .code { font-family: var(--display); font-size: 22px; color: var(--gold); letter-spacing: 3px; }
.room-bar .mate { padding: 3px 10px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); font-weight: 900; }
.room-bar .mate.me { outline: 2px solid var(--gold); }
.room-bar .note { color: var(--muted); font-weight: 800; flex-basis: 100%; text-align: center; font-size: 13px; }
.hero-card.taken { opacity: 0.45; cursor: not-allowed; }
.hero-card.taken::after {
  content: 'TAKEN';
  position: absolute;
  top: 6px;
  right: 6px;
  font: 900 11px 'Nunito', sans-serif;
  background: #b91c1c;
  color: #fff;
  padding: 2px 6px;
  border-radius: 999px;
}
.levelup-timer { color: var(--gold); font-weight: 900; min-height: 1.2em; }
.team-list { display: grid; gap: 6px; width: min(460px, 100%); }
.team-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel);
  text-align: left;
  font-weight: 800;
}
.team-row .k { font-variant-numeric: tabular-nums; }
.team-row .mvp { color: var(--gold); font-size: 12px; }

/* ---------- pause: controls ---------- */
.controls {
  display: grid;
  gap: 7px;
  width: min(560px, 100%);
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: left;
  font-size: 14px;
}
.controls > div { display: grid; grid-template-columns: 100px 1fr 1fr; gap: 10px; }
.controls .ctl-head { font-size: 12px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.controls b { color: var(--gold); }
body.is-touch .controls { display: none; }

/* ---------- level up ---------- */
#levelup-sub { color: var(--muted); font-weight: 800; }
#upgrade-cards { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.up-card {
  position: relative;
  width: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 14px 16px;
  background: linear-gradient(180deg, #45290f, #24150a);
  border: 2px solid rgba(255, 207, 92, 0.35);
  border-radius: 18px;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  animation: pop 0.3s ease-out backwards;
}
.up-card:nth-child(2) { animation-delay: 0.07s; }
.up-card:nth-child(3) { animation-delay: 0.14s; }
.up-card:hover { border-color: var(--gold); transform: translateY(-4px); }
.up-card.focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 207, 92, 0.35); }
.up-key { position: absolute; top: 8px; left: 12px; font-family: var(--display); font-size: 13px; opacity: 0.5; }
.up-icon { font-size: 40px; line-height: 1.1; }
.up-name { font-family: var(--display); font-size: 16px; color: var(--gold); }
.up-desc { font-size: 14px; color: var(--muted); }
.up-lv { font-size: 12px; font-weight: 900; color: #ffd27a; }

/* ---------- game over ---------- */
#over-stats { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.big-score { font-family: var(--display); font-size: clamp(44px, 10vw, 80px); line-height: 1; color: var(--gold); text-shadow: 0 4px 0 #7c2d12; }
.score-label { font-size: 13px; color: var(--muted); font-weight: 900; letter-spacing: 2px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; width: min(460px, 100%); }
.stat-grid div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; }
.stat-grid b { display: block; font-size: 22px; font-weight: 900; }
.stat-grid span { font-size: 12px; color: var(--muted); }
.badge { display: inline-block; padding: 7px 16px; border-radius: 999px; background: var(--gold); color: #3a1a05; font-weight: 900; animation: pulse 1s ease-in-out infinite; }
.taunt { color: var(--muted); font-weight: 800; }

/* ---------- touch controls ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; display: none; }
#touch.on { display: block; }
#stick {
  position: absolute;
  width: 120px;
  height: 120px;
  margin: -60px 0 0 -60px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: none;
}
#knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: rgba(255, 255, 255, 0.6); }
#btn-special {
  position: absolute;
  right: calc(22px + var(--safe-r));
  bottom: calc(26px + var(--safe-b));
  width: 86px;
  height: 86px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  color: #fff;
  font-size: 38px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  pointer-events: auto;
  background: conic-gradient(var(--c, #ffb347) calc(var(--cd, 1) * 360deg), rgba(0, 0, 0, 0.45) 0);
}
#btn-special.ready { animation: pulse 0.9s ease-in-out infinite; }
#btn-dodge {
  position: absolute;
  right: calc(124px + var(--safe-r));
  bottom: calc(32px + var(--safe-b));
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.75);
  color: #fff;
  font-size: 28px;
  pointer-events: auto;
  background: conic-gradient(#d9b98a calc(var(--cd, 1) * 360deg), rgba(0, 0, 0, 0.45) 0);
}

/* story mode: a big FIRE button you hold down */
#btn-fire {
  position: absolute;
  right: calc(26px + var(--safe-r));
  bottom: calc(128px + var(--safe-b));
  width: 92px;
  height: 92px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: radial-gradient(circle at 50% 40%, rgba(239, 68, 68, 0.75), rgba(127, 29, 29, 0.75));
  font-size: 40px;
  pointer-events: auto;
  display: none;
}
#btn-fire.held { transform: scale(0.92); background: radial-gradient(circle at 50% 40%, #f87171, #991b1b); }
body.tactical #btn-fire { display: block; }

.story-only { display: none !important; }
body.tactical .story-only { display: grid !important; }
body.tactical p.story-only, body.tactical button.story-only { display: inline-block !important; }
body.tactical .survival-only { display: none !important; }
body.is-touch .keys-only.story-only, body:not(.is-touch) .touch-only.story-only { display: none !important; }

/* ---------- Elder Mosi's dialogue ---------- */
.dialogue {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: max(16px, var(--safe-t)) max(16px, var(--safe-r)) max(22px, 4vh, var(--safe-b)) max(16px, var(--safe-l));
  background: linear-gradient(180deg, rgba(10, 5, 2, 0.15) 0%, rgba(10, 5, 2, 0.35) 45%, rgba(10, 5, 2, 0.78) 100%);
  cursor: pointer;
}
.dialogue.on { display: flex; }
.dlg-panel {
  width: min(1000px, 100%);
  display: grid;
  grid-template-columns: clamp(130px, 21vw, 230px) 1fr;
  gap: clamp(12px, 2vw, 26px);
  align-items: end;
  padding: clamp(14px, 2vw, 22px) clamp(16px, 2.4vw, 28px);
  background: linear-gradient(180deg, rgba(48, 28, 12, 0.96), rgba(26, 14, 6, 0.97));
  border: 3px solid #d9b98a;
  border-radius: 24px;
  box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.35), 0 18px 50px rgba(0, 0, 0, 0.6);
  animation: rise 0.28s ease-out;
}
.dlg-face { position: relative; align-self: stretch; }
.dlg-face canvas {
  position: absolute;
  left: 0;
  bottom: -6px;
  width: 100%;
  aspect-ratio: 1;
  height: auto;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
}
.dlg-body { text-align: left; min-height: clamp(150px, 22vh, 210px); display: flex; flex-direction: column; gap: 8px; }
.dlg-title { font: 900 13px 'Nunito', sans-serif; letter-spacing: 2px; color: var(--muted); }
.dlg-title:empty { display: none; }
.dlg-name { font-family: var(--display); font-size: clamp(18px, 2.2vw, 26px); color: var(--gold); text-shadow: 0 2px 0 #7c2d12; }
.dlg-text { font-size: clamp(19px, 2.3vw, 27px); font-weight: 800; line-height: 1.35; color: var(--ink); flex: 1; }
.dlg-rest { opacity: 0; }
.dlg-choices { display: flex; gap: 10px; flex-wrap: wrap; }
.dlg-choices:empty { display: none; }
.dlg-choices .btn { font-size: clamp(15px, 1.8vw, 20px); padding: 10px 22px; }
.dlg-choices .btn.focus { outline: 3px solid #fff; outline-offset: 3px; }
.dlg-foot { display: flex; align-items: center; gap: 14px; }
.dlg-dots { display: flex; gap: 6px; }
.dlg-dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(217, 185, 138, 0.35); }
.dlg-dots i.on { background: var(--gold); }
.dlg-hint { flex: 1; text-align: right; font: 900 14px 'Nunito', sans-serif; color: var(--gold); animation: nudge 1s ease-in-out infinite; }
.dlg-skip { font: 900 12px 'Nunito', sans-serif; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes nudge { 50% { transform: translateX(4px); } }
@media (max-width: 600px) {
  .dlg-panel { grid-template-columns: 96px 1fr; border-radius: 18px; }
  .dlg-body { min-height: 150px; }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(130px + var(--safe-b));
  transform: translate(-50%, 16px);
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(20, 12, 6, 0.9);
  border: 1px solid var(--line);
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#btn-pause {
  position: absolute;
  left: calc(12px + var(--safe-l));
  bottom: calc(14px + var(--safe-b));
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font-size: 16px;
  pointer-events: auto;
}

/* ---------- animation ---------- */
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse { 50% { transform: scale(1.06); } }
@keyframes float { 50% { transform: translateY(-8px); } }

@media (max-width: 600px) {
  #hero-grid { gap: 6px; }
  .hero-card { padding: 6px 2px 8px; border-radius: 12px; }
  .hero-card canvas { width: 50px; height: 50px; }
  .hc-name { font-size: 12px; }
  .hc-title { display: none; }
  #hero-detail { grid-template-columns: 1fr; }
  .d-name { font-size: 24px; }
  .up-card { width: 100%; max-width: 340px; padding: 14px; }
  .up-icon { font-size: 30px; }
  .stat-grid b { font-size: 18px; }
  .seg-btn { font-size: 12px; padding: 7px 9px; }
  .controls > div { grid-template-columns: 84px 1fr; }
  .controls > div > :nth-child(3) { display: none; }
}

/* ---------- phones, tablets and small screens ---------- */
.corner {
  position: fixed;
  top: calc(10px + var(--safe-t));
  right: calc(10px + var(--safe-r));
  display: flex;
  gap: 8px;
  z-index: 5;
}
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(20, 12, 6, 0.6);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(40, 24, 10, 0.75); }

/* narrow screens: the logo starts below the sound and full-screen buttons */
@media (max-width: 520px) {
  #screen-title { padding-top: max(66px, calc(var(--safe-t) + 56px)); }
}

/* a phone on its side: FIRE joins the bottom row (left of dodge), so it doesn't sit on the HUD at the top right */
@media (max-height: 500px) {
  body.is-touch #btn-fire { right: calc(204px + var(--safe-r)); bottom: calc(26px + var(--safe-b)); }
}

/* touch screens: every button at least 44 px, so small fingers hit it */
body.is-touch .btn, body.is-touch .chip, body.is-touch .tab, body.is-touch .seg-btn, body.is-touch .dlg-skip { min-height: 44px; min-width: 44px; }

/* a phone held upright during play */
.rotate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: rgba(15, 8, 4, 0.92);
}
.rotate p { font-family: var(--display); font-size: 22px; line-height: 1.3; color: var(--gold); text-shadow: 0 3px 0 #7c2d12; max-width: 300px; }
.rotate-phone { font-size: 64px; animation: turn 2s ease-in-out infinite; }
@keyframes turn { 0%, 25% { transform: rotate(0deg); } 55%, 85% { transform: rotate(-90deg); } 100% { transform: rotate(0deg); } }

/* the crash screen (js/crash.js) */
.crash {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 8, 4, 0.9);
  cursor: pointer;
}
.crash-box { display: flex; flex-direction: column; align-items: center; gap: 24px; text-align: center; }

/* short screens (phones on their side): a smaller logo and tighter menus, so START is in reach */
@media (max-height: 540px) {
  .screen { gap: 10px; padding-top: max(12px, var(--safe-t)); padding-bottom: max(12px, var(--safe-b)); }
  .logo { font-size: clamp(36px, 14vh, 130px); }
  .tagline { font-size: 14px; }
  .btn.big { font-size: 20px; padding: 10px 30px; }
  h2 { font-size: 24px; }
  h2.shout { font-size: 34px; }
  #hero-detail { padding: 10px 14px; }
  .d-name { font-size: 22px; }
}
/* on small and short screens (phones, 1366 x 768 laptops) START stays at the bottom while the rest scrolls past */
@media (max-height: 900px), (max-width: 600px) {
  .start-row {
    position: sticky;
    bottom: calc(-1 * max(24px, var(--safe-b)));
    z-index: 2;
    align-self: stretch;
    margin: 0 calc(-1 * max(16px, var(--safe-r))) 0 calc(-1 * max(16px, var(--safe-l)));
    padding: 14px 16px max(14px, var(--safe-b));
    background: linear-gradient(180deg, rgba(34, 18, 12, 0), rgba(34, 18, 12, 0.94) 38%);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
