* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Visual language single source of truth.
   UI chrome uses this token block. Game art assets use theming/visual-theme.v1.json.
   JS templates should use classes or CSS vars from here, not hardcoded colors. */
:root {
  /* Primitive palette */
  --color-black: #040404;
  --color-black-soft: #0b0a12;
  --color-red: #ef4444;
  --color-red-ink: #b91c1c;
  --color-blue: #3b82f6;
  --color-blue-ink: #1d4ed8;
  --color-purple: #a855f7;
  --color-purple-ink: #7c3aed;

  /* Semantic UI chrome */
  --ui-bg: var(--color-black);
  --ui-bg-soft: var(--color-black-soft);
  --ui-surface: #11111a;
  --ui-surface-2: #18182a;
  --ui-surface-code: #0a0a14;
  --ui-border: #2a2a45;
  --ui-border-soft: #3a3a5a;
  --ui-hover: #25253d;
  --ui-text: #f4f4ff;
  --ui-text-soft: #9e9eb8;
  --ui-text-subtle: #686886;
  --ui-code-text: #c8e0c8;
  --ui-success: #6ee7b7;
  --ui-success-ink: #1e3a2c;
  --ui-warning: #facc15;

  --ui-red: var(--color-red);
  --ui-red-ink: var(--color-red-ink);
  --ui-blue: var(--color-blue);
  --ui-blue-ink: var(--color-blue-ink);
  --ui-purple: var(--color-purple);
  --ui-purple-ink: var(--color-purple-ink);
  --ui-purple-bright: #c084fc;
  --ui-pink: #ec4899;
  --ui-pink-ink: #be185d;
  --context-card-height: 112px;
  --context-card-height-mobile: 136px;

  /* Canvas fallback renderer. Full asset palettes belong in theming/. */
  --arena-bg: #14141e;
  --arena-sky-top: #141020;
  --arena-sky-mid: #0e1520;
  --arena-sky-bottom: #080c14;
  --arena-platform-solid: #141c28;
  --arena-platform-soft: #151e2a;
  --arena-platform-highlight: rgba(255,255,255,0.07);
  --arena-p1: var(--ui-blue);
  --arena-p1-trim: #93c5fd;
  --arena-p1-shadow: var(--ui-blue-ink);
  /* P2 is purple, not red — red is reserved for hallucination /
   * over-budget / danger signals across the whole UI. */
  --arena-p2: var(--ui-purple);
  --arena-p2-trim: #d8b4fe;
  --arena-p2-shadow: var(--ui-purple-ink);
  --arena-goal-normal: #d946ef;
  --arena-goal-urgent: #ef4444;
  --arena-token: #ffd700;
  --arena-token-glow: rgba(255,215,0,0.15);
  --arena-weapon-glow: rgba(255,255,255,0.18);
  --arena-weapon-active: #fffaf0;
  --arena-weapon-dive: #ffe8c0;
  --arena-weapon-idle: #d8dae0;
  --arena-weapon-tip-idle: #aab;
  --arena-hud-text: #fff;
  --arena-hud-soft: rgba(248,247,244,0.6);
  --arena-idle-bg: #08080e;
  --arena-idle-text: #667;

  /* Breakpoint contract:
   * 640px  = phone chrome / touch ergonomics
   * 800px  = Live collapses to one column
   * 900px  = generic tablet stacking + Build fold controls
   * 1024px = desktop-only bounded Build panels
   * 1100px = Live three-column to two-column handoff
   * 1200px = Build three-column to two-column handoff
   */
  --mobile-nav-h: 58px;
}

html,
body {
  background: var(--ui-bg);
  color: var(--ui-text);
  font-family: -apple-system, system-ui, sans-serif;
  min-height: 100vh;
  /* Firefox + modern spec: thin scrollbars, theme-matched colors. */
  scrollbar-width: thin;
  scrollbar-color: var(--ui-border) var(--ui-bg-soft);
}

body {
  display: flex;
  flex-direction: column;
}

/* Chrome / Safari / Edge scrollbar styling. Scoped via the universal
 * selector so every scrollable container in the app — page body,
 * .grid-3 side panels, .code-export, .stream-log — gets the same
 * dark-track + accent-thumb treatment instead of the browser default. */
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: var(--ui-bg-soft);
}
*::-webkit-scrollbar-thumb {
  background: var(--ui-border);
  border-radius: 4px;
  border: 1px solid var(--ui-bg-soft);
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--ui-border-soft);
}
*::-webkit-scrollbar-corner {
  background: var(--ui-bg-soft);
}

/* Side-tinted scrollbars inside each player panel so the P1/P2 accent
 * carries through the scroll chrome too. */
.player-panel.is-p1 *::-webkit-scrollbar-thumb {
  background: var(--ui-blue-ink);
}
.player-panel.is-p1 *::-webkit-scrollbar-thumb:hover {
  background: var(--ui-blue);
}
.player-panel.is-p2 *::-webkit-scrollbar-thumb {
  background: var(--ui-purple-ink);
}
.player-panel.is-p2 *::-webkit-scrollbar-thumb:hover {
  background: var(--ui-purple);
}
.player-panel.is-p1 {
  scrollbar-color: var(--ui-blue-ink) var(--ui-bg-soft);
}
.player-panel.is-p2 {
  scrollbar-color: var(--ui-purple-ink) var(--ui-bg-soft);
}

