/*
File: components.css
Description: Shared design system components including layout, typography,
    buttons, panels, forms, and accessibility rules.
Author(s): Tyler Black, Richard Hall, Steph Rivera, Cameron Greeson
*/

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Animated inputs for the panel energy loop (one loop drives every layer) */
@property --energy {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

@property --pulse {
  syntax: "<number>";
  inherits: true;
  initial-value: 0.6;
}

@keyframes panel-energy {
  0% {
    --energy: 0;
    --pulse: 0.5;
  }

  50% {
    --pulse: 1;
  }

  100% {
    --energy: 1;
    --pulse: 0.5;
  }
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    linear-gradient(
      to right,
      var(--grid) var(--border-1),
      transparent var(--border-1)
    ),
    linear-gradient(
      to bottom,
      var(--grid) var(--border-1),
      transparent var(--border-1)
    );
  background-size: var(--grid-size) var(--grid-size);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-14);
  line-height: 1.5;
}

/* Old-monitor vignette: darkens the grid toward the screen edges */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    transparent 50%,
    var(--vignette) 100%
  );
}

/* Site header and brand wordmark */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  background:
    linear-gradient(
        90deg,
        color-mix(in srgb, var(--cyan) 45%, transparent),
        color-mix(in srgb, var(--magenta) 45%, transparent)
      )
      bottom / 100% var(--border-1) no-repeat,
    var(--surface);
}

.header-wordmark,
[data-testid="header-wordmark"] {
  font-family: var(--font-display);
  font-size: var(--text-22);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-strong);
  text-decoration: none;
  text-shadow:
    calc(-1 * var(--anaglyph-offset-sm)) 0 var(--anaglyph-cyan),
    var(--anaglyph-offset-sm) 0 var(--anaglyph-red);
}

.header-wordmark:hover,
[data-testid="header-wordmark"]:hover {
  color: var(--cyan);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}

.header-username {
  font-family: var(--font-mono);
  font-size: var(--text-14);
  color: var(--cyan);
}

.header-logout-form {
  display: inline-block;
  margin: 0;
}

.header-link {
  font-family: var(--font-display);
  font-size: var(--text-14);
  font-weight: 700;
  color: var(--ink);
  text-decoration: none;
}

.header-link:hover {
  color: var(--cyan);
  text-decoration: none;
}

/* Main content region, capped and centered */
main {
  max-width: var(--width-page);
  margin-inline: auto;
  padding: var(--space-6);
}

/* Headings get a faint red/cyan anaglyph split */
h1 {
  margin: 0 0 var(--space-4);
  font-family: var(--font-display);
  font-size: var(--text-34);
  line-height: 1.2;
  color: var(--ink-strong);
  text-shadow:
    calc(-1 * var(--anaglyph-offset)) 0 var(--anaglyph-cyan),
    var(--anaglyph-offset) 0 var(--anaglyph-red);
}

/*
Floating panel: cut corners, inner bevel, and a hard offset shadow that
carries energy. One loop (panel-energy) drives the glow pulse, the bright
band running along the shadow edge, the holographic top edge, and the
surface glint.
*/
.floating-panel {
  --panel-shadow: var(--magenta);
  --panel-hot: var(--magenta-hot);
  --panel-glow: var(--glow-magenta);
  position: relative;
  isolation: isolate;
  padding: var(--space-6);
  margin-top: var(--space-6);
  margin-bottom: var(--space-6);
  filter: drop-shadow(
      0 0 calc(var(--glow-tight) * (0.5 + var(--pulse))) var(--panel-glow)
    )
    drop-shadow(0 0 calc(var(--glow-wide) * var(--pulse)) var(--panel-glow));
  animation: panel-energy var(--energy-period) linear infinite;
}

.floating-panel--cyan {
  --panel-shadow: var(--cyan);
  --panel-hot: var(--cyan-hot);
  --panel-glow: var(--glow-cyan);
}

/* Narrow, centered panel for forms and short pages */
.floating-panel--form {
  max-width: var(--width-form);
  margin-inline: auto;
  margin-top: var(--grid-size);
}

.floating-panel::before,
.floating-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  clip-path: polygon(
    var(--cut-window) 0%,
    100% 0%,
    100% calc(100% - var(--cut-window)),
    calc(100% - var(--cut-window)) 100%,
    0% 100%,
    0% var(--cut-window)
  );
}

