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

[hidden] {
  display: none !important;
}

/* 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;
  --meter-track-bg-warn: color-mix(in srgb, var(--ui-red) 18%, black);

  /* 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);
}

/* --- account control (top-right profile dot or sign-in pill) --- */
.account {
  margin-left: auto;
  position: relative;
  font-size: 12px;
}

.account .account-signin {
  color: var(--ui-blue);
  text-transform: lowercase;
  letter-spacing: 0.04em;
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--ui-bg-soft);
  font: inherit;
  cursor: pointer;
}

.account-trigger {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--ui-border);
  background: linear-gradient(160deg, rgba(239, 68, 68, 0.18), rgba(56, 189, 248, 0.12));
  color: var(--ui-text);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.account-trigger:hover {
  border-color: var(--ui-red);
}

.account-initial {
  line-height: 1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  padding: 6px 0;
  background: var(--ui-bg-soft);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.42);
  z-index: 90;
  display: flex;
  flex-direction: column;
}

.account-menu-handle {
  padding: 6px 14px 8px;
  color: var(--ui-text);
  font-weight: 600;
  border-bottom: 1px solid var(--ui-border);
  margin-bottom: 4px;
  word-break: break-all;
}

.account-menu-item {
  display: block;
  padding: 8px 14px;
  text-align: left;
  background: none;
  border: 0;
  color: var(--ui-text);
  font: inherit;
  cursor: pointer;
}

.account-menu-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--ui-red);
}

/* --- 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;
    /* auto-fit so the bar doesn't silently squash if another tab appears.
     * Items can shrink to 64px floor; beyond that, items marked
     * data-nav="overflow" should be hidden (rule below) and a "more"
     * trigger surfaced. */
    grid-template-columns: repeat(auto-fit, minmax(64px, 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[data-nav="overflow"] {
    display: none !important;
  }

  #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;
  }

  .account {
    margin-left: auto;
    min-width: 0;
    max-width: 46vw;
    text-align: right;
    font-size: 11px;
  }

  .account-menu {
    /* Anchor the popover to the right edge of the viewport on phones so
     * narrow trigger placement doesn't push the menu off-screen. */
    right: 8px;
    left: auto;
    min-width: 220px;
  }

  #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--auto {
  height: auto;
  overflow: visible;
}

.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,
.ui-button {
  background: var(--ui-surface-2);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  border-radius: 0;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
}

a.buttonish,
.ui-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

a.buttonish {
  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,
.ui-button:hover {
  background: var(--ui-hover);
  color: var(--ui-text);
}

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

a.buttonish.primary:hover,
.ui-button.is-primary:hover,
.ui-button.is-primary:focus-visible {
  background: var(--ui-blue);
}

a.buttonish.danger,
.ui-button.is-danger {
  color: var(--ui-red);
  border-color: var(--ui-red);
}

a.buttonish.danger:hover,
a.buttonish.danger:focus-visible,
.ui-button.is-danger:hover,
.ui-button.is-danger: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);
}

button,
.ui-button {
  cursor: pointer;
}

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

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

button.primary:hover,
.ui-button.is-primary:hover,
.ui-button.is-primary:focus-visible {
  background: var(--ui-blue);
}

button.is-simulating,
button.is-simulating:disabled,
.ui-button.is-busy,
.ui-button.is-busy: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,
.ui-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,
.ui-button.is-danger {
  border-color: var(--ui-red);
  color: var(--ui-red);
}

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

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

