/* Shared dark-mode styling for the Connect 4 game, Experiment Lab, replay panel, and report. */
:root {
  --bg: #080d18;
  --panel: #101827;
  --panel-soft: #141f31;
  --ink: #edf4ff;
  --muted: #94a7bd;
  --line: #26364d;
  --blue: #4ba3ff;
  --blue-dark: #1c6dc2;
  --board: #0f5fa8;
  --board-light: #2287d9;
  --board-shadow: #052946;
  --red: #df243a;
  --red-dark: #8d1427;
  --red-rim: #b9182d;
  --red-light: #ff6674;
  --yellow: #ffd342;
  --yellow-dark: #bd8509;
  --yellow-rim: #d69a10;
  --yellow-light: #ffe985;
  --empty: #101928;
  --focus: #f8fafc;
  --felt: #2dd4bf;
  --drop-cursor: url("../assets/red-arrow-cursor.svg") 5 4, pointer;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% 12%, rgba(75, 163, 255, 0.2), transparent 30%),
    radial-gradient(circle at 86% 18%, rgba(255, 211, 66, 0.14), transparent 26%),
    radial-gradient(circle at 72% 88%, rgba(223, 36, 58, 0.18), transparent 30%),
    linear-gradient(145deg, #060914 0%, var(--bg) 44%, #111827 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: clamp(14px, 3.2vw, 34px) 0;
  display: grid;
  grid-template-columns: minmax(590px, 1fr) 360px;
  gap: 24px;
}

.game-panel,
.side-panel {
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(20, 31, 49, 0.92), rgba(12, 18, 30, 0.94)),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(14px);
}

.game-panel {
  padding: clamp(18px, 3vw, 30px);
  background:
    linear-gradient(180deg, rgba(20, 31, 49, 0.94), rgba(9, 14, 25, 0.96)),
    linear-gradient(135deg, rgba(75, 163, 255, 0.12), rgba(255, 211, 66, 0.08));
}

.side-panel {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border: 1px solid rgba(75, 163, 255, 0.18);
  border-radius: 10px;
  background: rgba(7, 13, 24, 0.5);
}

.side-tab {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 900;
}

.side-tab.active {
  background: linear-gradient(180deg, rgba(47, 156, 255, 0.95), rgba(28, 109, 194, 0.95));
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(28, 109, 194, 0.22);
}

.side-tab:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.side-panel[data-active-view="game"] .side-replay-view,
.side-panel[data-active-view="replay"] .side-game-view {
  display: none;
}

.side-game-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.top-bar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.top-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--felt);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.2rem, 5vw, 4.4rem);
  line-height: 1.05;
  color: #f8fbff;
  text-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}

h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.report-link {
  flex: 0 0 auto;
  color: #ffffff;
  background: linear-gradient(180deg, #2f9cff, var(--blue-dark));
  border-radius: 8px;
  padding: 11px 15px;
  text-decoration: none;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(28, 109, 194, 0.24);
}

.top-action-button {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid rgba(75, 163, 255, 0.28);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(35, 52, 78, 0.96), rgba(20, 32, 52, 0.96));
  color: #dceeff;
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
}

.top-action-button:hover {
  background: linear-gradient(180deg, rgba(45, 68, 102, 0.98), rgba(25, 42, 68, 0.98));
}

.report-link:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.status {
  height: 76px;
  margin: 22px 0 18px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-left: 6px solid var(--felt);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(8, 13, 24, 0.58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 12px 24px rgba(0, 0, 0, 0.16);
  font-weight: 700;
  line-height: 1.35;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.board-wrap {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 0 0 8px;
  touch-action: manipulation;
}

.column-controls,
.board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: clamp(6px, 1.4vw, 10px);
}

.column-controls {
  margin-bottom: 12px;
  padding: 0 clamp(8px, 1.6vw, 14px);
}

.column-button {
  min-height: 44px;
  border: 1px solid rgba(75, 163, 255, 0.28);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(34, 52, 80, 0.96), rgba(17, 27, 44, 0.96));
  color: #dff0ff;
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.2);
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
  touch-action: manipulation;
}

.board.manual-drop-turn {
  touch-action: none;
}

.column-controls.manual-drop-turn .column-button:not(:disabled) {
  cursor: var(--drop-cursor);
}

.column-button:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(55, 84, 126, 0.98), rgba(28, 47, 76, 0.98));
  border-color: rgba(75, 163, 255, 0.68);
  transform: translateY(-2px);
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.26);
}

.column-button.hover-preview:not(:disabled) {
  border-color: rgba(255, 102, 116, 0.78);
  color: #ffe5e8;
  background:
    linear-gradient(180deg, rgba(91, 35, 52, 0.98), rgba(45, 24, 38, 0.98));
}

.column-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.board {
  position: relative;
  aspect-ratio: 7 / 6;
  padding: clamp(10px, 1.8vw, 18px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), transparent 34%),
    linear-gradient(180deg, var(--board-light), var(--board));
  border: clamp(5px, 1vw, 9px) solid var(--board-shadow);
  border-radius: 16px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.26),
    inset 0 -14px 20px rgba(4, 38, 70, 0.22),
    0 18px 0 #031d35,
    0 28px 45px rgba(0, 0, 0, 0.45);
  isolation: isolate;
  touch-action: manipulation;
}

.board-face-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
  shape-rendering: geometricPrecision;
}

