/* ============================================================
   INFERENCE ARCADE — component styles (index.html)
   Requires css/theme.css (tokens, base, titlebar, boot, lamps).

   Contents:
     1. app shell (sections, steps, headings)
     2. step 1 — cartridge wall (game cards)
     3. step 2 — tactic + machine settings (strategy, chips, model)
     4. step 3 — cabinet (frame, glass, status strip, controls)
     5. trace printer (reasoning log, autopsy)
     6. run summary
     7. operator desk (prompt dashboard)
     8. telemetry
     9. responsive
    10. reduced motion
   ============================================================ */

/* light reset — markup was authored against zeroed margins */
h1, h2, h3, h4, h5, p, ul, ol, figure {
  margin: 0;
}

button {
  font-family: inherit;
}

/* ---------- 1. app shell ---------- */

#app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-5) var(--space-8);
}

.section {
  display: none;
}

.section.active {
  display: block;
  animation: section-in 260ms ease-out;
}

@keyframes section-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.step {
  display: none;
  padding-top: var(--space-8);
}

.step.active {
  display: block;
}

.step-label {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: none;
  color: var(--arcade-accent-bright);
  text-shadow: 0 0 10px rgba(123, 239, 195, 0.22);
}

.step-label::before {
  content: "▸ ";
  color: var(--arcade-accent-dim);
}

.step h2,
.dashboard-heading h2 {
  margin: 0 0 var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--arcade-text);
}

.step h2 span {
  color: var(--arcade-accent);
}

.step-note {
  margin: 0 0 var(--space-5);
  max-width: 78ch;
  color: var(--arcade-text-secondary);
  font-size: var(--text-lg);
  line-height: 1.55;
}

h3 {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--arcade-text);
}

a {
  color: var(--arcade-accent);
}

small {
  color: var(--arcade-text-dim);
}

/* ---------- buttons ---------- */

.btn-primary,
.btn-secondary,
.btn-danger {
  appearance: none;
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: var(--text-sm);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
    border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-primary {
  background: transparent;
  border: 1px solid transparent;
  color: var(--arcade-accent-bright);
}

.btn-primary:hover:not(:disabled) {
  background: var(--arcade-accent);
  border-color: var(--arcade-accent);
  color: var(--abyss);
  box-shadow: var(--shadow-hover);
}

.btn-primary:disabled {
  background: transparent;
  border-color: transparent;
  color: var(--arcade-accent-dim);
  cursor: wait;
}

.btn-secondary {
  background: transparent;
  border: 1px solid transparent;
  color: var(--arcade-text-secondary);
}

.btn-secondary:hover {
  color: var(--arcade-accent-bright);
  background: var(--arcade-accent-faint);
  border-color: var(--arcade-accent-dim);
}

.btn-danger {
  background: transparent;
  border: 1px solid transparent;
  color: var(--arcade-danger);
}

.btn-danger:hover {
  background: var(--arcade-danger);
  border-color: var(--arcade-danger);
  color: var(--foam);
}

.btn-start {
  margin-top: 0;
  min-width: 220px;
  max-width: 100%;
  min-height: 54px;
  padding: var(--space-3) var(--space-6);
  background: var(--arcade-accent);
  border-color: var(--arcade-accent);
  color: var(--abyss);
  font-size: var(--text-sm);
  font-weight: 700;
  box-shadow:
    0 0 0 1px rgba(123, 239, 195, 0.28),
    0 14px 34px rgba(0, 0, 0, 0.48),
    0 0 24px rgba(123, 239, 195, 0.22);
}

.btn-start:hover:not(:disabled) {
  background: var(--arcade-accent-bright);
  border-color: var(--arcade-accent-bright);
}

.btn-start:disabled {
  background: var(--arcade-accent-faint);
  border-color: var(--arcade-accent-dim);
  color: var(--arcade-text-secondary);
}

.btn-sm {
  margin: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-2xs);
}

/* ---------- form controls ---------- */

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-md);
  color: var(--arcade-text);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  transition: border-color var(--transition-fast);
}

input::placeholder,
textarea::placeholder {
  color: var(--arcade-text-dim);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--arcade-accent);
  box-shadow: 0 0 0 1px var(--arcade-accent-faint);
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

label {
  display: block;
  margin-bottom: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--arcade-text-secondary);
}

.form-group {
  margin-bottom: var(--space-4);
}

.form-group small {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-sm);
}

.settings-row {
  display: flex;
  gap: var(--space-4);
}

.settings-row .form-group {
  flex: 1;
}

/* ---------- 2. step 1 — cartridge wall ---------- */

.games-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--arcade-border-soft);
}

.games-mode-label {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: none;
  color: var(--arcade-accent-bright);
  text-shadow: 0 0 10px rgba(123, 239, 195, 0.18);
}

#game-search {
  margin-bottom: var(--space-4);
}

#games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-3);
  max-height: min(58vh, 620px);
  overflow-y: auto;
  padding: var(--space-1);
}

/* Featured cabinet board on narrow viewports: the 15-game showcase is
   arranged as three rows of five instead of a single horizontal strip. */
@media (max-width: 760px) {
  #games-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(104px, 1fr));
    grid-auto-rows: minmax(116px, auto);
    gap: var(--space-2);
    overflow-x: auto;
    overflow-y: visible;
    max-height: none;
    padding: var(--space-2) 0 var(--space-3);
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  #games-grid .game-card {
    width: auto;
    min-width: 0;
    min-height: 116px;
    padding: var(--space-2) 6px;
    overflow: hidden;
    scroll-snap-align: start;
  }

  #games-grid .game-card h3 {
    max-width: 100%;
    overflow: hidden;
    font-size: var(--text-2xs);
    line-height: 1.15;
    letter-spacing: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #games-grid .game-card .levels {
    max-width: 100%;
    overflow: hidden;
    font-size: var(--text-2xs);
    line-height: 1.15;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #games-grid .game-card-meta {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    padding-right: 0;
    font-size: 0.5625rem;
    line-height: 1.1;
    letter-spacing: 0;
  }

  #games-grid .game-card-meta span {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #games-grid .game-card-meta > span:not(.trace-badge) {
    padding-right: 12px;
  }

  #games-grid .trace-badge {
    width: auto;
    max-width: 100%;
    padding: 1px 2px;
    font-size: 0.4375rem;
    line-height: 1.1;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 400px) {
  #games-grid {
    grid-template-columns: repeat(5, minmax(104px, 1fr));
    grid-auto-rows: minmax(112px, auto);
  }

  #games-grid .game-card {
    min-height: 112px;
  }
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 142px;
  padding: var(--space-3);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: border-color var(--transition-fast), background var(--transition-fast),
    box-shadow var(--transition-fast);
}

.game-card:hover {
  background: var(--arcade-panel-strong);
  border-color: var(--arcade-accent);
  box-shadow: var(--shadow-hover);
}

/* ready lamp — lights on hover, always lit on featured cartridges */
.game-card::after {
  content: "";
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--arcade-text-dim);
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}

.game-card:hover::after,
.game-card.featured::after {
  background: var(--arcade-accent);
  box-shadow: var(--lamp-glow);
}

.game-card-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-1) var(--space-2);
  padding-right: 14px;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.game-card-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-card h3 {
  margin: var(--space-3) 0 var(--space-1);
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--arcade-text);
  overflow-wrap: anywhere;
}

.game-card:hover h3 {
  color: var(--arcade-accent-bright);
}

.game-card .levels {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-md);
  color: var(--arcade-text-secondary);
}

/* human play-trace badge (appended into the card meta row by app.js) */
.trace-badge {
  flex-basis: 100%;
  align-self: flex-start;
  justify-self: start;
  width: fit-content;
  max-width: 100%;
  padding: 1px 6px;
  border: 1px solid var(--arcade-accent-dim);
  color: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: 1.1;
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* enough human plays captured to fine-tune on */
.trace-badge.ready {
  border-color: var(--arcade-success);
  color: var(--arcade-success);
}

/* companion rooms */

.companion-games {
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--arcade-border-soft);
}

.companion-kicker {
  margin: 0 0 var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--arcade-accent);
}

.companion-games h3 {
  margin: 0 0 var(--space-5);
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.companion-list {
  /* auto-fit at a 200px floor: 4 cards fill the row now, 5 fit automatically
     once cadavre-exquis is added (no layout edit needed). */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
  gap: var(--space-4);
  width: min(100%, 1160px);
  max-width: 100%;
}

.companion-link {
  isolation: isolate;
  min-height: 158px;
  overflow: hidden;
  padding: var(--space-4);
}

.companion-link > * {
  position: relative;
  z-index: 1;
}

.companion-link .companion-subtitle {
  justify-content: flex-start;
  align-items: flex-start;
  padding-right: 34px;
  color: var(--arcade-text-secondary);
  flex-wrap: nowrap;
  font-size: var(--text-md);
  font-weight: 700;
  line-height: 1.28;
  white-space: normal;
}

.companion-link .companion-subtitle span {
  overflow-wrap: break-word;
  white-space: normal;
}

.companion-link h3 {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.12;
}

.room-cloze {
  color: #26180a;
  background:
    linear-gradient(112deg, transparent 0 48%, rgba(115, 78, 34, 0.12) 48.4% 49.4%, transparent 49.8%),
    linear-gradient(0deg, rgba(67, 42, 17, 0.08) 0 1px, transparent 1px 38px),
    linear-gradient(90deg, rgba(67, 42, 17, 0.07) 0 1px, transparent 1px 42px),
    radial-gradient(circle at 18% 18%, rgba(96, 57, 21, 0.13), transparent 26%),
    radial-gradient(circle at 84% 76%, rgba(96, 57, 21, 0.1), transparent 25%),
    linear-gradient(90deg, transparent 0 64%, rgba(58, 37, 14, 0.18) 64% 65%, transparent 65%),
    linear-gradient(0deg, transparent 0 64%, rgba(58, 37, 14, 0.14) 64% 65%, transparent 65%),
    linear-gradient(145deg, rgba(255, 245, 210, 0.92), rgba(229, 195, 128, 0.72) 55%, rgba(201, 155, 84, 0.6)),
    #e5c383;
  border-color: rgba(93, 61, 24, 0.72);
  box-shadow:
    inset 0 0 0 1px rgba(255, 249, 222, 0.38),
    inset 0 0 0 6px rgba(60, 40, 17, 0.08),
    0 10px 24px rgba(40, 25, 9, 0.24);
}

.room-cloze::before {
  content: "";
  position: absolute;
  inset: 8px;
  z-index: 0;
  pointer-events: none;
  border: 2px solid rgba(43, 29, 12, 0.42);
  box-shadow:
    inset 0 0 0 1px rgba(255, 249, 222, 0.32),
    inset 0 -18px 36px rgba(70, 45, 18, 0.1);
}

.room-cloze::after {
  content: "A_";
  position: absolute;
  top: 13px;
  right: 13px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 2px solid rgba(48, 31, 12, 0.74);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 250, 226, 0.72), transparent 34%),
    linear-gradient(145deg, rgba(239, 212, 150, 0.94), rgba(186, 132, 57, 0.78));
  color: #2f1f0d;
  font-family: var(--font-display);
  font-size: var(--text-sm);
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 246, 215, 0.55);
  box-shadow:
    inset 0 0 0 1px rgba(255, 246, 215, 0.28),
    0 0 14px rgba(80, 47, 16, 0.22);
}