/* Shadow layer with a hot band sweeping along its edge */
.floating-panel::before {
  background:
    linear-gradient(
        115deg,
        transparent 44%,
        var(--panel-hot) 50%,
        transparent 56%
      )
      calc(100% - var(--energy) * 100%) 0 / 300% 100% no-repeat,
    var(--panel-shadow);
  transform: translate(
    var(--shadow-offset-window),
    var(--shadow-offset-window)
  );
}

/* Surface: metal shading, a drifting glint, and a holographic top edge */
.floating-panel::after {
  background:
    linear-gradient(90deg, var(--cyan), var(--magenta), var(--cyan))
      calc(var(--energy) * 100%) 0 / 200% var(--border-1) repeat-x,
    linear-gradient(
        115deg,
        transparent 40%,
        var(--sheen) 50%,
        transparent 60%
      )
      calc(var(--energy) * 100%) 0 / 300% 100% no-repeat,
    linear-gradient(to bottom, var(--surface-raised), var(--surface));
  background:
    linear-gradient(
        90deg in oklch,
        var(--cyan),
        var(--magenta),
        var(--cyan)
      )
      calc(var(--energy) * 100%) 0 / 200% var(--border-1) repeat-x,
    linear-gradient(
        115deg,
        transparent 40%,
        var(--sheen) 50%,
        transparent 60%
      )
      calc(var(--energy) * 100%) 0 / 300% 100% no-repeat,
    linear-gradient(to bottom, var(--surface-raised), var(--surface));
  box-shadow:
    inset var(--border-1) var(--border-1) 0 var(--bevel-light),
    inset
      calc(-1 * var(--border-1))
      calc(-1 * var(--border-1))
      0
      var(--bevel-dark);
}

/* Admin budget readouts: label left, mono value right */
.budget-readouts {
  margin: 0 0 var(--space-6);
}

.budget-readout {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  border-bottom: var(--border-1) solid var(--line);
}

.budget-readout dt {
  font-size: var(--text-12);
  color: var(--muted);
}

.budget-readout dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-14);
  color: var(--ink-strong);
}

/* Form fields and labels */
label,
.form-label {
  display: block;
  font-family: var(--font-body);
  font-size: var(--text-12);
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--space-1);
}

/* Fields sit in a recessed well */
input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select,
.form-input {
  display: block;
  width: 100%;
  font-family: var(--font-mono);
  font-size: var(--text-14);
  color: var(--ink-strong);
  background-color: var(--bg);
  border: var(--border-1) solid var(--line);
  box-shadow:
    inset 0 var(--border-2) 0 var(--well),
    inset 0 calc(-1 * var(--border-1)) 0 var(--bevel-light);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  border-radius: 0;
  transition:
    border-color var(--press-duration) ease-out,
    box-shadow var(--press-duration) ease-out;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
.form-input {
  max-width: var(--width-form);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus,
.form-input:focus {
  border-color: var(--cyan);
  outline: var(--focus-outline) solid var(--cyan);
  outline-offset: var(--focus-offset);
  box-shadow:
    inset 0 var(--border-2) 0 var(--well),
    0 0 var(--glow-wide) var(--glow-cyan);
}

/* Field error text */
.field-error,
.form-error {
  display: block;
  font-family: var(--font-body);
  font-size: var(--text-12);
  color: var(--magenta);
  margin-top: calc(-1 * var(--space-2));
  margin-bottom: var(--space-3);
}

/* Buttons */
.btn,
button,
input[type="submit"],
input[type="button"] {
  --button-shape: polygon(
    var(--cut-button) 0%,
    100% 0%,
    calc(100% - var(--cut-button)) 100%,
    0% 100%
  );
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: var(--text-14);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-4);
  border: none;
  cursor: pointer;
  text-decoration: none;
  clip-path: var(--button-shape);
  border-radius: 0;
  transition:
    filter var(--press-duration) ease-out,
    transform var(--press-duration) ease-out;
}

/* Primary button: filled cyan parallelogram with magenta hard shadow */
.btn-primary,
.btn--primary {
  position: relative;
  isolation: isolate;
  background: transparent;
  clip-path: none;
  color: var(--bg);
}

.btn-primary::before,
.btn-primary::after,
.btn--primary::before,
.btn--primary::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  clip-path: var(--button-shape);
}

.btn-primary::before,
.btn--primary::before {
  background: var(--magenta);
  transform: translate(
    var(--shadow-offset-button),
    var(--shadow-offset-button)
  );
}

