/*
  Holdout — visual system.

  Deliberately single-theme, like a piece of field equipment rather than a
  document: the whole readability model rests on bright signal colours against
  a dark board, and a light variant would flatten the one thing the palette is
  doing. Every colour is painted explicitly rather than inherited.

  Distinct from Drop on purpose. Drop is navy and a hue sweep; this is deep
  space with phosphor teal for what is yours, amber for the station, and red
  for what is coming down the lanes.
*/

:root {
  --ink:       #05070E;
  --ink-2:     #0A1019;
  --ink-3:     #101927;
  --line:      #202C3D;
  --line-soft: #17202E;

  --teal:      #5EEAD4;
  --teal-dim:  #2A6D63;
  --amber:     #F5A524;
  --violet:    #A78BFA;
  --danger:    #FF5C5C;
  --text:      #E6EAF2;
  --muted:     #76839B;

  /* min(), not clamp(): a clamp floor wider than the viewport makes the frame
     overflow horizontally on very narrow screens instead of shrinking. */
  --col:  min(100vw, 520px);
  --r-sm: 7px;
  --r-md: 12px;
  --r-lg: 18px;

  --f-display: "Chakra Petch", "Arial Narrow", system-ui, sans-serif;
  --f-body:    "IBM Plex Sans", system-ui, -apple-system, Segoe UI, sans-serif;
  --f-mono:    "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }

body {
  background: var(--ink);
  color: var(--text);
  font-family: var(--f-body);
  /* A game is direct manipulation: selection and double-tap zoom both fight
     the controls rather than helping. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 70% at 50% 0%, #10182B 0%, transparent 62%),
    radial-gradient(100% 50% at 50% 100%, #0A1018 0%, transparent 55%);
  opacity: 0.85;
}

.frame {
  position: relative;
  z-index: 1;
  width: var(--col);
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
}

/* ----------------------------------------------------------------- topbar */

.topbar { display: flex; align-items: center; gap: 7px; flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 7px; margin-right: auto; }

/* The mark is the game in one glyph: a line held, with a shot rising. */
.mark {
  width: 20px; height: 20px;
  border-radius: 4px;
  background: linear-gradient(180deg, #16233A, #080C14);
  border: 1px solid var(--teal-dim);
  position: relative;
}
.mark::before {
  content: ""; position: absolute;
  left: 3px; right: 3px; bottom: 3.5px; height: 2.5px;
  border-radius: 2px; background: var(--amber);
}
.mark::after {
  content: ""; position: absolute;
  left: 50%; top: 3px; width: 2.5px; height: 7px;
  margin-left: -1.25px; border-radius: 2px; background: var(--teal);
}

.wordmark {
  font-family: var(--f-display);
  font-size: 18px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
}

.chip {
  font-family: var(--f-mono);
  font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--ink-2);
  border-radius: 999px;
  padding: 4px 9px;
  max-width: 40%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  font-family: var(--f-mono);
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s;
}
.icon-btn:hover { color: var(--text); border-color: #32455E; }
.icon-btn[aria-pressed="false"] { color: #45536B; }

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

.hud {
  display: grid;
  grid-template-columns: 1.25fr 1fr auto;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.label {
  display: block;
  font-family: var(--f-mono);
  font-size: 8.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}
.label b { color: var(--teal); font-weight: 600; }

.bar {
  height: 9px;
  border-radius: 5px;
  background: #131C29;
  overflow: hidden;
  border: 1px solid var(--line-soft);
}
.bar i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, #F5A524, #FFD37A);
  transition: width 0.25s ease, background 0.3s;
}
/* A low station flips the bar to danger and pulses it. */
.bar i[data-low="true"] {
  background: linear-gradient(90deg, #FF5C5C, #FF9A8A);
  animation: throb 0.9s ease-in-out infinite;
}
@keyframes throb { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.hud-base { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "l l" "b n"; gap: 0 8px; align-items: center; }
.hud-base .label { grid-area: l; }
.hud-base .bar { grid-area: b; }
.hud-base .num { grid-area: n; font-family: var(--f-mono); font-size: 11px; font-variant-numeric: tabular-nums; }

.bar.xp i { background: linear-gradient(90deg, #2A6D63, var(--teal)); }

.hud-cell { text-align: right; }
.num.big {
  display: block;
  font-family: var(--f-display);
  font-size: 22px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- phasebar */

.phasebar { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; min-height: 24px; }
.phase-text {
  font-family: var(--f-mono);
  font-size: 9.5px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--muted);
  margin-right: auto;
}
.phase-text[data-warn="true"] { color: var(--danger); }

.mini-btn {
  font-family: var(--f-mono);
  font-size: 9.5px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--teal);
  background: rgba(94, 234, 212, 0.09);
  border: 1px solid var(--teal-dim);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.16s, transform 0.12s;
}
.mini-btn:hover { background: rgba(94, 234, 212, 0.18); }
.mini-btn:active { transform: scale(0.97); }

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

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  display: block;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-soft);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 16px 40px rgba(0,0,0,0.6);
  /* Steering is a drag; without this the page pans instead. */
  touch-action: none;
}

/* ------------------------------------------------------------- status bar */

.deploy-prompt {
  flex: 0 0 auto;
  margin: 0;
  text-align: center;
  font-family: var(--f-mono);
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--teal);
  animation: nudge 1.5s ease-in-out infinite;
}
@keyframes nudge { 0%,100% { opacity: 0.65; } 50% { opacity: 1; } }

.statusbar {
  color: var(--text);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  flex: 0 0 auto;
}

.turret-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 2px 5px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
  background: var(--ink-2);
  transition: border-color 0.2s, opacity 0.2s;
  /* Types you have never drafted stay visible but recede — they are what the
     next deploy card might give you. */
  opacity: 0.4;
}
.turret-cell[data-owned="true"] { opacity: 1; border-color: var(--line); }
.turret-cell[data-waiting="true"] {
  border-color: var(--teal);
  box-shadow: 0 0 0 1px rgba(94, 234, 212, 0.35);
}
.turret-cell canvas { width: 24px; height: 24px; display: block; }
.turret-n {
  font-family: var(--f-mono);
  font-size: 10px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.turret-cell[data-owned="true"] .turret-n { color: var(--text); }
.turret-cell[data-waiting="true"] .turret-n { color: var(--teal); }

/* --------------------------------------------------------------- overlays */

.overlay {
  /* Fixed to the column rather than absolute inside the stage: the stage is
     only about two thirds of the frame, and the result and draft panels do
     not fit in it. */
  position: fixed;
  top: 0; bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: var(--col);
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(4, 6, 11, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 5;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.24s ease, visibility 0.24s;
}
.overlay[data-open="true"] { opacity: 1; visibility: visible; }

.panel { width: 100%; max-height: 100%; overflow-y: auto; text-align: center; }
.overlay[data-open="true"] .panel > * { animation: rise 0.38s cubic-bezier(0.2, 0.8, 0.25, 1) backwards; }
.overlay[data-open="true"] .panel > *:nth-child(1) { animation-delay: 0.02s; }
.overlay[data-open="true"] .panel > *:nth-child(2) { animation-delay: 0.06s; }
.overlay[data-open="true"] .panel > *:nth-child(3) { animation-delay: 0.10s; }
.overlay[data-open="true"] .panel > *:nth-child(4) { animation-delay: 0.14s; }
.overlay[data-open="true"] .panel > *:nth-child(5) { animation-delay: 0.18s; }
.overlay[data-open="true"] .panel > *:nth-child(6) { animation-delay: 0.22s; }
.overlay[data-open="true"] .panel > *:nth-child(7) { animation-delay: 0.26s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.kicker {
  font-family: var(--f-mono);
  font-size: 9px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--teal);
  margin: 0 0 8px;
}
.title {
  font-family: var(--f-display);
  font-size: clamp(40px, 14vw, 58px);
  font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  margin: 0 0 12px; line-height: 0.98;
}
.subtitle {
  font-family: var(--f-display);
  font-size: 22px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin: 0 0 12px;
}
.blurb {
  font-size: 13.5px; line-height: 1.55;
  color: var(--muted);
  margin: 0 auto 14px; max-width: 34ch;
  text-wrap: balance;
}

.final {
  font-family: var(--f-display);
  font-size: clamp(42px, 15vw, 60px);
  font-weight: 700; font-variant-numeric: tabular-nums;
  margin: 0 0 14px; line-height: 1;
}
.stars { font-size: 25px; letter-spacing: 6px; margin: 0 0 8px; color: var(--amber); }

.statrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.stat { padding: 8px 4px; border: 1px solid var(--line-soft); border-radius: var(--r-md); background: var(--ink-2); }
.stat-v { display: block; font-family: var(--f-mono); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.stat-l { display: block; font-family: var(--f-mono); font-size: 8px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

.namerow { margin-bottom: 10px; text-align: left; }
#nameInput {
  width: 100%;
  font-family: var(--f-body); font-size: 15px;
  color: var(--text);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 9px 11px;
}
#nameInput:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
#nameInput::placeholder { color: #45536B; }

.btnrow { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.btnrow > .btn:only-child { grid-column: 1 / -1; }

.btn {
  font-family: var(--f-body);
  font-size: 14px; font-weight: 600;
  color: var(--text);
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 16px;
  cursor: pointer;
  transition: transform 0.13s, border-color 0.16s, box-shadow 0.16s;
}
.btn:hover { border-color: #32455E; transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.985); }
.btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.btn[hidden] { display: none; }

.btn.primary {
  color: #03140F;
  background: linear-gradient(180deg, #7DF5E2, var(--teal));
  border-color: #3FBBA6;
  box-shadow: 0 5px 16px rgba(94, 234, 212, 0.2);
}
.btn.primary:hover { box-shadow: 0 8px 22px rgba(94, 234, 212, 0.3); }

.fineprint {
  font-family: var(--f-mono);
  font-size: 10px; color: var(--muted);
  margin: 8px 0 0; min-height: 13px;
}

/* ------------------------------------------------------------------ draft */

/* The draft is the reward moment, so it gets the loudest treatment in the
   game — a violet wash that appears nowhere else. */
.overlay.draft { background: rgba(9, 6, 20, 0.94); }
.overlay.draft .kicker { color: var(--violet); }

.cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 430px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  --card-hue: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 10px 13px;
  /* Buttons do not inherit body colour — without this the card title falls
     back to the UA default (near-black) and vanishes into the card. */
  color: var(--text);
  border-radius: var(--r-md);
  border: 1px solid hsl(var(--card-hue) 40% 34%);
  background:
    radial-gradient(120% 70% at 50% 0%, hsl(var(--card-hue) 60% 22% / 0.55), transparent 70%),
    var(--ink-2);
  cursor: pointer;
  text-align: center;
  transition: transform 0.14s, border-color 0.18s, box-shadow 0.18s;
}
.card:hover {
  transform: translateY(-3px);
  border-color: hsl(var(--card-hue) 80% 62%);
  box-shadow: 0 10px 26px hsl(var(--card-hue) 70% 40% / 0.3);
}
.card:active { transform: translateY(-1px) scale(0.99); }
.card:focus-visible { outline: 2px solid hsl(var(--card-hue) 85% 68%); outline-offset: 2px; }

.card-art { width: 56px; height: 56px; display: block; }
.card-tag {
  font-family: var(--f-mono);
  font-size: 8px; letter-spacing: 0.18em; text-transform: uppercase;
  color: hsl(var(--card-hue) 80% 70%);
}
.card[data-kind="deploy"] .card-tag { color: var(--teal); }
.card-name {
  font-family: var(--f-display);
  font-size: 14px; font-weight: 700;
  letter-spacing: 0.02em; text-transform: uppercase;
  line-height: 1.15;
}
.card-desc {
  font-size: 11.5px; line-height: 1.45;
  color: var(--muted);
  max-width: 26ch;
}

/* ------------------------------------------------------------- level grid */

.levelgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin-bottom: 12px; }
.lvl {
  text-align: left;
  color: var(--text);
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--ink-2);
  cursor: pointer;
  transition: border-color 0.16s, transform 0.12s;
}
.lvl:hover { border-color: var(--teal-dim); transform: translateY(-1px); }
.lvl[data-locked="true"] { opacity: 0.38; cursor: default; }
.lvl[data-locked="true"]:hover { transform: none; border-color: var(--line); }
.lvl .n { font-family: var(--f-mono); font-size: 9px; color: var(--muted); letter-spacing: 0.1em; }
.lvl .t { display: block; font-family: var(--f-display); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; margin: 2px 0 3px; }
.lvl .s { font-size: 11px; color: var(--amber); letter-spacing: 2px; }
.lvl .s .off { color: #2A3446; }

/* ------------------------------------------------------------ leaderboard */

.board { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); text-align: left; }
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.lb li {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
}
.lb li:nth-child(odd) { background: rgba(255,255,255,0.022); }
.lb li[data-you="true"] {
  background: rgba(94, 234, 212, 0.1);
  box-shadow: inset 0 0 0 1px rgba(94, 234, 212, 0.3);
}
.lb .r { font-family: var(--f-mono); font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .s { font-family: var(--f-mono); font-weight: 600; font-variant-numeric: tabular-nums; }
.lb .empty { display: block; color: var(--muted); font-size: 12.5px; padding: 6px 8px; }

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

.toast {
  position: fixed;
  left: 50%; bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 40;
  padding: 9px 15px;
  border-radius: 999px;
  background: #131E2C;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12.5px; font-weight: 500;
  box-shadow: 0 10px 26px rgba(0,0,0,0.6);
  opacity: 0; visibility: hidden;
  transition: opacity 0.22s, transform 0.22s, visibility 0.22s;
}
.toast[data-open="true"] { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* ------------------------------------------------------------ a11y and fit */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* Short viewports: give the field back the space the chrome is using. */
@media (max-height: 700px) {
  .num.big { font-size: 18px; }
  .frame { gap: 4px; }
  .turret-cell { padding: 4px 2px 3px; }
  .turret-cell canvas { width: 20px; height: 20px; }
  .card { padding: 9px 8px 10px; }
  .card-art { width: 44px; height: 44px; }
}
