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

html {
  scroll-behavior: smooth;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --p1: #DA1D00;
  --p2: #F6D300;
  --win: #22c55e;
  --radius: 8px;
  --cell-step: 80px; /* set by ResizeObserver */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem 0.75rem;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 0.75rem;
}

.app-footer-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.app-footer-link:hover {
  color: var(--text);
}

.hidden { display: none !important; }

/* ── Buttons ─────────────────────────────────────────────── */
button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover { background: var(--accent-hover); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.icon-only-button { display: inline-flex; align-items: center; justify-content: center; }
.btn-delete { background: #7f1d1d !important; color: #fca5a5 !important; }
.btn-delete:hover { background: #991b1b !important; }
.icon-text-button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

/* ── Difficulty badges ───────────────────────────────────── */
.difficulty-badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.diff-easy     { background: #166534; color: #86efac; }
.diff-moderate { background: #1e3a5f; color: #93c5fd; }
.diff-hard     { background: #7c2d12; color: #fdba74; }
.diff-god      { background: #3b0764; color: #e879f9; }

/* ── Lobby ───────────────────────────────────────────────── */
#lobby {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background-color: var(--bg);
  background-image: linear-gradient(rgba(15, 23, 42, 0.45), rgba(15, 23, 42, 0.85)), url("ott-photo-crop.jpg");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
}
.lobby-header { text-align: center; padding: 1rem 0 1.5rem; position: relative; }
.lobby-logo-title {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 128px;
  margin-bottom: 0.85rem;
}
.lobby-logo {
  display: block;
  width: auto;
  max-width: min(520px, 92vw);
  height: 100%;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, 0.28));
}
.subtitle { color: var(--p2); font-size: 0.9rem; }

.landing-panel,
.setup-panel {
  max-width: 1100px;
  margin: 0 auto 1.5rem;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px);
  background: color-mix(in srgb, var(--bg) 54%, transparent);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
}

.landing-panel {
  padding: 1.75rem;
}

.landing-panel-copy {
  max-width: 760px;
}

.landing-eyebrow {
  margin-bottom: 0.55rem;
  color: var(--p2);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.landing-panel h2,
.setup-panel h2 {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  line-height: 1.05;
  margin-bottom: 0.75rem;
}

.landing-thesis {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
}

.landing-panel p,
.setup-panel-intro,
.setup-card p {
  color: var(--text-dim);
  line-height: 1.6;
}

.landing-panel-copy > p + p {
  margin-top: 0.9rem;
}

.landing-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.4rem;
}

.landing-primary-action,
.landing-secondary-action,
.snippet-copy-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.landing-secondary-action {
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  background: color-mix(in srgb, var(--surface) 26%, transparent);
}

.landing-secondary-action:hover {
  background: color-mix(in srgb, var(--surface) 48%, transparent);
}

.auth-status {
  position: fixed;
  top: 15px;
  right: 15px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
	z-index: 5000;
	box-shadow: 0 8px 16px -8px black;
}

.support-link {
	position: fixed;
  top: 15px;
  left: 15px;
	display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  transition: color 0.15s ease, opacity 0.15s ease;
	z-index: 5000;
	box-shadow: 0 8px 16px -8px black;
}

.support-link img {
	height: 44px;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
}

.auth-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.auth-username {
  font-size: 0.875rem;
  color: var(--text);
  font-weight: 500;
}

.auth-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  color: white;
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s;
}

.auth-login-btn:hover {
  background: var(--accent-hover);
}

.auth-logout-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.auth-logout-btn:hover {
  background: var(--border);
  color: var(--text);
}

/* Debug admin-mask toggle — only shown to real admins */
.auth-mask-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  opacity: 0.7;
}

.auth-mask-btn:hover {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}


.lobby-card {
  max-width: 480px;
  margin: 0 auto 1.5rem;
  background: var(--surface);
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
}
.lobby-card h2 { font-size: 1rem; margin-bottom: 0.75rem; }
.lobby-card input[type="text"] {
  display: block;
  width: 100%;
  padding: 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  box-sizing: border-box;
}
.lobby-card input[type="text"]#playerName {
	text-align: center;
	width: 320px;
	margin: auto;
	padding: 1rem 0.5rem;
	font-size: 1.125rem;
}
.lobby-field { display: flex; flex-direction: column; gap: 0.4rem; text-align: left; margin-bottom: 1.25rem; }
.lobby-label { font-size: 0.72rem; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; text-align: center; }
.lobby-switch {
	display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg);
	width: 320px;
	margin: 0 auto;
}
.lobby-switch-opt { padding: 0.55rem 0; font-size: 1.125rem; background: transparent; color: var(--text-dim); border: none; border-radius: 0; cursor: pointer; transition: background 0.15s, color 0.15s; display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; }
.lobby-switch-opt:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); }
.lobby-switch-opt-active { background: var(--accent); color: #fff; }
.lobby-switch-opt-active:hover { background: var(--accent-hover); color: #fff; }
.lobby-switch .material-symbol-slot { width: 2rem; height: 2rem; }
.lobby-range-wrap { display: flex; flex-direction: column; gap: 0.4rem; }
.lobby-range-wrap input[type="range"] { width: 100%; cursor: pointer; }
/*
.lobby-range-wrap input[type="range"]::-webkit-slider-runnable-track { background: linear-gradient(to right, var(--range-color) var(--range-fill, 40%), var(--border) var(--range-fill, 40%)); border-radius: 999px; }
.lobby-range-wrap input[type="range"]::-moz-range-track { background: linear-gradient(to right, var(--range-color) var(--range-fill, 40%), var(--border) var(--range-fill, 40%)); border-radius: 999px; }
*/
.lobby-range-wrap input[type="range"]::-webkit-slider-runnable-track { background: linear-gradient(to right, color-mix(in srgb, var(--range-color) 25%, var(--bg)) 0%, var(--range-color) var(--range-fill, 40%), var(--border) var(--range-fill, 40%)); border-radius: 999px; }
.lobby-range-wrap input[type="range"]::-moz-range-track { background: linear-gradient(to right, color-mix(in srgb, var(--range-color) 25%, var(--bg)) 0%, var(--range-color) var(--range-fill, 40%), var(--border) var(--range-fill, 40%)); border-radius: 999px; }
.lobby-range-labels { position: relative; height: 1.3em; }
.lobby-range-labels span { position: absolute; font-size: 1rem; color: var(--text-dim); white-space: nowrap; transform: translateX(-50%); cursor: pointer; user-select: none; }
.lobby-range-labels span:hover { color: var(--text); }
.lobby-range-label-active { color: #fff !important; font-weight: bold; }
.lobby-range-labels span:nth-child(1) { left: 20%; }
.lobby-range-labels span:nth-child(2) { left: 40%; }
.lobby-range-labels span:nth-child(3) { left: 60%; }
.lobby-range-labels span:nth-child(4) { left: 80%; }

.games-list {
  max-width: 1100px;
  /*margin: 0 auto;*/
  background: var(--surface);
  background: color-mix(in srgb, var(--bg) 45%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.games-list h2 { font-size: 1rem; margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.5rem; }

.setup-panel {
  padding: 1.5rem;
}

.setup-panel-header {
  margin-bottom: 1.25rem;
}

.setup-panel-header h2 {
  margin-bottom: 0.45rem;
}

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

.setup-card {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--border) 84%, transparent);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.35);
}

.setup-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.setup-card h3 {
  margin-bottom: 0.3rem;
  font-size: 1rem;
}

.setup-card code {
  font-family: inherit;
  color: var(--text);
}

.snippet-copy-button {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 34%, transparent);
  color: var(--text);
  white-space: nowrap;
}

.snippet-copy-button:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.snippet-copy-button[data-copy-state="copied"] {
  border-color: color-mix(in srgb, var(--win) 46%, var(--border));
  color: var(--win);
}

.snippet-copy-button[data-copy-state="error"] {
  border-color: #7f1d1d;
  color: #fca5a5;
}

.setup-code-block {
  overflow-x: auto;
  padding: 1rem;
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  border-radius: var(--radius);
  background: rgba(2, 6, 23, 0.84);
}

.setup-code-block code {
  display: block;
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.84rem;
  line-height: 1.55;
  white-space: pre;
}
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.4rem 0.25rem; text-align: left; border-bottom: 1px solid rgba(255,255,255,0.2); }
td:first-child {
	padding-left: 1rem;
}
th { color: var(--text-dim); font-weight: 600; }
td button { font-size: 0.75rem; padding: 0.2rem 0.5rem; }
/* Highlight rows for active games created by the current user */
tr.tr-own-game td {
	background: color-mix(in srgb, var(--accent) 33%, transparent);
}
tr.tr-own-game.tr-own-game-review td {
	background: color-mix(in srgb, var(--accent) 14%, transparent);
}
tr.tr-own-game td:first-child {
	border-top-left-radius: 16px;
	border-bottom-left-radius: 16px;
}
tr.tr-own-game td:last-child {
	border-top-right-radius: 16px;
	border-bottom-right-radius: 16px;
}
.seat-role-mark { display: inline-flex; vertical-align: text-bottom; margin-right: 0.18rem; }
.seat-name { display: inline; }
.seat-versus { color: var(--text-dim); margin: 0 0.3rem; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Game View ───────────────────────────────────────────── */
#gameView {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Game Header ─────────────────────────────────────────── */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 1rem;
}
.game-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.game-header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  white-space: nowrap;
}
.brand-logo {
  display: block;
  height: 48px;
  width: auto;
  max-width: min(46vw, 188px);
}
.hdiv    { color: var(--border); }
.hitem   { font-size: 0.85rem; color: var(--p2); white-space: nowrap; }
.htime   { color: var(--text); display: inline-flex; align-items: center; gap: 0.35rem; }
.hgameid { font-family: monospace; font-size: 0.8rem; }
.game-id-copy {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--p2);
}
.game-id-copy:hover {
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border-color: var(--border);
}
.game-id-copy:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.game-id-copy .hgameid { color: inherit; }
.material-symbol-slot {
  display: inline-flex;
  width: 0.95rem;
  height: 0.95rem;
  color: inherit;
  opacity: 0.9;
}
.material-symbol-icon {
  width: 100%;
  height: 100%;
  display: block;
  fill: currentColor;
}
.game-id-copy-state {
  font-size: 0.72rem;
  color: var(--text-dim);
}
.game-id-copy[data-copy-state="idle"] .game-id-copy-state {
  display: none;
}
.game-id-copy[data-copy-state="copied"] {
  color: var(--win);
  border-color: color-mix(in srgb, var(--win) 45%, var(--border));
}
.game-id-copy[data-copy-state="copied"] .game-id-copy-state {
  color: var(--win);
}
.game-id-copy[data-copy-state="error"] {
  color: #fca5a5;
  border-color: #7f1d1d;
}
.game-id-copy[data-copy-state="error"] .game-id-copy-state {
  color: #fca5a5;
}