.room-cloze .companion-subtitle::before {
  content: "";
  flex: 0 0 auto;
  width: 13px;
  height: 38px;
  margin-right: 10px;
  border-radius: 85% 20% 75% 25%;
  background:
    linear-gradient(90deg, rgba(35, 24, 11, 0.92) 0 2px, transparent 2px),
    repeating-linear-gradient(135deg, rgba(35, 24, 11, 0.58) 0 1px, transparent 1px 5px);
  transform: rotate(-10deg);
}

.room-cloze .companion-subtitle {
  color: #2c1a08;
  text-shadow: 0 1px 0 rgba(255, 247, 219, 0.58);
}

.room-cloze h3 {
  margin-top: var(--space-4);
  color: #201306;
}

.room-cloze .companion-url {
  color: #34210d;
}

/* ---- Cadavre Exquis: folded ink-and-bone parlor sheet ---- */
.room-cadavre {
  color: #e7e0d0;
  background:
    linear-gradient(176deg, transparent 0 24%, rgba(231, 224, 208, 0.16) 24.2% 24.8%, transparent 25% 49%, rgba(231, 224, 208, 0.12) 49.2% 49.8%, transparent 50% 73%, rgba(231, 224, 208, 0.1) 73.2% 73.8%, transparent 74%),
    radial-gradient(circle at 18% 20%, rgba(207, 116, 134, 0.24), transparent 26%),
    radial-gradient(circle at 86% 78%, rgba(231, 224, 208, 0.08), transparent 28%),
    linear-gradient(145deg, rgba(27, 29, 36, 0.98), rgba(15, 17, 22, 0.96) 56%, rgba(9, 10, 13, 0.98)),
    #0c0d10;
  border-color: rgba(231, 224, 208, 0.22);
  box-shadow:
    inset 0 0 0 1px rgba(231, 224, 208, 0.08),
    inset 0 -30px 54px rgba(0, 0, 0, 0.34),
    0 10px 28px rgba(0, 0, 0, 0.36);
}

.room-cadavre::before {
  content: "";
  position: absolute;
  inset: 13px 14px;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(231, 224, 208, 0.16), rgba(231, 224, 208, 0.04)),
    repeating-linear-gradient(180deg, transparent 0 23px, rgba(231, 224, 208, 0.13) 24px 25px);
  clip-path: polygon(0 0, 92% 0, 100% 16%, 94% 100%, 5% 96%);
  opacity: 0.9;
}

.room-cadavre::after {
  content: "CE";
  position: absolute;
  top: 13px;
  right: 13px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(231, 224, 208, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 26%, rgba(231, 224, 208, 0.28), transparent 32%),
    linear-gradient(145deg, rgba(164, 72, 86, 0.92), rgba(98, 34, 46, 0.9));
  color: #f1d7dd;
  font-family: var(--font-display);
  font-size: var(--text-sm);
  line-height: 1;
  box-shadow:
    inset 0 0 0 1px rgba(255, 219, 226, 0.12),
    0 0 16px rgba(207, 116, 134, 0.42);
}

.room-cadavre .companion-subtitle {
  color: #b8b2a4;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.74);
}

.room-cadavre .companion-subtitle::before {
  content: "";
  flex: 0 0 auto;
  width: 16px;
  height: 36px;
  margin-right: 10px;
  background:
    linear-gradient(180deg, rgba(231, 224, 208, 0.78), rgba(231, 224, 208, 0.28)),
    repeating-linear-gradient(180deg, transparent 0 9px, rgba(12, 13, 16, 0.48) 10px 11px);
  clip-path: polygon(5% 0, 88% 6%, 100% 100%, 0 92%);
  transform: rotate(-3deg);
}

.room-cadavre h3 {
  margin-top: var(--space-4);
  color: #e7e0d0;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.64);
}

.room-cadavre .companion-url {
  color: #d4cbb9;
}

.room-jeopardy {
  color: #f4f9ff;
  background:
    linear-gradient(90deg, rgba(255, 218, 64, 0.18) 0 2px, transparent 2px 16.66%, rgba(255, 218, 64, 0.16) 16.66% calc(16.66% + 2px), transparent calc(16.66% + 2px) 33.33%, rgba(255, 218, 64, 0.13) 33.33% calc(33.33% + 2px), transparent calc(33.33% + 2px) 50%),
    repeating-linear-gradient(0deg, rgba(214, 234, 255, 0.09) 0 1px, transparent 1px 14px),
    radial-gradient(circle at 88% 18%, rgba(255, 218, 64, 0.2), transparent 24%),
    linear-gradient(145deg, rgba(33, 105, 214, 0.95), rgba(10, 63, 171, 0.9) 58%, rgba(5, 34, 118, 0.86)),
    #174fbd;
  border-color: rgba(255, 211, 47, 0.58);
  box-shadow:
    inset 0 0 0 1px rgba(214, 234, 255, 0.14),
    inset 0 -28px 48px rgba(4, 24, 88, 0.24),
    0 10px 28px rgba(7, 37, 111, 0.36);
}

.room-jeopardy .companion-subtitle {
  color: #f8fbff;
  text-shadow: 0 1px 0 rgba(2, 18, 67, 0.78);
}

.room-jeopardy::after {
  content: "J";
  position: absolute;
  top: 13px;
  right: 13px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 2px solid rgba(255, 220, 59, 0.78);
  border-radius: 4px;
  background:
    linear-gradient(180deg, rgba(32, 93, 201, 0.92), rgba(7, 38, 121, 0.9));
  color: #ffdc3b;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: 1;
  box-shadow:
    inset 0 0 0 1px rgba(214, 234, 255, 0.12),
    0 0 16px rgba(255, 220, 59, 0.42);
}

.room-jeopardy h3 {
  margin-top: var(--space-4);
  color: #ffdc3b;
  text-shadow: 0 2px 0 rgba(2, 18, 67, 0.62);
}

.room-jeopardy .companion-url {
  color: #eef7ff;
}

.room-cloze:hover {
  background:
    linear-gradient(112deg, transparent 0 48%, rgba(115, 78, 34, 0.14) 48.4% 49.4%, transparent 49.8%),
    linear-gradient(0deg, rgba(67, 42, 17, 0.08) 0 1px, transparent 1px 38px),
    linear-gradient(90deg, rgba(67, 42, 17, 0.07) 0 1px, transparent 1px 42px),
    radial-gradient(circle at 18% 18%, rgba(96, 57, 21, 0.13), transparent 26%),
    radial-gradient(circle at 84% 76%, rgba(96, 57, 21, 0.1), transparent 25%),
    linear-gradient(90deg, transparent 0 64%, rgba(58, 37, 14, 0.18) 64% 65%, transparent 65%),
    linear-gradient(0deg, transparent 0 64%, rgba(58, 37, 14, 0.14) 64% 65%, transparent 65%),
    linear-gradient(145deg, rgba(255, 248, 220, 0.98), rgba(235, 202, 137, 0.82) 55%, rgba(207, 162, 91, 0.66)),
    #ecd19a;
  border-color: rgba(108, 70, 26, 0.84);
}

.room-cloze:hover h3 {
  color: #211305;
}

.room-cadavre:hover {
  background:
    linear-gradient(176deg, transparent 0 24%, rgba(231, 224, 208, 0.18) 24.2% 24.8%, transparent 25% 49%, rgba(231, 224, 208, 0.14) 49.2% 49.8%, transparent 50% 73%, rgba(231, 224, 208, 0.12) 73.2% 73.8%, transparent 74%),
    radial-gradient(circle at 18% 20%, rgba(207, 116, 134, 0.3), transparent 26%),
    radial-gradient(circle at 86% 78%, rgba(231, 224, 208, 0.1), transparent 28%),
    linear-gradient(145deg, rgba(31, 33, 42, 0.98), rgba(17, 19, 25, 0.96) 56%, rgba(10, 11, 15, 0.98)),
    #101116;
  border-color: rgba(207, 116, 134, 0.52);
}

.room-cadavre:hover h3 {
  color: #f0e9db;
}

.room-jeopardy:hover {
  background:
    linear-gradient(90deg, rgba(255, 218, 64, 0.2) 0 2px, transparent 2px 16.66%, rgba(255, 218, 64, 0.18) 16.66% calc(16.66% + 2px), transparent calc(16.66% + 2px) 33.33%, rgba(255, 218, 64, 0.15) 33.33% calc(33.33% + 2px), transparent calc(33.33% + 2px) 50%),
    repeating-linear-gradient(0deg, rgba(214, 234, 255, 0.1) 0 1px, transparent 1px 14px),
    radial-gradient(circle at 88% 18%, rgba(255, 218, 64, 0.24), transparent 24%),
    linear-gradient(145deg, rgba(39, 115, 225, 0.98), rgba(13, 73, 186, 0.92) 58%, rgba(7, 42, 128, 0.86)),
    #195cc7;
  border-color: rgba(255, 222, 76, 0.72);
}

