@font-face {
  font-family: 'Pixelify Sans';
  src: url('./fonts/pixelify-sans-latin-600.woff2') format('woff2');
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}
:root {
  color-scheme: dark;
  --night: #142520;
  --slate: #203932;
  --iron: #63766b;
  --brass: #efc681;
  --bone: #fff0d0;
  --mist: #d8e1cd;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --rail-height: 38px;
  --pixel: 'Pixelify Sans', ui-monospace, monospace;
  --ui: system-ui, -apple-system, sans-serif;
  background: var(--night);
  color: var(--bone);
  font-family: var(--ui);
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
main {
  position: relative;
  width: 100%; height: 100%; height: 100dvh;
  isolation: isolate;
  -webkit-user-select: none; user-select: none;
}
/* Keep the system clock and indicators legible over the arena on iPhone. */
@media (display-mode: standalone) {
  main::before {
    content: ''; position: absolute; inset: 0 0 auto; z-index: 3;
    height: env(safe-area-inset-top, 0px); pointer-events: none;
    background: #192e2ae6;
  }
}
#board {
  display: block; width: 100%; height: 100%;
  touch-action: none; cursor: crosshair; outline: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#steering-ring {
  --travel: 22px;
  --rim: calc(var(--travel) + 14px);
  --stick-x: 50vw;
  --stick-y: 50vh;
  --view-height: 100vh;
  position: fixed; z-index: 1; pointer-events: none;
  left: calc(0px - var(--rim)); top: calc(0px - var(--rim));
  width: calc(var(--rim) * 2); height: calc(var(--rim) * 2);
  /* At the edge, translate the entire dial together to preserve its bearing. */
  transform: translate3d(
    clamp(calc(var(--rim) + env(safe-area-inset-left, 0px) + 2px), var(--stick-x),
          calc(100vw - var(--rim) - env(safe-area-inset-right, 0px) - 2px)),
    clamp(calc(var(--rim) + env(safe-area-inset-top, 0px) + 2px), var(--stick-y),
          calc(var(--view-height) - var(--rim) - env(safe-area-inset-bottom, 0px) - 2px)), 0);
  border-radius: 50%;
  background: radial-gradient(circle, #ffdb97dc 0 1.5px, #182933a6 2px 2.6px, transparent 3px), #12222e27;
  box-shadow: inset 0 0 0 1px #d7e3d6a8, inset 0 0 0 2.5px #0b1c26c0, 0 0 0 1px #0b19236e;
  opacity: 0;
}
@supports (height: 100dvh) { #steering-ring { --view-height: 100dvh; } }
#steering-ring.active { opacity: .92; }
/* A short gilt segment keeps the bearing visible beyond the fingertip. */
#steering-ring::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from -20deg, #ffe5a3 0 40deg, transparent 40deg);
  -webkit-mask: radial-gradient(closest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(closest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  transform: rotate(var(--bearing, 0rad)); opacity: var(--pull, 0);
}
#steering-thumb {
  position: absolute; left: calc(50% - 11px); top: calc(50% - 11px);
  width: 22px; height: 22px; border-radius: 50%;
  background: #839e9866;
  box-shadow: inset 0 0 0 1px #0f202cc2, inset 0 0 0 2px #f8e2b0ba;
  transform: translate3d(0, 0, 0);
}
#steering-ring.active #steering-thumb { transform: translate3d(var(--thumb-x), var(--thumb-y), 0); }
@media (prefers-reduced-motion: no-preference) {
  #steering-ring { transition: opacity 125ms ease-out; }
  #steering-ring.active { transition-duration: 45ms; }
  #steering-ring:not(.active) #steering-thumb { transition: transform 95ms ease-out; }
}
header, #hint { position: absolute; pointer-events: none; }
header {
  inset: env(safe-area-inset-top) 0 auto;
  display: flex; align-items: center; gap: clamp(8px, 2.8vw, 18px);
  height: var(--rail-height);
  padding: 0 max(5px, env(safe-area-inset-right)) 0 max(13px, env(safe-area-inset-left));
  isolation: isolate;
}
header::before {
  content: ''; position: absolute; inset: 0 0 -7px; z-index: -1;
  background: linear-gradient(#0d211de8, #142820a8 60%, #14282000);
}
h1 {
  margin: 0 0 1px; white-space: nowrap;
  font: 600 clamp(22px, 5.9vw, 28px)/1 var(--pixel);
  letter-spacing: .015em; color: var(--bone); text-shadow: 1px 2px #10191f;
}
.floor, #battle-hud { font: 600 16px/1 var(--pixel); white-space: nowrap; color: var(--mist); }
header h1, header span { text-shadow: 1px 2px #111827, -1px -1px #19212c; }
.floor { display: flex; align-items: baseline; gap: 6px; margin-left: auto; }
.floor b, #battle-hud b { color: var(--brass); font-weight: inherit; }
#battle-hud { display: inline-flex; gap: 3px; align-items: center; }
button {
  cursor: pointer; color: inherit; background: none; border: 0;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
button:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
#pause {
  pointer-events: auto; align-self: flex-start; position: relative;
  width: 44px; height: 44px; padding: 0 0 6px; display: flex;
  justify-content: center; align-items: center; gap: 4px;
}
#pause::before { content: ''; position: absolute; left: 0; top: 10px; width: 1px; height: 16px; background: var(--iron); }
#pause i { height: 12px; width: 3px; background: var(--bone); box-shadow: 1px 1px var(--night); }
#pause:focus-visible { outline-offset: -4px; }
header.over-mage::before { opacity: .08; }
header.over-mage h1, header.over-mage .floor, header.over-mage #battle-hud { opacity: .18; }
#hint {
  left: 50%; bottom: max(9px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 12px); margin: 0;
  padding: 5px 10px 6px; background: #182d27ed; color: var(--bone);
  border: 1px solid #64747596; box-shadow: 0 1px 0 #071318;
  text-align: center; font: 500 14px/1.25 var(--ui);
}
#hint.over-mage { top: calc(env(safe-area-inset-top) + var(--rail-height) + 4px); bottom: auto; }
[hidden] { display: none !important; }
dialog {
  width: min(356px, calc(100vw - 28px)); max-height: calc(100dvh - 26px);
  padding: 0; overscroll-behavior: contain;
  color: var(--bone); background: var(--slate); border: 2px solid var(--night);
  outline: 1px solid #82908a; outline-offset: -3px; box-shadow: 3px 4px 0 #080f15aa;
}
dialog::backdrop { background: #091019b8; }
.vault-scene {
  display: block; width: 100%; height: auto; aspect-ratio: 176 / 60;
  object-fit: cover; image-rendering: pixelated; border-bottom: 2px solid #6d6856;
}
.menu-copy { padding: 14px 20px 18px; }
dialog h2 { margin: 0; font: 600 29px/1.08 var(--pixel); }
dialog p { margin: 8px 0 15px; font: 400 16px/1.4 var(--ui); color: var(--mist); text-wrap: pretty; }
dialog dl {
  display: grid; grid-template-columns: auto 1fr; gap: 7px 15px;
  margin: 0 0 16px; padding: 12px 0; border-block: 1px solid var(--iron);
}
dialog dt { font: 600 16px/1.3 var(--pixel); color: var(--brass); }
dialog dd { margin: 0; font: 400 14px/1.4 var(--ui); }
#primary {
  display: block; width: 100%; min-height: 44px; padding: 6px 16px;
  color: #211e1c; background: #d8ac71;
  border: 2px solid; border-color: #efd099 #98704b #98704b #e7c58d;
  font: 600 18px/1.2 var(--pixel);
}
#primary:active { background: #c99b66; border-color: #98704b #e7c58d #e7c58d #98704b; }
@media (min-width: 720px) {
  :root { --rail-height: 42px; }
  header { padding-left: max(17px, env(safe-area-inset-left)); }
  #pause { padding-bottom: 2px; }
  #pause::before { top: 12px; }
}
@media (prefers-reduced-motion: no-preference) {
  header::before, header h1, header .floor, header #battle-hud { transition: opacity 100ms; }
}
@media (max-height: 470px) {
  dialog { width: min(410px, 88vw); }
  .vault-scene { height: 42px; }
  .menu-copy { padding: 9px 16px 12px; }
  dialog h2 { font-size: 24px; }
  dialog p { margin: 4px 0 8px; }
  dialog dl { margin-bottom: 10px; padding-block: 6px; gap: 3px 12px; }
}

#stats {
  position: absolute; pointer-events: none; z-index: 1;
  top: calc(env(safe-area-inset-top) + var(--rail-height) + 2px);
  left: max(10px, env(safe-area-inset-left));
  display: flex; gap: 8px;
  font: 600 14px/1 var(--pixel); color: var(--mist);
  text-shadow: 1px 1px #0a1018;
  transition: opacity 100ms;
}
#stats.over-mage { opacity: .25; }
#stats .stat { display: inline-flex; align-items: center; gap: 1px; padding: 2px 5px 2px 2px; background: #11251fcc; border: 1px solid #43594d; }
#stats .stat b { color: var(--brass); font-weight: inherit; }
#stats .stat.maxed b { color: #ffe3a0; }
#stats img { width: 20px; height: 20px; image-rendering: pixelated; }
#banner {
  position: absolute; left: 50%; top: 32%; z-index: 2; pointer-events: none;
  transform: translate(-50%, -50%); text-align: center; opacity: 0;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  text-shadow: 2px 3px #0a1018, -1px -1px #19212c;
}
#banner b { font: 600 clamp(34px, 9vw, 54px)/1 var(--pixel); color: var(--bone); letter-spacing: .02em; }
#banner span { font: 600 17px/1.2 var(--pixel); color: var(--brass); }
#banner.show { animation: banner 2.2s ease-out both; }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(.92); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -58%); }
}
@media (prefers-reduced-motion: reduce) { #banner.show { animation-duration: 2.2s; animation-timing-function: steps(1, end); } }
#popups { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.popup {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font: 600 18px/1 var(--pixel); color: #fff2cf;
  text-shadow: 1px 2px #1a0d0a, -1px -1px #1a0d0a, 1px -1px #1a0d0a, -1px 1px #1a0d0a;
  will-change: transform, opacity;
}
.popup.hot { color: #ffb08a; }
.popup.gain { color: #b9f0d8; }
#sound {
  display: block; width: 100%; margin-top: 8px; min-height: 36px;
  font: 600 15px/1 var(--pixel); color: var(--mist);
  border: 1px solid var(--iron);
}
#sound[aria-pressed="false"] { color: #8d9a98; }
@media (max-width: 520px) {
  h1 { display: none; }
  header { gap: 12px; }
}

/* Travel chevron: where the mage is actually going, just outside the rim. */
#steering-ring::before {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 0; height: 0; margin: -6px 0 0 -6px;
  border: 6px solid transparent; border-bottom: 8px solid #ffe5a3;
  filter: drop-shadow(0 1px 0 #0b1c26);
  transform: rotate(var(--travel-bearing, 0rad)) translateY(calc(-1 * var(--rim) - 9px));
  opacity: 0;
}
#steering-ring.travelling::before { opacity: .95; }
@media (prefers-reduced-motion: no-preference) {
  #steering-ring::before { transition: opacity 90ms; }
}

/* Out of bombs: the bomb counter flushes and shakes once. */
#stats .stat.denied { animation: denied 420ms ease-out; }
@keyframes denied {
  0%, 100% { transform: none; background: #0b141ccc; }
  15% { transform: translateX(-3px); background: #5a1a14e6; }
  35% { transform: translateX(3px); }
  55% { transform: translateX(-2px); }
  75% { transform: translateX(1px); }
}
@media (prefers-reduced-motion: reduce) {
  #stats .stat.denied { animation: denied-still 420ms steps(1, end); }
  @keyframes denied-still { 0% { background: #5a1a14e6; } 100% { background: #0b141ccc; } }
}

/* ---- Iteration: readability and social feedback ---------------------- */
/* The pixel face's 2 reads as an 8 at this size; numerals use the UI face. */
#arena-clock { font: 700 15px/1 var(--ui); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
#arena-clock.urgent { color: #ffb08a; }

#stats .stat { background: #0b1a16f0; border-color: #6d8576; box-shadow: 0 1px 0 #050b09; }
#stats .stat b { color: #ffd894; }
#stats.over-mage { opacity: .5; }
#stats .stat.up { animation: stat-up 520ms ease-out; }
@keyframes stat-up {
  0% { transform: scale(1); background: #0b1a16f0; }
  25% { transform: scale(1.25); background: #2f6b45f0; border-color: #b9f0d8; }
  100% { transform: scale(1); background: #0b1a16f0; }
}

#feed {
  position: absolute; z-index: 2; pointer-events: none; margin: 0; padding: 0; list-style: none;
  top: calc(env(safe-area-inset-top) + var(--rail-height) + 34px);
  right: max(8px, env(safe-area-inset-right));
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
#feed li {
  padding: 3px 8px 4px; background: #0b1a16d9; border: 1px solid #43594d;
  font: 500 13px/1.2 var(--ui); color: var(--mist); white-space: nowrap;
  transition: opacity 400ms, transform 400ms;
}
#feed li.mine { border-color: var(--brass); }
#feed li i { font-style: normal; color: #ffb08a; padding: 0 2px; }
#feed li b { font-weight: 700; }
#feed li.gone { opacity: 0; transform: translateX(8px); }

#offscreen { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
#offscreen .marker {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
}
#offscreen .marker b {
  position: absolute; left: -12px; top: -12px; width: 24px; height: 24px;
  display: grid; place-items: center; border-radius: 50%;
  background: #0b1a16e6; border: 2px solid var(--color); color: var(--color);
  font: 700 12px/1 var(--ui);
}
#offscreen .marker i {
  position: absolute; left: -6px; top: -6px; width: 12px; height: 12px;
}
#offscreen .marker i::before {
  content: ''; position: absolute; left: 0; top: -17px;
  border: 6px solid transparent; border-bottom: 8px solid var(--color);
}
#offscreen .marker.threat b { animation: threat 600ms ease-in-out infinite; }
@keyframes threat {
  0%, 100% { box-shadow: 0 0 0 0 #ff7b5acc; }
  50% { box-shadow: 0 0 0 6px #ff7b5a00; background: #5a1a14e6; }
}

#standings { list-style: none; margin: 4px 0 12px; padding: 0; display: grid; gap: 3px; }
#standings li {
  display: grid; grid-template-columns: 18px 12px 1fr auto auto; gap: 8px; align-items: center;
  padding: 5px 8px; background: #0b1a1680; border: 1px solid #2c3c36;
  font: 500 14px/1.2 var(--ui);
}
#standings li.me { border-color: var(--brass); }
#standings .place { font: 700 14px/1 var(--ui); color: var(--brass); font-variant-numeric: tabular-nums; }
#standings .swatch { width: 12px; height: 12px; border-radius: 50%; }
#standings .ko { color: #c4cdbd; font-variant-numeric: tabular-nums; }
#standings .pips { display: inline-flex; gap: 3px; }
#standings .pips i { width: 8px; height: 8px; border: 1px solid var(--brass); transform: rotate(45deg); }
#standings .pips i.on { background: var(--brass); }
@media (prefers-reduced-motion: reduce) {
  #stats .stat.up, #offscreen .marker.threat b { animation: none; }
}
/* Every changing number uses the UI face for the same reason as the clock. */
#alive-count, #stats .stat b, #duel-countdown { font-family: var(--ui); font-weight: 700; font-variant-numeric: tabular-nums; }