.btn-primary::after,
.btn--primary::after,
.btn-primary:hover::before,
.btn--primary:hover::before {
  background: var(--cyan);
}

/* Hover glows; press pushes the face halfway onto its shadow */
.btn-primary:hover,
.btn--primary:hover {
  filter: drop-shadow(0 0 var(--glow-tight) var(--glow-cyan));
}

.btn-primary:active,
.btn--primary:active {
  transform: translate(
    calc(var(--shadow-offset-button) / 2),
    calc(var(--shadow-offset-button) / 2)
  );
}

.btn-primary:active::before,
.btn--primary:active::before {
  transform: translate(
    calc(var(--shadow-offset-button) / 2),
    calc(var(--shadow-offset-button) / 2)
  );
}

input.btn-primary,
input.btn--primary {
  background: var(--cyan);
  clip-path: var(--button-shape);
}

/* Secondary button: cyan outline */
.btn-secondary,
.btn--secondary {
  background: transparent;
  color: var(--cyan);
  box-shadow: inset 0 0 0 var(--border-1) var(--cyan);
}

.btn-secondary:hover,
.btn--secondary:hover {
  background-color: var(--surface-raised);
  color: var(--ink-strong);
  filter: drop-shadow(0 0 var(--glow-tight) var(--glow-cyan));
}

/* Flash messages */
.flash-container {
  max-width: calc(var(--width-form) + 2 * var(--space-6));
  margin: var(--space-4) auto 0;
  padding-inline: var(--space-6);
}

.flash-message,
[data-testid="flash-message"] {
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  background-color: var(--surface-raised);
  border-left: var(--space-1) solid var(--cyan);
  color: var(--ink-strong);
  font-family: var(--font-body);
  font-size: var(--text-14);
  border-radius: 0;
}

.flash-message--error {
  border-left-color: var(--magenta);
}

/* Links */
a {
  color: var(--cyan);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Read by screen readers, never shown */
.visually-hidden {
  position: absolute;
  inline-size: var(--border-1);
  block-size: var(--border-1);
  margin: calc(var(--border-1) * -1);
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Global focus outline */
:focus-visible {
  outline: var(--focus-outline) solid var(--cyan);
  outline-offset: var(--focus-offset);
}

.btn:focus-visible {
  clip-path: none;
}

/* Difficulty cards */
.start-panel {
  margin-block: 0;
  padding-block: var(--space-4);
}

/* Heading row: the title on the left; Leaderboard and Resume run on the right */
.start-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
}

.start-heading > h1 {
  margin: 0;
}

.start-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.tier-grid {
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(min(100%, calc(var(--grid-size) * 4)), 1fr)
  );
  gap: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
}

.tier-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: var(--border-1) solid var(--line);
  background: var(--surface);
}

.tier-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--text-22);
  line-height: 1.2;
  color: var(--ink-strong);
}

.tier-rules {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-1) var(--space-2);
  margin: 0;
}

.tier-rules dt,
.tier-coming-soon {
  color: var(--muted);
}

.tier-rules dd {
  margin: 0;
  font-family: var(--font-mono);
}

.tier-coming-soon {
  margin: 0;
  padding-block: var(--space-2);
}

.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-6);
}

.start-error {
  color: var(--magenta);
}

/* Stage workspace: header pieces */
.header-brand {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.page-game .header-wordmark {
  white-space: nowrap;
}

@media (max-width: 480px) {
  .page-game .header-wordmark {
    font-size: var(--text-17);
  }
}

@property --spin {
  syntax: "<angle>";
  inherits: true;
  initial-value: 0deg;
}

/* Difficulty badge: a neon parallelogram in the tier's color */
.tier-badge {
  --tier: var(--tier-beginner);
  --tier-ring: var(--tier);
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-4);
  color: var(--tier);
  font-family: var(--font-mono);
  font-size: var(--text-12);
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 0 var(--glow-tight) var(--tier);
  filter: drop-shadow(
      0 0 var(--glow-tight)
        color-mix(in srgb, var(--tier) 70%, transparent)
    )
    drop-shadow(
      0 0 var(--glow-wide) color-mix(in srgb, var(--tier) 35%, transparent)
    );
}