.cell {
  position: relative;
  z-index: 4;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border-radius: 50%;
  cursor: default;
  background:
    radial-gradient(circle at 50% 50%, rgba(9, 15, 28, 0.5) 0 46%, #0b1321 47% 58%, rgba(3, 16, 29, 0.76) 59% 100%);
  box-shadow:
    inset 0 9px 14px rgba(0, 0, 0, 0.52),
    inset 0 -2px 4px rgba(255, 255, 255, 0.08),
    0 2px 0 rgba(255, 255, 255, 0.12);
}

.game-panel.manual-drop-turn .board-wrap,
.game-panel.manual-drop-turn .board,
.column-controls.manual-drop-turn {
  cursor: var(--drop-cursor);
}

.board.manual-drop-turn .cell.drop-target {
  cursor: var(--drop-cursor);
}

.board.manual-drop-turn .cell.column-hover {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 102, 116, 0.24) 0 45%, rgba(104, 24, 42, 0.26) 46% 57%, rgba(3, 16, 29, 0.72) 58% 100%);
  box-shadow:
    inset 0 9px 14px rgba(0, 0, 0, 0.44),
    inset 0 -2px 4px rgba(255, 255, 255, 0.1),
    0 0 0 2px rgba(255, 102, 116, 0.34),
    0 0 18px rgba(223, 36, 58, 0.22);
}

.board.manual-drop-turn .cell.column-hover:not(.red):not(.yellow)::before {
  background:
    radial-gradient(circle at 50% 55%, rgba(255, 102, 116, 0.16) 0 45%, rgba(223, 36, 58, 0.12) 46% 70%, transparent 72%);
}

.board.manual-drop-turn.yellow-turn .cell.column-hover {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 210, 76, 0.24) 0 45%, rgba(127, 91, 20, 0.28) 46% 57%, rgba(3, 16, 29, 0.72) 58% 100%);
  box-shadow:
    inset 0 9px 14px rgba(0, 0, 0, 0.44),
    inset 0 -2px 4px rgba(255, 255, 255, 0.1),
    0 0 0 2px rgba(255, 210, 76, 0.38),
    0 0 18px rgba(255, 184, 43, 0.24);
}

.board.manual-drop-turn.yellow-turn .cell.column-hover:not(.red):not(.yellow)::before {
  background:
    radial-gradient(circle at 50% 55%, rgba(255, 210, 76, 0.18) 0 45%, rgba(255, 184, 43, 0.12) 46% 70%, transparent 72%);
}

.cell::before,
.falling-piece::before {
  content: "";
  position: absolute;
  inset: 14%;
  border-radius: 50%;
  pointer-events: none;
}

.cell.red::before,
.falling-piece.red::before {
  background:
    radial-gradient(circle at 34% 24%, rgba(255, 255, 255, 0.42) 0 11%, transparent 12%),
    radial-gradient(circle at 50% 55%, var(--red-light) 0 46%, var(--red) 47% 70%, var(--red-dark) 100%);
  box-shadow:
    inset 0 4px 7px rgba(255, 255, 255, 0.22),
    inset 0 -8px 12px rgba(89, 4, 18, 0.36);
}

.cell.yellow::before,
.falling-piece.yellow::before {
  background:
    radial-gradient(circle at 34% 24%, rgba(255, 255, 255, 0.5) 0 11%, transparent 12%),
    radial-gradient(circle at 50% 55%, var(--yellow-light) 0 46%, var(--yellow) 47% 70%, var(--yellow-dark) 100%);
  box-shadow:
    inset 0 4px 7px rgba(255, 255, 255, 0.3),
    inset 0 -8px 12px rgba(118, 74, 0, 0.3);
}

.cell::after,
.falling-piece::after {
  content: "";
  position: absolute;
  inset: 31%;
  border-radius: 50%;
  background: transparent;
  pointer-events: none;
}

.cell.red {
  z-index: 2;
  background:
    linear-gradient(145deg, var(--red-light), var(--red) 42%, var(--red-rim) 70%, var(--red-dark));
  box-shadow:
    inset 0 3px 4px rgba(255, 255, 255, 0.32),
    inset 0 -8px 12px rgba(84, 0, 12, 0.36),
    0 6px 9px rgba(64, 18, 26, 0.22);
}

.cell.ghost {
  z-index: 4;
  cursor: pointer;
  background:
    linear-gradient(145deg, rgba(255, 102, 116, 0.42), rgba(223, 36, 58, 0.34) 42%, rgba(185, 24, 45, 0.3) 70%, rgba(141, 20, 39, 0.34));
  outline: 3px dashed rgba(255, 230, 233, 0.72);
  outline-offset: -7px;
  box-shadow:
    inset 0 3px 4px rgba(255, 255, 255, 0.18),
    inset 0 -8px 12px rgba(84, 0, 12, 0.18),
    0 0 24px rgba(223, 36, 58, 0.3);
}

.cell.ghost::before {
  opacity: 0.52;
}

.cell.ghost.yellow {
  z-index: 4;
  background:
    linear-gradient(145deg, rgba(255, 233, 142, 0.44), rgba(255, 210, 76, 0.34) 42%, rgba(216, 154, 33, 0.3) 70%, rgba(160, 106, 18, 0.34));
  outline: 3px dashed rgba(255, 245, 198, 0.72);
  outline-offset: -7px;
  box-shadow:
    inset 0 3px 4px rgba(255, 255, 255, 0.2),
    inset 0 -8px 12px rgba(118, 74, 0, 0.18),
    0 0 24px rgba(255, 184, 43, 0.28);
}

.cell.red::after,
.falling-piece.red::after {
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.2),
    inset 0 -2px 5px rgba(96, 0, 15, 0.26);
}

