:root {
  --bg: #10131a;
  --panel: #171b24;
  --panel-2: #1d222d;
  --line: #2a3040;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #4da3ff;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --warn: #ffc857;
  --card-bg: #fdfaf3;
  --card-back: #223049;
  --card-back-line: #3b5480;
  --felt: #17603f;
  --felt-2: #114b32;
  --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9; --panel: #ffffff; --panel-2: #eef1f7; --line: #d7dce8;
    --text: #171c27; --muted: #5d6577; --card-back: #2b3d5c; --card-back-line: #93a8cd;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #06131f; border-color: transparent; font-weight: 600; }
button:disabled { opacity: .45; cursor: not-allowed; }
select, input { font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; }
h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hidden { display: none !important; }

/* ------------------------------------------------------------- top bar */
.topbar { display: flex; align-items: center; gap: 18px; padding: 10px 18px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; letter-spacing: .04em; }
.brand span { color: var(--accent); }
.tabs { display: flex; gap: 6px; }
.tab.active { background: var(--accent); color: #06131f; border-color: transparent; }
.spacer { flex: 1; }
.status { color: var(--muted); font-size: 12px; }
main { padding: 16px; max-width: 1500px; margin: 0 auto; }

.setup-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.setup-bar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.setup-bar label.check { cursor: pointer; }
.hint { color: var(--muted); font-size: 13px; }

/* --------------------------------------------------------------- table */
.play-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 1080px) { .play-grid { grid-template-columns: 1fr; } }
.table-wrap { display: flex; flex-direction: column; gap: 14px; }
.table {
  position: relative; border-radius: 20px; min-height: 400px; padding: 14px;
  background: radial-gradient(circle at 50% 45%, var(--felt), var(--felt-2));
  border: 1px solid var(--line);
}
.seat { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.seat-top { top: 10px; left: 50%; transform: translateX(-50%); }
.seat-left { left: 12px; top: 50%; transform: translateY(-50%); }
.seat-right { right: 12px; top: 50%; transform: translateY(-50%); }
.seat-info { font-size: 12px; text-align: center; color: #dfe7e2; background: rgba(0,0,0,.35);
  padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.seat.active .seat-info { background: var(--accent); color: #06131f; font-weight: 600; }
.seat.partner .seat-info { outline: 1px solid var(--good); }
.seat-cards { display: flex; gap: -6px; }
.seat-cards .card-svg { margin-left: -22px; }
.seat-cards .card-svg:first-child { margin-left: 0; }
.trick { position: absolute; inset: 22% 26%; display: grid; place-items: center;
  grid-template-areas: ". top ." "left . right" ". bottom ."; pointer-events: none; }
.trick .slot { display: grid; place-items: center; }
.trick .slot.top { grid-area: top; } .trick .slot.left { grid-area: left; }
.trick .slot.right { grid-area: right; } .trick .slot.bottom { grid-area: bottom; }
.trick .card-svg { filter: drop-shadow(0 4px 8px rgba(0,0,0,.45)); }
.trick .winning { outline: 3px solid var(--warn); border-radius: 10px; }
.trump-slot { position: absolute; right: 14px; bottom: 12px; text-align: center;
  color: #dfe7e2; font-size: 11px; }
.trump-slot .card-svg { transform: rotate(8deg); }

.hand-area { display: flex; flex-direction: column; gap: 8px; }
.hand { display: flex; flex-wrap: wrap; gap: 6px; min-height: 120px; align-items: flex-end; }
.hand .card-holder { position: relative; transition: transform .12s ease; cursor: not-allowed; }
.hand .card-holder.legal { cursor: pointer; }
.hand .card-holder.legal:hover { transform: translateY(-12px); }
.hand .card-holder.illegal .card-svg { opacity: .32; filter: grayscale(.6); }
.hand .card-holder.best .card-svg { outline: 3px solid var(--good); border-radius: 10px; }
.policy-badge { position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #06131f; font-size: 11px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px; }
.mv-badge { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); font-size: 10px;
  padding: 1px 5px; border-radius: 999px; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --------------------------------------------------------------- panels */
.side { display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.score-row { display: flex; justify-content: space-between; padding: 3px 0; }
.score-row.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-weight: 600; }
.pill { background: var(--panel-2); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
.log { max-height: 260px; overflow-y: auto; font-size: 12.5px; display: flex; flex-direction: column-reverse; }
.log div { padding: 2px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
.log div.big { color: var(--text); font-weight: 600; }

.insight-options { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.insight-options label { font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.model-tag { font-size: 10px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.meter { height: 22px; background: var(--panel-2); border-radius: 6px; overflow: hidden;
  display: flex; margin: 4px 0 8px; border: 1px solid var(--line); }
.meter .win { background: var(--good); } .meter .tie { background: var(--muted); }
.meter .loss { background: var(--bad); }
.meter span { display: grid; place-items: center; font-size: 11px; color: #06131f; font-weight: 700; }
.kv { display: flex; justify-content: space-between; font-size: 12.5px; padding: 2px 0; }
.kv b { font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 54px; }
.belief-grid { display: grid; grid-template-columns: 34px repeat(10, 1fr); gap: 2px; font-size: 10px; }
.belief-grid .cell { height: 20px; border-radius: 3px; display: grid; place-items: center;
  color: #fff; font-size: 9px; }
.belief-grid .head { color: var(--muted); display: grid; place-items: center; }
.legend { display: flex; gap: 10px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; margin-right: 4px; }
.move-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.move-table td { padding: 2px 4px; border-bottom: 1px solid var(--line); }
.move-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.good { color: var(--good); } .bad { color: var(--bad); } .muted { color: var(--muted); }

/* --------------------------------------------------------------- replay */
.replay-grid { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1080px) { .replay-grid { grid-template-columns: 1fr; } }
.games-list { max-height: 640px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.game-item { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; cursor: pointer; font-size: 12.5px; }
.game-item:hover, .game-item.active { border-color: var(--accent); }
.game-item .row { display: flex; justify-content: space-between; }
.replay-controls { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.replay-table { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.replay-seat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.replay-seat.active { border-color: var(--accent); }
.replay-seat h4 { margin: 0 0 6px; font-size: 12px; }
.replay-seat .cards { display: flex; flex-wrap: wrap; gap: 3px; }
.replay-seat .cards .card-svg.played { opacity: .25; }
.replay-detail { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.empty { color: var(--muted); padding: 30px; text-align: center; }

/* ------------------------------------------------------------ dashboard */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
/* wide tables scroll inside their own card rather than pushing the page sideways */
.panel { overflow-x: auto; }
table.metrics { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 420px; }
table.metrics th, table.metrics td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.metrics td.num, table.metrics th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); }
.chart { width: 100%; height: 220px; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .grid { stroke: var(--line); stroke-width: .5; stroke-dasharray: 3 3; }
.chart text { fill: var(--muted); font-size: 10px; }

/* a card another legal card is never worse than: struck off, not just discouraged */
.card-holder.dominated { opacity: 0.55; }
.card-holder.dominated svg { filter: grayscale(0.6); }
.dom-badge {
  position: absolute; top: -8px; left: -6px;
  background: var(--bad, #c0392b); color: #fff;
  border-radius: 50%; width: 18px; height: 18px;
  font-size: 11px; line-height: 18px; text-align: center; font-weight: 700;
}
.move-table tr.dominated-row td { opacity: 0.6; }
.move-table .tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--bad, #c0392b); color: #fff; padding: 1px 5px; border-radius: 3px;
}

/* ---------------------------------------------------------------- training */
/* Categorical slots, one per run. Stepped separately for each surface and
   checked for colour-blind separation and contrast against the panel — not an
   automatic flip of the light values. */
:root {
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
}
@media (prefers-color-scheme: light) {
  :root {
    --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  }
}
.train-controls { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.train-controls .muted { margin-left: auto; font-size: 12px; color: var(--muted); }
.run-card { margin-bottom: 12px; }
.run-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.run-name {
  font-weight: 600; font-size: 15px; padding: 2px 10px;
  border-left: 3px solid var(--accent); display: inline-flex; align-items: center; gap: 7px;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 0 0 var(--good); animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 151, .6); }
  70% { box-shadow: 0 0 0 7px rgba(61, 220, 151, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 151, 0); }
}
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted);
}
.badge-running { color: var(--good); border-color: var(--good); }
.badge-done { color: var(--accent); border-color: var(--accent); }
.bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .4s ease; }
.stat-row { display: flex; flex-wrap: wrap; gap: 22px; margin-top: 12px; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: 11.5px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  font-size: 11px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}
.legend-row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.legend-item i, .tip-row i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.chart-grid-4 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.chart { margin: 0; position: relative; }
.chart figcaption { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .ax { fill: var(--muted); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.chart .tip-label { font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .hit { cursor: crosshair; }
.chart-tip {
  position: absolute; top: 4px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; font-size: 12px; pointer-events: none; z-index: 5; min-width: 130px;
}
.tip-head { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.tbl-run { padding-top: 10px; font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.failure {
  white-space: pre-wrap; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--bad); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px; margin: 0 0 10px; overflow-x: auto;
}

/* --------------------------------------------------------- replay hand bar */
.hand-bar { display: flex; gap: 20px; align-items: center; margin-bottom: 12px; }
.trump-box { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.trump-name { font-size: 12px; font-weight: 600; }
.tiny { font-size: 10px; letter-spacing: .08em; }
.score-box { flex: 1; }
.score-line { display: flex; align-items: baseline; gap: 10px; margin: 2px 0 3px; }
.score-line .team { font-size: 13px; color: var(--muted); }
.score-line .team b { font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; margin-left: 5px; }
.score-line .team.ahead b { color: var(--good); }
.table-card { text-align: center; position: relative; padding-top: 14px; }
.table-card.winning svg { outline: 2px solid var(--good); outline-offset: 2px; border-radius: 6px; }
.win-tag {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em;
  background: var(--good); color: #06131f; border-radius: 4px; padding: 1px 6px; font-weight: 700;
}

/* ------------------------------------------------------------ agent report */
.dist-row { display: flex; align-items: center; gap: 10px; margin: 3px 0; }
.dist-label { flex: 0 0 150px; font-size: 12.5px; color: var(--muted); }
.dist-bar { flex: 1; height: 12px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.dist-bar > div { height: 100%; border-radius: 999px; }
.dist-val { flex: 0 0 58px; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tree { font-size: 13px; }
.tree-node { padding: 3px 0 3px 4px; }
.tree-kids { border-left: 2px solid var(--line); margin-left: 10px; padding-left: 12px; }
.tree-q { font-weight: 600; }
.tree-edge {
  display: inline-block; min-width: 30px; font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
}
.tree-node.leaf b { color: var(--accent); }

/* -------------------------------------------------------------------- lab */
.lab-grid { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 14px; align-items: start; }
.lab-seat { cursor: pointer; margin-bottom: 10px; border: 1px solid transparent; }
.lab-seat.active { border-color: var(--accent); }
.lab-seat .cards { display: flex; flex-wrap: wrap; gap: 3px; }
.lab-count { font-size: 12px; margin-bottom: 6px; }
.lab-count.ok { color: var(--good); }
.lab-count.short { color: var(--warn); }
.deck { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 5px; }
.deck-card { position: relative; cursor: pointer; border-radius: 6px; padding: 2px; }
.deck-card.free { opacity: .42; }
.deck-card:hover { outline: 2px solid var(--accent); }
.deck-card.is-trump { outline: 2px solid var(--warn); }
.deck-card .owner {
  position: absolute; top: 0; right: 0; font-size: 10px; font-weight: 700;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 3px;
}
.deck-card.s0 .owner, .deck-card.s2 .owner { color: var(--series-1); }
.deck-card.s1 .owner, .deck-card.s3 .owner { color: var(--series-2); }
.lab-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.lab-sep { flex: 0 0 1px; height: 24px; background: var(--line); }
.lab-bad { color: var(--bad); }

/* The id of a hand you just played. It exists to be quoted, so the text is
   selectable in one click and the link goes straight to the replay. */
.game-id { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-top: .3rem; }
.game-id code { user-select: all; font-size: .85em; padding: .1rem .35rem;
  border-radius: 4px; background: var(--panel-2); border: 1px solid var(--line); }
.game-id button { font-size: .8em; padding: .1rem .45rem; }
.pill { font-size: .72em; padding: .05rem .45rem; border-radius: 999px;
  background: var(--accent); color: #06131f; font-weight: 600; margin-left: auto; }