a {
  color: var(--ui-blue);
  text-decoration: none;
}

a:hover {
  color: var(--ui-purple);
}

/* --- header / nav --- */
#topnav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 24px;
  padding: 10px 18px;
  background: var(--ui-bg-soft);
  border-bottom: 1px solid var(--ui-border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ui-red);
  text-transform: lowercase;
}

.logo-caret {
  color: var(--ui-text-soft);
  font-weight: 400;
}

.tagline {
  color: var(--ui-text-subtle);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#topnav nav {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
}

#topnav nav a {
  color: var(--ui-text-soft);
  font-size: 13px;
  letter-spacing: 0.04em;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}

#topnav nav a[hidden] {
  display: none !important;
}

#topnav nav a:hover {
  color: var(--ui-text);
}

#topnav nav a.active {
  color: var(--ui-red);
  border-bottom-color: var(--ui-red);
}

.whoami {
  margin-left: auto;
  color: var(--ui-text-subtle);
  font-size: 12px;
}

.whoami a {
  color: var(--ui-blue);
}

/* --- main content area --- */
/* No max-width cap: the dominant surfaces (arena canvas, build editor,
 * spectator) benefit from filling the viewport on wide/ultrawide
 * monitors. Text-heavy panels are short enough to read comfortably
 * even at 2000+px line lengths, and grid layouts cap themselves
 * where appropriate (e.g. .grid-3's middle column).
 */
#app {
  flex: 1;
  padding: 16px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 640px) {
  body {
    padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
  }

  #app {
    padding: 10px;
  }

  #topnav {
    position: sticky;
    top: 0;
    z-index: 80;
    flex-wrap: nowrap;
    gap: 10px;
    min-height: 48px;
    padding: 8px 12px;
  }

  .brand {
    min-width: 0;
  }

  .logo {
    white-space: nowrap;
  }

  #topnav nav {
    position: fixed;
    z-index: 100;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    min-height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom));
    padding: 0 0 env(safe-area-inset-bottom);
    background: var(--ui-bg-soft);
    border-top: 1px solid var(--ui-border);
    box-shadow: 0 -12px 28px rgba(0, 0, 0, 0.42);
  }

  #topnav nav a {
    min-width: 0;
    min-height: var(--mobile-nav-h);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 2px 7px;
    border-bottom: 0;
    border-top: 2px solid transparent;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1;
    text-align: center;
    text-transform: uppercase;
    touch-action: manipulation;
  }

  #topnav nav a:hover {
    color: var(--ui-text);
    background: rgba(255, 255, 255, 0.03);
  }

  #topnav nav a.active {
    color: var(--ui-red);
    border-top-color: var(--ui-red);
    border-bottom-color: transparent;
    background:
      linear-gradient(to bottom, rgba(239, 68, 68, 0.16), rgba(239, 68, 68, 0)),
      var(--ui-bg-soft);
  }

  .tagline {
    display: none;
  }

  .whoami {
    margin-left: auto;
    min-width: 0;
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
    font-size: 11px;
  }

  #bottom {
    padding: 8px 12px;
  }
}

.page {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: calc(100svh - 112px);
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 4px;
  flex-wrap: wrap;
  gap: 8px;
}

.page-header h1 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ui-red);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.page-header h1 small {
  color: var(--ui-text-subtle);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  margin-left: 6px;
}

.panel {
  background: var(--ui-surface);
  border: 1px solid var(--ui-border);
  padding: 12px;
}

.panel h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--ui-text-soft);
  margin-bottom: 8px;
}

.context-card {
  display: grid;
  align-content: center;
  gap: 8px;
  height: var(--context-card-height);
  overflow: hidden;
  background: var(--ui-surface);
  border: 1px solid var(--ui-purple);
  padding: 14px 16px;
}

.context-card > * {
  min-width: 0;
}

.context-card-kicker {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ui-text-subtle);
}

.context-card h2 {
  color: var(--ui-purple);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-card p {
  color: var(--ui-text-soft);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* --- buttons / inputs --- */
button,
select,
input[type="text"],
textarea {
  background: var(--ui-surface-2);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
}

a.buttonish {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ui-surface-2);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
}

a.buttonish:hover {
  background: var(--ui-hover);
  color: var(--ui-text);
}

a.buttonish.primary {
  background: var(--ui-blue-ink);
  border-color: var(--ui-blue);
}

a.buttonish.primary:hover {
  background: var(--ui-blue);
}

a.buttonish.intro-cta-purple {
  border-color: var(--ui-purple);
  background: var(--ui-purple-ink);
}

a.buttonish.intro-cta-purple:hover {
  background: var(--ui-purple);
}

a.buttonish.intro-cta-red {
  border-color: var(--ui-red);
  color: var(--ui-red);
}

a.buttonish.intro-cta-red:hover,
a.buttonish.intro-cta-red:focus-visible {
  background: rgba(239, 68, 68, 0.14);
  color: var(--ui-text);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.35);
}

a.buttonish.intro-cta-red:active {
  background: var(--ui-red);
  border-color: var(--ui-red);
  color: var(--ui-bg);
  transform: translateY(1px);
}

button {
  cursor: pointer;
}

button:hover,
select:hover {
  background: var(--ui-hover);
}

button.primary {
  background: var(--ui-blue-ink);
  border-color: var(--ui-blue);
  color: var(--ui-text);
}