.cell.yellow {
  z-index: 2;
  background:
    linear-gradient(145deg, #fff0a0, var(--yellow) 42%, var(--yellow-rim) 72%, var(--yellow-dark));
  box-shadow:
    inset 0 3px 4px rgba(255, 255, 255, 0.38),
    inset 0 -8px 12px rgba(118, 74, 0, 0.3),
    0 6px 9px rgba(87, 61, 10, 0.2);
}

.cell.yellow::after,
.falling-piece.yellow::after {
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.24),
    inset 0 -2px 5px rgba(118, 74, 0, 0.22);
}

.cell.win {
  z-index: 5;
  outline: 4px solid #ffffff;
  outline-offset: -8px;
  animation: win-pulse 900ms ease-in-out infinite alternate;
}

.falling-piece {
  position: absolute;
  z-index: 2;
  border-radius: 50%;
  pointer-events: none;
  will-change: transform;
  transform: translate3d(0, 0, 0);
}

.falling-piece.red {
  background: linear-gradient(145deg, var(--red-light), var(--red) 42%, var(--red-rim) 70%, var(--red-dark));
  box-shadow:
    inset 0 3px 4px rgba(255, 255, 255, 0.32),
    inset 0 -8px 12px rgba(84, 0, 12, 0.36),
    0 12px 18px rgba(64, 18, 26, 0.26);
}

.falling-piece.yellow {
  background: linear-gradient(145deg, #fff0a0, var(--yellow) 42%, var(--yellow-rim) 72%, var(--yellow-dark));
  box-shadow:
    inset 0 3px 4px rgba(255, 255, 255, 0.38),
    inset 0 -8px 12px rgba(118, 74, 0, 0.3),
    0 12px 18px rgba(87, 61, 10, 0.24);
}

.falling-piece.css-drop {
  animation: drop-piece var(--drop-duration) linear forwards;
}

.falling-piece.css-drop-reduced {
  animation: drop-piece-reduced var(--drop-duration) ease-out forwards;
}

@keyframes drop-piece {
  0% {
    transform: translate3d(0, var(--drop-start), 0);
  }

  18% {
    transform: translate3d(0, var(--drop-step-18), 0);
  }

  35% {
    transform: translate3d(0, var(--drop-step-35), 0);
  }

  52% {
    transform: translate3d(0, var(--drop-step-52), 0);
  }

  68% {
    transform: translate3d(0, var(--drop-step-68), 0);
  }

  82% {
    transform: translate3d(0, var(--drop-step-82), 0);
  }

  93% {
    transform: translate3d(0, var(--drop-step-93), 0);
  }

  96% {
    transform: translate3d(0, 0, 0);
  }

  98% {
    transform: translate3d(0, var(--drop-settle), 0);
  }

  100% {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes drop-piece-reduced {
  from {
    transform: translate3d(0, var(--drop-start), 0);
  }

  to {
    transform: translate3d(0, 0, 0);
  }
}

@keyframes win-pulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.16);
  }
}