.room-jeopardy:hover h3 {
  color: #ffe36a;
}

/* ---- Chess LM: bone-and-oxblood endgame board ---- */
.room-chess {
  color: #e1ddd1;
  background:
    linear-gradient(90deg, transparent 0 25%, rgba(225, 221, 209, 0.06) 25% 50%, transparent 50% 75%, rgba(225, 221, 209, 0.05) 75%),
    linear-gradient(0deg, transparent 0 25%, rgba(225, 221, 209, 0.05) 25% 50%, transparent 50% 75%, rgba(225, 221, 209, 0.04) 75%),
    radial-gradient(circle at 84% 22%, rgba(145, 52, 47, 0.34), transparent 28%),
    linear-gradient(145deg, rgba(31, 34, 33, 0.98), rgba(14, 17, 16, 0.97) 58%, rgba(7, 9, 9, 0.98)),
    #090b0b;
  border-color: rgba(225, 221, 209, 0.34);
  box-shadow:
    inset 0 0 0 1px rgba(225, 221, 209, 0.08),
    inset 0 -30px 54px rgba(0, 0, 0, 0.38),
    0 10px 28px rgba(0, 0, 0, 0.4);
}

.room-chess::before {
  content: "";
  position: absolute;
  inset: 12px;
  z-index: 0;
  pointer-events: none;
  border: 1px solid rgba(225, 221, 209, 0.2);
  background:
    linear-gradient(176deg, transparent 0 54%, rgba(225, 221, 209, 0.12) 54.4% 55%, transparent 55.4%),
    radial-gradient(ellipse at 16% 76%, rgba(225, 221, 209, 0.1), transparent 24%),
    radial-gradient(ellipse at 84% 78%, rgba(225, 221, 209, 0.07), transparent 26%);
}

.room-chess::after {
  content: "\265C";
  position: absolute;
  top: 13px;
  right: 13px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(225, 221, 209, 0.48);
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(109, 41, 37, 0.96), rgba(55, 22, 20, 0.94));
  color: #e1ddd1;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: 1;
  box-shadow:
    inset 0 0 0 1px rgba(225, 221, 209, 0.08),
    0 0 16px rgba(145, 52, 47, 0.46);
}

.room-chess .companion-subtitle {
  color: #c7c2b6;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.78);
}

.room-chess h3 {
  margin-top: var(--space-4);
  color: #e1ddd1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.72);
}

.room-chess .companion-url {
  color: #c7c2b6;
}

.room-chess:hover {
  background:
    linear-gradient(90deg, transparent 0 25%, rgba(225, 221, 209, 0.075) 25% 50%, transparent 50% 75%, rgba(225, 221, 209, 0.065) 75%),
    linear-gradient(0deg, transparent 0 25%, rgba(225, 221, 209, 0.065) 25% 50%, transparent 50% 75%, rgba(225, 221, 209, 0.055) 75%),
    radial-gradient(circle at 84% 22%, rgba(182, 73, 66, 0.42), transparent 28%),
    linear-gradient(145deg, rgba(36, 39, 38, 0.98), rgba(17, 20, 19, 0.97) 58%, rgba(8, 10, 10, 0.98)),
    #0b0d0d;
  border-color: rgba(182, 73, 66, 0.58);
}

.room-chess:hover h3 {
  color: #f0ece0;
}

/* ---- Haggle: coral bartering cabinet ---- */
.room-haggle {
  color: #fff3ef;
  background:
    linear-gradient(90deg, transparent 0 calc(50% - 1px), rgba(255, 225, 216, 0.24) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    repeating-linear-gradient(0deg, rgba(255, 225, 216, 0.12) 0 1px, transparent 1px 28px),
    radial-gradient(circle at 82% 22%, rgba(255, 236, 218, 0.22), transparent 30%),
    radial-gradient(circle at 16% 76%, rgba(86, 35, 24, 0.22), transparent 28%),
    linear-gradient(145deg, rgba(210, 112, 91, 0.96), rgba(170, 68, 52, 0.92) 55%, rgba(102, 38, 32, 0.9)),
    #aa4434;
  border-color: rgba(255, 190, 156, 0.44);
  box-shadow:
    inset 0 0 0 1px rgba(255, 232, 222, 0.24),
    inset 0 -28px 48px rgba(55, 18, 14, 0.28),
    0 10px 28px rgba(80, 25, 18, 0.36);
}

.room-haggle::before {
  content: "";
  position: absolute;
  inset: 12px;
  z-index: 0;
  pointer-events: none;
  border: 1px solid rgba(255, 226, 210, 0.28);
  background:
    linear-gradient(90deg, transparent 0 30%, rgba(255, 226, 210, 0.12) 30% 31%, transparent 31% 70%, rgba(255, 226, 210, 0.12) 70% 71%, transparent 71%),
    linear-gradient(0deg, transparent 0 48%, rgba(255, 226, 210, 0.1) 48% 49%, transparent 49%);
}

.room-haggle::after {
  content: "$";
  position: absolute;
  top: 13px;
  right: 13px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 2px solid rgba(255, 214, 208, 0.78);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(224, 138, 128, 0.95), rgba(150, 52, 46, 0.9));
  color: #ffe8e4;
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: 1;
  box-shadow:
    inset 0 0 0 1px rgba(255, 232, 228, 0.14),
    0 0 16px rgba(196, 82, 74, 0.5);
}

.room-haggle .companion-subtitle {
  color: #fff7f3;
  text-shadow: 0 1px 0 rgba(70, 18, 14, 0.68);
}

.room-haggle h3 {
  margin-top: var(--space-4);
  color: #fff2ef;
  text-shadow: 0 2px 0 rgba(70, 18, 14, 0.5);
}

.room-haggle .companion-url {
  color: #ffeae6;
}

.room-haggle:hover {
  background:
    linear-gradient(90deg, transparent 0 calc(50% - 1px), rgba(255, 225, 216, 0.28) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    repeating-linear-gradient(0deg, rgba(255, 225, 216, 0.14) 0 1px, transparent 1px 28px),
    radial-gradient(circle at 82% 22%, rgba(255, 236, 218, 0.26), transparent 30%),
    radial-gradient(circle at 16% 76%, rgba(86, 35, 24, 0.22), transparent 28%),
    linear-gradient(145deg, rgba(224, 124, 100, 0.98), rgba(186, 76, 58, 0.94) 55%, rgba(116, 42, 35, 0.9)),
    #ba4c3a;
  border-color: rgba(255, 176, 168, 0.62);
}

.room-haggle:hover h3 {
  color: #fff6f4;
}

/* ---- LanGames: cyan language cabinet ---- */
.room-langgames {
  color: #061d2a;
  background:
    linear-gradient(120deg, transparent 0 30%, rgba(8, 45, 90, 0.14) 30% 31%, transparent 31% 62%, rgba(8, 45, 90, 0.13) 62% 63%, transparent 63%),
    repeating-linear-gradient(0deg, rgba(237, 251, 255, 0.16) 0 1px, transparent 1px 24px),
    radial-gradient(circle at 18% 20%, rgba(224, 246, 255, 0.26), transparent 28%),
    radial-gradient(circle at 84% 76%, rgba(0, 64, 138, 0.22), transparent 30%),
    linear-gradient(145deg, rgba(138, 216, 236, 0.96), rgba(72, 160, 213, 0.92) 55%, rgba(31, 90, 154, 0.9)),
    #48a0d5;
  border-color: rgba(189, 235, 250, 0.46);
  box-shadow:
    inset 0 0 0 1px rgba(224, 246, 255, 0.22),
    inset 0 -28px 48px rgba(10, 45, 84, 0.24),
    0 10px 28px rgba(10, 45, 84, 0.34);
}

.room-langgames::before {
  content: "";
  position: absolute;
  inset: 12px;
  z-index: 0;
  pointer-events: none;
  border: 1px solid rgba(237, 251, 255, 0.26);
  background:
    radial-gradient(circle at 74% 32%, transparent 0 15px, rgba(237, 251, 255, 0.18) 16px 17px, transparent 18px),
    linear-gradient(90deg, rgba(237, 251, 255, 0.14) 0 1px, transparent 1px 100%),
    repeating-linear-gradient(90deg, transparent 0 42px, rgba(237, 251, 255, 0.08) 42px 43px);
}

.room-langgames::after {
  content: "\6587"; /* 文 — multilingual mark */
  position: absolute;
  top: 13px;
  right: 13px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 2px solid rgba(224, 246, 255, 0.8);
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(126, 214, 240, 0.95), rgba(42, 120, 160, 0.9));
  color: #eaf9ff;
  font-family: var(--font-mono);
  font-size: var(--text-md);
  line-height: 1;
  box-shadow:
    inset 0 0 0 1px rgba(224, 246, 255, 0.14),
    0 0 16px rgba(90, 176, 224, 0.5);
}

.room-langgames .companion-subtitle {
  color: #06283b;
  text-shadow: 0 1px 0 rgba(226, 249, 255, 0.46);
}

.room-langgames h3 {
  margin-top: var(--space-4);
  color: #f2fbff;
  text-shadow: 0 2px 0 rgba(4, 40, 56, 0.5);
}

.room-langgames .companion-url {
  color: #e6f6ff;
}

.room-langgames:hover {
  background:
    linear-gradient(120deg, transparent 0 30%, rgba(8, 45, 90, 0.16) 30% 31%, transparent 31% 62%, rgba(8, 45, 90, 0.15) 62% 63%, transparent 63%),
    repeating-linear-gradient(0deg, rgba(237, 251, 255, 0.18) 0 1px, transparent 1px 24px),
    radial-gradient(circle at 18% 20%, rgba(224, 246, 255, 0.3), transparent 28%),
    radial-gradient(circle at 84% 76%, rgba(0, 64, 138, 0.24), transparent 30%),
    linear-gradient(145deg, rgba(148, 224, 244, 0.98), rgba(82, 171, 222, 0.94) 55%, rgba(38, 104, 168, 0.9)),
    #52abde;
  border-color: rgba(180, 232, 250, 0.62);
}