.tier-badge::before,
.tier-badge::after {
  content: "";
  position: absolute;
  z-index: -1;
  clip-path: polygon(
    var(--space-2) 0%,
    100% 0%,
    calc(100% - var(--space-2)) 100%,
    0% 100%
  );
}

.tier-badge::before {
  inset: 0;
  background: var(--tier-ring);
}

.tier-badge::after {
  inset: var(--border-2);
  background: color-mix(in srgb, var(--tier) 12%, var(--surface));
}

.tier-badge--easy {
  --tier: var(--tier-easy);
}

.tier-badge--medium {
  --tier: var(--tier-medium);
}

.tier-badge--hard {
  --tier: var(--tier-hard);
}

.tier-badge--expert {
  --tier: var(--tier-expert);
}

/* Impossible: every tier color races around the rim, and the glow follows */
.tier-badge--impossible {
  --tier: var(--ink-strong);
  --tier-ring: conic-gradient(
    from var(--spin),
    var(--tier-beginner),
    var(--tier-easy),
    var(--tier-medium),
    var(--tier-hard),
    var(--tier-expert),
    var(--tier-beginner)
  );
  filter: drop-shadow(0 0 var(--glow-tight) var(--impossible-glow))
    drop-shadow(0 0 var(--glow-wide) var(--impossible-glow));
  animation: impossible-spin var(--impossible-period) linear infinite;
}

@property --impossible-glow {
  syntax: "<color>";
  inherits: true;
  initial-value: transparent;
}

@keyframes impossible-spin {
  0%,
  100% {
    --spin: 0deg;
    --impossible-glow: var(--tier-hard);
  }

  20% {
    --impossible-glow: var(--tier-expert);
  }

  40% {
    --impossible-glow: var(--tier-beginner);
  }

  60% {
    --impossible-glow: var(--tier-easy);
  }

  80% {
    --impossible-glow: var(--tier-medium);
  }

  99.99% {
    --spin: 360deg;
  }
}

.game-hud,
.game-lives {
  display: flex;
  align-items: center;
}

.game-hud {
  gap: var(--space-4);
}

.game-timer {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--text-22);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Lives: glowing diamonds beside the timer; a lost life is a dim outline */
.game-lives {
  gap: var(--space-2);
}

.game-life {
  inline-size: var(--space-3);
  block-size: var(--space-3);
  border: var(--border-1) solid var(--muted);
  transform: rotate(45deg);
}

.game-life--full {
  border-color: var(--cyan);
  background: var(--cyan);
  box-shadow: 0 0 var(--glow-tight) var(--glow-cyan);
}

/* Stage bar: one cell per stage along the header's bottom edge */
.page-game .site-header {
  position: relative;
  padding-block-end: var(--space-5);
}

.stage-bar {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 0;
  display: flex;
  gap: var(--space-1);
  block-size: var(--space-1);
}

.stage-bar-cell {
  flex: 1;
  background: color-mix(in srgb, var(--muted) 30%, transparent);
}

.stage-bar-cell--done {
  background: color-mix(in srgb, var(--cyan) 50%, transparent);
}

.stage-bar-cell--current {
  --heat-from: var(--cyan);
  --heat-to: var(--cyan);
  --heat-glow: var(--glow-cyan);
  background:
    linear-gradient(to right, var(--heat-from), var(--heat-to))
      left center / calc(var(--heat, 1) * 100%) 100% no-repeat,
    color-mix(in srgb, var(--muted) 30%, transparent);
  box-shadow:
    0 0 var(--glow-tight) var(--heat-glow),
    0 0 var(--glow-wide) var(--heat-glow);
}

/* Stage workspace: the two floating windows */
.page-game .flash-container {
  margin-top: 0;
}

.page-game main {
  max-width: var(--width-game);
  padding-block-end: var(--space-8);
}

/* Clip sideways overflow (Monaco lags a resize) without cutting the glow */
.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-8);
  overflow-x: clip;
  overflow-clip-margin: var(--space-6);
}

.game-layout > .floating-panel {
  display: grid;
  gap: var(--space-4);
  min-inline-size: 0;
  min-block-size: 0;
  margin-block: 0;
  padding: var(--space-5);
}

.game-overlord-panel {
  grid-template-rows: auto auto;
}

.game-editor-panel {
  --console-min-size: var(--grid-size);
  --console-default-size: calc(var(--grid-size) * 3);
  --editor-min-size: calc(var(--grid-size) * 2);
  grid-template-rows: auto auto auto auto;
  gap: var(--space-3);
  padding: var(--space-4);
}