button.primary:hover {
  background: var(--ui-blue);
}

button.is-simulating,
button.is-simulating:disabled {
  opacity: 1;
  color: var(--ui-text);
  background: var(--ui-purple-ink);
  border-color: var(--ui-purple-bright);
  animation: build-preview-pulse 520ms ease-in-out infinite alternate;
}

button.needs-resim {
  color: var(--ui-red);
  background: var(--ui-surface-2);
  border-color: var(--ui-red);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.18);
}

button.danger {
  border-color: var(--ui-red);
  color: var(--ui-red);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
}

.config-json-textarea {
  width: 100%;
  min-height: 360px;
  white-space: pre;
  overflow: auto;
}

/* --- profile roster: 5 parallel seats --- */
.profile-roster-panel {
  display: grid;
  gap: 12px;
}

.roster-intro-claim {
  display: grid;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px dotted var(--ui-border);
}

.roster-intro-panel {
  display: grid;
  gap: 9px;
}

.context-card-copy,
.roster-intro-copy {
  display: grid;
  gap: 4px;
  color: var(--ui-text-soft);
  font-size: 13px;
  line-height: 1.4;
}

.context-card-copy strong,
.roster-intro-copy strong {
  color: var(--ui-text);
  font-weight: 600;
}

.profile-roster-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.profile-roster-head h3 {
  margin-bottom: 0;
}

.profile-roster-head small {
  color: var(--ui-text-soft);
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.seat-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-height: 132px;
  padding: 12px 14px;
  background: var(--ui-surface-code);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  color: var(--ui-text);
  font-family: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}

.seat-card:hover {
  background: var(--ui-hover);
  border-color: var(--ui-border-soft);
}

.seat-card.is-active {
  border-color: var(--ui-blue);
  background: var(--ui-surface-2);
  box-shadow: 0 0 0 1px var(--ui-blue) inset;
}

.seat-card.is-empty {
  opacity: 0.72;
}

.seat-card.is-empty .seat-name {
  color: var(--ui-text-subtle);
  font-style: italic;
}

.seat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.seat-label {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--ui-text-subtle);
}

.seat-state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ui-border-soft);
}

.seat-card.is-filled .seat-state-dot {
  background: var(--ui-blue);
  box-shadow: 0 0 6px var(--ui-blue-ink);
}

.seat-card.is-active .seat-state-dot {
  background: var(--ui-blue);
}

.seat-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--ui-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-elo {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--ui-blue);
  line-height: 1.1;
}

.seat-wl {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--ui-text-soft);
}

.seat-last {
  font-size: 10px;
  color: var(--ui-text-subtle);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.seat-editor {
  display: grid;
  gap: 10px;
  border-top: 1px dotted var(--ui-border);
  padding-top: 12px;
}

.seat-editor-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.seat-editor-head h3 {
  margin-bottom: 0;
}

#editor-note {
  color: var(--ui-text-soft);
}

.profile-submit-row {
  display: grid;
  grid-template-columns: minmax(180px, 320px) 1fr;
  gap: 10px;
  align-items: end;
}

.profile-submit-row label {
  display: grid;
  gap: 4px;
  color: var(--ui-text-soft);
  font-size: 11px;
  text-transform: uppercase;
}

.profile-submit-row input {
  width: 100%;
  text-transform: none;
}

.profile-submit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.profile-editor-meter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  min-height: 24px;
  padding: 7px 9px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-surface-code);
  color: var(--ui-text-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
}

.profile-editor-meter .is-over {
  color: var(--ui-red);
}

.profile-editor-tabs {
  display: inline-flex;
  width: fit-content;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-surface-code);
}

.profile-editor-tabs button {
  min-height: 30px;
  padding: 5px 12px;
  border-color: transparent;
  background: transparent;
}

.profile-editor-tabs button.is-active {
  border-color: var(--ui-border-soft);
  background: var(--ui-surface-2);
  color: var(--ui-text);
}

.profile-slider-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
}

.profile-json-panel {
  display: grid;
  gap: 8px;
}

.profile-json-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.config-json-preview {
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-surface-code);
  color: var(--ui-text-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre;
}

.json-import-dialog {
  width: min(720px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--ui-border-soft);
  border-radius: 8px;
  background: var(--ui-surface);
  color: var(--ui-text);
}

.json-import-dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
}

.json-import-card {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.json-import-card h3 {
  margin-bottom: 0;
}

.json-import-dialog .config-json-textarea {
  min-height: 240px;
}

button.primary.is-dirty {
  box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.35) inset;
}

@media (max-width: 980px) {
  .roster-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }
}

@media (max-width: 640px) {
  .profile-submit-row {
    grid-template-columns: 1fr;
  }

  .profile-submit-actions {
    justify-content: stretch;
  }

  .profile-submit-actions button {
    flex: 1 1 160px;
  }
}

/* --- canvas --- */
canvas {
  display: block;
  width: 100%;
  max-width: 1280px;
  background: var(--ui-bg);
  border: 2px solid var(--ui-border);
  outline: none;
}

/* --- leaderboard table --- */
.lb {
  overflow-x: hidden;
}

.lb table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
}

.lb td {
  padding: 3px 6px;
}

.lb tr + tr td {
  border-top: 1px dotted var(--ui-border);
}

.lb .rank {
  color: var(--ui-text-soft);
  width: 2em;
  text-align: right;
}