/* --- profile roster: 4 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(4, 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-main {
  min-width: 0;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.seat-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.seat-portrait {
  width: 54px;
  aspect-ratio: 1;
  align-self: start;
  background-color: rgba(59, 130, 246, 0.08);
  background-repeat: no-repeat;
  background-size: 200% 200%;
  background-position: 100% 100%;
  border: 1px solid rgba(59, 130, 246, 0.28);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  image-rendering: pixelated;
}

.seat-portrait.is-empty {
  opacity: 0.35;
  filter: grayscale(1);
}

.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-locked .seat-state-dot {
  background: var(--ui-red);
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.35);
}

.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-cosmetics {
  min-height: 15px;
  color: var(--ui-text-soft);
  font-size: 10px;
  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-last.is-cooldown {
  color: var(--ui-red);
}

.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(150px, 220px) minmax(130px, 160px) minmax(300px, 1fr) minmax(130px, 180px) max-content;
  gap: 10px;
  align-items: end;
}

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

.field-label {
  color: var(--ui-text-soft);
}

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

.weapon-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 6px;
}

.weapon-option {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  text-align: left;
  text-transform: none;
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.34);
  color: #bcd7ff;
  text-shadow: 0 0 8px rgba(59, 130, 246, 0.14);
}

.weapon-option:hover,
.weapon-option:focus-visible {
  background: rgba(59, 130, 246, 0.18);
  border-color: var(--ui-blue);
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.22);
  outline: none;
}

.weapon-option.is-selected {
  background: rgba(59, 130, 246, 0.24);
  border-color: var(--ui-blue);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.34);
}

.weapon-option.is-locked,
.weapon-option.is-locked:disabled {
  opacity: 1;
  color: var(--ui-text-soft);
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.34);
  cursor: not-allowed;
  text-shadow: 0 0 8px rgba(239, 68, 68, 0.12);
}

.weapon-option.is-locked:hover,
.weapon-option.is-locked:focus-visible {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.42);
  box-shadow: none;
}

.weapon-option-visual {
  position: relative;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
}

.weapon-option-sprite {
  position: absolute;
  inset: 2px;
  border-radius: 4px;
  border: 1px solid rgba(59, 130, 246, 0.28);
  background-color: rgba(15, 23, 42, 0.85);
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  image-rendering: pixelated;
}

.weapon-option-sprite.is-locked {
  filter: grayscale(1) brightness(0.82);
}

.weapon-option-sprite.is-missing {
  background-image:
    linear-gradient(135deg,
      transparent 0 44%,
      rgba(239, 68, 68, 0.7) 44% 56%,
      transparent 56% 100%);
}

.weapon-option-status {
  position: absolute;
  right: -2px;
  bottom: -2px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.35);
}

.weapon-lock-glyph {
  width: 12px;
  height: 12px;
  image-rendering: pixelated;
}

.weapon-unlocked-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--ui-blue);
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.38);
}

.weapon-option-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.weapon-option-name,
.weapon-option-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weapon-option-name {
  color: var(--ui-text);
  font-size: 11px;
  line-height: 1.1;
}

.weapon-option-meta {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
  line-height: 1.1;
}

.weapon-unlock-hint {
  min-height: 32px;
  display: flex;
  align-items: center;
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  line-height: 1.25;
}

.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-slider-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px;
}

button.primary.is-dirty,
.ui-button.is-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;
}

.leaderboard-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.leaderboard-head h3 {
  margin: 0 0 10px;
}

.leaderboard-count {
  color: var(--ui-text-subtle);
  font: 700 10px ui-monospace, Menlo, monospace;
}

.leaderboard-scroll {
  max-height: 220px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.leaderboard-scroll:focus-visible {
  outline: 1px solid var(--ui-blue);
  outline-offset: 3px;
}

.leaderboard-more {
  display: block;
  margin: 8px 0 0 auto;
}

.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;
}

.live-bots-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--ui-border);
}

.live-bots-head h3 {
  margin: 0;
}

.live-bots-more {
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--ui-bg-soft);
  color: var(--ui-text-soft);
  font: 700 10px ui-monospace, Menlo, monospace;
  text-transform: uppercase;
  cursor: pointer;
}

.live-bots-more:hover:not(:disabled) {
  color: var(--ui-text);
  border-color: var(--ui-blue);
}

.live-bots-more:disabled {
  opacity: 0.48;
  cursor: default;
}

.live-bots-list,
.live-bot-events {
  display: grid;
  gap: 6px;
  color: var(--ui-text-soft);
  font-size: 11px;
}

.live-bot-row,
.live-bot-event {
  min-width: 0;
  border: 1px solid rgba(58, 58, 90, 0.72);
  border-radius: 6px;
  background: rgba(17, 17, 26, 0.72);
}

.live-bot-row {
  display: grid;
  gap: 5px;
  padding: 7px 8px;
}

.live-bot-main,
.live-bot-meta {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.live-bot-main strong,
.live-bot-main span,
.live-bot-event strong,
.live-bot-event span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-bot-main strong,
.live-bot-event strong {
  color: var(--ui-text);
}

.live-bot-main span,
.live-bot-event span {
  color: var(--ui-text-subtle);
}

.live-bot-meta {
  color: var(--ui-blue);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
}

.spectate-feed-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 14px;
}

.live-bot-event {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) minmax(0, 0.8fr) auto;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  font-family: ui-monospace, Menlo, monospace;
}

.live-bot-event-type {
  color: var(--ui-purple-bright) !important;
  text-transform: uppercase;
  font-size: 9px;
}

.live-bot-event time {
  color: var(--ui-text-subtle);
  white-space: nowrap;
}

/* --- 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 stage with compute-dash PIP cycle ----- */

.spectate-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-width: 1280px;
  background: #000;
  overflow: hidden;
  border-radius: 6px;
}
.spectate-stage-canvas-wrap,
.spectate-stage-dash-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  transition: top 0.18s ease, left 0.18s ease, width 0.18s ease, height 0.18s ease, opacity 0.18s ease;
}
.spectate-stage-canvas-wrap > canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* State 1: battle only. Dash is hidden (also unmounted via JS). */
.spectate-stage[data-dash-state="1"] .spectate-stage-dash-wrap { display: none; }

/* State 2: compute only. Canvas suppressed via opacity + pointer-events,
   but kept in the DOM so the WS / renderer keep ticking. */
.spectate-stage[data-dash-state="2"] .spectate-stage-canvas-wrap {
  opacity: 0;
  pointer-events: none;
}
.spectate-stage[data-dash-state="2"] .spectate-stage-dash-wrap {
  inset: 0;
  z-index: 2;
}

/* State 3: battle primary, compute PIP bottom-right. Dash shrinks into a
   16:9 corner card — clamped so narrow stages never have a PIP wider
   than their stage minus margins. */
.spectate-stage[data-dash-state="3"] .spectate-stage-dash-wrap {
  top: auto; left: auto;
  right: 12px; bottom: 12px;
  width: min(320px, calc(100% - 24px));
  aspect-ratio: 16 / 9;
  height: auto;
  z-index: 3;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}

/* State 4: compute primary, battle PIP bottom-right. Canvas shrinks via
   the wrap's dimensions; the canvas element scales to 100% of the wrap. */
.spectate-stage[data-dash-state="4"] .spectate-stage-dash-wrap {
  inset: 0;
  z-index: 2;
}
.spectate-stage[data-dash-state="4"] .spectate-stage-canvas-wrap {
  top: auto; left: auto;
  right: 12px; bottom: 12px;
  width: min(320px, calc(100% - 24px));
  aspect-ratio: 16 / 9;
  height: auto;
  z-index: 3;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  border-radius: 6px;
  overflow: hidden;
  pointer-events: none;
}

