/* ============================================
   40K HORDE MODE — Companion App
   Visual system: dark, splatter-textured, italic display,
   four category accents matching the cards.
   ============================================ */

:root {
  /* Category accents (from cards) */
  --c-misery: #e1242a;
  --c-misery-deep: #6e0d11;
  --c-resupply: #3fae45;
  --c-resupply-deep: #134e16;
  --c-secondary: #2c8ad6;
  --c-secondary-deep: #0e3c6b;
  --c-secret: #7e3fb8;
  --c-secret-deep: #3a1959;
  --c-horde: #c73a1f; /* horde / spawn — burnt orange */

  /* Surfaces */
  --bg: #0a0908;
  --bg-2: #131210;
  --bg-3: #1d1c1a;
  --bg-card: #232220;
  --line: #3a3835;
  --line-soft: #2a2824;

  /* Text */
  --ink: #f4f1ec;
  --ink-2: #b8b3aa;
  --ink-3: #807a70;
  --ink-mute: #555049;

  /* Type */
  --display: 'Big Shoulders Display', 'Bebas Neue', 'Saira Stencil One', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, monospace;

  /* Density */
  --density: 1;
  --pad-1: calc(6px * var(--density));
  --pad-2: calc(10px * var(--density));
  --pad-3: calc(16px * var(--density));
  --pad-4: calc(22px * var(--density));
  --pad-5: calc(32px * var(--density));
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--body);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* ===== Background field — subtle splatter on dark ===== */
.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 20% 10%, rgba(225,36,42,0.05) 0, transparent 35%),
    radial-gradient(circle at 80% 90%, rgba(63,174,69,0.04) 0, transparent 40%),
    radial-gradient(circle at 60% 40%, rgba(44,138,214,0.04) 0, transparent 45%),
    var(--bg);
}
.app-bg::after {
  content: "";
  position: absolute; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.18 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: 0.5;
  mix-blend-mode: overlay;
  pointer-events: none;
}

/* ===== Display headings ===== */
h1, h2, h3, h4, .display, .h-display {
  font-family: var(--display);
  font-weight: 800;
  font-style: italic;
  letter-spacing: 0.01em;
  margin: 0;
  text-transform: uppercase;
  line-height: 0.95;
}
h1, .h1 { font-size: 32px; letter-spacing: 0.02em; }
h2, .h2 { font-size: 24px; }
h3, .h3 { font-size: 18px; letter-spacing: 0.04em; }
h4, .h4 { font-size: 14px; letter-spacing: 0.06em; }