.lb .handle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb .elo {
  text-align: right;
  color: var(--ui-blue);
  font-weight: 700;
  width: 3.5em;
}

.lb .wl {
  text-align: right;
  color: var(--ui-text-subtle);
  width: 3.5em;
}

/* --- spectate 3-column layout: leaderboard | centered arena | live stats --- */
.spectate-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 240px;
  gap: 14px;
  align-items: start;
}

.spectate-center {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-width: 0;
}

.spectate-center canvas {
  max-width: 100%;
  display: block;
}

.spectate-side {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}

.live-briefing-card {
  align-content: center;
}

.live-briefing-sides {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.live-briefing-side {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 9px 12px;
  background: var(--ui-surface-code);
  border: 1px solid var(--ui-border);
  border-left-width: 3px;
}

.live-briefing-side.is-p1 {
  border-left-color: var(--ui-blue);
}

.live-briefing-side.is-p2 {
  border-left-color: var(--ui-purple);
}

.live-briefing-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  text-transform: uppercase;
}

.live-briefing-head span {
  color: var(--ui-text-subtle);
  letter-spacing: 0.12em;
}

.live-briefing-head strong {
  color: var(--ui-text);
  min-width: 0;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-briefing-side.is-p1 .live-briefing-head strong {
  color: var(--ui-blue);
}

.live-briefing-side.is-p2 .live-briefing-head strong {
  color: var(--ui-purple);
}

.live-briefing-binding,
.live-briefing-weapon {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-briefing-binding,
.live-briefing-weapon {
  color: var(--ui-text-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
}

.live-briefing-vs {
  align-self: center;
  color: var(--ui-red);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.spectate-stats .stat-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.spectate-stats .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 7px 2px;
  border-bottom: 1px dotted var(--ui-border);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}

.spectate-stats .stat-row:last-child {
  border-bottom: none;
}

.spectate-stats dt {
  color: var(--ui-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  font-weight: 600;
}

.spectate-stats dd {
  color: var(--ui-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  min-width: 0;
}

.spectate-stats .p1-accent { color: var(--ui-blue); font-weight: 700; }
.spectate-stats .p2-accent { color: var(--ui-purple); font-weight: 700; }

@media (max-width: 640px) {
  .context-card {
    height: var(--context-card-height-mobile);
    padding: 12px 14px;
  }

  .live-briefing-sides {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 8px;
  }

  .live-briefing-side {
    gap: 3px;
    padding: 7px 8px;
  }

  .live-briefing-vs {
    justify-self: stretch;
    text-align: center;
  }
}

@media (max-width: 1100px) {
  .spectate-grid {
    grid-template-columns: minmax(0, 1fr) 220px;
  }
  .spectate-center { grid-column: 1 / 2; }
  .spectate-stats { grid-column: 2 / 3; grid-row: 1 / 2; }
  .spectate-grid .lb { grid-column: 1 / -1; grid-row: 2 / 3; position: static; max-height: none; }
}

@media (max-width: 800px) {
  .spectate-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .spectate-center, .spectate-stats, .spectate-grid .lb {
    grid-column: 1 / -1;
  }
  .spectate-center { grid-row: 1 / 2; }
  .spectate-stats { grid-row: 2 / 3; }
  .spectate-grid .lb { grid-row: 3 / 4; }
  .spectate-side { position: static; max-height: none; }
}

/* --- footer --- */
#bottom {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 18px;
  background: var(--ui-bg-soft);
  border-top: 1px solid var(--ui-border);
  font-size: 11px;
  color: var(--ui-text-subtle);
}

.spacer {
  flex: 1;
}

/* --- error / toast --- */
.error {
  color: var(--ui-red);
  font-size: 11px;
  margin-top: 4px;
}

.ok {
  color: var(--ui-blue);
  font-size: 11px;
}

.is-ready {
  background: var(--ui-success-ink);
  border-color: var(--ui-success);
}

/* --- layout helpers --- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 14px;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Build page: 3 columns. Middle (game canvas) gets extra weight so
 * wider screens give the arena more room; side panels stay a fixed
 * max-height and scroll their contents internally so they don't grow
 * to match a tall canvas. On narrow screens the layout collapses.
 */
/* Symmetric P1 | canvas | P2. Side panels are static-width at every
 * viewport ≥ 1200px so P1 (blue) and P2 (purple) always read as a mirror
 * pair. The canvas (middle column) absorbs the rest of the width.
 */
.grid-3 {
  display: grid;
  grid-template-columns: 340px minmax(480px, 1fr) 340px;
  gap: 14px;
  align-items: stretch;
}

.build-page .grid-3 {
  flex: 1 1 auto;
  min-height: 0;
}

.grid-3 > .panel {
  min-height: 0;
  height: 100%;
}
/* Keep the three columns bounded by viewport height on desktop; each
 * panel scrolls its own overflow so the whole page doesn't scroll. */
@media (min-width: 1024px) {
  .build-page .grid-3 > .panel {
    height: calc(100svh - 202px);
    max-height: none;
    overflow-y: auto;
  }
}

/* Narrow desktop / tablet: canvas goes full-width on top, player panels
 * side-by-side and still symmetric below. */
@media (max-width: 1200px) {
  .grid-3 {
    grid-template-columns: 1fr 1fr;
  }
  .grid-3 > :nth-child(2) {
    grid-column: 1 / -1;
    order: -1;
  }
}

@media (max-width: 640px) {
  .grid-3 {
    grid-template-columns: 1fr;
  }
  .grid-3 > :nth-child(2) {
    order: 0;
  }
}

/* --- collapsible JSON export inside each player panel --- */
.json-fold {
  margin-top: 6px;
}
.json-fold > summary {
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ui-text-soft);
  padding: 4px 0;
  user-select: none;
  list-style: none;
}
.json-fold > summary::-webkit-details-marker { display: none; }
.json-fold > summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 120ms ease;
}
.json-fold[open] > summary::before {
  transform: rotate(90deg);
  margin-right: 2px;
}
.json-fold > summary:hover { color: var(--ui-text); }
.json-fold > .code-export { margin-top: 6px; }

/* --- match bar on build (stage + reset + test fight row) --- */
.match-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.funnel-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.funnel-strip span,
.intro-mechanic-strip span {
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-code);
  color: var(--ui-text-soft);
  padding: 4px 8px;
}

.funnel-strip span + span::before,
.intro-mechanic-strip span + span::before {
  content: "> ";
  color: var(--ui-text-subtle);
}

.funnel-strip .is-blue {
  color: var(--ui-blue);
  border-color: var(--ui-blue-ink);
}

.funnel-strip .is-purple {
  color: var(--ui-purple-bright);
  border-color: var(--ui-purple-ink);
}

.funnel-strip .is-red {
  color: var(--ui-red);
  border-color: rgba(239, 68, 68, 0.45);
}

.build-funnel {
  padding: 0 4px;
}

.build-install-note {
  color: var(--ui-text-subtle);
  margin-top: 2px;
}

/* Build page header row — title + stage selector + match controls all
 * on one horizontal line on desktop. Wraps to multiple lines on mobile.
 * Replaces the old separate .page-header + .match-bar stack. */
.page-header-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 0 4px;
}
.page-header-row .page-title-stack {
  margin-right: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.page-header-row .page-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ui-red);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.page-header-row .page-subtitle {
  color: var(--ui-text-subtle);
  font-size: 11px;
  letter-spacing: 0.04em;
  line-height: 1.35;
  max-width: 64ch;
  white-space: pre-line;
}
.page-header-row .inline-control {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.page-header-row #test-hud {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--ui-text-subtle);
}