.room-langgames:hover h3 {
  color: #f8fdff;
}

.companion-link .companion-url {
  display: block;
  min-width: 0;
  max-width: 100%;
  color: var(--arcade-accent-dim);
  font-size: var(--text-md);
  font-weight: 600;
  overflow-wrap: anywhere;
  white-space: normal;
  transition: color var(--transition-fast);
}

.companion-link:hover .companion-url {
  color: var(--arcade-accent);
}

.companion-link.room-cloze .companion-url,
.companion-link.room-cloze:hover .companion-url {
  color: #34210d;
}

.companion-link.room-cadavre .companion-url,
.companion-link.room-cadavre:hover .companion-url {
  color: #d4cbb9;
}

.companion-link.room-jeopardy .companion-url,
.companion-link.room-jeopardy:hover .companion-url {
  color: #eef7ff;
}

.companion-link.room-chess .companion-url,
.companion-link.room-chess:hover .companion-url {
  color: #c7c2b6;
}

.companion-link.room-haggle .companion-url,
.companion-link.room-haggle:hover .companion-url {
  color: #fff0eb;
}

.companion-link.room-langgames .companion-url,
.companion-link.room-langgames:hover .companion-url {
  color: #ecfaff;
}

/* ---------- 3. step 2 — launch + prompt setup ---------- */

.setup-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.setup-heading h2 {
  margin-bottom: 0;
}

.setup-heading .btn-secondary {
  flex: 0 0 auto;
  margin-top: var(--space-1);
}

.launch-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: var(--space-4);
  padding: var(--space-4);
  background: linear-gradient(180deg, rgba(123, 239, 195, 0.08), rgba(5, 11, 9, 0.94));
  border: 1px solid var(--arcade-accent-dim);
  border-radius: var(--radius-lg);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.02),
    0 12px 36px rgba(0, 0, 0, 0.44);
}

.launch-panel-main {
  display: grid;
  grid-template-columns: minmax(170px, 0.45fr) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: end;
}

.selected-game-info {
  display: flex;
  flex-direction: column;
  justify-content: end;
  gap: var(--space-1);
  margin: 0;
  min-width: 0;
}

.selected-game-kicker {
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.selected-game-info h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--arcade-text);
  overflow-wrap: anywhere;
}

.selected-game-info h3 span {
  color: var(--arcade-accent);
}

.launch-controls {
  display: grid;
  grid-template-columns: minmax(190px, auto) minmax(120px, 0.35fr);
  gap: var(--space-4);
  align-items: end;
}

.launch-controls .form-group {
  margin-bottom: 0;
}

.level-group {
  min-width: 132px;
}

/* player-type toggle (Model plays / I'll play) */

.player-type-toggle {
  margin-bottom: 0;
}

.toggle-group {
  display: flex;
  gap: var(--space-2);
}

.toggle-btn {
  appearance: none;
  padding: var(--space-2) var(--space-4);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-md);
  color: var(--arcade-text-dim);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast),
    border-color var(--transition-fast);
}

.toggle-btn:hover {
  border-color: var(--arcade-accent);
  color: var(--arcade-text);
}

.toggle-btn.active {
  background: var(--arcade-accent);
  border-color: var(--arcade-accent);
  color: var(--abyss);
}

.setup-game-stack {
  margin-top: var(--space-5);
}

.setup-cabinet-frame {
  padding: var(--space-3);
}

.setup-game-display {
  display: grid;
  place-items: center;
  gap: var(--space-2);
  min-height: 300px;
  background:
    linear-gradient(rgba(123, 239, 195, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(123, 239, 195, 0.04) 1px, transparent 1px),
    #000;
  background-size: 24px 24px;
  border: 1px solid var(--arcade-accent-dim);
  border-radius: var(--radius-md);
  color: var(--arcade-text);
  text-align: center;
}

.setup-game-display span {
  align-self: end;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.setup-game-display strong {
  align-self: start;
  font-family: var(--font-display);
  font-size: var(--text-4xl);
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--arcade-accent);
  overflow-wrap: anywhere;
  max-width: min(96%, 720px);
}

.setup-game-display .setup-game-meta {
  align-self: start;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.setup-game-meta .meta-chip {
  padding: 2px 8px;
  border: 1px solid var(--arcade-border-soft);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--arcade-text-secondary);
}

.prompting-panel {
  margin-top: var(--space-5);
  padding-top: var(--space-5);
  border-top: 1px solid var(--arcade-border-soft);
}

.prompting-panel-head {
  margin-bottom: var(--space-4);
}

.prompting-panel-head h3 {
  margin: var(--space-1) 0 0;
  font-family: var(--font-mono);
  font-size: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--arcade-text);
}

/* human controls reference (key legend for "I'll play") */

.human-controls-ref {
  margin-bottom: 0;
  padding: var(--space-4);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border);
  border-left: 3px solid var(--arcade-accent);
  border-radius: var(--radius-md);
}

.human-controls-ref h4 {
  margin: 0 0 var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-accent);
}

.control-keys {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.control-key {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--arcade-text);
}

.control-key .key-cap {
  font-weight: 600;
  color: var(--arcade-accent);
}

.control-key .key-label {
  color: var(--arcade-text-dim);
}

.control-note {
  font-size: var(--text-sm);
  color: var(--arcade-text-dim);
}

/* strategy presets */

.strategy-preset-select {
  margin-bottom: var(--space-3);
  cursor: pointer;
}

.strategy-text {
  min-height: 72px;
}

.strategy-warn {
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid rgba(224, 178, 90, 0.4);
  border-left: 3px solid var(--arcade-warning);
  background: rgba(224, 178, 90, 0.08);
  color: var(--arcade-warning);
  font-size: var(--text-sm);
}

.unfold-rules {
  margin-top: var(--space-3);
  border: 1px solid var(--arcade-border-soft);
  border-radius: var(--radius-md);
  background: var(--arcade-panel);
}

.unfold-rules summary {
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--arcade-accent);
  cursor: pointer;
}

.unfold-rules summary:hover {
  color: var(--arcade-accent-bright);
}

.unfold-note {
  margin: 0;
  padding: 0 var(--space-3) var(--space-2);
  color: var(--arcade-text-dim);
  font-size: var(--text-sm);
}

.unfold-chips {
  padding: 0 var(--space-3) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.unfold-group-label {
  margin-bottom: var(--space-1);
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.unfold-group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.unfold-chip {
  appearance: none;
  padding: 3px 10px;
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-md);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.unfold-chip:hover {
  border-color: var(--arcade-accent);
  color: var(--arcade-text);
}

.unfold-chip.added {
  border-color: var(--arcade-accent);
  background: var(--arcade-accent-faint);
  color: var(--arcade-accent);
}

/* model chip rack — cabinet brains (rendered by app.js; select stays hidden) */

.chip-rack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.model-chip {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-md);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.model-chip:hover {
  border-color: var(--arcade-accent);
}

.model-chip.selected {
  background: var(--arcade-accent-faint);
  border-color: var(--arcade-accent);
}

.model-chip-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--arcade-text);
}

.model-chip.selected .model-chip-name {
  color: var(--arcade-accent-bright);
}

.chip-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.chip-badge {
  padding: 1px 6px;
  border: 1px solid var(--arcade-border-soft);
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.chip-badge.provider {
  border-color: var(--arcade-accent-dim);
  color: var(--arcade-accent);
}

/* ---------- 4. step 3 — the cabinet ---------- */

.game-container {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.7fr);
  gap: var(--space-4);
  align-items: start;
  margin-top: var(--space-4);
}

.cabinet-frame {
  padding: var(--space-3);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-accent-dim);
  border-radius: var(--radius-lg);
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(123, 239, 195, 0.12),
    0 12px 32px rgba(0, 0, 0, 0.55);
}

.game-display {
  position: relative;
  aspect-ratio: var(--game-aspect-ratio, 4 / 3);
  background: #000;
  border: 1px solid var(--arcade-accent-dim);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* glass scanlines — on the display itself so they survive :fullscreen */
.game-display::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.2) 0px,
    rgba(0, 0, 0, 0.2) 1px,
    transparent 1px,
    transparent 3px
  );
}

.game-display.is-live {
  border-color: var(--arcade-accent);
  box-shadow: 0 0 12px rgba(123, 239, 195, 0.2);
}

.game-display:fullscreen {
  border: 0;
  border-radius: 0;
  background: #000;
}

.game-display:fullscreen #game-canvas {
  object-fit: contain;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #000;
}

.frame-status {
  position: absolute;
  left: var(--space-2);
  bottom: var(--space-2);
  z-index: 3;
  padding: 2px 8px;
  background: rgba(5, 11, 9, 0.85);
  border: 1px solid var(--arcade-border-soft);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.game-display.is-live .frame-status {
  color: var(--arcade-accent);
  border-color: var(--arcade-accent-dim);
}

/* cabinet status strip — below the glass, inside the frame */
.game-overlay {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0;
  margin-top: var(--space-3);
  border: 1px solid var(--arcade-border-soft);
  background: var(--arcade-bg);
}

.game-overlay > div {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: var(--space-2) var(--space-3);
  border-right: 1px solid var(--arcade-border-soft);
  min-width: 0;
}

.game-overlay > div:last-child {
  border-right: 0;
}

.game-overlay span {
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.game-overlay strong {
  font-family: var(--font-mono);
  font-size: var(--text-md);
  font-variant-numeric: tabular-nums;
  color: var(--arcade-accent);
  overflow-wrap: anywhere;
}

.game-overlay strong span {
  font-family: var(--font-mono);
  font-size: inherit;
  letter-spacing: 0;
  text-transform: none;
  color: inherit;
}

/* session controls — CloudRetro-style affordances */

.session-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.session-controls .btn-secondary {
  font-size: var(--text-2xs);
  padding: var(--space-1) var(--space-3);
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.viewer-toolbar h2 {
  margin: 0;
  flex: 1;
}

/* ---------- 5. trace printer ---------- */

.reasoning-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: 640px;
  padding: var(--space-3) var(--space-3) var(--space-4);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-lg);
}

/* printer slot */
.reasoning-panel::before {
  content: "";
  display: block;
  height: 5px;
  margin: 0 var(--space-2) var(--space-3);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-accent-dim);
  border-radius: 3px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
}

