@font-face {
  font-family: "Big Shoulders Display";
  src: url("/fonts/big-shoulders-display.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Big Shoulders Stencil Display";
  src: url("/fonts/big-shoulders-stencil.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Big Shoulders Text";
  src: url("/fonts/big-shoulders-text.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --hull: #0e1a20;   /* page */
  --deck: #16272f;   /* arena floor, panels */
  --plate: #213842;  /* raised surfaces */
  --line: #2f4b58;
  --paper: #eef3f2;
  --muted: #93a8b0;
  --amber: #ffb627;
  --alert: #ff5d4d;
  --display: "Big Shoulders Display", "Arial Narrow", Impact, sans-serif;
  --stencil: "Big Shoulders Stencil Display", "Big Shoulders Display", Impact, sans-serif;
  --text: "Big Shoulders Text", "Arial Narrow", system-ui, sans-serif;
  /* armor-plate corner: one cut, top right and bottom left */
  --cut: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
  background: var(--hull);
  color: var(--paper);
  font: 500 1.125rem/1.35 var(--text);
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; letter-spacing: inherit; }

/* ------------------------------------------------------------------ stage */

.stage {
  grid-row: 2;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  padding: 10px;
}
.stage canvas {
  display: block;
  background: var(--deck);
  box-shadow: 0 0 0 1px var(--line), 0 24px 80px rgba(0, 0, 0, 0.55);
}
body:not([data-screen="game"]) .stage { justify-items: end; padding: 0; }
body:not([data-screen="game"]) .stage canvas { box-shadow: none; }

/* -------------------------------------------------------------------- hud */

.hud {
  grid-row: 1;
  display: none;
  align-items: center;
  gap: 0.5rem 1.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  background: var(--deck);
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
body[data-screen="game"] .hud { display: flex; }

.hud-level { display: flex; align-items: baseline; gap: 0.6rem; white-space: nowrap; }
.hud-level strong { font: 800 1.7rem/1 var(--display); }
.hud-level span { color: var(--amber); font-weight: 700; }

.hud-wave { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.hud-wave-count { color: var(--muted); white-space: nowrap; }
.hud-wave-count b { color: var(--paper); font: 800 1.35rem/1 var(--display); margin-right: 0.15rem; }
.pips { display: flex; flex-wrap: wrap; gap: 3px; max-width: 13.5rem; }
.pips i { width: 6px; height: 9px; background: #8794a0; border-radius: 1.5px 1.5px 1px 1px; }

.hud-status { display: flex; gap: 0.5rem; }
.hud-status span { padding: 0.05rem 0.55rem; border: 1px solid currentColor; border-radius: 3px; font-weight: 700; white-space: nowrap; }
.hud-status .emp { color: #6cb4ff; }
.hud-status .fort { color: #c9d3dc; }

.hud-players { display: flex; gap: 0.5rem; margin: 0 0 0 auto; padding: 0; list-style: none; flex-wrap: wrap; }
.hud-players li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: baseline;
  column-gap: 0.6rem;
  min-width: 9.5rem;
  padding: 0.2rem 0.65rem 0.25rem;
  background: var(--plate);
  border-left: 4px solid var(--c);
}
.hud-players .p-name { font-weight: 700; max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-players .p-lives { color: var(--muted); white-space: nowrap; }
.hud-players .p-lives b { color: var(--paper); }
.hud-players .p-score { text-align: right; font: 800 1.25rem/1 var(--display); color: var(--c); }
.hud-players .p-rank { grid-column: 1 / -1; display: flex; gap: 3px; height: 4px; }
.hud-players .p-rank i { width: 18px; height: 4px; background: var(--line); }
.hud-players .p-rank i.on { background: var(--c); }
.hud-players li.out { opacity: 0.45; }

.hud-tools { display: flex; align-items: center; gap: 0.5rem; }
.ping { color: var(--muted); min-width: 3.2rem; text-align: right; }
.tool {
  padding: 0.25rem 0.7rem;
  background: none;
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
}
.tool:hover { border-color: var(--muted); }
.tool:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ------------------------------------------------------------------ menus */

.menu {
  position: fixed;
  inset: 0;
  display: none;
  overflow-y: auto;
  background: linear-gradient(90deg, rgba(14, 26, 32, 0.97) 0, rgba(14, 26, 32, 0.93) 26rem, rgba(14, 26, 32, 0.5) 62%, rgba(14, 26, 32, 0.2) 100%);
}
body[data-screen="home"] #home,
body[data-screen="lobby"] #lobby { display: block; }

.menu-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: clamp(0.8rem, 2.2vh, 1.25rem);
  width: min(27rem, 100%);
  min-height: 100%;
  padding: clamp(1.25rem, 5vh, 4rem) clamp(1.25rem, 4vw, 3.5rem) clamp(1rem, 3vh, 2.5rem);
}

.wordmark {
  margin: 0;
  font: 900 clamp(3.4rem, min(11vw, 13vh), 6.4rem) / 0.82 var(--stencil); /* sized for the two-word name on one line */
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: -0.005em;
}
/* a strip of tread marks under the name */
.treads {
  width: min(100%, 21rem);
  height: 12px;
  margin-top: -0.6rem;
  background: repeating-linear-gradient(115deg, var(--amber) 0 7px, transparent 7px 13px);
  -webkit-mask: linear-gradient(90deg, #000 60%, transparent);
  mask: linear-gradient(90deg, #000 60%, transparent);
}
.pitch { margin: 0; max-width: 24rem; color: var(--muted); }

.field { display: grid; gap: 0.3rem; width: 100%; max-width: 21rem; }
.field span { color: var(--muted); }
.field input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: rgba(9, 17, 21, 0.8);
  border: 1px solid var(--line);
  border-radius: 0;
  font-weight: 700;
  font-size: 1.25rem;
}
.field input::placeholder { color: #4f6670; }
.field input:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
#code { text-transform: uppercase; letter-spacing: 0.3em; }

.actions { display: grid; gap: 0.55rem; width: 100%; max-width: 21rem; }

.btn {
  display: block;
  width: 100%;
  padding: 0.7rem 1.1rem 0.75rem;
  background: var(--plate);
  border: 0;
  clip-path: var(--cut);
  font: 700 1.4rem/1.1 var(--display);
  letter-spacing: 0.02em;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s, transform 0.08s;
}
.btn:hover { background: #2b4753; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--paper); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--amber); color: #1c1300; }
.btn-primary:hover { background: #ffc750; }
.btn-primary:focus-visible { box-shadow: inset 0 0 0 3px #1c1300; }

.join { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 0.55rem; width: 100%; max-width: 21rem; }
.join .btn { width: auto; white-space: nowrap; }

.keys { display: grid; gap: 0.3rem; color: var(--muted); }
.keys div { display: grid; grid-template-columns: 3.6rem 1fr; align-items: baseline; }
.keys dt { color: var(--paper); font-weight: 700; }
.keys dd { margin: 0; }
kbd {
  display: inline-block;
  min-width: 1.55rem;
  margin-right: 0.2rem;
  padding: 0 0.35rem;
  background: var(--plate);
  border-bottom: 2px solid #0a1216;
  border-radius: 3px;
  color: var(--paper);
  font: 700 0.95rem/1.5 var(--text);
  text-align: center;
}

/* lobby */
.lobby-title { margin: 0; font: 800 2.6rem/1 var(--display); }
.room-code { font-family: var(--stencil); font-weight: 900; font-size: 1.6em; letter-spacing: 0.08em; color: var(--amber); vertical-align: -0.06em; }
.roster { display: grid; gap: 0.4rem; width: 100%; max-width: 21rem; margin: 0; padding: 0; list-style: none; }
.roster li { display: flex; align-items: center; gap: 0.7rem; padding: 0.45rem 0.75rem; background: rgba(33, 56, 66, 0.75); border-left: 4px solid var(--c, var(--line)); font-weight: 700; }
.roster li.open { color: #5d7580; font-weight: 500; background: rgba(33, 56, 66, 0.35); }
.roster small { margin-left: auto; color: var(--muted); font-size: 1rem; font-weight: 500; }
.hint { margin: 0; color: var(--muted); }

/* ----------------------------------------------------------------- banner */

.banner {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0.2rem;
  text-align: center;
  pointer-events: none;
  opacity: 0;
}
.banner strong { font: 900 clamp(3rem, 12vw, 8.5rem) / 0.85 var(--stencil); text-transform: uppercase; text-shadow: 0 6px 40px rgba(0, 0, 0, 0.7); }
.banner span { font: 700 clamp(1.2rem, 2.8vw, 2rem) / 1 var(--display); color: var(--amber); text-shadow: 0 2px 16px rgba(0, 0, 0, 0.8); }
.banner.show { animation: banner 2.3s both; }
@keyframes banner {
  0% { opacity: 0; transform: scale(1.12); }
  10% { opacity: 1; transform: none; }
  78% { opacity: 1; }
  100% { opacity: 0; }
}

/* ----------------------------------------------------------------- dialog */

.dialog { position: fixed; inset: 0; display: grid; place-items: center; padding: 1rem; background: rgba(8, 15, 19, 0.72); z-index: 5; }
.dialog[hidden] { display: none; }
.dialog-box { width: min(30rem, 100%); padding: 1.75rem 1.75rem 1.5rem; background: var(--deck); border: 1px solid var(--line); border-top: 4px solid var(--amber); }
.dialog-box h2 { margin: 0 0 0.4rem; font: 900 3rem/0.95 var(--stencil); text-transform: uppercase; }
.dialog-box p { margin: 0 0 1rem; color: var(--muted); }
.dialog-box p:empty { display: none; }
.dialog-box .actions { max-width: none; grid-auto-flow: column; grid-auto-columns: 1fr; }
.dialog-box .btn { padding-inline: 0.9rem; font-size: 1.25rem; white-space: nowrap; }

.scores { width: 100%; margin: 0 0 1.25rem; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores:empty { display: none; }
.scores th { padding: 0 0.5rem 0.3rem; color: var(--muted); font-weight: 500; text-align: right; }
.scores th:first-child { text-align: left; padding-left: 0.75rem; }
.scores td { padding: 0.4rem 0.5rem; background: var(--plate); border-bottom: 3px solid var(--deck); text-align: right; }
.scores td:first-child { border-left: 4px solid var(--c); padding-left: 0.75rem; font-weight: 700; text-align: left; }
.scores td:last-child { font: 800 1.35rem/1 var(--display); color: var(--c); }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  z-index: 6;
  max-width: min(32rem, calc(100% - 2rem));
  padding: 0.65rem 1rem;
  background: var(--paper);
  color: #10191d;
  font-weight: 700;
  transform: translate(-50%, 1rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
/* in a game the bottom of the screen is where the core is: keep messages clear of it */
body[data-screen="game"] .toast { top: 4.5rem; bottom: auto; }

/* ------------------------------------------------------------------ guide */

.menu-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; width: 100%; max-width: 21rem; margin-top: auto; }
.menu-foot .keys { margin: 0; }
.link {
  padding: 0.1rem 0;
  background: none;
  border: 0;
  border-bottom: 2px solid var(--amber);
  color: var(--paper);
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}
.link:hover { color: var(--amber); }
.link:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }

.help { position: fixed; inset: 0; z-index: 7; overflow-y: auto; background: rgba(8, 15, 19, 0.96); }
.help[hidden] { display: none; }
.help-page { width: min(64rem, 100%); margin: 0 auto; padding: clamp(1rem, 4vh, 2.5rem) clamp(1rem, 4vw, 2.5rem) 3rem; }
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.75rem; }
.help-head h2 { margin: 0; font: 900 clamp(2.4rem, 7vw, 3.6rem) / 0.9 var(--stencil); text-transform: uppercase; }
.help-head .btn { width: auto; }
.help-lead { max-width: 46rem; margin: 0 0 1.5rem; font-size: 1.25rem; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 3rem; }
.help h3 { margin: 1.5rem 0 0.6rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--line); color: var(--amber); font: 800 1.5rem/1.1 var(--display); }
.help-cols > div > h3:first-child { margin-top: 0; }
.help-note { margin: 0.6rem 0 0; color: var(--muted); }

.help-keys { width: 100%; border-collapse: collapse; }
.help-keys th { padding: 0 0.6rem 0.3rem 0; color: var(--muted); font-weight: 500; text-align: left; }
.help-keys td { padding: 0.3rem 0.6rem 0.3rem 0; vertical-align: top; border-top: 1px solid rgba(47, 75, 88, 0.6); }
.help-keys td:first-child { font-weight: 700; white-space: nowrap; }

.help-list, .help-plain { margin: 0; padding: 0; list-style: none; }
.help-list li { display: grid; grid-template-columns: 44px 1fr; align-items: center; gap: 0.9rem; padding: 0.4rem 0; }
.help-list img, .help-list canvas, .swatch { width: 44px; height: 44px; }
.help-list b { color: var(--paper); }
.help-list div, .help-plain li { color: #c3d0d4; }
.help-plain li { position: relative; padding: 0.25rem 0 0.25rem 1.1rem; }
.help-plain li::before { content: ""; position: absolute; left: 0; top: 0.85em; width: 0.5rem; height: 2px; background: var(--amber); }
.swatch { display: block; background-size: 96px 96px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45); }
.swatch-brick { background-image: url("/img/brick.jpg"); }
.swatch-steel { background-image: url("/img/steel.jpg"); background-size: 200px 200px; }
.swatch-water { background-image: url("/img/water.jpg"); background-size: 140px 140px; }
.swatch-canopy { background-image: url("/img/canopy.jpg"); background-size: 120px 120px; border-radius: 40%; }
.swatch-ice { background-image: url("/img/ice.jpg"); background-size: 160px 160px; }

/* --------------------------------------------------------- first-game tips */

.coach {
  position: absolute;
  top: clamp(3.2rem, 12%, 6rem);
  left: 50%;
  z-index: 3;
  width: min(30rem, calc(100% - 2rem));
  padding: 0.75rem 1rem 0.6rem;
  background: rgba(14, 26, 32, 0.94);
  border-left: 4px solid var(--amber);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  transform: translateX(-50%);
}
.coach[hidden] { display: none; }
.coach p { margin: 0; font-size: 1.25rem; font-weight: 700; }
.coach-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 0.4rem; color: var(--muted); }
.coach-foot button { padding: 0; background: none; border: 0; border-bottom: 1px solid currentColor; color: var(--muted); cursor: pointer; }
.coach-foot button:hover { color: var(--paper); }
.coach-foot button:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }

.noscript { position: fixed; inset: auto 0 0 0; z-index: 9; margin: 0; padding: 1rem; background: var(--amber); color: #1c1300; font-weight: 700; text-align: center; }

/* ------------------------------------------------------------------ touch */

.touch { display: none; }
@media (pointer: coarse) {
  body[data-screen="game"] .touch { display: block; }
  .pad, .fire { position: absolute; bottom: max(1.25rem, env(safe-area-inset-bottom)); touch-action: none; user-select: none; -webkit-user-select: none; }
  .pad {
    left: max(1.25rem, env(safe-area-inset-left));
    width: 9.5rem;
    height: 9.5rem;
    border-radius: 50%;
    background: rgba(33, 56, 66, 0.55);
    border: 2px solid rgba(238, 243, 242, 0.25);
  }
  .pad i { position: absolute; inset: 34%; border-radius: 50%; background: rgba(238, 243, 242, 0.35); transition: transform 0.06s; }
  .pad[data-dir="0"] i { transform: translateY(-70%); }
  .pad[data-dir="1"] i { transform: translateX(70%); }
  .pad[data-dir="2"] i { transform: translateY(70%); }
  .pad[data-dir="3"] i { transform: translateX(-70%); }
  .fire {
    right: max(1.5rem, env(safe-area-inset-right));
    width: 6.5rem;
    height: 6.5rem;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 182, 39, 0.8);
    color: #1c1300;
    font: 800 1.4rem var(--display);
  }
  .fire:active { background: var(--amber); }
  .keys { display: none; }
  .menu-foot { justify-content: flex-start; }
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 720px) {
  .menu { background: rgba(14, 26, 32, 0.92); }
  .help-cols { grid-template-columns: 1fr; }
  .help-cols > div + div > h3:first-child { margin-top: 1.5rem; }
  .hud { gap: 0.35rem 1rem; padding: 0.4rem 0.6rem; }
  .pips, .ping { display: none; }
  .hud-players li { min-width: 0; }
  .dialog-box .actions { grid-auto-flow: row; }
}

@media (prefers-reduced-motion: reduce) {
  .banner.show { animation: banner-fade 2.3s both; }
  @keyframes banner-fade { 0%, 100% { opacity: 0; } 10%, 78% { opacity: 1; } }
  .btn, .toast { transition: none; }
}