.controls-section,
.stats-section,
.experiment-section {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.experiment-section {
  border-bottom: 0;
  padding-bottom: 0;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.field span,
.compact-field span {
  font-size: 0.78rem;
  text-transform: uppercase;
  color: var(--muted);
}

select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #17243a, #111b2c);
  color: var(--ink);
  font-weight: 750;
  color-scheme: dark;
}

select option {
  background: #111b2c;
  color: var(--ink);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.control-card {
  display: grid;
  gap: 12px;
  padding: 13px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(21, 32, 50, 0.96), rgba(13, 21, 35, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.control-card.is-disabled,
.field.is-disabled,
.toggle.is-disabled {
  opacity: 0.48;
}

.control-card.is-disabled,
.field.is-disabled,
.toggle.is-disabled,
.control-card.is-disabled * {
  cursor: not-allowed;
}

.accent-card {
  border-color: rgba(223, 36, 58, 0.36);
  background:
    linear-gradient(180deg, rgba(35, 20, 33, 0.96), rgba(18, 17, 30, 0.96)),
    linear-gradient(135deg, rgba(223, 36, 58, 0.16), rgba(75, 163, 255, 0.07));
}

.compact-field {
  margin-top: 2px;
}

.speed-field {
  margin-bottom: 4px;
}

.speed-slider {
  width: 100%;
  accent-color: var(--felt);
  cursor: pointer;
}

.speed-label-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.76rem;
}

.speed-label-row strong {
  color: var(--ink);
  font-size: 0.9rem;
  text-align: center;
}

.switch-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  color: var(--ink);
  cursor: pointer;
}

.switch-row strong {
  display: block;
  font-size: 1rem;
  line-height: 1.2;
}

.switch-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.switch-row input {
  position: absolute;
  right: 0;
  top: 50%;
  width: 50px;
  height: 28px;
  margin: 0;
  opacity: 0;
  transform: translateY(-50%);
  cursor: pointer;
}

.switch-ui {
  position: relative;
  pointer-events: none;
  width: 50px;
  height: 28px;
  border-radius: 999px;
  background: #334158;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.32);
  transition: background 160ms ease, box-shadow 160ms ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 3px 7px rgba(20, 32, 48, 0.25);
  transition: transform 160ms ease;
}

.switch-row input:checked + .switch-ui {
  background: linear-gradient(180deg, var(--red-light), var(--red));
  box-shadow: inset 0 1px 3px rgba(84, 0, 12, 0.28), 0 6px 14px rgba(223, 36, 58, 0.22);
}

.switch-row input:checked + .switch-ui::after {
  transform: translateX(22px);
}

.switch-row input:focus-visible + .switch-ui {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  margin-top: 2px;
  background: linear-gradient(180deg, #2f9cff, var(--blue-dark));
  color: #ffffff;
  box-shadow: 0 14px 26px rgba(28, 109, 194, 0.24);
}

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

.secondary-button {
  background: linear-gradient(180deg, rgba(35, 52, 78, 0.96), rgba(20, 32, 52, 0.96));
  color: #dceeff;
  border: 1px solid rgba(75, 163, 255, 0.28);
}

.secondary-button:hover {
  background: linear-gradient(180deg, rgba(45, 68, 102, 0.98), rgba(25, 42, 68, 0.98));
}

.stats-grid {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats-grid div {
  min-width: 0;
  min-height: 74px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(21, 32, 50, 0.96), rgba(13, 21, 35, 0.96));
}

.stats-grid .wide-stat,
.replay-insight-grid .wide-stat {
  grid-column: 1 / -1;
}

.stats-grid .wide-stat {
  height: 156px;
  min-height: 156px;
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

dd {
  margin: 5px 0 0;
  font-size: 1rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

#statReason,
#replayMoveReason {
  display: block;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  line-height: 1.34;
}

#statReason {
  height: 6.05rem;
  padding-right: 4px;
  font-size: 0.94rem;
}

#replayMoveReason {
  height: 5.9rem;
  padding-right: 4px;
}

.experiment-section p {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.4;
}

.experiment-actions {
  display: grid;
  gap: 10px;
}

.secondary-action-link {
  width: 100%;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid rgba(75, 163, 255, 0.28);
  border-radius: 9px;
  background: linear-gradient(180deg, rgba(35, 52, 78, 0.96), rgba(20, 32, 52, 0.96));
  color: #dceeff;
  font-weight: 800;
  text-decoration: none;
}

.secondary-action-link:hover {
  background: linear-gradient(180deg, rgba(45, 68, 102, 0.98), rgba(25, 42, 68, 0.98));
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-heading-row h2 {
  margin-bottom: 0;
}

.replay-count {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid rgba(75, 163, 255, 0.28);
  border-radius: 999px;
  background: rgba(75, 163, 255, 0.12);
  color: #dceeff;
  font-size: 0.75rem;
  font-weight: 900;
}

.replay-section {
  width: 100%;
  margin: 0;
  padding: clamp(14px, 2.2vw, 18px);
  border: 1px solid rgba(75, 163, 255, 0.22);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(21, 32, 50, 0.96), rgba(10, 17, 29, 0.96)),
    radial-gradient(circle at 14% 0%, rgba(45, 212, 191, 0.14), transparent 34%);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

.replay-description {
  height: 76px;
  margin-bottom: 12px;
  padding: 11px 12px;
  border: 1px solid rgba(45, 212, 191, 0.22);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.08), rgba(255, 255, 255, 0.035)),
    rgba(9, 18, 30, 0.82);
  color: #c9d7e8;
  line-height: 1.35;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.replay-move-insight {
  display: grid;
  gap: 12px;
  height: 480px;
  margin-bottom: 14px;
  padding: 13px;
  border: 1px solid rgba(255, 211, 66, 0.24);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 211, 66, 0.1), rgba(255, 255, 255, 0.035)),
    rgba(13, 21, 35, 0.92);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.replay-move-insight[hidden] {
  display: none;
}

.insight-label {
  color: var(--yellow-light);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.replay-move-insight strong {
  color: var(--ink);
  line-height: 1.35;
}

.replay-insight-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.replay-insight-grid div {
  min-width: 0;
  min-height: 58px;
  padding: 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(7, 13, 24, 0.48);
}

.replay-insight-grid dd {
  overflow-wrap: normal;
  word-break: normal;
}

.replay-insight-grid .wide-stat {
  min-height: 62px;
}

.replay-field {
  margin-bottom: 12px;
}

.replay-slider {
  width: 100%;
  accent-color: var(--felt);
}

.replay-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.replay-actions .primary-button,
.replay-actions .secondary-button {
  min-height: 38px;
}

.replay-speed-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.76rem;
}

.replay-speed-row strong {
  justify-self: center;
  color: var(--ink);
  font-size: 0.82rem;
}

.replay-animation-row {
  margin-top: 12px;
  padding: 10px 0 2px;
}

.replay-animation-row strong {
  font-size: 0.9rem;
}

.replay-animation-row small {
  font-size: 0.76rem;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 12px;
  min-width: 0;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  color: var(--ink);
}

th,
td {
  padding: 8px 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 7, 14, 0.74);
  backdrop-filter: blur(12px);
}

.modal-overlay[hidden] {
  display: none;
}

.experiment-modal,
.walkthrough-modal {
  width: min(1040px, 100%);
  max-height: min(86vh, 820px);
  overflow: auto;
  padding: clamp(18px, 3vw, 28px);
  border: 1px solid rgba(75, 163, 255, 0.24);
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(20, 31, 49, 0.98), rgba(8, 13, 24, 0.98)),
    var(--panel);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.52);
}

.walkthrough-modal {
  width: min(1060px, 100%);
}

.modal-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal-header h2 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.5rem);
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.walkthrough-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid rgba(45, 212, 191, 0.22);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.08), rgba(255, 255, 255, 0.035)),
    rgba(9, 18, 30, 0.82);
}

.walkthrough-flow div {
  min-width: 0;
  padding: 11px;
  border: 1px solid rgba(75, 163, 255, 0.16);
  border-radius: 9px;
  background: rgba(7, 13, 24, 0.44);
}

.walkthrough-flow strong,
.walkthrough-flow span {
  display: block;
}

.walkthrough-flow strong {
  margin-bottom: 5px;
  color: var(--ink);
}