/* ── Game Area ───────────────────────────────────────────── */
.game-area {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 1rem;
  overflow: hidden;
  min-height: 0;
  align-items: stretch;
}

/* ── Board ───────────────────────────────────────────────── */
.board-container {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.trace-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  overflow: hidden;
}

.trace-stage h3 {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 0;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.column-buttons {
  width: min(calc(100vw - 328px), calc((100dvh - 112px - 1.62rem - 6px) * 7 / 6));
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.7%;
  margin-bottom: 4px;
}
.col-btn {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: bold;
  font-size: 0.85rem;
}
.col-btn:hover  { background: var(--accent); border-color: var(--accent); }
.col-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.board-wrap {
  /* Proportional sizing — board-wrap is the reference for cqw */
  width: min(calc(100vw - 328px), calc((100dvh - 112px - 1.62rem - 6px) * 7 / 6));
  max-width: 100%;
  aspect-ratio: 7 / 6;
  container-type: inline-size; /* enables cqw on .board */
}

.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  gap: 0.7cqw;        /* 0.7% of board's own width */
  background: linear-gradient(to bottom, var(--accent-hover), var(--accent));
  padding: 1cqw;      /* 1% of board's own width */
  border-radius: 1.5cqw;
  overflow: hidden;
}

.cell {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--accent-hover);
  border-radius: 50%;
  background: var(--bg);
  box-shadow: inset 0 6px 14px rgba(0,0,0,0.65), inset 0 2px 4px rgba(0,0,0,0.3);
  position: relative;
}
.cell.p1 {
  background: var(--p1);
  box-shadow: inset 0 6px 14px rgba(0,0,0,0.55), inset 0 2px 4px rgba(0,0,0,0.2), 0 2px 8px rgba(239,68,68,0.35);
}
.cell.p2 {
  background: var(--p2);
  box-shadow: inset 0 6px 14px rgba(0,0,0,0.55), inset 0 2px 4px rgba(0,0,0,0.2), 0 2px 8px rgba(250,204,21,0.35);
}
.cell.winning {
  box-shadow: inset 0 6px 14px rgba(0,0,0,0.55), inset 0 2px 4px rgba(0,0,0,0.2), 0 0 0 4px var(--win), 0 0 20px var(--win);
  z-index: 1;
}