/* Submit sits bottom right (design §8) */
.game-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

.game-actions .btn:disabled {
  cursor: progress;
  filter: saturate(0.5);
}

/*
Console: an IDE-style panel under the editor. Its top edge is a drag
handle, the bar collapses it, and its body scrolls inside the editor
window, never the page. console.js sets --console-size on the editor
window while the console is open; the editor gives up what it takes.
Wide output scrolls in the body instead of widening the window.
*/
.game-console {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-inline-size: 0;
  border-block-start: var(--border-1) solid var(--line);
}

/* The handle straddles the console's top line, which lights up cyan */
.game-console-handle {
  position: relative;
  block-size: var(--space-2);
  margin-block: calc(var(--space-1) * -1);
  cursor: row-resize;
  touch-action: none;
}

.game-console-handle::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block-start: calc(var(--space-1) - var(--border-1));
  block-size: var(--border-2);
}

.game-console-handle:hover::after,
.game-console-handle:focus-visible::after,
.game-console--resizing .game-console-handle::after {
  background: var(--cyan);
}

/* The bar reads like the editor's file tab, not a button */
.game-console-toggle {
  justify-content: flex-start;
  gap: var(--space-2);
  justify-self: start;
  padding: var(--space-2) 0;
  background: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--text-12);
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  clip-path: none;
}

.game-console-toggle:hover {
  color: var(--ink);
}

.game-console-chevron {
  inline-size: var(--space-3);
  block-size: var(--space-3);
  fill: none;
  stroke: currentcolor;
  stroke-width: var(--border-2);
  transform: rotate(-90deg);
}

.game-console-toggle[aria-expanded="true"] .game-console-chevron {
  transform: none;
}

.game-console-body {
  block-size: var(--console-size, var(--console-default-size));
  min-block-size: var(--console-min-size);
  overflow: auto;
  background: var(--surface);
}

/* Resizing: no text selection, and the row cursor everywhere */
.game-console--resizing,
.game-console--resizing * {
  cursor: row-resize;
  user-select: none;
}

.game-console-handle[hidden],
.game-console-body[hidden] {
  display: none;
}

.game-verdict {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
}

.game-verdict[hidden],
.game-verdict-heading[hidden],
.game-verdict-reason[hidden],
.game-verdict-code[hidden],
.game-verdict-screen[hidden] {
  display: none;
}

.game-verdict-heading {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-17);
  font-weight: 700;
  color: var(--magenta);
}

.game-verdict--pass .game-verdict-heading {
  color: var(--green);
}

.game-verdict-reason {
  margin: 0;
  color: var(--ink);
  font-size: var(--text-14);
}

.game-verdict-code {
  margin: 0;
  min-inline-size: 0;
  font-family: var(--font-mono);
  font-size: var(--text-12);
  color: var(--ink);
  white-space: pre;
  overflow-x: auto;
}

/* Inside the console, the body owns horizontal scrolling. */
.game-console-body .game-verdict-code {
  overflow-x: visible;
}

.game-verdict-screen {
  display: grid;
  min-inline-size: 0;
  gap: var(--space-1);
}

/* Python initialization failure. */
.game-run-load-error {
  margin: 0;
  color: var(--magenta);
  font-size: var(--text-12);
}

.game-run-load-error[hidden] {
  display: none;
}

/* Local Python execution inside the shared console. */
.game-run-output {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-2);
  padding: var(--space-3);
}

.game-run-output[hidden],
.game-run-error[hidden],
.game-run-hint[hidden],
.game-run-input-form[hidden] {
  display: none;
}

.game-run-heading {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-17);
  font-weight: 700;
  color: var(--cyan);
}

.game-run-status,
.game-run-hint {
  margin: 0;
  font-size: var(--text-12);
  color: var(--muted);
}

.game-run-screen,
.game-run-error {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-12);
  white-space: pre;
  overflow-x: auto;
  color: var(--ink);
}

.game-run-screen {
  min-block-size: var(--space-4);
}

.game-run-screen:focus-visible {
  outline: var(--border-1) solid var(--cyan);
}

.game-run-error {
  color: var(--magenta);
}

.game-run-input-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
}

.game-run-input-form label {
  grid-column: 1 / -1;
  font-family: var(--font-mono);
  font-size: var(--text-12);
  color: var(--muted);
}

