:root {
  --ink: #f3ece6;
  --ink-dim: rgba(243, 236, 230, 0.66);
  --ink-faint: rgba(243, 236, 230, 0.4);
  --bg: #0d0b14;
  --panel: rgba(18, 14, 26, 0.72);
  --line: rgba(243, 236, 230, 0.14);
  --gold: #e3c378;
  --t1: #f05434;
  --t2: #f6b91c;
  --t3: #6683ff;
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --sans: 'Outfit', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
canvas#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

/* ------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#score {
  position: absolute;
  top: calc(10px + var(--safe-t));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 16px;
  width: min(560px, calc(100vw - 120px));
  padding: 8px 18px 8px 20px;
  border-radius: 999px;
  background: rgba(14, 11, 20, 0.55);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
#score .sides { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 10px; min-width: 0; }
#score .side { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; }
#score .pct { font-weight: 700; font-size: 21px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
#score .s1 .pct { color: var(--t1); }
#score .s2 .pct { color: var(--t2); }
#score .s3 .pct { color: var(--t3); }
#score .name { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#score .name.you { color: var(--ink); }
#score .name.you::after { content: ' · you'; }
#timer { font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
#timer.low { color: #ffd9a8; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.bar {
  grid-column: 1 / -1;
  display: flex;
  width: 100%;
  height: 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.bar i, .resbar i { display: block; flex: none; height: 100%; width: 0; transition: width 0.25s linear; }
#bar1, #rb1 { background: var(--t1); }
#bar2, #rb2 { background: var(--t2); }
#bar3, #rb3 { background: var(--t3); }

.corner {
  position: absolute;
  top: calc(12px + var(--safe-t));
  right: calc(12px + var(--safe-r));
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(14, 11, 20, 0.55);
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.icon svg { width: 20px; height: 20px; }
.icon:hover { border-color: rgba(243, 236, 230, 0.4); }
#btn-mute .cross { display: none; }
#btn-mute.muted .cross { display: inline; }
#btn-mute.muted .wave { display: none; }

#caption {
  position: absolute;
  left: 50%;
  bottom: calc(26px + var(--safe-b));
  transform: translateX(-50%);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 1.2s ease;
}
#caption.show { opacity: 1; }
#hint {
  position: absolute;
  left: calc(16px + var(--safe-l));
  bottom: calc(16px + var(--safe-b));
  font-size: 12px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  transition: opacity 1s;
}

#banner {
  position: fixed;
  left: 50%;
  top: 27%;
  transform: translate(-50%, -50%);
  font-size: clamp(26px, 4.6vw, 46px);
  font-weight: 500;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  text-align: center;
  white-space: nowrap;
}
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1.04); }
#banner.minor { top: 68%; font-size: clamp(15px, 2.4vw, 20px); color: var(--ink-dim); }

/* ------------------------------------------------------------- touch */
#touch { position: fixed; inset: 0; pointer-events: none; }
#touch button {
  position: absolute;
  pointer-events: auto;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  background: rgba(14, 11, 20, 0.45);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: none;
}
#touch button.on { background: rgba(255, 255, 255, 0.28); }
#btn-bomb { width: 72px; height: 72px; right: calc(22px + var(--safe-r)); bottom: calc(150px + var(--safe-b)); }
#btn-dive { width: 64px; height: 64px; right: calc(108px + var(--safe-r)); bottom: calc(196px + var(--safe-b)); }

/* ------------------------------------------------------------- screens */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-t)) calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l));
  pointer-events: none;
}
.panel {
  pointer-events: auto;
  max-width: 440px;
  width: 100%;
  padding: 30px 30px 26px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  animation: rise 0.7s ease both;
}
.panel.small { max-width: 320px; text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
.kicker {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}
h1, h2 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: 0.005em; }
h1 { font-size: clamp(40px, 6.4vw, 60px); line-height: 0.95; }
h1 em { font-weight: 500; color: var(--ink-dim); }
h2 { font-size: 34px; line-height: 1.05; }
.sub { margin: 14px 0 20px; color: var(--ink-dim); line-height: 1.5; font-size: 15px; }
.choose { margin: 0 0 10px; font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-faint); }
.teams { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.team, .row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  font-size: 17px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s, border-color 0.2s;
}
.team:hover, .row button:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.09); }
.team:focus-visible, .row button:focus-visible, .icon:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.team { flex-direction: column; gap: 8px; min-height: 76px; padding: 10px 6px; font-size: 16px; }
.team .dot { width: 18px; height: 18px; border-radius: 4px; box-shadow: 0 0 18px currentColor; }
.team.t1 { border-color: rgba(240, 84, 52, 0.5); }
.team.t1 .dot { background: var(--t1); color: var(--t1); }
.team.t2 { border-color: rgba(246, 185, 28, 0.5); }
.team.t2 .dot { background: var(--t2); color: var(--t2); }
.team.t3 { border-color: rgba(102, 131, 255, 0.5); }
.team.t3 .dot { background: var(--t3); color: var(--t3); }
.howto {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin: 22px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.howto div { display: flex; flex-direction: column; gap: 2px; }
.howto dt { color: var(--ink-faint); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; }
.howto dd { margin: 0; color: var(--ink); }
.fine { margin: 16px 0 0; font-size: 12.5px; color: var(--ink-faint); line-height: 1.5; font-style: italic; font-family: var(--serif); font-size: 15px; }
body.touch .desktop-only { display: none; }
body:not(.touch) .touch-only { display: none; }

#title, #results { justify-content: flex-start; padding-left: max(5vw, calc(20px + var(--safe-l))); }
.row { display: flex; gap: 10px; margin-top: 22px; justify-content: center; flex-wrap: wrap; }
.row button { min-width: 130px; }
.row button.primary { background: var(--ink); color: #15111c; border-color: var(--ink); }
.row button.primary:hover { background: #fff; }

.resbar { display: flex; height: 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.1); overflow: hidden; margin: 22px 0 8px; }
.resbar i { transition: width 1.4s cubic-bezier(0.2, 0.8, 0.2, 1); }
.resnums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; font-variant-numeric: tabular-nums; }
.resnums div { display: flex; flex-direction: column; line-height: 1.15; }
.resnums span { font-weight: 700; font-size: 20px; }
.resnums small { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-dim); }
.resnums .r1 span { color: var(--t1); }
.resnums .r2 span { color: var(--t2); }
.resnums .r3 span { color: var(--t3); }
#rn0 { color: var(--ink-faint); font-size: 12px; letter-spacing: 0.08em; margin: 8px 0 0; }
#epitaph { font-family: var(--serif); font-style: italic; font-size: 21px; line-height: 1.35; color: var(--ink); margin: 20px 0 12px; }
#facts { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 13px; color: var(--ink-dim); }
#facts b { color: var(--ink); font-weight: 600; }
#results .panel { text-align: left; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; }