.spectate-stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.spectate-stats-head h3 {
  margin: 0;
}
.spectate-dash-cycle {
  background: rgba(14, 18, 26, 0.78);
  color: var(--ui-text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 4px 10px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  line-height: 1;
  flex: 0 0 auto;
}
.spectate-dash-cycle:hover { background: rgba(24, 30, 42, 0.92); }
.spectate-dash-cycle .spectate-dash-cycle-label { opacity: 0.7; }
.spectate-dash-cycle .spectate-dash-cycle-state {
  font-weight: 700;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 1px 7px;
}

/* ----- compute dash inner layouts ----- */

.compute-dash {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ui-bg, #0e121a);
  color: var(--ui-text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}
.compute-dash-frame {
  width: 100%;
  height: 100%;
  display: grid;
  overflow: hidden;
}

/* Full: 720 mosaic / 280 status / 280 feed */
.compute-dash-full {
  grid-template-columns: 720fr 280fr 280fr;
  gap: 0;
}
.compute-dash-mosaic-col,
.compute-dash-status-col,
.compute-dash-feed-col {
  overflow: hidden;
  padding: 12px;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.compute-dash-feed-col { border-right: none; }

/* PIP: one status line + mini mosaic + side column */
.compute-dash-pip {
  grid-template-rows: 26px 1fr;
  gap: 0;
  font-size: 11px;
}
.compute-dash-pip-top {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.compute-dash-pip-body {
  display: grid;
  grid-template-columns: 160fr 160fr;
  min-height: 0;
}
.compute-dash-pip-mosaic {
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.compute-dash-pip-side {
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  gap: 6px;
}
.compute-dash-pip-event { overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
.compute-dash-pip-meta { opacity: 0.7; }

.compute-dash-block {
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 4px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.02);
}
.compute-dash-title {
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.78;
  margin-bottom: 6px;
}
.compute-dash-kv {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  font-size: 12px;
}
.compute-dash-kv dt { opacity: 0.65; }
.compute-dash-kv dd { margin: 0; }

.compute-dash-progress {
  position: relative;
  height: 14px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}
.compute-dash-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, #22c55e, #84cc16);
  transition: width 0.2s ease;
}
.compute-dash-progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 700;
}

.compute-dash-quorum {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
}
.compute-dash-quorum th,
.compute-dash-quorum td { padding: 2px 6px; text-align: left; }
.compute-dash-quorum tr.ok td:nth-child(2) { color: #4ade80; }
.compute-dash-quorum tr.warn td:nth-child(2) { color: #facc15; }
.compute-dash-quorum tr.err td:nth-child(2) { color: #f87171; }

.compute-dash-certificate {
  border-color: rgba(132, 204, 22, 0.35);
  background: rgba(132, 204, 22, 0.08);
}
.compute-dash-verifier-link {
  display: inline-block;
  margin-top: 6px;
  color: #a3e635;
  text-decoration: underline dashed;
}

.compute-dash-feed { list-style: none; margin: 0; padding: 0; }
.compute-dash-feed-item { padding: 2px 0; opacity: 0.88; }
.compute-dash-feed-item.emph { opacity: 1; font-weight: 600; }
.compute-dash-feed-item code {
  opacity: 0.6;
  margin-right: 6px;
}

.compute-dash-mosaic {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 8), 1fr);
  grid-template-rows: repeat(var(--grid-rows, 8), 1fr);
  gap: 2px;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
  overflow: hidden;
}
.compute-dash-cell-preview {
  padding: 0;
  overflow: hidden;
  background: #000;
}
.compute-dash-cell-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  display: block;
}
.compute-dash-mosaic-compact {
  aspect-ratio: 1 / 1;
  max-width: 150px;
  max-height: 150px;
  gap: 1px;
}
.compute-dash-mosaic-empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
  min-height: 100px;
}
.compute-dash-cell {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
  min-width: 0;
  min-height: 0;
}
.compute-dash-cell-accepted { background: linear-gradient(135deg, #3b82f6, #22c55e); }
.compute-dash-cell-pending  { background: rgba(250, 204, 21, 0.25); }
.compute-dash-cell-rejected { background: rgba(248, 113, 113, 0.45); }

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

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

.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;
  min-width: 0;
  justify-items: start;
  padding: 10px 14px;
  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-binding {
  min-width: 0;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
  justify-self: start;
  gap: 8px;
  min-height: 50px;
  width: fit-content;
  max-width: 100%;
}

.live-briefing-copy {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 2px;
  flex: 0 1 auto;
  max-width: min(100%, 24ch);
}

.live-briefing-identity {
  display: block;
  min-width: 0;
  color: var(--ui-text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0;
  text-transform: none;
}

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

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

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

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

.live-briefing-portrait,
.live-briefing-weapon-tile {
  display: block;
  flex: 0 0 auto;
  background-repeat: no-repeat;
  background-color: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.28);
  image-rendering: pixelated;
}

.live-briefing-portrait {
  width: 50px;
  height: 50px;
  border-radius: 4px;
}

.live-briefing-weapon-tile {
  width: 50px;
  height: 50px;
  border-radius: 3px;
}

.live-briefing-portrait.is-missing,
.live-briefing-weapon-tile.is-missing {
  background-image:
    linear-gradient(135deg,
      transparent 0 44%,
      rgba(239, 68, 68, 0.7) 44% 56%,
      transparent 56% 100%);
}

.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;
  }

  .context-card--auto {
    height: auto;
  }

  .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-binding {
    gap: 6px;
    min-height: 40px;
  }

  .live-briefing-copy {
    max-width: min(100%, 22ch);
  }

  .live-briefing-portrait {
    width: 40px;
    height: 40px;
  }

  .live-briefing-weapon-tile {
    width: 40px;
    height: 40px;
  }

  .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-feed-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .live-bot-event {
    grid-template-columns: 68px minmax(0, 1fr);
  }
  .live-bot-event time {
    grid-column: 2 / 3;
  }
  .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: row;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 10px;
}
.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;
}

@media (max-width: 640px) {
  .page-header-row .page-title-stack {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
}
.page-header-row .inline-control {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.stage-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.page-header-row .stage-picker {
  max-width: min(100%, 470px);
}
.stage-picker-label {
  color: var(--ui-text-subtle);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.stage-option {
  width: 128px;
  height: 46px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  padding: 5px 7px 5px 5px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-surface);
  color: var(--ui-text-soft);
  cursor: pointer;
  text-align: left;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease, transform 120ms ease;
}
.stage-option:hover,
.stage-option:focus-visible {
  border-color: var(--ui-purple-ink);
  color: var(--ui-text);
  outline: none;
}
.stage-option.is-selected {
  border-color: var(--ui-blue);
  color: var(--ui-text);
  background: var(--ui-surface-code);
}
.stage-option:disabled {
  cursor: wait;
  opacity: 0.68;
}
.stage-option-thumb {
  position: relative;
  width: 52px;
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--ui-border);
  border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, rgba(125, 211, 252, 0.25) 0 2px, transparent 2px 8px),
    linear-gradient(180deg, #111827 0%, #070b12 100%);
}
.stage-option.has-thumb .stage-option-thumb {
  background-image: var(--stage-thumb);
  background-position: center;
  background-size: cover;
}
.stage-option.no-thumb .stage-option-thumb::after {
  content: "DC";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--ui-blue);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.stage-option-label {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.1;
  text-transform: uppercase;
}
@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: 8px;
  align-items: center;
  justify-content: flex-start;
  padding: 0 12px 12px;
}

.canvas-panel .u-canvas-fill {
  flex: 0 1 auto;
  display: block;
  margin-inline: auto;
  max-width: 100%;
}

.build-preview-topbar {
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
  display: grid;
  gap: 6px;
}

.build-context-card .build-preview-topbar {
  max-width: none;
  margin-inline: 0;
}

.build-preview-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.build-preview-controls .stage-picker {
  flex: 1 1 320px;
}

.build-preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}