.walkthrough-flow span {
  color: var(--muted);
  line-height: 1.35;
}

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

.walkthrough-card {
  min-width: 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(21, 32, 50, 0.92), rgba(9, 16, 28, 0.92)),
    rgba(255, 255, 255, 0.035);
}

.walkthrough-step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 26px;
  margin-bottom: 10px;
  border: 1px solid rgba(45, 212, 191, 0.28);
  border-radius: 999px;
  background: rgba(45, 212, 191, 0.1);
  color: var(--felt);
  font-size: 0.72rem;
  font-weight: 900;
}

.walkthrough-card h3 {
  margin: 0 0 8px;
  color: var(--ink);
}

.walkthrough-card p {
  margin: 0 0 12px;
  color: #c9d7e8;
  line-height: 1.48;
}

.walkthrough-card p code {
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-weight: 800;
}

.function-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 12px;
}

.function-list code {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 5px 8px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
  font-weight: 800;
}

.code-details {
  border: 1px solid rgba(75, 163, 255, 0.18);
  border-radius: 9px;
  background: rgba(7, 13, 24, 0.38);
}

.code-details summary {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 11px;
  color: #dceeff;
  cursor: pointer;
  font-weight: 900;
}

.code-details summary::marker {
  color: var(--felt);
}

.code-details pre {
  max-height: 260px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  border-top: 1px solid rgba(75, 163, 255, 0.14);
  background: rgba(3, 8, 15, 0.58);
}

.code-details code {
  display: block;
  white-space: pre;
  color: #edf4ff;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.5;
}

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

.experiment-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(75, 163, 255, 0.2);
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(21, 32, 50, 0.88), rgba(9, 16, 28, 0.9)),
    rgba(255, 255, 255, 0.035);
}

.experiment-toggle {
  min-height: 42px;
  align-self: end;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.experiment-toolbar .primary-button,
.experiment-toolbar .secondary-button {
  width: auto;
  min-width: 150px;
  padding: 0 14px;
}

.experiment-progress {
  margin-bottom: 14px;
  padding: 13px 14px;
  border: 1px solid rgba(45, 212, 191, 0.28);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.08), rgba(255, 255, 255, 0.035)),
    rgba(9, 18, 30, 0.82);
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  margin-bottom: 9px;
  color: #d8e6f7;
  font-weight: 800;
}

#experimentProgressLabel {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.3;
}

.progress-header strong {
  flex: 0 0 auto;
  color: var(--felt);
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(3, 12, 22, 0.76);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.36);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--felt), var(--blue));
  box-shadow: 0 0 20px rgba(45, 212, 191, 0.34);
  transition: width 180ms ease;
}

.experiment-summary {
  height: 96px;
  margin-bottom: 14px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.055);
  color: #d8e6f7;
  line-height: 1.45;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.verification-note {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid rgba(45, 212, 191, 0.26);
  border-left: 5px solid var(--felt);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(45, 212, 191, 0.09), rgba(255, 255, 255, 0.035)),
    rgba(9, 18, 30, 0.82);
}

.verification-note h3,
.lab-section h3 {
  margin: 0 0 10px;
  color: #f8fbff;
  font-size: 0.95rem;
}

.verification-note ul {
  margin: 0;
  padding-left: 18px;
  color: #c9d7e8;
  line-height: 1.48;
}

.verification-note li + li {
  margin-top: 4px;
}

.experiment-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.experiment-kpis div {
  min-width: 0;
  padding: 12px;
  border: 1px solid rgba(75, 163, 255, 0.22);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(75, 163, 255, 0.1), rgba(255, 255, 255, 0.035)),
    rgba(13, 21, 35, 0.94);
}

.experiment-kpis span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.experiment-kpis strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: clamp(1.05rem, 2vw, 1.35rem);
}

.proof-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.proof-card {
  min-width: 0;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(21, 32, 50, 0.96), rgba(13, 21, 35, 0.96));
}

.proof-card span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
}

.proof-card strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.25;
}

.proof-card.pass {
  border-color: rgba(45, 212, 191, 0.36);
}

.proof-card.fail {
  border-color: rgba(255, 102, 116, 0.5);
}

.proof-card.info {
  border-color: rgba(75, 163, 255, 0.34);
}

.lab-section {
  margin-top: 16px;
}

.validation-list,
.matchup-list {
  display: grid;
  gap: 8px;
}

.validation-list > div,
.matchup-list > div {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
  color: #cbd8ea;
}

.validation-row,
.matchup-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px 12px;
}

.validation-row span,
.matchup-row span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
  color: #dce6f4;
  font-size: 0.68rem;
  font-weight: 900;
}

.validation-row strong,
.matchup-row strong {
  min-width: 0;
  color: #f4f8ff;
  line-height: 1.28;
}

.matchup-row p {
  grid-column: 2;
  margin: -3px 0 0;
  color: var(--muted);
  line-height: 1.4;
}

.validation-row.pass,
.matchup-row.pass {
  border-color: rgba(45, 212, 191, 0.32);
}

.validation-row.pass span,
.matchup-row.pass span {
  background: rgba(45, 212, 191, 0.14);
  color: #8ff3e5;
}

.validation-row.fail,
.matchup-row.fail {
  border-color: rgba(255, 102, 116, 0.45);
}

.validation-row.fail span,
.matchup-row.fail span {
  background: rgba(255, 102, 116, 0.14);
  color: #ffc4cb;
}

.modal-table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
}