.reasoning-panel h3 {
  margin: 0 0 var(--space-1);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--arcade-accent);
}

.panel-note {
  margin: 0 0 var(--space-3);
  color: var(--arcade-text-dim);
  font-size: var(--text-sm);
}

.strategy-active {
  margin-bottom: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--arcade-accent-faint);
  border: 1px solid var(--arcade-accent-dim);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* mid-run steering: redirect the model while it plays */
.steer-form {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.steer-form input[type="text"] {
  flex: 1;
  font-size: var(--text-sm);
}

.steer-form .btn-secondary {
  flex-shrink: 0;
}

.adherence-ribbon {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border-soft);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.ribbon-label {
  color: var(--arcade-text-secondary);
  white-space: nowrap;
}

.ribbon-bar {
  flex: 1;
  height: 6px;
  background: rgba(123, 239, 195, 0.08);
  border: 1px solid var(--arcade-border-soft);
  overflow: hidden;
}

.ribbon-fill {
  height: 100%;
  background: var(--arcade-accent);
  transition: width var(--transition-base);
}

/* the paper */
#reasoning-log {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow-y: auto;
  padding: var(--space-3) 18px;
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border-soft);
  /* perforated tractor-feed edges */
  background-image:
    radial-gradient(circle at 6px 10px, var(--arcade-panel) 2px, transparent 2.5px),
    radial-gradient(circle at calc(100% - 6px) 10px, var(--arcade-panel) 2px, transparent 2.5px);
  background-size: 100% 20px;
  background-repeat: repeat-y;
}

.reasoning-entry {
  padding: var(--space-2) 0 var(--space-3);
  border-bottom: 1px dashed var(--arcade-border-soft);
  animation: print-feed 200ms ease-out;
}

@keyframes print-feed {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* human moves on the same tape */
.reasoning-entry.human-entry {
  border-left: 2px solid var(--arcade-accent);
  padding-left: var(--space-2);
}

.reasoning-entry .narration {
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.5;
}

.strategy-badge {
  display: inline-block;
  margin-top: var(--space-1);
  padding: 1px 8px;
  background: var(--arcade-accent-faint);
  border: 1px solid var(--arcade-accent-dim);
  color: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.reasoning-entry .action {
  display: inline-block;
  margin-top: var(--space-2);
  padding: 2px 8px;
  border: 1px solid;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.reasoning-entry .action.fast {
  color: var(--arcade-accent);
  border-color: var(--arcade-accent-dim);
}

.reasoning-entry .action.slow {
  color: var(--arcade-warning);
  border-color: rgba(224, 178, 90, 0.45);
}

.reasoning-entry .action.timeout {
  color: var(--arcade-danger);
  border-color: rgba(196, 82, 74, 0.5);
}

/* plan tape */

.plan-tape {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 2px;
  margin: var(--space-2) 0;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.plan-tape::-webkit-scrollbar {
  display: none;
}

.plan-cell {
  flex: 0 0 auto;
  padding: 1px 7px;
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border-soft);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  scroll-snap-align: center;
}

.plan-cell.is-live {
  background: var(--arcade-accent);
  border-color: var(--arcade-accent);
  color: var(--abyss);
  font-weight: 700;
}

.plan-cell.is-done {
  color: var(--arcade-accent-dim);
  text-decoration: line-through;
}

.plan-count {
  flex: 0 0 auto;
  margin-left: var(--space-1);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

/* decision autopsy — the printer's diagnostic tape */

.raw-toggle {
  margin-top: var(--space-2);
}

.raw-toggle summary {
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.raw-toggle summary:hover {
  color: var(--arcade-accent);
}

.raw-toggle[open] summary {
  color: var(--arcade-accent);
}

.autopsy-flow {
  margin: var(--space-2) 0;
  padding: var(--space-2);
  background: var(--arcade-panel);
  border-left: 2px solid var(--arcade-accent-dim);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

.layer-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: var(--space-2) 0;
}

.layer {
  border: 1px solid var(--arcade-border-soft);
  background: var(--arcade-panel);
}

.layer.layer-tactic {
  border-color: var(--arcade-accent-dim);
  background: var(--arcade-accent-faint);
}

.layer-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  cursor: pointer;
}

.layer-name {
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.layer-tactic .layer-name {
  color: var(--arcade-accent);
}

.layer-count {
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.layer-text {
  padding: var(--space-2);
  border-top: 1px solid var(--arcade-border-soft);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 180px;
  overflow-y: auto;
}

.reasoning-entry .response {
  margin-top: var(--space-2);
  padding: var(--space-2);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border-soft);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------- 6. run summary ---------- */

#game-end-message {
  margin-top: var(--space-5);
  padding: var(--space-5);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-accent-dim);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
}

#game-end-message h3 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-accent);
}

.final-score-line {
  margin: 0 0 var(--space-3);
  font-family: var(--font-mono);
  color: var(--arcade-text-secondary);
}

.final-score-line span {
  color: var(--arcade-text);
  font-weight: 700;
}

.summary-strategy {
  margin-bottom: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--arcade-well);
  border-left: 2px solid var(--arcade-accent-dim);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.summary-adherence {
  margin-bottom: var(--space-3);
  font-size: var(--text-md);
}

.adherence-label {
  display: inline-block;
  margin-right: var(--space-2);
  padding: 2px 10px;
  border: 1px solid;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.adherence-strongly {
  color: var(--arcade-accent);
  border-color: var(--arcade-accent-dim);
  background: var(--arcade-accent-faint);
}

.adherence-partially {
  color: var(--arcade-warning);
  border-color: rgba(224, 178, 90, 0.4);
  background: rgba(224, 178, 90, 0.08);
}

.adherence-drifted {
  color: var(--arcade-danger);
  border-color: rgba(196, 82, 74, 0.4);
  background: rgba(196, 82, 74, 0.08);
}

.adherence-detail {
  color: var(--arcade-text-secondary);
}

.summary-highlights h4 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-xs);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text-secondary);
}

.summary-highlights ul {
  margin: 0 0 var(--space-3);
  padding: 0;
  list-style: none;
}

.summary-highlights li {
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-1);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border-soft);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.hl-action {
  color: var(--arcade-accent);
  font-weight: 700;
}

.hl-score {
  color: var(--arcade-warning);
}

/* ---------- 7. operator desk (prompt dashboard) ---------- */

.dashboard-heading {
  padding-top: var(--space-8);
  margin-bottom: var(--space-5);
}

.dashboard-heading p:last-child {
  margin: 0;
  color: var(--arcade-text-secondary);
}

.dashboard-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--space-4);
  min-height: 500px;
}

.dashboard-sidebar {
  display: flex;
  flex-direction: column;
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  max-height: 72vh;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--arcade-border);
}

.sidebar-tab {
  appearance: none;
  flex: 1;
  padding: var(--space-2);
  background: transparent;
  border: 0;
  color: var(--arcade-text-dim);
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.sidebar-tab:hover {
  color: var(--arcade-text);
}

.sidebar-tab.active {
  color: var(--arcade-accent);
  background: var(--arcade-accent-faint);
  box-shadow: inset 0 -2px 0 var(--arcade-accent);
}

.sidebar-panel {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
}

.sidebar-panel.active {
  display: flex;
}

.sidebar-panel > input[type="text"] {
  margin: var(--space-2);
  width: calc(100% - var(--space-4));
}

.sidebar-list {
  display: flex;
  flex-direction: column;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid rgba(123, 239, 195, 0.06);
  color: var(--arcade-text-secondary);
  font-size: var(--text-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.sidebar-item:hover {
  background: var(--arcade-accent-faint);
}

.sidebar-item.active {
  background: var(--arcade-accent-faint);
  box-shadow: inset 2px 0 0 var(--arcade-accent);
}

.sidebar-item-name {
  flex: 1;
  color: var(--arcade-text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.sidebar-item-meta {
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.config-indicator {
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--arcade-border);
}

.config-indicator.configured {
  background: var(--arcade-accent);
  box-shadow: var(--lamp-glow);
}

.sidebar-group-label {
  padding: var(--space-2) var(--space-3);
  background: var(--arcade-well);
  color: var(--arcade-text-dim);
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.layer-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 1px solid var(--arcade-accent-dim);
  background: var(--arcade-accent-faint);
  color: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 700;
}

.featured-star {
  border-color: rgba(224, 178, 90, 0.4);
  background: rgba(224, 178, 90, 0.1);
  color: var(--arcade-warning);
}

.editor-panel {
  padding: var(--space-5);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-lg);
}

.editor-panel h3 {
  margin: 0 0 var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.editor-panel h3 span {
  color: var(--arcade-accent);
}

.editor-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  text-align: center;
}

.editor-section {
  margin-bottom: var(--space-5);
}

.sub-label {
  margin-top: var(--space-2);
  color: var(--arcade-text-dim);
  font-size: var(--text-xs);
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--arcade-border-soft);
}

.level-context-entry {
  margin-bottom: var(--space-2);
}

.prompt-preview {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border);
  border-radius: var(--radius-md);
}

.prompt-preview h4 {
  margin: 0 0 var(--space-3);
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-accent);
}

.preview-message {
  margin-bottom: var(--space-3);
}

.preview-role {
  display: inline-block;
  margin-bottom: var(--space-1);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--arcade-warning);
}

.preview-message pre {
  margin: 0;
  padding: var(--space-3);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border-soft);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-x: auto;
}

.preview-settings {
  margin-top: var(--space-2);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.variable-hints {
  margin-top: var(--space-2);
  color: var(--arcade-text-dim);
  font-size: var(--text-sm);
}

.variable-hints code {
  padding: 1px 4px;
  background: var(--arcade-accent-faint);
  color: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: 0.95em;
}

.dashboard-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--arcade-accent);
  color: var(--abyss);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--transition-base), transform var(--transition-base);
  pointer-events: none;
}