.build-preview-briefing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: var(--ui-surface-code);
}

.build-preview-side {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.build-preview-side.is-p2 {
  text-align: right;
}

.build-preview-side-label,
.build-preview-meta {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
}

.build-preview-side-label {
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.build-preview-side-name,
.build-preview-result,
.build-preview-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.build-preview-side-name {
  color: var(--ui-text);
  font-size: 11px;
}

.build-preview-side.is-p1 .build-preview-side-name {
  color: var(--ui-blue);
}

.build-preview-side.is-p2 .build-preview-side-name {
  color: var(--ui-purple);
}

.build-preview-center {
  min-width: 0;
  display: grid;
  gap: 2px;
  text-align: center;
}

.build-preview-result {
  color: var(--ui-text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
}

.build-preview-side.is-winner .build-preview-side-name,
.build-preview-side.is-winner .build-preview-side-label {
  color: var(--ui-text);
}

.build-preview-side.is-p1.is-winner {
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.build-preview-side.is-p2.is-winner {
  text-shadow: 0 0 10px rgba(168, 85, 247, 0.2);
}

.build-preview-side.is-loser {
  opacity: 0.72;
}

.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-controls {
    align-items: stretch;
  }

  .build-preview-controls .stage-picker,
  .build-preview-actions {
    flex: 1 1 100%;
  }

  .build-preview-actions {
    margin-left: 0;
  }

  .build-preview-briefing {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }

  .build-preview-side.is-p2,
  .build-preview-center {
    text-align: left;
  }

  .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;
}

body.alpha-locked > #topnav,
body.alpha-locked > #app,
body.alpha-locked > #bottom {
  display: none !important;
}

#alpha-overlay {
  position: fixed;
  inset: 0;
  background: var(--ui-bg);
  z-index: 9999;
  overflow: 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;
}

.meter-track--hallucination {
  background: var(--meter-track-bg-warn);
}

.slot-hall-val {
  color: var(--ui-red);
}

.slot-hall-bar {
  background: var(--ui-red);
}

.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;
  gap: 10px;
  margin: 0;
  max-width: 980px;
}

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

.rules-related {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 980px;
  border: 1px solid var(--ui-border);
  background: color-mix(in srgb, var(--ui-surface) 86%, var(--ui-purple) 14%);
  padding: 14px 16px;
}

.rules-related-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.rules-related-copy span {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  text-transform: uppercase;
}

.rules-related-copy strong {
  color: var(--ui-text);
  font-size: 15px;
}

.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-score-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(120px, auto) minmax(320px, 1.2fr);
  align-items: center;
  gap: 14px;
  border-top-color: var(--ui-blue);
}

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

.compute-score-title h3 {
  color: var(--ui-blue);
}

.compute-score-title span {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  text-transform: uppercase;
}

.compute-score-value {
  color: var(--ui-text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 34px;
  line-height: 1;
  text-align: right;
  text-shadow: 0 0 16px rgba(59, 130, 246, 0.3);
}

.compute-score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px;
}

.compute-score-grid div {
  min-width: 0;
  border: 1px solid var(--ui-border);
  background: rgba(59, 130, 246, 0.07);
  padding: 8px;
}

.compute-score-grid span,
.compute-score-grid strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compute-score-grid span {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
  text-transform: uppercase;
}

.compute-score-grid strong {
  color: var(--ui-blue);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 15px;
  line-height: 1.35;
}

.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-score-panel {
    grid-template-columns: 1fr;
  }

  .compute-score-value {
    text-align: left;
  }

  .compute-score-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .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: min(888px, calc(100% - 32px));
  max-width: none;
  margin: 0 auto;
  padding: 38px clamp(20px, 4vw, 56px) 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: #ff6b6b;
  font-size: 34px;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.intro-fork-lines {
  display: flex;
  flex-flow: row nowrap;
  gap: 8px;
  margin-bottom: 0;
}

.intro-line-cta {
  flex: 0 1 190px;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid currentColor;
  border-radius: 0;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  transition: background 0.14s, color 0.14s, box-shadow 0.14s, transform 0.08s;
}

.intro-line-cta.is-blue {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.2);
  text-shadow: 0 0 8px rgba(96, 165, 250, 0.18);
}

.intro-line-cta.is-red {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.2);
  text-shadow: 0 0 8px rgba(255, 107, 107, 0.18);
}

.intro-line-cta.is-purple {
  color: #c58bff;
  background: rgba(197, 139, 255, 0.2);
  text-shadow: 0 0 8px rgba(197, 139, 255, 0.18);
}

.intro-line-cta:hover,
.intro-line-cta:focus-visible {
  color: var(--ui-bg);
  outline: none;
  transform: translateY(-1px);
}