.game-run-input-form input {
  min-inline-size: 0;
  font-family: var(--font-mono);
}

.game-run-input-form .btn:disabled,
.game-actions [data-testid="game-stop"]:disabled {
  cursor: not-allowed;
}

/* Victory and game-over screen (US7): points per cleared stage, then the total */
.game-result-breakdown,
.game-result-score {
  display: grid;
  gap: var(--space-1);
  margin: 0;
}

.game-result-score {
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: var(--border-1) solid var(--line);
}

.game-result-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
}

.game-result-row dt {
  color: var(--muted);
}

.game-result-row dd {
  margin: 0;
  font-family: var(--font-mono);
}

.game-result-score dt,
.game-result-score dd {
  color: var(--ink-strong);
  font-weight: 700;
}

/* Leaderboard (US9): the overall table, then a grid of tier tables */
.leaderboard-tiers {
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(min(100%, calc(var(--grid-size) * 7)), 1fr)
  );
  gap: var(--space-6);
  margin-top: var(--space-6);
}

/* A grid item must be allowed to shrink so its table can scroll */
.leaderboard-board {
  min-width: 0;
}

.leaderboard-board h2 {
  margin: 0 0 var(--space-2);
  font-family: var(--font-display);
  font-size: var(--text-22);
  line-height: 1.2;
  color: var(--ink-strong);
}

/* A wide table scrolls inside its section, never the page */
.leaderboard-scroll {
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-14);
}

.leaderboard-table th,
.leaderboard-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border-1) solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.leaderboard-table th {
  color: var(--muted);
  font-size: var(--text-12);
  font-weight: 600;
}

.leaderboard-table td {
  font-family: var(--font-mono);
}

.leaderboard-table .leaderboard-player {
  font-family: var(--font-body);
  color: var(--ink-strong);
}

/* Dozens of badges share the screen here, so they neither glow nor spin */
.leaderboard-table .tier-badge {
  filter: none;
  text-shadow: none;
  animation: none;
}

.leaderboard-empty {
  margin: 0;
  color: var(--muted);
}

/* The run just won: a cyan left edge and bolder text, like the editor's
   current line, so it never depends on color alone */
.leaderboard-row--mine td {
  color: var(--ink-strong);
  font-weight: 700;
}

.leaderboard-row--mine td:first-child {
  box-shadow: inset var(--border-2) 0 0 var(--cyan);
}

/* The run just won, when it missed the table: a recessed well below it */
.leaderboard-your-score {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: var(--space-2) 0 0;
  padding: var(--space-2) var(--space-3);
  border: var(--border-1) solid var(--line);
  background: var(--well);
  color: var(--ink-strong);
  font-family: var(--font-mono);
}

.leaderboard-your-score > :first-child {
  margin-right: auto;
  color: var(--muted);
  font-family: var(--font-body);
}

/* The Overlord's stage: perspective floor, magenta horizon, scanlines */
.overlord-stage {
  --horizon: 62%;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: end;
  gap: var(--space-4);
  block-size: calc(var(--grid-size) * 2.5);
  min-block-size: 0;
  padding-inline: var(--space-4);
  border: var(--border-1) solid var(--line);
  background: var(--surface);
}

.overlord-stage::before {
  content: "";
  position: absolute;
  inset: var(--horizon) -50% -40%;
  z-index: -1;
  background-image:
    linear-gradient(
      to right,
      color-mix(in srgb, var(--cyan) 35%, transparent) var(--border-1),
      transparent var(--border-1)
    ),
    linear-gradient(
      to bottom,
      color-mix(in srgb, var(--cyan) 35%, transparent) var(--border-1),
      transparent var(--border-1)
    );
  background-size: calc(var(--grid-size) / 2) calc(var(--grid-size) / 2);
  background-position: center top;
  transform: perspective(var(--grid-size)) rotateX(55deg);
  transform-origin: center top;
  mask-image: linear-gradient(transparent, var(--ink) 60%);
}

/* Scanlines over the whole stage, plus the glowing magenta horizon */
.overlord-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(
      transparent calc(var(--horizon) - var(--border-1)),
      var(--magenta) calc(var(--horizon) - var(--border-1)) var(--horizon),
      transparent var(--horizon)
    ),
    linear-gradient(
      transparent calc(var(--horizon) - var(--space-2)),
      color-mix(in srgb, var(--magenta) 30%, transparent) var(--horizon),
      transparent calc(var(--horizon) + var(--space-1))
    ),
    repeating-linear-gradient(
      to bottom,
      var(--sheen) 0 var(--border-1),
      transparent var(--border-1) var(--space-1)
    );
}