.dashboard-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- 8. tournament leaderboard ---------- */

.leaderboard-section {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(24px, 4vw, 54px) var(--space-4) 90px;
}

body[data-section="leaderboard-dashboard"] .marble-popout {
  display: none;
}

.leaderboard-heading {
  max-width: 760px;
  margin-bottom: var(--space-5);
}

.leaderboard-error {
  padding: var(--space-3);
  border: 1px solid var(--arcade-danger, #ff7b7b);
  color: var(--arcade-danger, #ff7b7b);
  font-family: var(--font-mono);
}

.tournament-champion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  min-height: 210px;
  padding: clamp(24px, 5vw, 58px);
  border: 1px solid var(--arcade-accent-dim);
  background:
    radial-gradient(circle at 84% 34%, rgba(123, 239, 195, 0.14), transparent 32%),
    linear-gradient(135deg, rgba(15, 45, 36, 0.94), rgba(3, 11, 9, 0.98));
  box-shadow: inset 0 0 60px rgba(123, 239, 195, 0.04);
}

.tournament-kicker {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tournament-kicker .lamp-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--arcade-accent);
  box-shadow: 0 0 12px var(--arcade-accent);
}

.tournament-champion h3 {
  margin: var(--space-2) 0;
  color: var(--arcade-text);
  font-size: clamp(30px, 5vw, 66px);
  line-height: 0.98;
}

.tournament-champion p:last-child {
  max-width: 680px;
  color: var(--arcade-text-dim);
}

.tournament-crown {
  color: rgba(123, 239, 195, 0.14);
  font-family: var(--font-display);
  font-size: clamp(92px, 16vw, 190px);
  line-height: 0.75;
}

.tournament-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: var(--space-4) 0;
  border: 1px solid var(--arcade-border-soft);
}

.tournament-stats article {
  padding: var(--space-4);
  border-right: 1px solid var(--arcade-border-soft);
}

.tournament-stats article:last-child {
  border-right: 0;
}

.tournament-stats strong,
.tournament-stats span {
  display: block;
}

.tournament-stats strong {
  color: var(--arcade-accent);
  font-family: var(--font-display);
  font-size: clamp(26px, 4vw, 46px);
}

.tournament-stats span {
  margin-top: 4px;
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
}

.tournament-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 0.8fr);
  gap: var(--space-4);
}

.tournament-panel {
  margin-top: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--arcade-border-soft);
  background: rgba(2, 9, 7, 0.72);
}

.tournament-layout .tournament-panel {
  margin-top: 0;
}

.tournament-panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.tournament-panel-head h3 {
  margin: 2px 0 0;
  color: var(--arcade-text);
}

.tournament-panel-head > span {
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.tournament-standing-row {
  display: grid;
  grid-template-columns: 54px minmax(180px, 1.4fr) minmax(150px, 1fr) minmax(60px, 0.4fr);
  align-items: center;
  gap: var(--space-3);
  min-height: 62px;
  padding: var(--space-2) var(--space-3);
  border-top: 1px solid var(--arcade-border-soft);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
}

.tournament-standing-head {
  min-height: 34px;
  border-top: 0;
  color: var(--arcade-text-faint);
  font-size: var(--text-xs);
  text-transform: uppercase;
}

.tournament-standing-row.is-champion {
  border-color: var(--arcade-accent-dim);
  background: rgba(123, 239, 195, 0.06);
}

.tournament-standing-row > span strong,
.tournament-standing-row > span small {
  display: block;
}

.tournament-standing-row > span strong,
.tournament-standing-row > strong:last-child {
  color: var(--arcade-text);
}

.tournament-standing-row > span small {
  margin-top: 3px;
  color: var(--arcade-accent-dim);
  text-transform: uppercase;
}

.tournament-rank {
  color: var(--arcade-accent);
  font-size: var(--text-lg);
}

.tournament-challengers {
  display: grid;
  gap: var(--space-2);
}

.tournament-challenger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--arcade-border-soft);
}

.tournament-challenger span {
  padding: 2px 5px;
  color: #07120e;
  background: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: 9px;
}

.tournament-challenger strong {
  color: var(--arcade-text);
  font-size: var(--text-sm);
}

.tournament-empty {
  color: var(--arcade-text-dim);
  font-size: var(--text-sm);
}

.tournament-games,
.tournament-history {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-2);
}

.tournament-games article,
.tournament-history-card {
  min-height: 112px;
  padding: var(--space-3);
  border: 1px solid var(--arcade-border-soft);
}

.tournament-games span,
.tournament-games strong,
.tournament-games small,
.tournament-history-card span,
.tournament-history-card strong,
.tournament-history-card small {
  display: block;
}

.tournament-games span,
.tournament-history-card span {
  color: var(--arcade-accent-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.tournament-games strong,
.tournament-history-card strong {
  margin: var(--space-2) 0;
  color: var(--arcade-text);
}

.tournament-games small,
.tournament-history-card small {
  color: var(--arcade-text-dim);
  line-height: 1.45;
}

.tournament-history-card.is-latest {
  border-color: var(--arcade-accent-dim);
}

@media (max-width: 780px) {
  .tournament-champion {
    align-items: flex-start;
  }

  .tournament-crown {
    display: none;
  }

  .tournament-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .tournament-stats article:nth-child(2) {
    border-right: 0;
  }

  .tournament-stats article:nth-child(-n + 2) {
    border-bottom: 1px solid var(--arcade-border-soft);
  }

  .tournament-layout {
    grid-template-columns: 1fr;
  }

  .tournament-standing-row {
    grid-template-columns: 40px minmax(130px, 1fr) minmax(88px, 0.7fr);
  }

  .tournament-standing-row > strong:last-child,
  .tournament-standing-head span:last-child {
    display: none;
  }
}


/* ---------- 8. telemetry ---------- */

.telemetry-section .dashboard-heading {
  margin-bottom: var(--space-4);
}

/* electric-panel nodes are built by telemetry-dashboard.js — keep the
   class, retheme it as a plain deck panel */
.electric-panel {
  padding: var(--space-4);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border-soft);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}

/* --- exhibit stations: the A → B → C → D guided path ------------------- */

.telemetry-station {
  margin-bottom: var(--space-4);
  background: var(--arcade-panel);
  border: 1px solid var(--arcade-border-soft);
  border-radius: var(--radius-lg);
}

.station-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  list-style: none;
}

/* <summary> heads are buttons: show it, and keep focus visible */
details.telemetry-station > summary.station-head {
  cursor: pointer;
  user-select: none;
}

details.telemetry-station > summary.station-head::-webkit-details-marker {
  display: none;
}

details.telemetry-station > summary.station-head:focus-visible {
  outline: 2px solid var(--arcade-accent);
  outline-offset: -2px;
}

details.telemetry-station > summary.station-head:hover .station-title {
  color: var(--arcade-accent-bright);
}

/* The one loud element on the page: pixel-bitmap station letters, set in the
   Silkscreen face that the cabinet loads but the mono-alias theme never uses. */
.station-letter {
  flex: 0 0 auto;
  min-width: 44px;
  font-family: 'Silkscreen', var(--font-mono);
  font-size: 30px;
  line-height: 1;
  text-align: center;
  color: var(--arcade-accent);
  text-shadow: 0 0 12px rgba(123, 239, 195, 0.35);
}

.station-title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.station-title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--arcade-text);
}

.station-stat {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}

.station-stat strong {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  color: var(--arcade-accent);
}

.station-stat small {
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.station-caret {
  flex: 0 0 auto;
  color: var(--arcade-text-dim);
  font-size: var(--text-md);
  transition: transform var(--transition-fast);
}

details[open] > .station-head .station-caret {
  transform: rotate(90deg);
}

/* Museum plaque: the research-lineage caption each station opens with */
.station-plaque {
  margin: 0 var(--space-4) var(--space-4);
  padding: var(--space-2) 0 var(--space-2) var(--space-3);
  border-left: 1px solid var(--brass);
  color: var(--brass);
  font-size: var(--text-xs);
  line-height: 1.6;
  max-width: 68ch;
}

.station-inner {
  padding-bottom: var(--space-2);
}

.station-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: 0 var(--space-4) var(--space-4);
}

.station-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.station-cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.station-block {
  min-width: 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--arcade-border-soft);
}

.station-sub {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin: 0 0 var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--arcade-text-secondary);
}

.station-sub span {
  font-weight: 400;
  font-size: var(--text-2xs);
  color: var(--arcade-text-dim);
}

.station-microlabel {
  margin: 0 0 var(--space-2);
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.station-next {
  display: inline-block;
  margin: 0 var(--space-4) var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
  text-decoration: none;
  border-bottom: 1px solid var(--arcade-border-soft);
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.station-next:hover,
.station-next:focus-visible {
  color: var(--arcade-accent-bright);
  border-color: var(--arcade-accent);
}

.telemetry-panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.telemetry-panel-heading h3 {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-md);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.telemetry-panel-heading .step-label {
  margin-bottom: var(--space-1);
}

.telemetry-panel-heading > span {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.telemetry-status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  padding: 0;
  overflow: hidden;
}

.telemetry-status-strip > div {
  padding: var(--space-3) var(--space-4);
  border-right: 1px solid var(--arcade-border-soft);
}

.telemetry-status-strip > div:last-child {
  border-right: 0;
}

.telemetry-status-strip span {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.telemetry-status-strip strong {
  display: block;
  margin-top: var(--space-1);
  color: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  overflow-wrap: anywhere;
}

.telemetry-backend-panel {
  background:
    linear-gradient(180deg, rgba(123, 239, 195, 0.055), transparent 58%),
    var(--arcade-panel);
}

.telemetry-backend-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}

.backend-status-card {
  position: relative;
  min-height: 96px;
  padding: var(--space-3);
  overflow: hidden;
  background: rgba(0, 18, 15, 0.72);
  border: 1px solid rgba(123, 239, 195, 0.18);
  border-radius: var(--radius-sm);
}

.backend-status-card::before {
  content: "";
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--arcade-text-dim);
  box-shadow: none;
}

.backend-status-card span,
.backend-status-card strong,
.backend-status-card small {
  position: relative;
  z-index: 1;
  display: block;
}

.backend-status-card span {
  padding-right: var(--space-5);
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.backend-status-card strong {
  margin-top: var(--space-2);
  color: var(--arcade-text);
  font-family: var(--font-mono);
  font-size: var(--text-md);
  line-height: 1.25;
}

.backend-status-card small {
  margin-top: var(--space-2);
  color: var(--arcade-text-secondary);
  font-size: var(--text-xs);
  line-height: 1.35;
}

.backend-status-online {
  border-color: rgba(123, 239, 195, 0.34);
}

.backend-status-online::before {
  background: var(--mint);
  box-shadow: var(--lamp-glow);
}

.backend-status-warn {
  border-color: rgba(224, 178, 90, 0.34);
}

.backend-status-warn::before {
  background: var(--brass);
  box-shadow: 0 0 10px rgba(224, 178, 90, 0.45);
}

.backend-status-offline {
  border-color: rgba(143, 179, 165, 0.16);
}

.leaderboard-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-4);
}