.intro-line-cta.is-blue:hover,
.intro-line-cta.is-blue:focus-visible {
  background: #60a5fa;
  box-shadow: 0 0 18px rgba(96, 165, 250, 0.32);
}

.intro-line-cta.is-red:hover,
.intro-line-cta.is-red:focus-visible {
  background: #ff6b6b;
  box-shadow: 0 0 18px rgba(255, 107, 107, 0.32);
}

.intro-line-cta.is-purple:hover,
.intro-line-cta.is-purple:focus-visible {
  background: #c58bff;
  box-shadow: 0 0 18px rgba(197, 139, 255, 0.32);
}

.intro-line-cta:active {
  transform: translateY(1px);
}

.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-crawl {
  position: relative;
  z-index: 2;
  width: min(888px, calc(100% - 32px));
  padding: 18px clamp(20px, 4vw, 56px) 76px;
  max-width: none;
  margin: 0 auto;
  font-size: 15px;
  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-boot {
  color: #a9ff90;
}

.intro-thinking {
  min-height: 1.55em;
  margin: -10px 0 28px;
  color: rgba(224, 255, 228, 0.72);
  font-size: 0.86em;
  letter-spacing: 0.04em;
}

.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 {
    width: min(888px, calc(100% - 20px));
    padding: 32px clamp(14px, 4vw, 22px) 14px;
  }
  .intro-fork h1 {
    font-size: 18px;
  }
  .intro-fork-lines {
    flex-direction: column;
    align-items: center;
  }
  .intro-line-cta {
    flex: 0 0 auto;
    width: min(100%, 320px);
    font-size: 17px;
  }
  .intro-crawl {
    width: min(888px, calc(100% - 20px));
    padding: 24px clamp(14px, 4vw, 22px) 76px;
    font-size: 12px;
    line-height: 1.55;
  }
  .intro-tagline { font-size: 20px; }
  .intro-stinger { font-size: 22px; }
}

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

.compute-intro-card {
  margin: 0;
}

.compute-opt-panel,
.compute-public-panel,
.compute-workloads-panel,
.compute-contact-map-panel,
.compute-my-work-panel {
  display: grid;
  gap: 12px;
}

.compute-opt-panel[hidden] {
  display: none;
}

.compute-opt-head,
.compute-public-head,
.compute-workloads-head,
.compute-contact-map-head,
.compute-my-work-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.compute-opt-title,
.compute-contact-map-title {
  display: grid;
  gap: 4px;
}

.compute-opt-title h3 {
  color: var(--ui-blue);
  margin-bottom: 0;
}

.compute-opt-actions,
.compute-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

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

.compute-mode-block {
  display: grid;
  gap: 8px;
}

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

.compute-policy-grid,
.compute-local-grid,
.compute-public-grid,
.compute-workloads-list {
  display: grid;
  gap: 8px;
}

.compute-policy-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.compute-policy-item {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  padding: 10px 12px;
  cursor: pointer;
}

.compute-policy-item .ui-toggle-label {
  color: var(--ui-text-soft);
  font-size: 13px;
  line-height: 1.35;
}

.ui-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.ui-toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.ui-toggle-track {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.18);
  border: 1px solid var(--ui-border);
  transition: background 120ms ease, border-color 120ms ease;
}

.ui-toggle-thumb {
  position: absolute;
  top: 1px;
  left: 1px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ui-text-soft);
  transition: transform 120ms ease, background 120ms ease;
}

.ui-toggle-input:checked + .ui-toggle-track {
  background: color-mix(in srgb, var(--ui-blue) 40%, transparent);
  border-color: var(--ui-blue);
}

.ui-toggle-input:checked + .ui-toggle-track .ui-toggle-thumb {
  transform: translateX(16px);
  background: var(--ui-blue);
}

.ui-toggle-input:focus-visible + .ui-toggle-track {
  outline: 2px solid var(--ui-blue);
  outline-offset: 2px;
}

.ui-toggle-input:disabled + .ui-toggle-track {
  opacity: 0.5;
  cursor: not-allowed;
}

.ui-toggle-label {
  font-size: 13px;
  line-height: 1.35;
  color: var(--ui-text-soft);
}

.ui-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: rgba(148, 163, 184, 0.08);
  color: var(--ui-text-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.4;
}

.ui-chip.is-family-m3t4 {
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--ui-red);
  background: rgba(239, 68, 68, 0.08);
}

.ui-chip.is-family-science {
  border-color: rgba(34, 197, 94, 0.5);
  color: #4ade80;
  background: rgba(34, 197, 94, 0.08);
}

.ui-chip.is-family-ml {
  border-color: rgba(168, 85, 247, 0.5);
  color: #c4b5fd;
  background: rgba(168, 85, 247, 0.08);
}

.ui-chip.is-family-plasma {
  border-color: rgba(59, 130, 246, 0.5);
  color: var(--ui-blue);
  background: rgba(59, 130, 246, 0.08);
}

.ui-chip.is-family-device-witness {
  border-color: rgba(245, 158, 11, 0.5);
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.08);
}

.ui-chip.is-family-infra {
  border-color: rgba(100, 116, 139, 0.5);
  color: #94a3b8;
  background: rgba(100, 116, 139, 0.08);
}

.ui-chip.is-runtime-webgpu {
  border-color: rgba(236, 72, 153, 0.5);
  color: #f472b6;
  background: rgba(236, 72, 153, 0.08);
}

.ui-chip.is-runtime-webrtc {
  border-color: rgba(14, 165, 233, 0.5);
  color: #38bdf8;
  background: rgba(14, 165, 233, 0.08);
}

.compute-workload-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ui-chip.is-runtime-cpu {
  border-color: rgba(100, 116, 139, 0.45);
  color: #cbd5e1;
  background: rgba(100, 116, 139, 0.08);
}

.compute-flow-panel {
  display: grid;
  gap: 12px;
}

.compute-flow-steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
}

.compute-flow-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  padding: 10px 12px;
}

