/* Inkforged Match Lab — single-page UI.
   Design tokens per the UI research pass (2026-07-12): surface-elevation
   scale (elevation = lightness on dark), modular type scale (headlines
   dominate, tables recede), 8px-within / 24-32px-between spacing rhythm,
   WCAG-tuned semantic colors with direction as the primary channel. */

:root {
  /* surfaces: page -> card -> raised (hover/expanded) -> popover */
  --surface-0: #0f1115;
  --surface-1: #171a21;
  --surface-2: #1e222b;
  --surface-3: #252a35;
  --border: #2a2f3a;
  --border-soft: #21252e;

  /* text */
  --text: #e6e8ec;   /* off-white: >=4.5:1 on surface-0 without halation */
  --muted: #8a93a5;

  /* semantics: desaturated green/red tuned for >=3:1 on surface-0,
     deuteranopia-friendlier than pure hues; direction carries meaning first */
  --accent: #57c7ff;
  --good: #3dd68c;
  --bad: #f2657a;
  --low-opacity: 0.45;

  /* type scale (~major third): body/table 13.5-14, labels 12, headline 36 */
  --fs-small: 12px;
  --fs-table: 13.5px;
  --fs-body: 14px;
  --fs-sub: 16px;
  --fs-stat: 20px;
  --fs-hero: 36px;

  /* spacing rhythm: tight inside blocks, generous between sections */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text);
  font: var(--fs-body)/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: 18px 22px 10px;
}
header h1 { margin: 0; font-size: 22px; letter-spacing: 0.3px; }
header h1 span { color: var(--accent); font-weight: 400; }

.muted { color: var(--muted); font-size: var(--fs-small); font-weight: 400; }

/* --- sticky filter bar (shared state for everything below) --- */
#filter-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 10px 22px 8px;
  background: var(--surface-1);
  border-block: 1px solid var(--border);
}
#filter-bar label,
#filter-bar .filter-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
#filter-bar select,
#filter-bar input {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  min-width: 90px;
}
#filter-bar input[type="number"] { width: 70px; min-width: 0; }

/* active-filter chips: always-visible record of what the page is filtered to */
#active-filters {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--border-soft);
}
.games-count {
  font-size: var(--fs-small);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-right: var(--sp-2);
  text-transform: none;
  letter-spacing: normal;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: var(--fs-small);
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}
.chip:hover { border-color: var(--accent); }
.chip .x { color: var(--muted); }
.chip.clear-all { color: var(--accent); background: transparent; }

/* --- multi-select deck picker --- */
.multi { position: relative; }
.multi > button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  min-width: 200px;
  text-align: left;
  cursor: pointer;
}
.multi > button::after { content: " ▾"; color: var(--muted); }
.multi-pop {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 30;
  min-width: 300px;
  max-height: 340px;
  overflow-y: auto;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
}
.multi-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.multi-row:hover { background: var(--surface-2); }
#filter-bar .multi-row input[type="checkbox"] {
  flex: none;
  order: -1;
  margin: 0;
  padding: 0;
  border: none;
  min-width: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}
.multi-row .rec { color: var(--muted); font-variant-numeric: tabular-nums; }
.multi-clear {
  padding: 2px 8px 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.multi-clear button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 0;
}

.tag-edit { display: flex; gap: 6px; }
.tag-edit input { width: 140px; }
.tag-edit button {
  background: var(--surface-2);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}
.tag-edit button:hover { border-color: var(--accent); }

main { padding: var(--sp-3) 22px 40px; max-width: 1200px; }

/* --- page tabs + always-visible bar legend --- */
#turn-tabs, #page-tabs { display: flex; gap: 6px; margin-bottom: var(--sp-2); }
#page-tabs { margin: var(--sp-1) 0 var(--sp-4); align-items: center; flex-wrap: wrap; }
#turn-tabs button, #page-tabs button {
  background: var(--surface-1);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
}
#turn-tabs button.active, #page-tabs button.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface-2);
}
.legend {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--fs-small);
}