.report-body {
  --panel: #121820;
  --ink: #f8f3f4;
  --muted: #b7a8ad;
  --line: #3a2530;
  --focus: #ffffff;
  --brand-maroon: #5d1725;
  --brand-maroon-dark: #3f0f19;
  --brand-silver: #d9d2d3;
  background:
    radial-gradient(circle at 16% 12%, rgba(93, 23, 37, 0.38), transparent 30%),
    radial-gradient(circle at 86% 20%, rgba(217, 210, 211, 0.12), transparent 26%),
    radial-gradient(circle at 74% 88%, rgba(93, 23, 37, 0.25), transparent 32%),
    linear-gradient(145deg, #08090d 0%, #121820 48%, #1a0d13 100%);
  color: var(--ink);
}

.report-page {
  width: min(1080px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 30px 0 56px;
  min-width: 0;
}

.report-hero,
.report-section {
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(24, 31, 42, 0.94), rgba(13, 16, 23, 0.96)),
    rgba(18, 24, 32, 0.94);
  border: 1px solid rgba(128, 38, 57, 0.42);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
}

.report-hero {
  position: relative;
  overflow: hidden;
  padding: clamp(24px, 4vw, 42px);
  margin-bottom: 18px;
  border-top: 8px solid var(--brand-maroon);
}

.report-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 88% 22%, rgba(128, 38, 57, 0.28), transparent 24%),
    radial-gradient(circle at 78% 78%, rgba(217, 210, 211, 0.1), transparent 22%),
    linear-gradient(135deg, rgba(93, 23, 37, 0.2), transparent 48%);
  pointer-events: none;
}

.report-hero > * {
  position: relative;
}

.report-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 42px;
  min-width: 0;
}

.pdf-button {
  flex: 0 0 auto;
  min-height: 41px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border: 0;
  border-radius: 6px;
  background: linear-gradient(180deg, #7a2334, var(--brand-maroon-dark));
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 9px 18px rgba(93, 23, 37, 0.22);
}

.project-button {
  flex: 0 0 auto;
  min-height: 41px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 15px;
  border: 1px solid rgba(217, 210, 211, 0.26);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.075);
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  box-shadow: 0 9px 18px rgba(0, 0, 0, 0.18);
}

.project-button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.pdf-button:hover {
  background: var(--brand-maroon);
}

.report-author {
  margin: 8px 0 0;
  color: #ffffff;
  font-size: 0.94rem;
  font-weight: 800;
  letter-spacing: 0;
}

.report-project-links {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 12px;
}

.report-project-links a {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(217, 210, 211, 0.22);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.report-project-links a:hover {
  background: rgba(255, 255, 255, 0.12);
}

.report-lede {
  max-width: 760px;
  margin: 14px 0 0;
  color: #d8cfd2;
  font-size: 1.12rem;
  line-height: 1.55;
}

.report-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 28px;
  min-width: 0;
}

.report-metrics div {
  min-width: 0;
  padding: 13px;
  border: 1px solid rgba(128, 38, 57, 0.36);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.report-metrics span,
.heuristic-list span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.report-metrics strong,
.heuristic-list strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 1rem;
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  min-width: 0;
}

.report-section {
  padding: clamp(20px, 3vw, 28px);
}

.report-section.span-2 {
  grid-column: span 2;
}

.report-section h2 {
  margin-bottom: 12px;
  font-size: 1.14rem;
}

.report-section p {
  margin: 0;
  color: #d8cfd2;
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.report-section p + p {
  margin-top: 12px;
}

.report-section code {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
  border-radius: 4px;
  padding: 2px 5px;
}

.heuristic-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
  min-width: 0;
}

.algorithm-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  min-width: 0;
}

.algorithm-grid div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.035));
}

.algorithm-grid strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}

.algorithm-grid span {
  display: block;
  color: #d8cfd2;
  line-height: 1.4;
}

.checklist-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.checklist-grid div {
  position: relative;
  min-width: 0;
  padding: 12px 12px 12px 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.035));
  color: #d8cfd2;
  line-height: 1.42;
}

.checklist-grid div::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 15px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--brand-maroon);
  box-shadow: 0 0 0 3px rgba(128, 38, 57, 0.28);
}

.heuristic-list div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.035));
}

.command-list {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.command-list code {
  display: block;
  overflow-wrap: anywhere;
}

.source-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
  min-width: 0;
}

.source-list a,
.source-list div {
  display: block;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.055);
  color: #ffffff;
  font-weight: 800;
  text-decoration: none;
}

.source-list strong {
  display: block;
  color: #ffffff;
  font-size: 0.86rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.source-list span {
  display: block;
  margin-top: 4px;
  color: #d8cfd2;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.source-list a:hover {
  background: rgba(255, 255, 255, 0.09);
}

.report-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  max-width: 100%;
}

.report-table-wrap table {
  background: rgba(255, 255, 255, 0.035);
}