.leaderboard-column {
  min-width: 0;
}

.leaderboard-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--arcade-border-soft);
}

.leaderboard-title-row span {
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.leaderboard-title-row strong {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  color: var(--arcade-text-secondary);
}

.leaderboard-table {
  display: grid;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 26px minmax(100px, 1fr) 48px 52px 54px;
  gap: var(--space-2);
  align-items: center;
  min-height: 40px;
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(123, 239, 195, 0.07);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.leaderboard-row:last-child {
  border-bottom: 0;
}

.leaderboard-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.leaderboard-row strong {
  display: block;
  color: var(--arcade-text);
  font-size: var(--text-sm);
}

.leaderboard-row small {
  display: block;
  color: var(--arcade-text-dim);
  font-size: var(--text-xs);
}

.leaderboard-head,
.usage-head,
.session-head {
  min-height: 26px;
  color: var(--arcade-text-dim);
  font-size: var(--text-2xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.leaderboard-rank {
  color: var(--arcade-accent);
  font-weight: 700;
}

/* bars (tote board, eval outcomes, trace categories) */

.telemetry-bars {
  display: grid;
}

.bar-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  min-height: 36px;
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid rgba(123, 239, 195, 0.07);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--arcade-text-secondary);
}

.bar-row:last-child {
  border-bottom: 0;
}

.bar-row::before {
  content: "";
  position: absolute;
  inset: 2px auto 2px 0;
  width: var(--bar-width, 0%);
  background: var(--arcade-accent-faint);
  border-right: 1px solid var(--arcade-accent);
}

.bar-row > * {
  position: relative;
  z-index: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.bar-row strong {
  color: var(--arcade-text);
  font-variant-numeric: tabular-nums;
}

.bar-row small {
  color: var(--arcade-text-dim);
  font-size: var(--text-xs);
}

.bar-row.tone-danger::before {
  background: rgba(196, 82, 74, 0.14);
  border-right-color: var(--arcade-danger);
}

.bar-row.tone-success::before {
  background: var(--arcade-accent-faint);
  border-right-color: var(--arcade-accent);
}

.bar-row.tone-neutral::before {
  background: rgba(143, 179, 165, 0.1);
  border-right-color: var(--arcade-text-dim);
}

/* persistence pipeline */

.pipeline-rail {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--arcade-border-soft);
  background: var(--arcade-well);
}

.pipeline-step {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: var(--space-2);
  min-height: 88px;
  padding: var(--space-3);
  border-right: 1px solid var(--arcade-border-soft);
}

.pipeline-step:last-child {
  border-right: 0;
}

.pipeline-index {
  color: var(--arcade-accent);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 700;
}

.pipeline-step span {
  font-family: var(--font-display);
  font-size: var(--text-2xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--arcade-text-dim);
}

.pipeline-step strong {
  display: block;
  margin: var(--space-1) 0;
  color: var(--arcade-text);
  font-family: var(--font-mono);
  font-size: clamp(var(--text-lg), 2.2vw, var(--text-2xl));
  font-variant-numeric: tabular-nums;
  line-height: 1;
  overflow-wrap: anywhere;
}

.pipeline-step small {
  display: block;
  color: var(--arcade-text-dim);
  font-size: var(--text-xs);
  overflow-wrap: anywhere;
}

/* data flow lanes */

.telemetry-flow {
  display: grid;
  gap: var(--space-3);
  min-height: 310px;
  padding: var(--space-3);
  background: var(--arcade-well);
  border: 1px solid var(--arcade-border-soft);
}

.flow-lane {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 36px;
  align-items: center;
  gap: var(--space-3);
}

.flow-label {
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.flow-line {
  position: relative;
  height: 38px;
  min-width: 0;
  overflow: clip;
  border-bottom: 1px solid var(--arcade-border-soft);
}

.flow-spark {
  position: absolute;
  bottom: 2px;
  width: 3px;
  height: 65%;
  background: currentColor;
  color: var(--arcade-accent);
  opacity: 0.75;
}

.flow-count {
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* event family tints (flow sparks + event log) */

.family-evaluation { color: var(--arcade-accent); }
.family-user_experience { color: var(--arcade-accent-bright); }
.family-clickthrough { color: var(--arcade-warning); }
.family-model_telemetry { color: var(--foam-dim); }
.family-trace { color: var(--arcade-text-dim); }
.family-system { color: var(--arcade-danger); }

/* event log */

.telemetry-event-table {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--arcade-border-soft);
  background: var(--arcade-well);
  padding: 0 var(--space-2);
}

.telemetry-event-row {
  display: grid;
  grid-template-columns:
    minmax(54px, 0.72fr)
    minmax(68px, 0.82fr)
    minmax(86px, 1.2fr)
    minmax(58px, 0.7fr)
    minmax(44px, 0.52fr);
  gap: var(--space-2);
  align-items: center;
  min-height: 34px;
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(123, 239, 195, 0.06);
  color: var(--arcade-text-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.telemetry-event-row:last-child {
  border-bottom: 0;
}

.telemetry-event-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.telemetry-event-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--arcade-well);
  color: var(--arcade-text-dim);
  font-weight: 700;
  font-size: var(--text-2xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.event-family {
  font-weight: 700;
}

/* charts */

.telemetry-funnel {
  display: grid;
}

.funnel-step {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-2);
  align-items: center;
  min-height: 34px;
  padding: var(--space-2);
  border-bottom: 1px solid rgba(123, 239, 195, 0.07);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--arcade-text-secondary);
}

.funnel-step:last-child {
  border-bottom: 0;
}

.funnel-step::before {
  content: "";
  position: absolute;
  inset: 2px auto 2px 0;
  width: var(--bar-width, 0%);
  background: var(--arcade-accent-faint);
  border-right: 1px solid var(--arcade-accent);
}

.funnel-step > * {
  position: relative;
  z-index: 1;
}

.funnel-step strong {
  color: var(--arcade-text);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.funnel-step.tone-danger::before {
  background: rgba(196, 82, 74, 0.14);
  border-right-color: var(--arcade-danger);
}

.funnel-step.tone-success::before {
  background: var(--arcade-accent-faint);
  border-right-color: var(--arcade-accent);
}

.funnel-step.tone-neutral::before {
  background: rgba(143, 179, 165, 0.1);
  border-right-color: var(--arcade-text-dim);
}

.telemetry-model-list {
  display: grid;
  gap: var(--space-1);
}

.model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 40px;
  padding: var(--space-2) 0;
  border-bottom: 1px solid rgba(123, 239, 195, 0.07);
}

.model-row:last-child {
  border-bottom: 0;
}

.model-row strong {
  color: var(--arcade-text);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.model-row span {
  display: block;
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.telemetry-empty {
  padding: var(--space-4);
  color: var(--arcade-text-dim);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- 8b. floating autoplay player ---------- */

.marble-popout {
  --marble-popout-inset: clamp(12px, 2vmin, 28px);
  position: fixed;
  right: var(--marble-popout-inset);
  bottom: var(--marble-popout-inset);
  z-index: 420;
  width: clamp(340px, min(39vw, 66vh), 760px);
  max-width: calc(100vw - var(--marble-popout-inset) - var(--marble-popout-inset));
  max-height: calc(100dvh - var(--marble-popout-inset) - var(--marble-popout-inset));
  background: #000;
  border: 1px solid rgba(123, 239, 195, 0.46);
  border-radius: 8px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.75),
    0 16px 44px rgba(0, 0, 0, 0.65),
    0 0 30px rgba(123, 239, 195, 0.18);
  overflow: hidden;
  touch-action: pan-y;
}

.marble-popout.is-hidden {
  display: none;
}

.marble-popout.is-expanded {
  width: min(1120px, calc(100vw - var(--marble-popout-inset) - var(--marble-popout-inset)));
  height: min(720px, calc(100dvh - var(--marble-popout-inset) - var(--marble-popout-inset)));
}

.marble-popout-chrome {
  /* in flow above the frame — an absolute overlay occluded the top of the
     board once the embed stopped cover-cropping */
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: 34px;
  padding: 4px 5px 4px var(--space-2);
  background: linear-gradient(180deg, rgba(18, 37, 29, 0.98), rgba(5, 11, 9, 0.9));
  border-bottom: 1px solid rgba(123, 239, 195, 0.34);
  opacity: 0.92;
  transform: translateY(0);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.marble-popout:hover .marble-popout-chrome,
.marble-popout:focus-within .marble-popout-chrome,
.marble-popout.is-expanded .marble-popout-chrome {
  opacity: 1;
  transform: translateY(0);
}

.marble-popout-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-family: var(--font-display);
  font-size: var(--text-xs);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--arcade-text);
  text-shadow: 0 0 8px rgba(123, 239, 195, 0.22);
}

.marble-popout-title .lamp {
  flex: 0 0 auto;
  gap: 0;
  font-size: 0;
}

.marble-popout-title > span:not(.lamp) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marble-popout-title strong {
  color: var(--arcade-accent-bright);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.marble-popout-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 3px;
}

.marble-popout-action {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 24px;
  padding: 0;
  background: rgba(5, 11, 9, 0.82);
  border: 1px solid rgba(123, 239, 195, 0.24);
  border-radius: 3px;
  color: var(--arcade-text);
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast),
    background var(--transition-fast);
}

.marble-popout-action:hover,
.marble-popout-action:focus-visible {
  background: var(--arcade-accent-faint);
  border-color: var(--arcade-accent);
  color: var(--arcade-accent-bright);
}

.marble-popout-frame {
  position: relative;
  /* follow the streamed game's real ratio (set by marble-popout.js from the
     iframe's marble-frame-size messages); 4/3 fits the attract canvas and
     most GVGAI boards until the first frame lands */
  aspect-ratio: var(--marble-popout-aspect, 4 / 3);
  padding: 6px;
  background: #000;
}

.marble-popout.is-expanded .marble-popout-frame {
  height: calc(100% - 34px);
  aspect-ratio: auto;
}

.marble-popout-frame iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* ---------- 9. responsive ---------- */

@media (max-width: 1024px) {
  .marble-popout {
    width: min(440px, calc(100vw - var(--marble-popout-inset) - var(--marble-popout-inset)));
  }

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

  .station-cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .pipeline-step {
    border-bottom: 1px solid var(--arcade-border-soft);
  }
}

@media (min-width: 760px) {
  #game-selector .step-note {
    white-space: nowrap;
  }
}

/* ---------- "under development" corner ribbon ----------
   A service tag taped to the cabinet glass. Brass is the theme's existing
   warning token and appears nowhere else in the header, so the band reads as
   maintenance signage rather than a live control. Set in the micro-label
   register (mono / 10px / wide tracking) shared with .titlebar-backend —
   deliberately NOT the Silkscreen face, which .station-letter reserves as the
   page's one loud element.

   Geometry: a 45° band across a corner spans a chord of 2 x its distance from
   that corner, so distance sets how much room the text gets. At ~83px out the
   chord is ~166px against ~122px of text, leaving ~22px of band past the final
   letter before the viewport clips it — closer in and the text reads as though
   it were running off-screen. The band's outer edge therefore sweeps ~134px
   along the titlebar, so .titlebar-status carries a matching padding-right to
   move the status cluster clear of it. Inert and unselectable: it overlays the
   titlebar and the page beneath it, and must never eat a tap. */
.dev-ribbon {
  position: fixed;
  top: 54px;
  right: -58px;
  z-index: 101; /* over the sticky titlebar (100), under the boot screen (1000) */
  width: 220px;
  margin: 0;
  padding: 4px 0;
  background: linear-gradient(180deg, rgba(18, 37, 29, 0.97), rgba(13, 28, 22, 0.97));
  border-top: 1px solid rgba(224, 178, 90, 0.32);
  border-bottom: 1px solid rgba(224, 178, 90, 0.32);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  color: var(--brass);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: 13px;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  white-space: nowrap;
  transform: rotate(45deg);
  pointer-events: none;
  user-select: none;
}

/* Clears the ribbon's diagonal sweep across the titlebar. Paired with
   .dev-ribbon — if the ribbon goes, this goes with it. */
.titlebar-status {
  padding-right: 100px;
}

/* The ribbon costs the titlebar 100px of its right end, which the brand, nav
   and status cluster can only spare on a wide viewport — below this the status
   items start wrapping to two lines. A signage flourish is not worth breaking
   the header over, so retire the ribbon and its clearance together and let the
   narrow layout stand as it did before. */
@media (max-width: 1100px) {
  .dev-ribbon {
    display: none;
  }

  .titlebar-status {
    padding-right: 0;
  }
}

@media (max-width: 900px) {
  /* minmax(0, 1fr) rather than 1fr: a plain 1fr keeps an `auto` minimum,
     so a wide child (event table, code editor) can force the collapsed
     column past the viewport */
  .launch-panel,
  .launch-panel-main {
    grid-template-columns: minmax(0, 1fr);
  }

  .launch-panel .btn-start {
    width: 100%;
  }

  .game-container {
    grid-template-columns: minmax(0, 1fr);
  }

  .reasoning-panel {
    max-height: 420px;
  }

  .dashboard-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-sidebar {
    max-height: 320px;
  }

  .leaderboard-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .station-cols,
  .station-cols-3 {
    grid-template-columns: minmax(0, 1fr);
  }

  .telemetry-status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .telemetry-status-strip > div {
    border-bottom: 1px solid var(--arcade-border-soft);
  }

  .arcade-titlebar {
    flex-wrap: wrap;
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
  }

  .titlebar-sub {
    display: none;
  }

  .arcade-titlebar #main-nav {
    order: 3;
    flex-basis: 100%;
    margin-left: 0;
  }

  .arcade-titlebar .nav-link {
    flex: 1;
    padding: var(--space-2) 0;
  }
}

@media (max-width: 700px), ((max-height: 520px) and (max-width: 900px)) {
  #app {
    padding: 0 var(--space-3) calc(var(--space-8) + 52px);
  }

  .telemetry-backend-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-row {
    flex-direction: column;
    gap: 0;
  }

  .setup-heading {
    flex-direction: column;
    align-items: stretch;
  }

  .setup-heading .btn-secondary {
    width: fit-content;
  }

  .launch-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  .toggle-group {
    flex-wrap: wrap;
  }

  .toggle-btn {
    flex: 1 1 138px;
  }

  .btn-start {
    min-width: 0;
  }

  .selected-game-info h3 {
    font-size: var(--text-lg);
  }

  .setup-game-display {
    min-height: 190px;
  }

  .setup-game-display strong {
    font-size: var(--text-2xl);
  }

  .station-head {
    gap: var(--space-3);
  }

  .station-letter {
    min-width: 32px;
    font-size: 22px;
  }

  .game-overlay {
    grid-auto-flow: row;
    grid-template-columns: repeat(3, 1fr);
  }

  /* the event log keeps its five columns and scrolls inside its own box */
  .telemetry-event-table {
    overflow-x: auto;
  }

  .telemetry-event-row {
    min-width: 330px;
  }

  .flow-lane {
    grid-template-columns: 84px minmax(0, 1fr) 34px;
    gap: var(--space-2);
  }

  .marble-popout {
    left: var(--space-2);
    right: var(--space-2);
    bottom: var(--space-2);
    width: auto;
    min-height: 52px;
    max-height: 52px;
    border: 1px solid rgba(123, 239, 195, 0.46);
    border-radius: 8px;
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.75),
      0 14px 36px rgba(0, 0, 0, 0.66),
      0 0 26px rgba(123, 239, 195, 0.2);
  }

  .marble-popout:not(.is-expanded)::before {
    content: "";
    position: absolute;
    top: 5px;
    left: 50%;
    z-index: 4;
    width: 34px;
    height: 2px;
    border-radius: 999px;
    background: rgba(228, 251, 240, 0.55);
    transform: translateX(-50%);
  }

  .marble-popout:not(.is-expanded) .marble-popout-chrome {
    position: relative;
    min-height: 52px;
    padding: 14px var(--space-3) 8px;
    opacity: 1;
    border-bottom: 0;
  }

  .marble-popout:not(.is-expanded) .marble-popout-action:not(#marble-popout-expand) {
    display: none;
  }

  .marble-popout:not(.is-expanded) .marble-popout-frame {
    height: 0;
    aspect-ratio: auto;
    overflow: hidden;
  }

  .marble-popout.is-expanded {
    width: auto;
    height: min(58dvh, 460px);
    min-height: 0;
    max-height: calc(100dvh - 96px);
    top: auto;
    left: var(--space-2);
    right: var(--space-2);
    bottom: var(--space-2);
    border-radius: 8px;
  }

  .marble-popout.is-expanded .marble-popout-chrome {
    min-height: 38px;
    padding: 5px var(--space-2);
  }

  .marble-popout.is-expanded .marble-popout-frame {
    height: calc(100% - 38px);
    min-height: 0;
  }

  .marble-popout-title {
    font-size: var(--text-xs);
  }

  .marble-popout-action {
    width: 28px;
    height: 26px;
    font-size: var(--text-lg);
  }

  #game-selector .step-note {
    white-space: normal;
  }
}