.eyebrow {
  font-family: var(--display);
  font-weight: 700;
  font-style: italic;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.body-text { line-height: 1.5; color: var(--ink-2); }

/* ===== App shell — mobile first ===== */
.app-shell {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  position: relative;
  background:
    radial-gradient(circle at 10% 0%, rgba(199,58,31,0.08) 0%, transparent 60%),
    radial-gradient(circle at 90% 100%, rgba(126,63,184,0.06) 0%, transparent 50%),
    var(--bg);
  border-left: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
}
.app-header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--pad-2);
  padding: calc(var(--pad-2) + env(safe-area-inset-top)) var(--pad-3) var(--pad-2);
  background: linear-gradient(180deg, rgba(10,9,8,0.95) 0%, rgba(10,9,8,0.85) 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.app-header .brand { display: flex; align-items: center; gap: 10px; flex: 1; }
.app-header .logo-mark {
  font-family: var(--display); font-style: italic; font-weight: 800;
  background: var(--c-misery); color: var(--ink); padding: 4px 8px;
  font-size: 13px; letter-spacing: 0.04em;
}
.app-header .title { line-height: 1; }
.app-header .title .word1 {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 17px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink);
}
.app-header .title .word2 {
  font-family: var(--display); font-style: italic; font-weight: 600;
  font-size: 9px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-3); margin-top: 2px;
}
.app-header .header-right { margin-left: auto; }
.room-btn {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--ink-3); padding: 5px 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  -webkit-tap-highlight-color: transparent;
}
.room-btn .net-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-mute); }
.room-btn.on { color: var(--c-resupply); border-color: rgba(63,174,69,0.4); }
.room-btn.on .net-dot { background: var(--c-resupply); box-shadow: 0 0 6px var(--c-resupply); }
.app-header .round-pill {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 5px 10px; color: var(--ink);
}
.player-tabs {
  position: sticky; top: 56px; z-index: 49;
  display: flex; gap: 4px; overflow-x: auto;
  padding: 8px var(--pad-3); background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
  scrollbar-width: none;
}
.player-tabs::-webkit-scrollbar { display: none; }
.player-tab {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--ink-3); padding: 6px 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  -webkit-tap-highlight-color: transparent;
}
.player-tab.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.player-tab .dot { width: 6px; height: 6px; background: currentColor; transform: rotate(45deg); opacity: 0.6; }
.player-tab .meta { font-size: 10px; opacity: 0.7; font-style: normal; }
.player-tab.ko { opacity: 0.4; text-decoration: line-through; }
.app-main { display: block; }
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; max-width: 480px; margin: 0 auto;
  background: rgba(10,9,8,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav .nav-item {
  flex: 1; background: transparent; border: 0; color: var(--ink-3);
  padding: 10px 4px 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav .nav-item.active { color: var(--ink); }
.bottom-nav .nav-item.active::before {
  content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2px;
  background: var(--c-misery);
}
.bottom-nav .nav-item .lbl { font-size: 10px; }

/* legacy alias kept for any older partials */
.app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent 60px);
  border-left: 1px solid rgba(255,255,255,0.03);
  border-right: 1px solid rgba(255,255,255,0.03);
  position: relative;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  .app { max-width: 520px; }
}

/* ===== Top bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: var(--pad-2);
  padding: var(--pad-3) var(--pad-3);
  padding-top: calc(var(--pad-3) + env(safe-area-inset-top));
  background: rgba(10,9,8,0.86);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar .brand {
  font-family: var(--display); font-weight: 800; font-style: italic;
  font-size: 18px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.topbar .brand .dot {
  width: 8px; height: 8px; background: var(--c-misery);
  transform: rotate(45deg);
}
.topbar .round-pill {
  margin-left: auto; display: flex; align-items: center; gap: 6px;
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 4px 10px; color: var(--ink-2);
}
.topbar .round-pill .num {
  font-size: 16px; color: var(--ink); margin-left: 2px;
}

.topbar .player-tabs {
  display: flex; gap: 2px;
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 2px;
}
.topbar .player-tab {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 12px; letter-spacing: 0.06em;
  width: 26px; height: 24px; display: grid; place-items: center;
  background: transparent; border: 0; color: var(--ink-3);
  cursor: pointer;
}
.topbar .player-tab.active { background: var(--ink); color: var(--bg); }
.topbar .player-tab.gm.active { background: var(--c-misery); color: var(--ink); }

/* ===== Bottom nav ===== */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: rgba(10,9,8,0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-soft);
  display: flex; justify-content: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .inner {
  display: flex; width: 100%; max-width: 480px;
}
.bottomnav button {
  flex: 1; background: transparent; border: 0; color: var(--ink-3);
  padding: 10px 4px 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 10px; letter-spacing: 0.1em;
  position: relative;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}
.bottomnav button.active { color: var(--ink); }
.bottomnav button.active::before {
  content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2px;
  background: var(--ink);
}
.bottomnav .icon { width: 22px; height: 22px; }

/* ===== View padding ===== */
.view { padding: var(--pad-3); display: flex; flex-direction: column; gap: var(--pad-3); }
.view-wide { padding: var(--pad-3) 0; }