/* Drop animation */
@keyframes drop-piece {
  0%   { transform: translateY(calc(var(--drop-rows, 0) * -1 * var(--cell-step))); }
  65%  { transform: translateY(5px); }
  82%  { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}
.cell.dropping {
  animation: drop-piece 0.4s cubic-bezier(0.33, 1, 0.68, 1) forwards;
}

/* ── Side Panel ──────────────────────────────────────────── */
.side-panel {
  flex: 0 0 280px;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: hidden;
}
.side-panel > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  flex-shrink: 0;
}
.side-panel h3 {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
#statusText {
  font-size: 1rem;
  font-weight: 600;
}

.status-win-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  margin-right: 0.38rem;
  vertical-align: text-bottom;
}

.status-win-mark .material-symbol-slot,
.status-win-mark .material-symbol-icon {
  display: inline-flex;
  width: 100%;
  height: 100%;
}
.reasoning-content {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  font-size: 0.85rem;
  color: var(--text-dim);
  overflow-y: auto;
}

.reasoning-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

.reasoning-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
  background: rgba(15, 23, 42, 0.45);
  min-width: 0;
}

.reasoning-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  margin-bottom: 0.5rem;
}

.reasoning-stat-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.38rem;
  width: 100%;
  min-width: 0;
}

.reasoning-stat-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  min-width: 0;
}