.compute-flow-step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.18);
  color: var(--ui-blue);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  flex: 0 0 auto;
}

.compute-flow-step-body {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.compute-flow-step-body strong {
  color: var(--ui-text);
  font-size: 13px;
  line-height: 1.3;
}

.compute-flow-step-body span {
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.4;
}

.compute-workloads-table-wrap {
  overflow-x: auto;
}

.compute-workloads-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.compute-workloads-table th,
.compute-workloads-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(59, 130, 246, 0.12);
  vertical-align: top;
}

.compute-workloads-table th {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
}

.compute-workloads-table strong {
  color: var(--ui-text);
}

.compute-workloads-table code {
  color: var(--ui-text-soft);
  font-size: 11px;
}

.compute-workloads-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: rgba(148, 163, 184, 0.08);
  color: var(--ui-text-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#compute-my-work-scope {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.compute-my-work-linking {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--ui-border);
  border-left: 3px solid var(--ui-blue);
  background: rgba(59, 130, 246, 0.06);
  color: var(--ui-text-soft);
  font-size: 12px;
  line-height: 1.4;
}

.compute-my-work-linking[hidden] {
  display: none;
}

.compute-my-work-linking a {
  color: var(--ui-blue);
  font-weight: 700;
}

.compute-workloads-head {
  align-items: flex-start;
}

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

.compute-workloads-intake {
  display: flex;
  align-items: center;
}

.ui-chip.is-intake-open {
  border-color: rgba(34, 197, 94, 0.55);
  color: #4ade80;
  background: rgba(34, 197, 94, 0.1);
}

.ui-chip.is-intake-closed {
  border-color: rgba(100, 116, 139, 0.5);
  color: #94a3b8;
  background: rgba(100, 116, 139, 0.08);
}