.section-title {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: var(--pad-1);
}
.section-title .num {
  font-family: var(--display); font-style: italic; font-weight: 700;
  color: var(--ink-3); font-size: 12px; letter-spacing: 0.1em;
}

/* ===== Buttons ===== */
.btn {
  font-family: var(--display); font-style: italic; font-weight: 800;
  letter-spacing: 0.06em; text-transform: uppercase;
  font-size: 14px;
  padding: 12px 16px;
  background: var(--ink); color: var(--bg);
  border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.btn:active { transform: translate(0, 1px); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.subtle { background: var(--bg-3); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--c-misery); color: var(--ink); }
.btn.full { width: 100%; }
.btn.lg { padding: 16px 20px; font-size: 16px; }
.btn.sm { padding: 8px 12px; font-size: 12px; }
.btn.icon-only { padding: 10px; width: 40px; height: 40px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn.misery { background: var(--c-misery); color: white; }
.btn.resupply { background: var(--c-resupply); color: white; }
.btn.secondary-c { background: var(--c-secondary); color: white; }
.btn.secret { background: var(--c-secret); color: white; }

/* Cut-corner accent */
.cut-corner {
  clip-path: polygon(0 0, calc(100% - 12px) 0, 100% 12px, 100% 100%, 12px 100%, 0 calc(100% - 12px));
}

/* ===== Tile / container ===== */
.tile {
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  padding: var(--pad-3);
  position: relative;
}
.tile.accent-misery { border-left: 3px solid var(--c-misery); }
.tile.accent-resupply { border-left: 3px solid var(--c-resupply); }
.tile.accent-secondary { border-left: 3px solid var(--c-secondary); }
.tile.accent-secret { border-left: 3px solid var(--c-secret); }

.row { display: flex; align-items: center; gap: var(--pad-2); }
.row.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: var(--pad-2); }
.gap-1 { gap: var(--pad-1); }
.gap-3 { gap: var(--pad-3); }
.gap-4 { gap: var(--pad-4); }
.grow { flex: 1; }
.center { display: flex; align-items: center; justify-content: center; }

/* ===== Chip / tag ===== */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 3px 7px;
  background: var(--bg-3); color: var(--ink-2);
  border: 1px solid var(--line);
}
.chip.misery { background: rgba(225,36,42,0.15); color: var(--c-misery); border-color: rgba(225,36,42,0.4); }
.chip.resupply { background: rgba(63,174,69,0.15); color: var(--c-resupply); border-color: rgba(63,174,69,0.4); }
.chip.secondary-c { background: rgba(44,138,214,0.15); color: var(--c-secondary); border-color: rgba(44,138,214,0.4); }
.chip.secret { background: rgba(126,63,184,0.18); color: #b386e0; border-color: rgba(126,63,184,0.4); }

/* ===== Stat readout (large CP/SP) ===== */
.stat-block {
  display: flex; align-items: center; gap: var(--pad-2);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  padding: var(--pad-3);
  flex: 1;
  position: relative;
  overflow: hidden;
}
.stat-block .label {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-3);
}
.stat-block .value {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 48px; line-height: 0.9; color: var(--ink);
}
.stat-block .ctrl {
  display: flex; flex-direction: column; gap: 4px;
}
.stat-block .ctrl button {
  width: 30px; height: 26px;
  background: var(--bg-3); border: 1px solid var(--line);
  color: var(--ink); font-family: var(--display);
  font-weight: 800; font-size: 16px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.stat-block .ctrl button:active { transform: translate(0, 1px); }

.stat-block.cp .value { color: #f4d35e; }
.stat-block.sp .value { color: var(--c-resupply); }

/* ===== Card image (PNG) container ===== */
.card-png {
  position: relative;
  width: 100%;
  aspect-ratio: 750 / 1010;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.card-png img {
  width: 100%; height: 100%; object-fit: contain; display: block;
}
.card-png.lift { transition: transform 0.18s ease; }
.card-png.lift:active { transform: scale(0.98); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--pad-2);
}
.card-grid.three { grid-template-columns: repeat(3, 1fr); }

/* ===== Modal / drawer ===== */
.modal-back {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer {
  background: var(--bg-2);
  width: 100%; max-width: 480px;
  max-height: 92dvh;
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  animation: slide-up 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.modal {
  align-self: center; max-height: 90dvh;
}
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.drawer-handle { width: 36px; height: 4px; background: var(--ink-mute); margin: 8px auto 0; border-radius: 2px; }
.drawer-header {
  display: flex; align-items: center; gap: var(--pad-2);
  padding: var(--pad-3);
  border-bottom: 1px solid var(--line-soft);
}
.drawer-body { overflow: auto; padding: var(--pad-3); flex: 1; }
.drawer-footer { padding: var(--pad-3); border-top: 1px solid var(--line-soft); display: flex; gap: var(--pad-2); }

.icon-btn {
  background: transparent; border: 0; color: var(--ink-2);
  width: 36px; height: 36px; cursor: pointer;
  display: grid; place-items: center; border-radius: 0;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { color: var(--ink); }

/* ===== Round tracker phase list ===== */
.phase-list { display: flex; flex-direction: column; gap: 0; }
.phase-row {
  display: flex; align-items: center; gap: var(--pad-2);
  padding: var(--pad-2) var(--pad-3);
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.phase-row:last-child { border-bottom: 0; }
.phase-row .check {
  width: 22px; height: 22px; border: 1px solid var(--line);
  display: grid; place-items: center; flex: none;
  font-size: 14px; color: transparent;
}
.phase-row.done .check {
  background: var(--c-resupply); border-color: var(--c-resupply); color: var(--bg);
}
.phase-row.done .label { text-decoration: line-through; color: var(--ink-3); }
.phase-row .label {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink);
}
.phase-row .desc { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* ===== Setup wizard ===== */
.setup-bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(circle at 50% 80%, rgba(225,36,42,0.18), transparent 50%),
    var(--bg);
}
.setup-bg::after {
  content: ""; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.32 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: 0.7;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* Selectable list (factions, deployments) */
.option-list { display: flex; flex-direction: column; gap: 6px; }
.option-row {
  background: var(--bg-2); border: 1px solid var(--line-soft);
  padding: var(--pad-2) var(--pad-3);
  display: flex; align-items: center; gap: var(--pad-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.option-row.active { border-color: var(--ink); background: var(--bg-3); }
.option-row .name {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase;
}
.option-row .meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.option-row.active .name { color: var(--ink); }

.player-pills { display: flex; gap: 6px; }
.player-pills button {
  flex: 1; padding: 10px;
  background: var(--bg-2); border: 1px solid var(--line-soft);
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 14px; letter-spacing: 0.06em;
  color: var(--ink-3); cursor: pointer;
}
.player-pills button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ===== Active effects strip ===== */
.effect-card {
  background: var(--bg-2); border: 1px solid var(--line-soft);
  padding: var(--pad-2) var(--pad-3);
  display: flex; align-items: flex-start; gap: var(--pad-2);
  position: relative;
  border-left: 3px solid var(--ink-mute);
}
.effect-card.misery { border-left-color: var(--c-misery); }
.effect-card.resupply { border-left-color: var(--c-resupply); }
.effect-card.secondary-c { border-left-color: var(--c-secondary); }
.effect-card.secret { border-left-color: var(--c-secret); }
.effect-card .name {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 15px; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--ink);
}
.effect-card .num {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 11px; color: var(--ink-3); letter-spacing: 0.1em;
}

/* ===== Spawn tool ===== */
.dice-area {
  background: var(--bg-2); border: 1px solid var(--line-soft);
  padding: var(--pad-4);
  display: flex; flex-direction: column; align-items: center; gap: var(--pad-3);
}
.dice {
  display: flex; gap: var(--pad-2);
}
.die {
  width: 64px; height: 64px;
  background: #f6f1e1; color: #16110b;
  border: 2px solid #16110b;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 8px;
  position: relative;
  box-shadow: 0 2px 0 rgba(0,0,0,0.4), inset 0 0 0 1px rgba(255,255,255,0.4);
}
.die .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #16110b;
  align-self: center;
  justify-self: center;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.3);
}
.die.shake { animation: dieShake 0.4s ease; }
@keyframes dieShake {
  0%   { transform: rotate(0deg)   translateY(0)   scale(1); }
  20%  { transform: rotate(-15deg) translateY(-6px) scale(1.05); }
  40%  { transform: rotate( 12deg) translateY(-3px) scale(1.08); background: var(--c-horde); }
  60%  { transform: rotate(-8deg)  translateY(-5px) scale(1.05); }
  80%  { transform: rotate( 5deg)  translateY(-2px) scale(1.02); }
  100% { transform: rotate(0deg)   translateY(0)   scale(1); }
}
.spawn-result {
  text-align: center;
}
.spawn-result .total {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 56px; line-height: 1;
  color: var(--ink);
}
.spawn-result .bracket {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 22px; color: var(--c-horde);
  margin-top: 4px;
  letter-spacing: 0.05em;
}
.spawn-result.no-spawn .total { color: var(--ink-mute); }
.spawn-result.no-spawn .bracket { color: var(--ink-mute); }

.unit-list { display: flex; flex-direction: column; gap: 4px; max-height: 50dvh; overflow: auto; }
.unit-row {
  background: var(--bg-2); border: 1px solid var(--line-soft);
  padding: var(--pad-2) var(--pad-3);
  font-size: 13px; color: var(--ink-2);
  display: flex; align-items: center; gap: var(--pad-2);
}
.unit-row .marker { color: var(--c-horde); font-weight: 700; }

.modifier-stepper {
  display: flex; align-items: center; gap: 0;
  background: var(--bg-3); border: 1px solid var(--line);
}
.modifier-stepper button {
  width: 32px; height: 32px;
  background: transparent; border: 0; color: var(--ink);
  font-family: var(--display); font-weight: 800; font-size: 16px;
  cursor: pointer;
}
.modifier-stepper .val {
  min-width: 38px; text-align: center;
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 16px;
}

/* ===== Resupply shop ===== */
.shop-item {
  background: var(--bg-2); border: 1px solid var(--line-soft);
  padding: var(--pad-2) var(--pad-3);
  display: flex; align-items: center; gap: var(--pad-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.shop-item.locked { opacity: 0.45; }
.shop-item .cost {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 22px;
  background: var(--c-resupply); color: white;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  flex: none;
}
.shop-item .name {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 14px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink);
}

/* ===== Empty state ===== */
.empty {
  padding: var(--pad-4);
  text-align: center;
  color: var(--ink-3);
  border: 1px dashed var(--line);
  background: rgba(255,255,255,0.01);
}
.empty .h-display { color: var(--ink-2); margin-bottom: 4px; }

/* ===== Detail readouts ===== */
.kv {
  display: flex; align-items: center; gap: var(--pad-2);
  padding: var(--pad-2) 0;
  border-bottom: 1px solid var(--line-soft);
}
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--ink-3); font-family: var(--display); font-style: italic; font-weight: 700; font-size: 12px; letter-spacing: 0.1em; }
.kv .v { margin-left: auto; color: var(--ink); font-weight: 600; }

/* ===== Faction rule readout ===== */
.faction-rule {
  background: linear-gradient(135deg, rgba(199,58,31,0.1), rgba(199,58,31,0.02));
  border: 1px solid rgba(199,58,31,0.4);
  padding: var(--pad-3);
  border-left: 3px solid var(--c-horde);
}

/* ===== Splash on setup ===== */
.brand-mark {
  position: relative;
  font-family: var(--display); font-weight: 800; font-style: italic;
  letter-spacing: 0.02em; text-transform: uppercase;
  line-height: 0.9;
}
.brand-mark .l1 { font-size: 56px; color: var(--ink); }
.brand-mark .l2 { font-size: 56px; color: var(--c-misery); }
.brand-mark .tag { font-size: 11px; letter-spacing: 0.3em; color: var(--ink-3); margin-top: 6px; }

/* ===== Misc utilities ===== */
.hr { height: 1px; background: var(--line-soft); margin: var(--pad-2) 0; }
.spacer { height: var(--pad-3); }
.center-text { text-align: center; }
.muted { color: var(--ink-3); }
.danger-text { color: var(--c-misery); }

/* No focus ring outline for tap-buttons */
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }

/* ===== Round badge ===== */
.round-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: var(--bg-3); border: 1px solid var(--line);
}
.round-badge .num {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 26px; line-height: 1; color: var(--ink);
}
.round-badge .word {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-3);
}

/* Round gauge */
.round-gauge {
  display: flex; gap: 4px;
  margin-top: var(--pad-1);
}
.round-gauge .seg {
  flex: 1; height: 4px; background: var(--bg-3); border: 1px solid var(--line);
}
.round-gauge .seg.passed { background: var(--c-resupply); border-color: var(--c-resupply); }
.round-gauge .seg.current { background: var(--c-misery); border-color: var(--c-misery); }

/* Inline player rename input */
.player-name-input {
  margin-top: 2px;
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 28px; letter-spacing: 0.02em; text-transform: uppercase;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px dashed var(--line);
  padding: 0 0 2px;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
}
.player-name-input:focus { border-bottom-color: var(--c-horde); }
.player-name-input::placeholder { color: var(--ink-mute); }


/* ============================================
   END-OF-GAME SCREEN
   ============================================ */
.endgame {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* ---- Hero ---- */
.endgame-hero {
  position: relative;
  padding: calc(var(--pad-5) + env(safe-area-inset-top)) var(--pad-3) var(--pad-4);
  background: linear-gradient(180deg, #1d0907 0%, #110504 60%, var(--bg) 100%);
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  isolation: isolate;
}
.endgame-hero .hero-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(199,58,31,0.35) 0%, transparent 50%),
    radial-gradient(ellipse at 75% 30%, rgba(225,36,42,0.25) 0%, transparent 60%);
  z-index: -1;
}
.endgame-hero .hero-streaks {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: -1;
}
.endgame-hero .hero-streaks span {
  position: absolute; top: 0;
  width: 1px;
  background: linear-gradient(180deg, transparent 0%, rgba(255,180,150,0.7) 30%, transparent 100%);
  animation: streakDrop 3.6s ease-in-out infinite;
  transform-origin: top;
}
@keyframes streakDrop {
  0%   { transform: translateY(-20%) scaleY(0.4); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translateY(80%) scaleY(1); opacity: 0; }
}
.endgame-hero .hero-content {
  position: relative;
  text-align: center;
  animation: heroIn 0.6s ease-out both;
}
@keyframes heroIn {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.endgame-eyebrow {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 11px; letter-spacing: 0.32em; text-transform: uppercase;
  color: var(--c-horde);
  margin-bottom: var(--pad-3);
  text-shadow: 0 0 12px rgba(199,58,31,0.5);
}
.endgame-title {
  font-family: var(--display); font-style: italic; font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  line-height: 0.85;
  margin: 0;
  font-size: clamp(64px, 19vw, 120px);
  color: var(--ink);
}
.endgame-title .line { display: block; }
.endgame-title .line-1 { color: var(--ink); }
.endgame-title .line-2 {
  color: transparent;
  -webkit-text-stroke: 2px var(--c-horde);
  text-stroke: 2px var(--c-horde);
  margin-top: -0.05em;
}
.endgame-faction {
  margin-top: var(--pad-3);
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-2);
}
.endgame-meta {
  margin-top: var(--pad-2);
  font-family: var(--display); font-style: italic; font-weight: 600;
  font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink-3);
  display: inline-flex; flex-wrap: wrap; gap: 6px; justify-content: center;
}
.endgame-meta .dot-sep { color: var(--ink-mute); }