.reasoning-time-row {
  display: flex;
  width: 100%;
  min-width: 0;
}

.reasoning-stat-label .player-name {
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
}

.reasoning-stat-label .player-time {
  margin-left: auto;
  margin-right: 0;
}

.reasoning-player-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.9rem;
  height: 0.9rem;
  flex: 0 0 auto;
}

.reasoning-player-pill.p1,
.trace-player-pill.p1 {
  color: var(--p1);
}

.reasoning-player-pill.p2,
.trace-player-pill.p2 {
  color: var(--p2);
}

.reasoning-player-pill .material-symbol-slot,
.reasoning-player-pill .material-symbol-icon {
  display: inline-flex;
  width: 100%;
  height: 100%;
}

.trace-player-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.4rem;
  padding: 0.14rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--bg);
}

.trace-player-pill.p1 {
  background: var(--p1);
}

.trace-player-pill.p2 {
  background: var(--p2);
}

.trace-player-name {
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  overflow-wrap: anywhere;
}

.reasoning-panel-no-body .reasoning-panel-head {
  margin-bottom: 0;
}

.reasoning-panel-body {
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.reasoning-empty {
  color: var(--text-dim);
  font-style: italic;
}

.trace-summary-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.6rem;
  align-content: start;
}

.trace-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(15, 23, 42, 0.5);
  padding: 1.5rem;
}

.trace-card h4 {
  font-size: 0.76rem;
  color: var(--text-dim);
  margin-bottom: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.trace-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.18rem 0;
  font-size: 0.82rem;
}

.trace-row span:first-child {
  flex: 0 0 auto;
}

.trace-row span:last-child {
  color: var(--text-dim);
  text-align: right;
  min-width: 0;
  overflow-wrap: anywhere;
}