@keyframes build-preview-pulse {
  from {
    box-shadow: 0 0 0 rgba(192, 132, 252, 0);
    filter: brightness(1);
  }
  to {
    box-shadow: 0 0 18px rgba(192, 132, 252, 0.45);
    filter: brightness(1.22);
  }
}

/* Panel-level fold: whole player config collapses to a single compact
 * row on mobile. Tap the summary to expand. On desktop the summary is
 * hidden and the panel stays expanded. */
.player-fold-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px 10px;
  user-select: none;
}
.player-fold-summary::-webkit-details-marker { display: none; }
.player-fold-summary .player-title {
  color: var(--slot-accent);
  font-size: 12px;
  letter-spacing: 0.1em;
  margin: 0;
}
.player-fold-summary .player-fold-badge {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--ui-text-soft);
  padding: 3px 8px;
  background: var(--ui-surface-code);
  border: 1px solid var(--ui-border);
  border-radius: 3px;
}
.player-fold-summary .player-fold-chevron {
  margin-left: auto;
  color: var(--slot-accent);
  font-size: 14px;
  transition: transform 120ms ease;
}
details.player-fold[open] > .player-fold-summary .player-fold-chevron {
  transform: rotate(90deg);
}
/* Desktop ≥900px: panel-fold summary hidden, content always shows. */
@media (min-width: 900px) {
  .player-fold-summary { display: none; }
}

/* Build body is now a <details> so mobile can collapse it. Show a
 * clean, accent-colored chevron summary; hide the native marker. */
.build-fold-summary {
  cursor: pointer;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--slot-accent, var(--ui-text-soft));
  padding: 6px 0;
  user-select: none;
  list-style: none;
  margin-bottom: 6px;
}
.build-fold-summary::-webkit-details-marker { display: none; }
.build-fold-summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 120ms ease;
}
details.player-build-body[open] > .build-fold-summary::before {
  transform: rotate(90deg);
  margin-right: 2px;
}

/* Desktop: summary hidden; body always shows. Mobile: summary visible
 * so users can toggle. */
@media (min-width: 900px) {
  .build-fold-summary { display: none; }
}

/* --- symmetric P1/P2 player panels on build --- */
.player-panel {
  border-top-width: 3px;
}
.player-panel.is-p1 {
  --slot-accent: var(--ui-blue);
  --slot-accent-ink: var(--ui-blue-ink);
  border-top-color: var(--ui-blue);
}
.player-panel.is-p2 {
  --slot-accent: var(--ui-purple);
  --slot-accent-ink: var(--ui-purple-ink);
  border-top-color: var(--ui-purple);
}
.player-panel .player-title {
  color: var(--slot-accent);
  font-size: 12px;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}
.canvas-panel {
  /* The middle column is also .panel. Keep it neutral and pin the arena
   * to the top-center while setupCanvas sizes it to the content width. */
  border-top-color: var(--ui-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  justify-content: center;
}

.canvas-panel .u-canvas-fill {
  flex: 0 1 auto;
  margin-inline: auto;
}

.build-preview-stats {
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  border-top: 1px solid var(--ui-border);
  padding-top: 9px;
}

.build-preview-copy {
  margin-bottom: 7px;
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
}

.build-preview-stats .stat-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}