/* ---- Body container ---- */
.endgame-body {
  padding: var(--pad-4) var(--pad-3) calc(var(--pad-5) + env(safe-area-inset-bottom));
  display: flex; flex-direction: column;
  gap: var(--pad-4);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}
.endgame-body.revealed { opacity: 1; transform: translateY(0); }

/* ---- Big stat grid ---- */
.endgame-statgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--pad-2);
}
.endgame-stat {
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-top: 3px solid var(--accent);
  padding: var(--pad-3);
  position: relative;
  overflow: hidden;
}
.endgame-stat .lbl {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-3);
}
.endgame-stat .val {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 56px; line-height: 0.9;
  color: var(--ink);
  margin-top: 4px;
}
.endgame-stat .sub {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 6px;
  letter-spacing: 0.04em;
}

/* ---- Sections ---- */
.endgame-section { display: flex; flex-direction: column; gap: var(--pad-2); }
.endgame-section-head { display: flex; flex-direction: column; gap: 2px; }
.endgame-section-eyebrow {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 10px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--c-horde);
}
.endgame-section-title {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 22px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink);
  margin: 0;
}

/* ---- Bracket distribution ---- */
.bracket-bars {
  display: flex; flex-direction: column; gap: 6px;
  padding: var(--pad-3);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
}
.bracket-bar {
  display: grid;
  grid-template-columns: 56px 1fr 28px;
  gap: var(--pad-2);
  align-items: center;
}
.bracket-bar .bar-label {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 13px; color: var(--ink-2);
  letter-spacing: 0.04em;
}
.bracket-bar .bar-track {
  height: 14px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  position: relative;
}
.bracket-bar .bar-fill {
  position: absolute; inset: 0 auto 0 0;
  background: linear-gradient(90deg, var(--c-horde), #ff6a3a);
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}
.bracket-bar .bar-count {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 16px; color: var(--ink);
  text-align: right;
}

/* ---- Timeline ---- */
.timeline {
  display: flex; flex-direction: column; gap: var(--pad-2);
}
.timeline-round {
  display: flex; gap: var(--pad-2);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  padding: var(--pad-3);
  position: relative;
}
.timeline-round::before {
  content: ''; position: absolute;
  left: 0; top: 0; bottom: 0; width: 2px;
  background: var(--c-horde);
  opacity: 0.7;
}
.tl-marker {
  flex: none; width: 44px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
}
.tl-num {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 22px; color: var(--ink);
  letter-spacing: 0.04em;
}
.tl-body { flex: 1; min-width: 0; }
.tl-head {
  display: flex; align-items: baseline; gap: var(--pad-2);
  margin-bottom: 6px;
}
.tl-count {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--c-horde);
}
.tl-sub {
  font-size: 10px; color: var(--ink-3); letter-spacing: 0.06em;
}
.tl-zones { display: flex; flex-direction: column; gap: 3px; }
.tl-zone {
  display: grid;
  grid-template-columns: 32px 32px 1fr;
  gap: 6px; align-items: center;
  padding: 4px 6px;
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  font-size: 12px;
}
.tl-zone.no-spawn { opacity: 0.5; }
.tl-zone .tl-z {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 11px; color: var(--ink-3); letter-spacing: 0.08em;
}
.tl-zone .tl-total {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 14px; color: var(--ink);
  text-align: center;
}
.tl-zone .tl-unit {
  font-size: 12px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- Unit tally ---- */
.unit-tally {
  display: flex; flex-direction: column; gap: 4px;
}
.unit-tally-row {
  display: flex; align-items: center; gap: var(--pad-2);
  padding: var(--pad-2) var(--pad-3);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
}
.unit-tally-row .rank {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 14px; color: var(--ink-3);
  width: 36px; letter-spacing: 0.04em;
}
.unit-tally-row .name {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 14px; color: var(--ink);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.unit-tally-row .count {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 18px; color: var(--c-horde);
}

/* ---- Misery faced ---- */
.misery-faced { display: flex; flex-direction: column; gap: 4px; }
.misery-faced-row {
  display: flex; align-items: center; gap: var(--pad-2);
  padding: var(--pad-2) var(--pad-3);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--c-misery);
  cursor: pointer;
  text-align: left;
  color: var(--ink);
  font-family: inherit;
}
.misery-faced-row:active { transform: translate(0, 1px); }
.misery-faced-row .m-num {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 12px; color: var(--c-misery); letter-spacing: 0.1em;
  width: 36px;
}
.misery-faced-row .m-name {
  font-size: 13px; color: var(--ink);
}
.misery-faced-row .m-arrow {
  color: var(--ink-3); font-size: 16px;
}

/* ---- Player results ---- */
.player-results {
  display: flex; flex-direction: column; gap: var(--pad-2);
}
.pr-card {
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  padding: var(--pad-3);
  display: flex; flex-direction: column; gap: var(--pad-2);
  position: relative;
}
.pr-card.eliminated { opacity: 0.65; }
.pr-card.eliminated::after {
  content: 'ELIMINATED';
  position: absolute; top: 12px; right: 12px;
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 10px; letter-spacing: 0.2em;
  color: var(--c-misery);
  border: 1px solid var(--c-misery);
  padding: 2px 6px;
}
.pr-head { display: flex; align-items: center; gap: var(--pad-2); }
.pr-id {
  width: 36px; height: 36px;
  background: var(--ink); color: var(--bg);
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 16px; letter-spacing: 0.04em;
  display: grid; place-items: center;
}
.pr-name {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 18px; letter-spacing: 0.02em; text-transform: uppercase;
  color: var(--ink);
}
.pr-status {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--c-misery);
}
.pr-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--pad-2);
  padding: var(--pad-2);
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
}
.pr-stat { text-align: center; }
.pr-stat .lbl {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-3);
}
.pr-stat .val {
  font-family: var(--display); font-style: italic; font-weight: 800;
  font-size: 28px; line-height: 1; color: var(--ink);
  margin-top: 2px;
}
.pr-secret {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--c-secret);
  padding: var(--pad-2) var(--pad-3);
  text-align: left;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}