/* --- layman aids: ? hints, shared tooltip, how-to panel --- */
#page-tabs #howto-open {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  font-size: 13px;
  flex: none;
  color: var(--accent);
}
.hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
  margin-left: 5px;
  cursor: help;
  user-select: none;
  text-transform: none;
  letter-spacing: normal;
  vertical-align: 1px;
}
.hint:hover, .hint:focus { border-color: var(--accent); color: var(--accent); outline: none; }
tr.low .hint { opacity: 1; }
#tip {
  position: absolute;
  z-index: 100;
  max-width: 300px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: var(--fs-small);
  line-height: 1.45;
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  text-transform: none;
  letter-spacing: normal;
  pointer-events: none;
  white-space: pre-line; /* delta tips are two lines: verdict + range */
}
#howto {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 14px 18px;
  margin: 0 0 var(--sp-4);
  max-width: 780px;
  font-size: var(--fs-body);
}
#howto .howto-head { display: flex; align-items: center; justify-content: space-between; }
#howto h3 { margin: 0; font-size: var(--fs-sub); }
#howto ol { margin: 10px 0 8px; padding-left: 20px; }
#howto li { margin: 6px 0; }
#howto p { margin: 8px 0 0; font-size: var(--fs-table); }
#howto-dismiss {
  background: var(--surface-2);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
}
#howto-dismiss:hover { border-color: var(--accent); }

/* --- section headers: small, quiet labels so content carries the weight --- */
section h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  margin: var(--sp-5) 0 var(--sp-3);
}
section h2 .muted { font-size: 11px; margin-left: var(--sp-2); text-transform: none; letter-spacing: normal; font-weight: 400; }
section:first-of-type h2 { margin-top: 0; }