.build-preview-stats .stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 6px 2px;
  border-bottom: 1px dotted var(--ui-border);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
}

.build-preview-stats dt {
  color: var(--ui-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 9px;
  font-weight: 700;
}

.build-preview-stats dd {
  color: var(--ui-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
  min-width: 0;
}

@media (max-width: 640px) {
  .build-preview-stats .stat-list {
    grid-template-columns: minmax(0, 1fr);
  }
}

.player-mode-row {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
.mode-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 6px 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  color: var(--ui-text-soft);
  cursor: pointer;
  user-select: none;
}
.mode-pill input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.mode-pill:hover { background: var(--ui-hover); }
.mode-pill.is-active {
  background: var(--slot-accent-ink, var(--ui-blue-ink));
  color: var(--ui-text);
  border-color: var(--slot-accent, var(--ui-blue));
}

.player-mode-detail {
  height: 132px;
  margin-bottom: 10px;
}

.player-mode-detail > [hidden] {
  display: none !important;
}

.player-mode-copy,
.player-human-hint {
  height: 132px;
  padding: 14px;
  background: var(--ui-surface-code);
  border: 1px dashed var(--slot-accent, var(--ui-border));
}

.mode-copy-title {
  color: var(--slot-accent, var(--ui-text));
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.35;
  margin-bottom: 8px;
}

.mode-copy-body {
  color: var(--ui-text-soft);
  font-size: 11px;
  line-height: 1.45;
}

.player-preset-row {
  height: 132px;
  padding: 14px;
  background: var(--ui-surface-code);
  border: 1px dashed var(--slot-accent, var(--ui-border));
}
.player-preset-row select {
  width: 100%;
  margin: 4px 0 8px;
}

.player-preset-row .player-mode-copy {
  min-height: 0;
  padding: 0;
  background: transparent;
  border: 0;
}

.player-human-hint {
  position: relative;
  overflow: hidden;
}
.player-human-quip {
  color: var(--slot-accent, var(--ui-text));
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  line-height: 1.55;
  margin-bottom: 10px;
  white-space: pre-line;
}
.player-human-keys {
  font-family: ui-monospace, Menlo, monospace;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.glitch-line {
  color: var(--ui-text-soft);
  white-space: pre-line;
}

.glitch-line b {
  color: var(--slot-accent);
  font-weight: 800;
}

/* PRESET mode: same layout as BUILD mode, sliders locked. Dims the
 * whole body and de-saturates the slider track fill so the lock state
 * reads clearly without changing the shape of the panel. */
.player-build-body.is-readonly {
  opacity: 0.85;
}
.player-build-body.is-readonly input[type="range"] {
  cursor: not-allowed;
  filter: saturate(0.7);
}
.player-build-body.is-human-noise {
  opacity: 0.92;
}
.player-build-body.is-human-noise input[type="range"] {
  filter: saturate(1.25) contrast(1.15);
}
.player-build-body.is-human-noise .knob-val {
  color: var(--ui-red);
  text-shadow: 1px 0 var(--slot-accent);
}
.player-build-body.is-human-noise .knob-val.is-pinned {
  color: var(--slot-accent);
  text-shadow: none;
}
.player-build-body.is-human-noise .knob-desc::after {
  content: " / signal disputed";
  color: var(--ui-red);
}
.player-build-body.is-readonly .toolbar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.player-panel .meter-bar:not(.over) {
  background: var(--slot-accent, var(--ui-blue));
}

/* Per-panel knob fill color: overrides the global --ui-blue used by
 * input[type=range] so each panel's sliders match its side color. */
.player-panel input[type="range"] {
  background:
    linear-gradient(
      to right,
      var(--slot-accent) 0%,
      var(--slot-accent) var(--fill),
      var(--ui-surface-code) var(--fill),
      var(--ui-surface-code) 100%
    );
}
.player-panel input[type="range"]::-webkit-slider-thumb {
  background: var(--slot-accent);
  border-color: var(--slot-accent-ink);
}
.player-panel input[type="range"]::-moz-range-thumb {
  background: var(--slot-accent);
  border-color: var(--slot-accent-ink);
}
.player-panel input[type="range"]::-moz-range-progress {
  background: var(--slot-accent);
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row-loose {
  gap: 12px;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tight {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--ui-text-soft);
}

.mt-xs {
  margin-top: 6px;
}

.mt-sm {
  margin-top: 8px;
}

.mb-xs {
  margin-bottom: 6px;
}

.mb-sm {
  margin-bottom: 8px;
}

.mb-md {
  margin-bottom: 10px;
}

.mb-lg {
  margin-bottom: 12px;
}

.u-fill {
  flex: 1;
}

.u-canvas-fill {
  width: 100%;
  max-width: 100%;
}

.live-test-controls {
  display: flex;
  align-items: end;
  gap: 8px;
  overflow-x: auto;
  flex-wrap: nowrap;
  padding-bottom: 2px;
}

.live-control {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 104px;
  padding: 4px 6px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-code);
}

.live-control span {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.live-control select {
  min-width: 0;
  max-width: 160px;
}

.live-control.role-build {
  border-color: var(--ui-success);
  box-shadow: inset 3px 0 0 var(--ui-success);
}

.live-control.role-preset {
  border-color: var(--ui-blue);
  box-shadow: inset 3px 0 0 var(--ui-blue);
}

.live-control.role-human {
  border-color: var(--ui-warning);
  box-shadow: inset 3px 0 0 var(--ui-warning);
}

.alpha-shell {
  max-width: 520px;
  margin: 12vh auto;
}

.toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.metric-row.loose {
  margin-bottom: 10px;
}

.metric-value {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 22px;
  font-weight: 700;
  color: var(--ui-success);
}

.metric-value.compact {
  font-size: 14px;
  color: var(--ui-text-soft);
}

.metric-value.is-full {
  color: var(--ui-warning);
}

.metric-value.is-over {
  color: var(--ui-red);
}

.meter-track {
  position: relative;
  height: 6px;
  background: var(--ui-surface-2);
  margin-bottom: 4px;
  overflow: visible;
}

.meter-bar {
  height: 100%;
  background: var(--ui-success);
  width: 0%;
  transition: width 0.15s;
}

.code-export {
  background: var(--ui-surface-code);
  border: 1px solid var(--ui-border);
  padding: 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10.5px;
  color: var(--ui-code-text);
  /* Let the JSON grow with its content. The outer Budget panel already
   * has max-height + overflow-y on wide viewports, so the pre doesn't
   * need its own scroll container. */
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.stream-log {
  max-height: 120px;
  overflow: auto;
}

.data-table {
  margin-top: 8px;
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  color: var(--ui-text-soft);
}

/* --- slider (builder) --- */
.knob {
  display: grid;
  grid-template-columns: minmax(90px, 120px) 1fr 48px;
  gap: 10px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px dotted var(--ui-border);
}

@media (max-width: 640px) {
  .knob {
    grid-template-columns: 1fr 48px;
  }
  .knob input[type="range"] {
    grid-column: 1 / -1;
  }
}

.knob:last-child {
  border-bottom: none;
}

.knob-name {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}

.knob-desc {
  font-size: 10px;
  color: var(--ui-text-subtle);
  display: block;
  margin-top: 2px;
}

.knob-val {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  color: var(--ui-blue);
  text-align: right;
  font-weight: 700;
}

/* Themed range input. Inactive track matches surface-code (dark),
 * filled portion is blue. Cross-browser approach: draw the track as a
 * linear-gradient on the input itself (Chrome/Safari don't expose a
 * ::progress pseudo), driven by a --fill custom property that JS sets
 * per slider based on its value.
 */
input[type="range"] {
  --fill: 0%;
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  padding: 0;
  margin: 0;
  border-radius: 3px;
  border: 1px solid var(--ui-border);
  background:
    linear-gradient(
      to right,
      var(--ui-blue) 0%,
      var(--ui-blue) var(--fill),
      var(--ui-surface-code) var(--fill),
      var(--ui-surface-code) 100%
    );
  cursor: pointer;
  outline: none;
}
input[type="range"]::-webkit-slider-runnable-track { height: 6px; background: transparent; border: none; }
input[type="range"]::-moz-range-track            { height: 6px; background: transparent; border: none; }
/* Firefox progress portion renders natively — keep it aligned. */
input[type="range"]::-moz-range-progress         { height: 6px; background: var(--ui-blue); border-radius: 3px; }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--ui-blue);
  border: 2px solid var(--ui-blue-ink);
  border-radius: 50%;
  margin-top: -5px;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--ui-blue);
  border: 2px solid var(--ui-blue-ink);
  border-radius: 50%;
  cursor: pointer;
}

/* --- match hud --- */
.match-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  flex-wrap: wrap;
  gap: 8px;
}

.match-hud .side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.match-hud .elo {
  color: var(--ui-purple);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}

.match-hud .name {
  font-weight: 700;
}

.match-hud .vs {
  color: var(--ui-text-subtle);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* --- rules --- */
.rules-page {
  width: 100%;
}

.rules-hero {
  align-items: flex-start;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.rules-card {
  border: 1px solid var(--ui-border);
  background: var(--ui-surface);
  padding: 16px;
}

.rules-card-feature {
  margin: 0;
}

.rules-about-copy {
  display: grid;
  align-content: start;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 0;
}

.rules-about-copy p {
  border-left: 1px solid var(--ui-border);
  color: var(--ui-text-soft);
  font-size: 13px;
  line-height: 1.5;
  padding-left: 12px;
}

.compute-witness-panel {
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border-top-color: var(--ui-purple);
}

.compute-witness-title {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.compute-witness-title h3 {
  color: var(--ui-purple);
}

.compute-witness-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compute-witness-controls,
.compute-witness-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.compute-witness-mode.is-active {
  background: var(--ui-purple-ink);
  border-color: var(--ui-purple);
  color: var(--ui-text);
}

@media (max-width: 760px) {
  .compute-witness-panel {
    grid-template-columns: 1fr;
  }
}

.rules-main-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.72fr) minmax(420px, 1.28fr);
  gap: 14px;
  align-items: start;
}

.rules-rules-column {
  display: grid;
  gap: 10px;
  min-width: 0;
}

@media (max-width: 900px) {
  .rules-main-layout {
    grid-template-columns: 1fr;
  }
}

.rules-card h2 {
  color: var(--ui-purple);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.rules-card p {
  color: var(--ui-text-soft);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.rules-card p:last-child {
  margin-bottom: 0;
}

.rules-section-label {
  margin: 0;
  color: var(--ui-red);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.rules-card ul {
  display: flex;
  flex-direction: column;
  gap: 9px;
  list-style: none;
}

.rules-card li {
  color: var(--ui-text-soft);
  font-size: 14px;
  line-height: 1.45;
}

.rules-card li::before {
  content: ">";
  color: var(--ui-red);
  margin-right: 8px;
}

/* --- intro crawl · late-80s/early-90s CRT terminal --- */
.intro-crt {
  position: relative;
  width: 100%;
  height: calc(100dvh - 120px);
  min-height: min(360px, calc(100dvh - 80px));
  background: #030504;
  color: #9cff7a;
  font-family: "VT323", "IBM Plex Mono", ui-monospace, Menlo, monospace;
  overflow: hidden;
  isolation: isolate;
  user-select: none;
  display: flex;
  flex-direction: column;
}

.intro-crt::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(70, 255, 140, 0.08) 0%, rgba(10, 16, 10, 0.0) 60%);
  pointer-events: none;
  z-index: 1;
}

.intro-scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.0) 0px,
    rgba(0, 0, 0, 0.0) 2px,
    rgba(0, 0, 0, 0.35) 3px,
    rgba(0, 0, 0, 0.35) 4px
  );
  mix-blend-mode: multiply;
  animation: intro-flicker 4.2s steps(12) infinite;
}