.trace-note {
  margin-top: 0.45rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.trace-card-session {
  grid-column: 1 / -1;
}

.trace-card-game {
  grid-column: 1 / -1;
}

.trace-card-players {
  grid-column: 1 / -1;
}

.trace-game-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.2rem 1.25rem;
}

.trace-game-grid .trace-row {
  padding: 0.12rem 0;
}

.trace-section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.trace-section-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
  background: rgba(15, 23, 42, 0.35);
  min-width: 0;
}

.trace-section-block h5 {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.trace-ai-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.7rem;
}

.trace-agent-headers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.trace-agent-header {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 0;
}

.trace-agent-header-right {
  align-items: flex-start;
  text-align: left;
}

.trace-agent-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-width: 0;
}

.trace-agent-header-right .trace-agent-title-row {
  justify-content: space-between;
}

.trace-agent-title {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  min-width: 0;
}

.trace-agent-header-right .trace-agent-title {
  justify-content: flex-start;
}

.trace-agent-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  flex: 0 0 auto;
}

.trace-agent-dot.p1 {
  background: var(--p1);
}

.trace-agent-dot.p2 {
  background: var(--p2);
}

.trace-agent-name {
  display: inline-flex;
  align-items: baseline;
  gap: 0.2rem;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text);
}

.trace-agent-header-winner .trace-agent-name {
  color: var(--win);
}

.trace-agent-name-main {
  min-width: 0;
  overflow-wrap: anywhere;
}

.trace-agent-name-status {
  color: inherit;
}

.trace-agent-victory {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--win);
  white-space: nowrap;
}

.trace-agent-victory-label {
  font-size: 0.8rem;
}

.trace-agent-victory-value {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.6rem;
  padding: 0.14rem 0.4rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--win) 45%, var(--border));
  background: rgba(34, 197, 94, 0.14);
  font-size: 0.86rem;
  font-weight: 800;
}

.trace-agent-alert {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  line-height: 1.45;
}

.trace-agent-subtitle {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.trace-model-edit-form {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.trace-model-edit-input {
  min-width: 12rem;
  max-width: min(18rem, 100%);
  padding: 0.42rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}

.trace-model-edit-button {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--p2) 40%, var(--border));
  background: color-mix(in srgb, var(--p2) 14%, var(--panel));
  color: var(--text);
  border-radius: 999px;
  padding: 0.36rem 0.72rem;
  font-size: 0.75rem;
  /*font-weight: 700;*/
  cursor: pointer;
}

.trace-model-edit-button:hover:not(:disabled) {
  /*background: color-mix(in srgb, var(--p2) 22%, var(--panel));*/
}

.trace-model-edit-button:disabled {
  opacity: 0.65;
  cursor: default;
}

.trace-model-edit-button-secondary {
  border-color: var(--border);
  background: transparent;
}

.trace-agent-subtitle {
  font-size: 0.78rem;
  color: var(--text-dim);
}

.trace-compare-metrics {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.trace-compare-metrics::before {
  content: "";
  position: absolute;
  top: 0.15rem;
  bottom: 0.15rem;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  background: color-mix(in srgb, var(--border) 80%, transparent);
}

.trace-compare-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1.6rem minmax(0, 1fr);
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.15rem 0;
  position: relative;
  z-index: 1;
}

.trace-compare-half {
  display: grid;
  align-items: baseline;
  gap: 0.65rem;
  min-width: 0;
}

.trace-compare-half-left {
  grid-template-columns: minmax(0, 1fr) auto;
}

.trace-compare-half-right {
  grid-template-columns: auto minmax(0, 1fr);
}

.trace-compare-score {
  min-width: 0;
  color: white;
  font-size: 0.92rem;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.trace-compare-score-left {
  justify-self: end;
  text-align: right;
}

.trace-compare-score-right {
  justify-self: start;
  text-align: left;
}

.trace-compare-score-best {
  color: var(--text);
  font-weight: 800;
}

.trace-compare-score-nan {
  color: var(--text-dim);
  font-style: italic;
}

.trace-compare-term {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
  line-height: 1.35;
}

.trace-compare-term-left {
  justify-content: flex-start;
  text-align: left;
}

.trace-compare-term-right {
  justify-content: flex-end;
  text-align: right;
}

.trace-compare-label-main {
  color: var(--text);
  font-size: 0.82rem;
}

.trace-compare-label-note {
  color: var(--text-dim);
  font-size: 0.74rem;
}

.trace-compare-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 1em;
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
}