/* --- stat cards: one hero, the rest demoted --- */
#stat-cards {
  display: grid;
  grid-template-columns: minmax(200px, 1.4fr) repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--sp-3);
  margin-bottom: var(--sp-2);
}
.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.stat-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.stat-card .value {
  font-size: var(--fs-stat);
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.stat-card .sub { font-size: var(--fs-small); color: var(--muted); }
.stat-card.hero { border-left: 3px solid var(--accent); }
.stat-card.hero .value { font-size: var(--fs-hero); line-height: 1.1; }

/* --- tables: low-chrome reference material, not featured content --- */
table {
  width: 100%;
  border-collapse: collapse;
  background: transparent;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
th, td { padding: 7px 10px; text-align: right; font-size: var(--fs-table); }
th:first-child, td:first-child { text-align: left; }
thead th {
  background: var(--surface-1);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
thead th.sorted { color: var(--accent); }
tbody tr { border-top: 1px solid var(--border-soft); }
tbody tr:nth-child(even):not(.drill) { background: rgba(255, 255, 255, 0.02); }
tbody tr.expandable { cursor: pointer; }
tbody tr.expandable:hover { background: var(--surface-2); }

tr.low > td { opacity: var(--low-opacity); }
.low-chip {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border: 1px solid var(--muted);
  color: var(--muted);
  border-radius: 4px;
  padding: 0 5px;
  margin-left: 6px;
  opacity: 1;
  cursor: help;
}

/* expanded drill-down row */
tr.drill > td { padding: 0 10px 10px 28px; background: var(--surface-2); }
tr.drill table { background: transparent; border: none; }
tr.drill th { background: transparent; cursor: default; }
tr.drill tbody tr:nth-child(even) { background: transparent; }

.caret { display: inline-block; width: 14px; color: var(--muted); }

/* --- diverging delta bar (baseline at center; fill opacity = confidence) --- */
.delta-cell { display: flex; align-items: center; gap: var(--sp-2); justify-content: flex-end; cursor: help; }
.delta-num { min-width: 52px; }
.delta-num.pos { color: var(--good); }
.delta-num.neg { color: var(--bad); }
.bar {
  position: relative;
  width: 110px;
  height: 10px;
  background: var(--surface-2);
  border-radius: 5px;
  overflow: hidden;
  flex: none;
}
.bar::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--muted);
}
.bar i { position: absolute; top: 0; bottom: 0; }
.bar i.pos { left: 50%; background: var(--good); }
.bar i.neg { right: 50%; background: var(--bad); }

/* Wilson-interval whiskers on the delta (D18): thick = 80%, thin = 95%.
   Neutral off-white so they read over both the green/red fill and the track;
   graded nesting avoids the "error bar = hard min/max" misreading. */
.bar .whisker { position: absolute; top: 50%; pointer-events: none; }
.bar .whisker.w95 { height: 2px; margin-top: -1px; background: rgba(230, 232, 236, 0.35); }
.bar .whisker.w80 { height: 4px; margin-top: -2px; background: rgba(230, 232, 236, 0.65); }

/* --- panels (cards with a purpose, distinct from tables) --- */
#summary-baseline {
  margin-bottom: var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-body);
}
#summary-baseline b { color: var(--text); font-size: var(--fs-sub); }
#turn-breakdown, .panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: var(--sp-3);
}
.turn-panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.turn-panel h3 {
  margin: 0 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
.play-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: var(--sp-2) 0;
  border-top: 1px solid var(--border-soft);
  font-size: var(--fs-table);
  font-variant-numeric: tabular-nums;
}
.play-row .rank { color: var(--muted); width: 16px; flex: none; }
.play-row .pname { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.play-row .pstats { color: var(--muted); white-space: nowrap; }
.play-row.low { opacity: var(--low-opacity); }
.shape-panel { max-width: 560px; margin-bottom: var(--sp-3); }
.shape-foot { padding-top: var(--sp-2); border-top: 1px solid var(--border-soft); font-size: var(--fs-small); }
.dim-cell { opacity: var(--low-opacity); }

footer { padding: 0 22px 30px; }

.error-box {
  margin: 20px 22px;
  padding: 16px;
  border: 1px solid var(--bad);
  border-radius: 10px;
  background: var(--surface-1);
  white-space: pre-wrap;
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

/* --- sync dialog (build step 4) ------------------------------------------ */

#sync-open {
  margin-left: auto;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-small);
  cursor: pointer;
}
#sync-open:hover { border-color: var(--accent); }

#sync-dialog, #gate-dialog {
  background: var(--surface-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--sp-4);
  max-width: 460px;
  font-size: var(--fs-body);
}
#sync-dialog::backdrop, #gate-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
#sync-dialog h3, #gate-dialog h3 { margin: 0 0 var(--sp-2); }
#sync-dialog p, #gate-dialog p { margin: 0 0 var(--sp-3); font-size: var(--fs-small); }
#sync-dialog label, #gate-dialog label {
  display: block;
  margin-bottom: var(--sp-2);
  font-size: var(--fs-small);
  color: var(--muted);
}
#sync-dialog input, #gate-dialog input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: var(--sp-1);
  background: var(--surface-0);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--sp-2);
  font-size: var(--fs-body);
}
.sync-actions { display: flex; gap: var(--sp-2); margin: var(--sp-3) 0 var(--sp-2); }
.sync-actions button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
}
#sync-run, #gate-submit { border-color: var(--accent); }
#sync-run:disabled, #gate-submit:disabled { opacity: 0.5; cursor: wait; }
#sync-progress, #gate-progress { min-height: 1.4em; font-size: var(--fs-small); }

/* --- team pool page (build step 5) ---------------------------------------- */

#pool-box {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--sp-3);
  margin-bottom: var(--sp-3);
  max-width: 640px;
}
#pool-box .sync-actions { margin: var(--sp-2) 0; }
#pool-unpublish { border-color: var(--bad); }
#pool-progress { min-height: 1.4em; font-size: var(--fs-small); }