.overlord {
  display: block;
  block-size: 92%;
  max-block-size: calc(var(--grid-size) * 4);
  inline-size: auto;
  aspect-ratio: 200 / 220;
  align-self: end;
  filter: drop-shadow(
    0 0 var(--glow-wide) color-mix(in srgb, var(--magenta) 25%, transparent)
  );
}

.overlord-metal-top {
  stop-color: color-mix(in srgb, var(--muted) 45%, var(--surface-raised));
}

.overlord-metal-bottom {
  stop-color: var(--bg);
}

.overlord-plate {
  fill: url("#overlord-metal");
  stroke: var(--bevel-light);
  stroke-width: var(--border-1);
  vector-effect: non-scaling-stroke;
}

.overlord-seam {
  fill: none;
  stroke: var(--line);
  stroke-width: var(--border-2);
}

.overlord-visor {
  fill: var(--cyan);
  filter: drop-shadow(0 0 var(--glow-tight) var(--cyan));
}

.overlord-scan {
  fill: var(--cyan-hot);
  transform-box: fill-box;
  animation: visor-scan var(--visor-period) ease-in-out infinite alternate;
}

@keyframes visor-scan {
  to {
    transform: translateX(390%);
  }
}

.overlord-dialog {
  align-self: start;
  min-inline-size: 0;
  min-block-size: 0;
  margin: 0;
  padding: var(--space-4) 0;
  list-style: none;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: var(--text-14);
  overflow-wrap: anywhere;
}

.overlord-stage .overlord-dialog {
  align-self: stretch;
  overflow-y: auto;
  overflow-anchor: none;
  scrollbar-color: var(--muted) transparent;
  scrollbar-width: thin;
}

.overlord-dialog li + li {
  margin-block-start: var(--space-3);
}

.overlord-stage .overlord-dialog--scrolled:not(:focus-within) {
  mask-image: linear-gradient(
    transparent,
    var(--ink) var(--space-6)
  );
}

/* The prompt: pinned under the Overlord, always visible */
.game-feed {
  min-block-size: 0;
  overflow-y: auto;
  overflow-wrap: anywhere;
  scrollbar-color: var(--muted) transparent;
  scrollbar-width: thin;
  color: var(--ink-strong);
  font-size: var(--text-17);
}

.game-feed--scrolled:not(:focus-visible) {
  mask-image: linear-gradient(transparent, var(--ink) var(--space-6));
}

.game-feed p {
  margin: 0;
  white-space: pre-wrap;
}

.game-feed code,
.game-editor-tab,
.game-editor textarea {
  font-family: var(--font-mono);
}

.game-feed code {
  color: var(--cyan);
}

/* Editor */
.game-editor-tab {
  color: var(--muted);
  font-size: var(--text-12);
}

/* Stacked layout: the editor shrinks as much as an open console grows */
.game-editor {
  position: relative;
  min-block-size: var(--editor-min-size);
  block-size: calc(
    max(60svh, calc(var(--grid-size) * 5)) + var(--console-default-size) -
      var(--console-size, var(--console-default-size))
  );
  background: var(--surface);
}

.game-editor:focus-within {
  outline: var(--focus-outline) solid var(--cyan);
  outline-offset: var(--focus-offset);
}

.game-editor > * {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
}

.game-editor textarea {
  resize: none;
  border: 0;
  padding: var(--space-3);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-14);
  tab-size: 4;
}

.game-editor .monaco-editor .view-overlays .current-line {
  border-inline-start: var(--border-2) solid var(--cyan);
}

/*
Desktop: the page becomes a fixed app shell. The editor takes every spare
pixel; the Overlord column keeps a readable measure and the prompt keeps
its space, while the Overlord's stage gives way first.
*/
@media (min-width: 960px) and (min-height: 560px) {
  .page-game {
    display: flex;
    flex-direction: column;
    block-size: 100dvh;
    overflow: hidden;
  }

  .page-game main {
    flex: 1;
    min-block-size: 0;
    inline-size: 100%;
  }

  .page-game .site-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
  }

  .page-game .header-actions {
    justify-self: end;
  }

  .game-layout {
    grid-template-columns:
      clamp(
        calc(var(--grid-size) * 5.5),
        34%,
        calc(var(--grid-size) * 7)
      )
      minmax(0, 1fr);
    block-size: 100%;
  }

  .game-overlord-panel {
    grid-template-rows: minmax(calc(var(--grid-size) * 2), 1fr) fit-content(70%);
  }

  .overlord-stage {
    block-size: auto;
  }

  /* console.js keeps the console small enough for the editor's minimum */
  .game-editor-panel {
    grid-template-rows: auto minmax(var(--editor-min-size), 1fr) auto auto;
  }

  .game-editor {
    block-size: auto;
  }
}