.trace-compare-arrow-left,
.trace-compare-arrow-right {
  color: color-mix(in srgb, var(--text-dim) 90%, var(--text));
}

.trace-timeline-block {
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
}

.trace-timeline-block h5 {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-bottom: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}

.trace-timeline-stage {
	/*
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  border-radius: calc(var(--radius) + 2px);
  background: rgba(15, 23, 42, 0.35);
  overflow: visible;
	*/
  padding: 2rem 1rem 3rem;
}

.trace-timeline-list {
  position: relative;
  overflow: visible;
  padding: 0 0.25rem 0.25rem;
}

.trace-timeline-entry {
  --trace-center-width: 2rem;
  --trace-node-size: 1.45rem;
  --trace-row-gap: 0.85rem;
  --trace-node-overlap: 0;
  position: relative;
  z-index: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 1.45rem minmax(0, 1fr);
  gap: 0;
  min-height: var(--trace-node-size);
  align-items: start;
}

.trace-timeline-side {
  min-width: 0;
  position: relative;
  z-index: 1;
  height: 0;
  overflow: visible;
}

.trace-timeline-side-content {
  position: absolute;
  top: calc(var(--trace-node-size) / 2);
  transform: translateY(-50%);
  align-items: center;
  width: 100%;
  max-width: none;
  min-width: 0;
}

.trace-timeline-side-content-empty {
  display: none;
}

.trace-timeline-side-content-bubble-left {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 4.8rem;
  right: 0;
}

.trace-timeline-side-content-bubble-right {
  display: grid;
  grid-template-columns: 4.8rem minmax(0, 1fr);
  left: 0;
}

.trace-timeline-side-content-bubble-left .trace-timeline-card {
  justify-self: end;
  max-width: 100%;
}

.trace-timeline-side-content-bubble-right .trace-timeline-card {
  justify-self: start;
  max-width: 100%;
}

.trace-timeline-center {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--trace-node-size);
  --trace-node-color: var(--border);
}

.trace-timeline-center::before {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(-1 * var(--trace-gap, 0px));
  transform: translateX(-50%);
  width: 3px;
  height: var(--trace-gap-extended, 0px);
  background: var(--trace-node-color);
}

.trace-timeline-center-p1 {
  --trace-node-color: var(--p1);
}

.trace-timeline-center-p2 {
  --trace-node-color: var(--p2);
}

/* .trace-timeline-center-win {
  --trace-node-color: var(--win);
} */

.trace-timeline-node {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--border);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
}

.trace-timeline-node-p1 {
  border-color: var(--p1);
  color: var(--p1);
}

.trace-timeline-node-p2 {
  border-color: var(--p2);
  color: var(--p2);
}

.trace-timeline-node-win {
  background-color: var(--win);
  color: var(--bg);
  /* border-color: var(--win); */
  box-shadow: 0 0 12px 6px var(--win);
}

.trace-timeline-elapsed {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.22rem;
  /*background: rgba(15, 23, 42, 0.96);*/
  color: var(--text-dim);
  font-size: 0.75rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
  z-index: 2;
}

.trace-timeline-lane {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 4.8rem;
  width: 4.8rem;
  height: 1.45rem;
  justify-self: stretch;
  align-self: center;
}

.trace-timeline-connector {
  width: 100%;
  height: 1px;
  opacity: 0.95;
}

.trace-timeline-side-content-elapsed {
  display: flex;
  align-items: center;
}

.trace-timeline-side-content-elapsed-left {
  justify-content: flex-end;
  right: 10px;
}

.trace-timeline-side-content-elapsed-left .trace-timeline-elapsed {
	color: var(--p2);
}

.trace-timeline-side-content-elapsed-right {
  justify-content: flex-start;
  left: 10px;
}

.trace-timeline-side-content-elapsed-right .trace-timeline-elapsed {
	color: var(--p1);
}