.compute-local-grid,
.compute-public-grid {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.compute-local-grid > div,
.compute-public-grid > div {
  border: 1px solid var(--ui-border);
  background: rgba(59, 130, 246, 0.06);
  padding: 10px;
}

.compute-local-grid span,
.compute-local-grid strong,
.compute-public-grid span,
.compute-public-grid strong {
  display: block;
}

.compute-local-grid span,
.compute-public-grid span {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.compute-local-grid strong,
.compute-public-grid strong {
  color: var(--ui-text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 16px;
  line-height: 1.4;
}

.compute-opt-note {
  color: var(--ui-text-soft);
}

.compute-workloads-list {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.compute-workload-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  padding: 12px;
}

.compute-workload-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.compute-workload-head strong {
  color: var(--ui-blue);
  font-size: 14px;
}

.compute-workload-head span {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.compute-workload-card p {
  color: var(--ui-text-soft);
  font-size: 13px;
  line-height: 1.45;
}

.compute-contact-map-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.compute-contact-map-summary > div {
  border: 1px solid var(--ui-border);
  background: rgba(59, 130, 246, 0.06);
  padding: 10px;
}

.compute-contact-map-summary span {
  display: block;
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.compute-contact-map-summary strong {
  display: block;
  color: var(--ui-text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 16px;
  line-height: 1.4;
}

.compute-contact-map-tiles {
  display: grid;
  gap: 10px;
}

.compute-contact-map-rollup,
.compute-contact-map-section,
.compute-contact-map-regions,
.compute-contact-map-samples {
  display: grid;
  gap: 10px;
}

.compute-contact-map-empty {
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  color: var(--ui-text-soft);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.compute-contact-map-region {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  padding: 10px 12px;
}

.compute-contact-map-region strong {
  color: var(--ui-text);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
  line-height: 1.35;
}

.compute-contact-map-region-counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: var(--ui-text-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
}

.compute-contact-map-region-counts em {
  color: var(--ui-text);
  font-style: normal;
  font-weight: 700;
}

.compute-contact-map-tile {
  display: grid;
  gap: 8px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  padding: 12px;
}

.compute-contact-map-tile-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.compute-contact-map-tile-head strong {
  color: var(--ui-blue);
  font-size: 14px;
  font-family: ui-monospace, Menlo, monospace;
}

.compute-contact-map-receipts {
  display: grid;
  gap: 4px;
  list-style: none;
  padding: 0;
  margin: 0;
}

.compute-contact-map-receipt {
  display: grid;
  grid-template-columns: 48px minmax(120px, 1fr) auto auto auto minmax(150px, 1fr);
  gap: 8px;
  align-items: center;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  color: var(--ui-text-soft);
  padding: 4px 0;
  border-bottom: 1px solid rgba(59, 130, 246, 0.12);
}

.compute-contact-map-receipt:not(:has(.compute-tile-preview)) {
  grid-template-columns: minmax(120px, 1fr) auto auto auto minmax(150px, 1fr);
}

.compute-contact-map-receipt:last-child {
  border-bottom: none;
}

.compute-contact-map-receipt code {
  color: var(--ui-text);
}

.compute-tile-preview {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
  border-radius: 3px;
  border: 1px solid rgba(59, 130, 246, 0.22);
  background: #000;
}

.compute-my-work-by-kernel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 8px;
}

.compute-my-work-kernel {
  display: grid;
  gap: 6px;
  border: 1px solid var(--ui-border);
  background: var(--ui-surface-2);
  padding: 10px 12px;
}

.compute-my-work-kernel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.compute-my-work-kernel-head strong {
  color: var(--ui-blue);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 13px;
}

.compute-my-work-kernel-counts {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--ui-text-soft);
  font-family: ui-monospace, Menlo, monospace;
}

.compute-my-work-kernel-counts em {
  color: var(--ui-text);
  font-style: normal;
  font-weight: 700;
}

.compute-my-work-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 2px;
}

.compute-my-work-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(180px, 1.2fr) minmax(70px, auto) minmax(60px, auto) minmax(70px, auto) minmax(80px, auto);
  gap: 8px;
  align-items: baseline;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 12px;
  color: var(--ui-text-soft);
  padding: 4px 0;
  border-bottom: 1px solid rgba(59, 130, 246, 0.12);
}

.compute-my-work-row:last-child {
  border-bottom: none;
}

.compute-my-work-row code {
  color: var(--ui-text);
}

.compute-my-work-row[data-decision="accepted"] code {
  color: var(--ui-green, #4ade80);
}

.compute-my-work-row[data-decision="rejected"] code,
.compute-my-work-row[data-decision="malformed"] code,
.compute-my-work-row[data-decision="input-mismatch"] code,
.compute-my-work-row[data-decision="output-mismatch"] code {
  color: var(--ui-red);
}

@media (max-width: 760px) {
  .compute-opt-head,
  .compute-public-head,
  .compute-workloads-head,
  .compute-contact-map-head,
  .compute-my-work-head {
    flex-direction: column;
    align-items: stretch;
  }
  .compute-contact-map-receipt,
  .compute-contact-map-region,
  .compute-my-work-row {
    grid-template-columns: 1fr;
  }

  .compute-contact-map-region-counts {
    justify-content: flex-start;
  }
}

/* --- duel page --- */
.duel-workbench {
  min-width: 0;
  display: grid;
  gap: 14px;
  align-items: start;
}

.duel-page .canvas-panel {
  position: relative;
  min-width: 0;
}

.duel-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.duel-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.duel-character-select {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.duel-fighter-slot {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.34);
}

.duel-fighter-head {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px 8px;
  align-items: baseline;
}

.duel-fighter-head strong,
.duel-fighter-head span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.duel-fighter-head strong {
  color: var(--ui-text);
  font-size: 13px;
}

.duel-fighter-head span:last-child {
  grid-column: 2;
  color: var(--ui-text-subtle);
  font-size: 11px;
}

.duel-fighter-kicker {
  grid-row: 1 / span 2;
  color: var(--ui-red);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 11px;
  font-weight: 800;
}

.duel-fighter-owner {
  grid-column: 2;
  color: var(--ui-text-subtle);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.duel-fighter-slot.is-readonly {
  background: rgba(15, 23, 42, 0.18);
  opacity: 0.92;
}

.duel-fighter-readonly {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  color: var(--ui-text-subtle);
}

.duel-fighter-readonly .duel-body-portrait {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
}

.duel-fighter-readonly-meta {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.duel-alias {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ui-text-subtle);
}

.duel-alias > span:first-child {
  flex: 0 0 auto;
}

.duel-alias-input {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--ui-bg-soft);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
  text-transform: none;
  letter-spacing: normal;
}

.duel-alias-input:focus {
  outline: none;
  border-color: var(--ui-accent, #6ee7b7);
}

.duel-alias-readonly {
  flex: 1 1 auto;
  min-width: 0;
  padding: 5px 8px;
  border: 1px dashed var(--ui-border);
  border-radius: 6px;
  color: var(--ui-text);
  font-size: 12px;
  text-transform: none;
  letter-spacing: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#duel-stage:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.duel-body-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.duel-body-option {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 4px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 6px;
  background: rgba(100, 116, 139, 0.08);
  color: var(--ui-text-soft);
  cursor: pointer;
}

.duel-body-option:hover,
.duel-body-option:focus-visible,
.duel-weapon-option:hover,
.duel-weapon-option:focus-visible {
  border-color: var(--ui-blue);
  background: rgba(59, 130, 246, 0.14);
  outline: none;
}

.duel-body-option.is-selected,
.duel-weapon-option.is-selected {
  border-color: var(--ui-red);
  background: rgba(239, 68, 68, 0.14);
  color: var(--ui-text);
  box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.18) inset;
}

.duel-body-option span:last-child {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 10px;
}

.duel-body-portrait {
  width: 42px;
  aspect-ratio: 1;
  background-color: rgba(59, 130, 246, 0.08);
  background-repeat: no-repeat;
  background-size: 200% 200%;
  background-position: 100% 100%;
  border: 1px solid rgba(59, 130, 246, 0.26);
  image-rendering: pixelated;
}

.duel-weapon-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.duel-weapon-option {
  min-width: 0;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.08);
  color: var(--ui-text-soft);
  text-align: left;
  cursor: pointer;
}

.duel-weapon-visual {
  position: relative;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
}

.duel-weapon-sprite {
  position: absolute;
  inset: 1px;
  border: 1px solid rgba(59, 130, 246, 0.28);
  border-radius: 4px;
  background-color: rgba(15, 23, 42, 0.85);
  background-repeat: no-repeat;
  image-rendering: pixelated;
}

.duel-weapon-sprite.is-missing {
  background-image:
    linear-gradient(135deg,
      transparent 0 44%,
      rgba(239, 68, 68, 0.7) 44% 56%,
      transparent 56% 100%);
}

.duel-weapon-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.duel-weapon-name,
.duel-weapon-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.duel-weapon-name {
  color: var(--ui-text);
  font-size: 11px;
}

.duel-weapon-meta {
  color: var(--ui-text-subtle);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 9px;
  text-transform: uppercase;
}

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

.duel-row label.tight {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ui-text-subtle);
}

.duel-row select,
.duel-p2p-row input[type="text"],
.duel-p2p-share input[type="text"] {
  background: var(--ui-bg-soft);
  color: var(--ui-text);
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  min-width: 160px;
}

.duel-keys {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px;
  font-size: 12px;
  color: var(--ui-text-soft);
}

.duel-keys b {
  display: block;
  color: var(--ui-red);
  letter-spacing: 0.06em;
}

.duel-key-card {
  min-width: 0;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.28);
}

.duel-key-card span {
  overflow-wrap: anywhere;
}

.duel-key-card.is-remote {
  opacity: 0.82;
}

.duel-touch-hint {
  display: none;
  color: var(--ui-blue);
}

.duel-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 8px 12px;
  border-top: 1px solid var(--ui-border);
}

.duel-stats .stat {
  display: inline-flex;
  flex-direction: column;
  min-width: 60px;
}

.duel-stats .stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ui-text-subtle);
}