@media (max-width: 1024px) {
  .app-shell {
    width: min(760px, calc(100vw - 24px));
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .side-panel {
    order: 0;
  }

  .report-metrics,
  .heuristic-list,
  .algorithm-grid,
  .source-list,
  .experiment-controls,
  .replay-insight-grid,
  .proof-grid,
  .walkthrough-flow {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 18px, 680px);
  }

  .game-panel {
    padding: 16px;
  }

  .board-wrap {
    width: min(100%, 560px);
  }

  .status {
    height: 64px;
    margin: 16px 0 14px;
    padding: 12px 13px;
    font-size: 0.95rem;
  }

  .column-controls,
  .board {
    gap: clamp(5px, 1.5vw, 8px);
  }

  .column-controls {
    margin-bottom: 10px;
    padding: 0 clamp(4px, 1.2vw, 8px);
  }

  .column-button {
    min-height: 42px;
    border-radius: 7px;
  }

  .board {
    padding: clamp(8px, 2.4vw, 12px);
    border-width: 5px;
    border-radius: 14px;
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.22),
      inset 0 -10px 16px rgba(4, 38, 70, 0.2),
      0 10px 0 #031d35,
      0 18px 30px rgba(0, 0, 0, 0.38);
  }

  .cell.win {
    outline-width: 3px;
    outline-offset: -6px;
  }

  .side-panel {
    padding: 16px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    padding: 0 8px 16px;
    gap: 10px;
  }

  .game-panel,
  .side-panel,
  .report-hero,
  .report-section {
    padding: 14px;
  }

  .top-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 8px;
  }

  .report-link,
  .top-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 10px;
    text-align: center;
  }

  h1 {
    font-size: clamp(2.05rem, 14vw, 3.15rem);
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  .status {
    height: 58px;
    font-size: 0.9rem;
  }

  .board-wrap {
    width: min(100%, 94vw);
  }

  .column-controls,
  .board {
    gap: clamp(4px, 1.15vw, 6px);
  }

  .column-controls {
    padding: 0 2px;
  }

  .column-button {
    min-height: 40px;
    padding: 0;
    font-size: 0.9rem;
  }

  .board {
    border-width: 4px;
    padding: clamp(7px, 2vw, 9px);
    border-radius: 12px;
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.2),
      inset 0 -8px 14px rgba(4, 38, 70, 0.18),
      0 7px 0 #031d35,
      0 13px 24px rgba(0, 0, 0, 0.36);
  }

  .cell {
    box-shadow:
      inset 0 6px 10px rgba(0, 0, 0, 0.5),
      inset 0 -2px 4px rgba(255, 255, 255, 0.07),
      0 1px 0 rgba(255, 255, 255, 0.1);
  }

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

  .stats-grid div {
    min-height: 66px;
  }

  .stats-grid .wide-stat {
    height: 138px;
    min-height: 138px;
  }

  #statReason {
    height: 5rem;
  }

  .replay-insight-grid {
    grid-template-columns: 1fr;
  }

  .replay-move-insight {
    height: min(420px, 62vh);
  }

  .report-actions {
    align-items: stretch;
    flex-direction: column;
    margin-bottom: 28px;
  }

  .pdf-button {
    width: 100%;
  }

  .report-grid,
  .report-metrics,
  .heuristic-list,
  .checklist-grid,
  .source-list,
  .experiment-controls,
  .proof-grid,
  .walkthrough-flow,
  .walkthrough-grid {
    grid-template-columns: 1fr;
  }

  .experiment-toolbar .primary-button,
  .experiment-toolbar .secondary-button {
    width: 100%;
  }

  .modal-overlay {
    padding: 0;
    place-items: stretch;
  }

  .experiment-modal,
  .walkthrough-modal {
    width: 100%;
    max-height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .report-section.span-2 {
    grid-column: span 1;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 6px;
  }

  .game-panel,
  .side-panel,
  .report-hero,
  .report-section {
    padding: 12px;
  }

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

  .report-link,
  .top-action-button {
    min-height: 38px;
    font-size: 0.88rem;
  }

  h1 {
    font-size: clamp(1.95rem, 13.2vw, 2.65rem);
  }

  .status {
    height: 54px;
    margin: 13px 0 12px;
  }

  .column-button {
    min-height: 36px;
    font-size: 0.82rem;
  }

  .board-wrap {
    width: 100%;
  }

  .board {
    padding: 6px;
    border-width: 3px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .replay-actions {
    grid-template-columns: 1fr;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app-shell {
    width: min(100vw - 16px, 1000px);
    padding: 8px 0 12px;
    gap: 10px;
  }

  .app-shell .game-panel {
    display: grid;
    grid-template-columns: minmax(170px, 0.72fr) minmax(260px, 1.28fr);
    grid-template-areas:
      "header board"
      "status board";
    align-items: start;
    gap: 10px 12px;
    padding: 10px;
  }

  .app-shell .top-bar {
    grid-area: header;
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .app-shell .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .app-shell .report-link,
  .app-shell .top-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 8px;
    font-size: 0.82rem;
    text-align: center;
  }

  .app-shell .eyebrow {
    font-size: 0.68rem;
  }

  .app-shell h1 {
    font-size: clamp(1.9rem, 5.2vw, 3rem);
  }

  .app-shell .status {
    grid-area: status;
    height: auto;
    min-height: 70px;
    max-height: 110px;
    margin: 0;
    padding: 10px 12px;
    font-size: 0.88rem;
  }

  .app-shell .board-wrap {
    grid-area: board;
    align-self: start;
    width: min(100%, calc((100dvh - 72px) * 7 / 6));
    padding-bottom: 0;
  }

  .app-shell .column-controls {
    margin-bottom: 7px;
    padding: 0 3px;
  }

  .app-shell .column-controls,
  .app-shell .board {
    gap: clamp(4px, 0.8vw, 6px);
  }

  .app-shell .column-button {
    min-height: 34px;
    border-radius: 7px;
    font-size: 0.84rem;
  }

  .app-shell .board {
    padding: clamp(6px, 1vw, 8px);
    border-width: 4px;
    border-radius: 12px;
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.22),
      inset 0 -8px 14px rgba(4, 38, 70, 0.18),
      0 7px 0 #031d35,
      0 12px 22px rgba(0, 0, 0, 0.34);
  }

  .app-shell .side-panel {
    padding: 12px;
  }
}

@media (max-width: 560px) {
  .report-body .report-page {
    width: 100%;
    padding: 0 8px 28px;
  }

  .report-body .report-hero {
    margin-bottom: 12px;
    padding: 14px;
    border-top-width: 5px;
  }

  .report-body .report-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 20px;
  }

  .report-body .report-link,
  .report-body .pdf-button {
    width: auto;
    min-height: 40px;
    padding: 0 8px;
    font-size: 0.9rem;
  }

  .report-body .report-hero h1 {
    font-size: clamp(2rem, 12vw, 2.8rem);
  }

  .report-body .report-author {
    line-height: 1.35;
  }

  .report-body .report-project-links {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .report-body .report-project-links a {
    justify-content: center;
    min-height: 36px;
    text-align: center;
  }

  .report-body .report-lede {
    font-size: 0.98rem;
    line-height: 1.45;
  }

  .report-body .report-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 16px;
  }

  .report-body .report-metrics div {
    padding: 10px;
  }

  .report-body .report-grid {
    gap: 12px;
  }

  .report-body .report-section {
    padding: 14px;
  }
}