@media (max-width: 760px), (max-height: 520px) and (orientation: landscape) {
  #title, #results { justify-content: center; align-items: flex-end; padding-left: calc(14px + var(--safe-l)); }
  #title .panel, #results .panel { padding: 20px 20px 18px; max-width: 520px; }
  h2 { font-size: 28px; }
  #epitaph { font-size: 18px; margin: 12px 0 8px; }
  .resbar { margin: 14px 0 6px; }
  .row { margin-top: 14px; }
  .sub { font-size: 14px; margin: 10px 0 14px; }
  .howto { margin-top: 14px; padding-top: 12px; }
  .fine { display: none; }
  #score { width: calc(100vw - 168px); left: calc(50% - 72px); gap: 10px; padding: 6px 12px; }
  #score .pct { font-size: 16px; }
  #score .sides { gap: 3px 6px; }
  #score .name.you::after { content: ''; }
  #score .name.you { text-decoration: underline; text-underline-offset: 3px; }
  #timer { font-size: 21px; }
  #caption { font-size: 11px; bottom: calc(120px + var(--safe-b)); }
  #hint { display: none; }
  #score .name { font-size: 9px; letter-spacing: 0.06em; }
  .team { min-height: 64px; font-size: 15px; }
  #btn-bomb { bottom: calc(26px + var(--safe-b)); right: calc(18px + var(--safe-r)); }
  #btn-dive { bottom: calc(40px + var(--safe-b)); right: calc(104px + var(--safe-r)); }
}
@media (max-height: 520px) and (orientation: landscape) {
  #title .panel { max-height: calc(100vh - 20px); overflow: auto; }
  h1 { font-size: 34px; }
  .sub { display: none; }
  #caption { bottom: calc(14px + var(--safe-b)); }
  #btn-bomb { bottom: calc(110px + var(--safe-b)); }
  #btn-dive { bottom: calc(150px + var(--safe-b)); }
}
/* Wide screens: the score panel stands at her side and she fills the height. */
body.side-hud { --side-w: 172px; }
body.side-hud #score {
  top: 50%;
  left: calc(12px + var(--safe-l));
  transform: translateY(-50%);
  width: var(--side-w);
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 16px 16px 18px;
  border-radius: 18px;
}
body.side-hud #timer { font-size: 34px; }
body.side-hud #hint { max-width: calc(var(--side-w) + 8px); line-height: 1.5; }
body.side-hud #score .sides { grid-template-columns: 1fr; gap: 12px; }
body.side-hud #score .pct { font-size: 27px; }
body.side-hud #score .name.you::after { content: ' · you'; }
body.side-hud #score .name.you { text-decoration: none; }
@media (max-height: 520px) and (orientation: landscape) {
  body.side-hud { --side-w: 118px; }
  body.side-hud #score { left: calc(8px + var(--safe-l)); gap: 8px; padding: 10px 10px 12px; border-radius: 14px; }
  body.side-hud #timer { font-size: 22px; }
  body.side-hud #score .sides { gap: 6px; }
  body.side-hud #score .pct { font-size: 17px; }
  body.side-hud #score .name.you::after { content: ''; }
  body.side-hud #score .name.you { text-decoration: underline; text-underline-offset: 3px; }
}
#btn-full .shrink, #btn-full.on .grow { display: none; }
#btn-full.on .shrink { display: inline; }

@media (prefers-reduced-motion: reduce) {
  .panel { animation: none; }
  #timer.low { animation: none; }
}