.trace-timeline-side-content-elapsed .trace-timeline-elapsed {
  position: static;
  transform: none;
}

.trace-timeline-connector-p1 {
  background: color-mix(in srgb, var(--p1) 80%, transparent);
}

.trace-timeline-connector-p2 {
  background: color-mix(in srgb, var(--p2) 80%, transparent);
}

.trace-timeline-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  background: rgba(15, 23, 42, 0.5);
  min-width: 0;
}

.trace-timeline-card-p1 {
  border-color: color-mix(in srgb, var(--p1) 60%, var(--border));
}

.trace-timeline-card-p2 {
  border-color: color-mix(in srgb, var(--p2) 60%, var(--border));
}

.trace-timeline-card-missing {
  border-style: dashed;
}

.trace-timeline-card-text {
  color: var(--text);
  font-size: 0.81rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.trace-timeline-card-missing .trace-timeline-card-text {
  color: var(--text-dim);
  font-style: italic;
}

.trace-timeline-card-column {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.trace-timeline-empty {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
}

/* ── Player stats ────────────────────────────────────────── */
.player-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.player-dot.p1 { background: var(--p1); }
.player-dot.p2 { background: var(--p2); }
.player-name { font-weight: 600; font-size: 0.82rem; white-space: nowrap; flex-shrink: 0; }
.player-time { color: var(--text-dim); font-size: 0.78rem; white-space: nowrap; flex-shrink: 0; margin-right: 0.2rem; }
.player-bar-track { flex: 1; min-width: 0; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.player-bar { height: 100%; border-radius: 2px; transition: width 0.3s ease; min-width: 2px; }
.player-bar.p1 { background: var(--p1); }
.player-bar.p2 { background: var(--p2); }

/* ── Move list ───────────────────────────────────────────── */
.moves-list {
  flex: 1 1 0;
  min-height: 0;
  font-size: 0.8rem;
  overflow-y: auto;
  font-family: monospace;
}
.move-entry { padding: 0.2rem 0; border-bottom: 1px solid var(--border); }
.moves-box {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.move-entry:last-child { border-bottom: none; }
.move-p1 { color: var(--p1); }
.move-p2 { color: var(--p2); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 780px) {
  .landing-panel,
  .setup-panel {
    padding: 1rem;
  }

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

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

  .snippet-copy-button {
    align-self: flex-start;
  }

  .game-area { flex-direction: column; overflow-y: auto; align-items: stretch; }
  .board-container { flex: 0 0 auto; }
  .trace-stage { flex: 0 0 auto; min-height: 340px; }
  .side-panel { flex: 0 0 auto; width: auto; max-height: none; }
  .trace-section-grid,
  .reasoning-grid,
  .trace-summary-content {
    grid-template-columns: 1fr;
  }

  .trace-agent-headers {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .trace-game-grid {
    grid-template-columns: 1fr;
  }

  .trace-agent-header-right {
    align-items: flex-start;
    text-align: left;
  }

  .trace-agent-header-right .trace-agent-title-row {
    flex-direction: row;
  }

  .trace-agent-header-right .trace-agent-title {
    justify-content: flex-start;
  }

  .trace-compare-row {
    grid-template-columns: minmax(0, 1fr) 1.2rem minmax(0, 1fr);
    gap: 0.35rem;
  }

  .trace-compare-half {
    gap: 0.35rem;
  }

  .trace-compare-label-note {
    display: none;
  }

  .trace-timeline-stage {
    padding: 0.85rem 0.4rem 0.85rem;
  }

  .trace-timeline-entry {
    --trace-center-width: 1.7rem;
    --trace-row-gap: 0.45rem;
    grid-template-columns: minmax(0, 1fr) 1.45rem minmax(0, 1fr);
    gap: 0;
  }

  .trace-timeline-lane {
    flex-basis: 3.2rem;
    width: 3.2rem;
  }

  .trace-timeline-side-content-bubble-left {
    grid-template-columns: minmax(0, 1fr) 3.2rem;
  }

  .trace-timeline-side-content-bubble-right {
    grid-template-columns: 3.2rem minmax(0, 1fr);
  }
}