@media print {
  @page {
    size: Letter;
    margin: 0;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  html {
    font-size: 13px;
  }

  body,
  .report-body {
    min-height: auto;
    background:
      radial-gradient(circle at 16% 12%, rgba(93, 23, 37, 0.28), transparent 28%),
      linear-gradient(145deg, #08090d 0%, #121820 52%, #1a0d13 100%);
    color: var(--ink);
  }

  .report-page {
    width: auto;
    max-width: none;
    min-height: 100vh;
    padding: 0.32in;
  }

  .report-actions {
    display: none;
  }

  .report-hero,
  .report-section {
    break-inside: auto;
    border-radius: 5px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  }

  .report-hero {
    padding: 24px 26px;
    margin-bottom: 13px;
    border-top-width: 4px;
  }

  .report-hero::before {
    opacity: 0.6;
  }

  .report-hero .eyebrow {
    margin-bottom: 4px;
    font-size: 0.68rem;
  }

  .report-hero h1 {
    font-size: 2.35rem;
    line-height: 1.05;
    text-shadow: none;
  }

  .report-lede {
    max-width: none;
    margin-top: 8px;
    font-size: 0.92rem;
    line-height: 1.45;
  }

  .report-author {
    margin-top: 5px;
    font-size: 0.72rem;
  }

  .report-project-links {
    gap: 5px;
    margin-top: 7px;
  }

  .report-project-links a {
    min-height: 24px;
    padding: 0 7px;
    border-radius: 5px;
    font-size: 0.62rem;
  }

  dt {
    font-size: 0.62rem;
  }

  dd {
    margin-top: 3px;
    font-size: 0.74rem;
  }

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

  .report-section {
    padding: 16px 18px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .report-grid .report-section:nth-child(4),
  .report-grid .report-section:nth-child(9) {
    break-before: page;
    page-break-before: always;
  }

  .report-grid .report-section:nth-child(4),
  .report-grid .report-section:nth-child(5),
  .report-grid .report-section:nth-child(9) {
    margin-top: 0.24in;
  }

  .report-section h2 {
    margin-bottom: 7px;
    font-size: 1rem;
    break-after: avoid;
    page-break-after: avoid;
  }

  .report-section p,
  .checklist-grid,
  .heuristic-list,
  .algorithm-grid,
  .command-list,
  .report-table-wrap {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .report-section p {
    font-size: 0.84rem;
    line-height: 1.42;
  }

  .report-section p + p {
    margin-top: 7px;
  }

  .report-section code {
    padding: 1px 3px;
  }

  .report-metrics {
    gap: 6px;
    margin-top: 11px;
  }

  .report-metrics div {
    padding: 8px 9px;
    border-radius: 6px;
  }

  .report-metrics span,
  .heuristic-list span {
    font-size: 0.62rem;
  }

  .report-metrics strong,
  .heuristic-list strong {
    margin-top: 3px;
    font-size: 0.76rem;
  }

  .report-metrics,
  .checklist-grid,
  .heuristic-list,
  .algorithm-grid,
  .source-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .checklist-grid,
  .heuristic-list,
  .algorithm-grid,
  .source-list {
    gap: 6px;
  }

  .checklist-grid div {
    padding: 8px 9px 8px 24px;
    border-radius: 6px;
    font-size: 0.76rem;
    line-height: 1.33;
  }

  .checklist-grid div::before {
    left: 9px;
    top: 10px;
    width: 6px;
    height: 6px;
    box-shadow: 0 0 0 2px rgba(128, 38, 57, 0.22);
  }

  .heuristic-list {
    margin-bottom: 8px;
  }

  .algorithm-grid {
    margin-bottom: 8px;
  }

  .algorithm-grid div {
    padding: 8px 9px;
    border-radius: 6px;
  }

  .algorithm-grid strong {
    margin-bottom: 3px;
    font-size: 0.78rem;
  }

  .algorithm-grid span {
    font-size: 0.74rem;
    line-height: 1.3;
  }

  .heuristic-list div {
    padding: 8px 9px;
    border-radius: 6px;
  }

  .source-list {
    margin-top: 7px;
  }

  .source-list a,
  .source-list div {
    padding: 7px 8px;
    border-radius: 6px;
  }

  .source-list strong {
    font-size: 0.72rem;
  }

  .source-list span {
    margin-top: 2px;
    font-size: 0.62rem;
    line-height: 1.25;
  }

  .table-wrap {
    margin-top: 7px;
  }

  table {
    font-size: 0.74rem;
  }

  th,
  td {
    padding: 4px 6px;
    white-space: normal;
  }

  th {
    font-size: 0.62rem;
  }
}