/* Short desktop screens: a smaller prompt keeps more of it in view */
@media (min-width: 960px) and (min-height: 560px) and (max-height: 760px) {
  .game-feed {
    font-size: var(--text-14);
  }
}

/* US10: Overlord escalation by remaining stage time */

.page-game[data-escalation="pressure"] .game-timer {
  color: var(--magenta);
}

.page-game[data-escalation="pressure"] .overlord-dialog li:last-child {
  color: var(--magenta);
  font-weight: 600;
}

.page-game[data-escalation="pressure"] .stage-bar-cell--current {
  --heat-from: var(--cyan);
  --heat-to: var(--magenta);
  --heat-glow: var(--glow-magenta);
}

/* Temporary visor colors; avatar animation remains part of US12. */

.page-game[data-escalation="pressure"] .overlord-visor {
  fill: var(--magenta);
  filter: drop-shadow(0 0 var(--glow-tight) var(--magenta));
}

.page-game[data-escalation="pressure"] .overlord-scan {
  fill: var(--magenta-hot);
}

/* Critical warning colors and interface effects. */

.page-game[data-escalation="critical"] .game-timer {
  color: var(--red);
  animation: critical-pulse var(--critical-pulse-period)
    ease-in-out infinite;
}

.page-game[data-escalation="critical"] .overlord-dialog li:last-child {
  color: var(--red);
  font-family: var(--font-shout);
  text-transform: uppercase;
  text-shadow:
    calc(-1 * var(--anaglyph-offset-sm)) 0 var(--anaglyph-cyan),
    var(--anaglyph-offset-sm) 0 var(--red);
  animation: critical-glitch var(--critical-glitch-duration) ease-out;
}

.page-game[data-escalation="critical"] .stage-bar-cell--current {
  --heat-from: var(--magenta);
  --heat-to: var(--red);
  --heat-glow: var(--glow-red);
}

.page-game[data-escalation="critical"] .overlord-visor {
  fill: var(--red);
  filter: drop-shadow(0 0 var(--glow-tight) var(--red));
}

.page-game[data-escalation="critical"] .overlord-scan {
  fill: color-mix(in srgb, var(--red), var(--ink-strong));
}

.page-game[data-escalation="critical"] .game-actions .btn-primary::before,
.page-game[data-escalation="critical"] .game-actions .btn-primary::after {
  background: var(--red);
}

.page-game[data-escalation="critical"] .game-actions .btn-primary:not(:disabled) {
  animation: critical-pulse var(--critical-pulse-period)
    ease-in-out infinite;
}

/* Non-interactive critical warning along the screen edges. */

.page-game[data-escalation="critical"]::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  box-shadow: inset 0 0 var(--glow-wide) var(--glow-red);
}

@keyframes critical-pulse {
  0%, 100% {
    filter: drop-shadow(0 0 var(--glow-tight) var(--glow-red));
  }

  50% {
    filter: drop-shadow(0 0 var(--glow-wide) var(--glow-red));
  }
}

@keyframes critical-glitch {
  50% {
    text-shadow:
      var(--anaglyph-offset) 0 var(--anaglyph-cyan),
      calc(-1 * var(--anaglyph-offset)) 0 var(--red);
  }
}

/* Motion accessibility preferences */
@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;
  }

  .floating-panel {
    animation: none;
  }

  .tier-badge--impossible,
  .overlord-scan {
    animation: none;
  }

  .page-game[data-escalation="critical"] .game-timer,
  .page-game[data-escalation="critical"] .overlord-dialog li:last-child,
  .page-game[data-escalation="critical"] .game-actions .btn-primary:not(:disabled) {
    animation: none;
  }

  .page-game[data-escalation="critical"] .overlord-dialog li:last-child {
    text-shadow: none;
  }
}