.duel-stats .stat-value {
  font-size: 14px;
  color: var(--ui-text);
}

.duel-stats .duel-status {
  margin-left: auto;
}

.duel-p2p-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px dashed var(--ui-border);
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.04);
  width: 100%;
}

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

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

.duel-p2p-status {
  color: var(--ui-text-subtle);
}

.duel-p2p-share {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

.duel-p2p-share[hidden] {
  display: none !important;
}

.duel-p2p-session-row {
  margin-top: 2px;
}

/* Two-state P2P panel: idle (host/join visible) vs is-active (stop/new
   + share visible). Toggling the class swaps which block renders so
   the panel doesn't carry empty hidden rows in either state. */
#duel-p2p-panel .duel-p2p-active { display: none; }
#duel-p2p-panel.is-active .duel-p2p-idle { display: none; }
#duel-p2p-panel.is-active .duel-p2p-active { display: block; }

.duel-p2p-takeover {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--ui-red, #fca5a5);
  border-radius: 6px;
  background: rgba(252, 165, 165, 0.08);
}

.duel-p2p-takeover[hidden] {
  display: none !important;
}

.duel-p2p-takeover .tight {
  flex: 1 1 auto;
  color: var(--ui-text);
}

.duel-p2p-link-label {
  min-width: min(100%, 360px);
  display: inline-flex;
  flex: 1 1 260px;
  flex-direction: column;
  gap: 4px;
  color: var(--ui-text-subtle);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.duel-p2p-link-label input {
  width: 100%;
  text-transform: none;
}

.duel-p2p-warning {
  color: var(--ui-red);
  font-size: 12px;
}

.duel-touch-controls,
.duel-touch-setup {
  display: none;
}

.duel-touch-controls {
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 4px 0;
  touch-action: none;
  user-select: none;
}

.duel-touch-pad {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 48px);
  gap: 6px;
}

.duel-touch-actions {
  display: flex;
  align-items: center;
  justify-content: center;
}

.duel-touch-control {
  border: 1px solid rgba(148, 163, 184, 0.42);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: var(--ui-text);
  font: 800 10px/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.duel-touch-control.is-pressed {
  background: rgba(239, 68, 68, 0.42);
  border-color: var(--ui-red);
  color: #fff;
}

.duel-touch-control.is-up {
  grid-column: 2;
  grid-row: 1;
}

.duel-touch-control.is-left {
  grid-column: 1;
  grid-row: 2;
}

.duel-touch-control.is-down {
  grid-column: 2;
  grid-row: 2;
}

.duel-touch-control.is-right {
  grid-column: 3;
  grid-row: 2;
}

.duel-touch-control.is-action {
  width: 92px;
  height: 92px;
  border-radius: 999px;
}

.duel-touch-setup {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  padding: 8px 10px;
  border: 1px solid rgba(148, 163, 184, 0.36);
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.82);
  color: var(--ui-text);
  font: 800 10px/1 ui-monospace, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@media (pointer: coarse) {
  .duel-touch-hint {
    display: inline;
  }

  .duel-touch-controls {
    display: flex;
  }
}

@media (max-width: 640px) {
  .duel-character-select {
    grid-template-columns: 1fr;
  }

  .duel-stats .duel-status {
    margin-left: 0;
    width: 100%;
  }
}

@media (min-width: 980px) {
  .duel-workbench {
    grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  }

  .duel-context-card {
    position: sticky;
    top: 68px;
    max-height: calc(100svh - 110px);
    overflow: auto;
    padding: 12px;
  }

  .duel-workbench .duel-character-select {
    grid-template-columns: 1fr;
  }

  .duel-workbench .duel-fighter-slot {
    padding: 8px;
  }

  .duel-workbench .duel-body-portrait {
    width: 34px;
  }

  .duel-workbench .duel-weapon-option {
    min-height: 44px;
  }

  .duel-workbench .duel-p2p-row input[type="text"] {
    flex: 1 1 180px;
    min-width: 0;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  body.duel-match-active {
    overflow: hidden;
  }

  body.duel-match-active #topnav,
  body.duel-match-active #bottom {
    display: none;
  }

  body.duel-match-active #app {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    padding: 0;
    margin: 0;
    background: var(--ui-bg);
    overflow: hidden;
  }

  .duel-page.is-playing {
    width: 100vw;
    height: 100dvh;
  }

  .duel-page.is-playing .page-header-row,
  .duel-page.is-playing .duel-context-card {
    display: none;
  }

  .duel-page.is-playing .canvas-panel {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: #000;
  }

  .duel-page.is-playing .canvas-panel .u-canvas-fill {
    width: min(100vw, calc(100dvh * 16 / 9)) !important;
    height: min(100dvh, calc(100vw * 9 / 16)) !important;
    max-width: none;
  }

  .duel-page.is-playing .duel-stats {
    position: absolute;
    z-index: 3;
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: auto;
    max-width: min(58vw, 420px);
    padding: 6px 8px;
    gap: 8px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 6px;
    background: rgba(4, 4, 4, 0.58);
    pointer-events: none;
  }

  .duel-page.is-playing .duel-stats .stat {
    min-width: 42px;
  }

  .duel-page.is-playing .duel-stats .stat-label {
    font-size: 8px;
  }

  .duel-page.is-playing .duel-stats .stat-value {
    font-size: 11px;
  }

  .duel-page.is-playing .duel-touch-controls {
    position: absolute;
    z-index: 4;
    inset: auto max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    max-width: none;
    padding: 0;
    pointer-events: none;
  }

  .duel-page.is-playing .duel-touch-control,
  .duel-page.is-playing .duel-touch-setup {
    pointer-events: auto;
  }

  .duel-page.is-playing .duel-touch-pad {
    grid-template-columns: repeat(3, 54px);
    grid-template-rows: repeat(3, 44px);
  }

  .duel-page.is-playing .duel-touch-control.is-action {
    width: 92px;
    height: 92px;
  }

  .duel-page.is-playing .duel-touch-setup {
    display: block;
  }
}