/* ---------- 10. reduced motion ---------- */

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

/* ---------- 11. guardrail bars ---------- */

.guardrail-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2fr auto;
  gap: var(--space-2);
  align-items: center;
  min-height: 36px;
  padding: var(--space-2);
  border-bottom: 1px solid rgba(123, 239, 195, 0.07);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--arcade-text-secondary);
}

.guardrail-bar:last-child {
  border-bottom: 0;
}

.bar-track {
  position: relative;
  height: 8px;
  background: rgba(123, 239, 195, 0.07);
  border-radius: 2px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--arcade-accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ---------- 12. marble controls ---------- */

.marble-controls {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) 0;
}

/* ---------- 12b. fine-tune pipeline panel ---------- */

.finetune-run.finetune-tone-danger .bar-fill {
  background: var(--arcade-danger);
}

.finetune-run.finetune-tone-success .bar-fill {
  background: var(--arcade-success);
}

.finetune-stage {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--arcade-text-secondary);
}

.finetune-stage small {
  color: var(--arcade-accent-dim);
}

.finetune-stage .finetune-error-text {
  color: var(--arcade-danger);
}

.weight-change {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  white-space: nowrap;
}

.weight-change.positive { color: var(--arcade-success); }
.weight-change.negative { color: var(--arcade-danger); }

.btn-small {
  padding: 4px 12px;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: rgba(123, 239, 195, 0.07);
  color: var(--arcade-text-secondary);
  border: 1px solid rgba(123, 239, 195, 0.15);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-small:hover:not(:disabled) {
  background: rgba(123, 239, 195, 0.12);
}

.btn-small:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-small.btn-danger {
  border-color: rgba(239, 123, 123, 0.2);
  color: rgba(239, 123, 123, 0.8);
}