.intro-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.85) 100%);
}

.intro-fork {
  position: relative;
  z-index: 4;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 38px 8vw 18px;
  flex: 0 0 auto;
  text-shadow:
    0 0 4px rgba(156, 255, 122, 0.55),
    0 0 18px rgba(80, 255, 120, 0.22);
}

.intro-fork-kicker {
  color: #57ffa0;
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.intro-fork h1 {
  color: #c8ffd2;
  font-size: 34px;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.intro-fork-lines {
  display: grid;
  gap: 4px;
  color: #a9ff90;
  font-size: 20px;
  line-height: 1.35;
  margin-bottom: 16px;
}

.intro-mechanic-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.intro-mechanic-strip span {
  border: none;
  background: transparent;
  padding: 0;
}

.intro-mechanic-strip span:nth-child(1) {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.5);
}

.intro-mechanic-strip span:nth-child(2) {
  color: #57ffa0;
  border-color: rgba(87, 255, 160, 0.45);
}

.intro-mechanic-strip span:nth-child(3),
.intro-mechanic-strip span:nth-child(4) {
  color: #c58bff;
  border-color: rgba(197, 139, 255, 0.48);
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.intro-actions .buttonish {
  text-shadow: none;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.intro-crawl {
  position: relative;
  z-index: 2;
  width: 100%;
  padding: 18px 8vw 76px;
  max-width: 920px;
  margin: 0 auto;
  font-size: 22px;
  line-height: 1.55;
  letter-spacing: 0.02em;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  text-shadow:
    0 0 4px rgba(156, 255, 122, 0.55),
    0 0 18px rgba(80, 255, 120, 0.22);
}

.intro-block {
  margin-bottom: 28px;
  white-space: pre-wrap;
  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;
}

.intro-header {
  color: #57ffa0;
  font-size: 16px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 10px;
}

.intro-tagline {
  color: #c8ffd2;
  font-size: 26px;
  margin-bottom: 44px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.intro-paragraph {
  color: #a9ff90;
}

.intro-stinger {
  margin-top: 54px;
  color: #e0ffe4;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.5;
}

.intro-stinger-line {
  margin-bottom: 10px;
}

.intro-stinger-line:nth-child(1) { color: #e0ffe4; }
.intro-stinger-line:nth-child(2) { color: #ff6b6b; }
.intro-stinger-line:nth-child(3) { color: #c58bff; }

.intro-tail {
  margin-top: 40px;
  color: #57ffa0;
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.7;
}

.intro-block:not(.intro-stinger):last-child::after,
.intro-stinger:last-child .intro-stinger-line:last-child::after {
  content: "▊";
  display: inline-block;
  margin-left: 4px;
  animation: intro-cursor 1s steps(2) infinite;
  color: inherit;
}

.intro-hint {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 4;
  font-size: 13px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(156, 255, 122, 0.45);
  pointer-events: none;
}

.intro-hint.is-final {
  color: #e0ffe4;
  animation: intro-cursor 0.8s steps(2) infinite;
  cursor: pointer;
  pointer-events: auto;
}

@keyframes intro-cursor {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes intro-flicker {
  0%, 100% { opacity: 0.9; }
  3% { opacity: 0.7; }
  6% { opacity: 0.95; }
  48% { opacity: 0.88; }
  52% { opacity: 0.72; }
  88% { opacity: 0.92; }
}

@media (max-width: 640px) {
  .intro-fork {
    padding: 32px 6vw 14px;
  }
  .intro-fork h1 {
    font-size: 26px;
  }
  .intro-fork-lines {
    font-size: 17px;
  }
  .intro-crawl {
    padding: 24px 6vw 76px;
    font-size: 17px;
    line-height: 1.55;
  }
  .intro-tagline { font-size: 20px; }
  .intro-stinger { font-size: 22px; }
}