.pr-secret:active { transform: translate(0, 1px); }
.pr-secret .ps-eyebrow {
  font-family: var(--display); font-style: italic; font-weight: 700;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--c-secret);
}
.pr-secret .ps-name {
  font-size: 13px; color: var(--ink); margin-top: 2px;
}
.pr-notes {
  font-style: italic; font-size: 13px; color: var(--ink-2);
  padding: 6px 10px;
  border-left: 2px solid var(--ink-mute);
}

/* ---- CTA + footer ---- */
.endgame-cta {
  display: flex; flex-direction: column; gap: var(--pad-2);
  margin-top: var(--pad-3);
}
.endgame-footer {
  display: flex; justify-content: center;
  margin-top: var(--pad-3);
  padding-top: var(--pad-3);
  border-top: 1px solid var(--line-soft);
}
.endgame-stamp {
  text-align: center;
  font-family: var(--display); font-style: italic; font-weight: 700;
}
.endgame-stamp .stamp-line {
  font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--ink-3);
}
.endgame-stamp .stamp-sub {
  font-weight: 600; font-size: 9px; letter-spacing: 0.18em;
  color: var(--ink-mute); margin-top: 2px;
}

@media (min-width: 480px) {
  .endgame-statgrid { grid-template-columns: repeat(4, 1fr); }
}
