/* styles.css — Win Math
   Dark theme matching parent site. DM Sans + DM Serif Display, teal accent. */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --surface3: #2a2f45;
  --border: #2e3347;
  --text: #e8eaf0;
  --text-muted: #8b92a8;
  --text-dim: #5c6278;
  --accent: #0d9488;
  --accent-dim: #0a7a70;
  --warning: #f59e0b;
  --danger: #ef4444;
  --success: #10b981;
  --p-ALP: #E63946; --p-LP: #1D6FA4; --p-NAT: #5C7A2E; --p-GRN: #2E8B57;
  --p-ON: #FFD700; --p-RIGHT: #D97706; --p-LIB: #F97316; --p-MINOR: #94A3B8;
  --p-IND: #6B7280; --p-CI: #0D9488; --p-EXH: #374151;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); font-size: 13px; line-height: 1.5; }
body { display: flex; flex-direction: column; overflow: hidden; }

/* ═══ Header ═══ */
header {
  flex-shrink: 0; background: var(--surface); border-bottom: 1px solid var(--border);
  height: 48px; padding: 0 14px; display: flex; align-items: center; gap: 10px; z-index: 10;
}
.logo { font-family: 'DM Serif Display', serif; font-size: 17px; letter-spacing: -.3px; white-space: nowrap; }
.logo span { color: var(--accent); }

/* ═══ Controls ═══ */
select, input[type=text], input[type=number] {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 5px 8px; border-radius: 5px; font-family: inherit; font-size: 13px;
}
select { padding-right: 24px; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%238b92a8' d='M5 7L1 3h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; }
select:focus, input:focus { outline: none; border-color: var(--accent); }
.seat-picker-wrap { position: relative; }
#seatSearch { min-width: 260px; }

button { background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 5px 10px; border-radius: 5px; font-family: inherit; font-size: 12px; cursor: pointer; transition: .15s; }
button:hover { background: var(--surface3); border-color: var(--accent-dim); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.sm { padding: 3px 8px; font-size: 11px; }
.right { margin-left: auto; }

/* ═══ Top bar: three-segment compact row ═══ */
.top-bar {
  flex-shrink: 0; display: flex; gap: 0; padding: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  min-height: 44px; align-items: stretch;
}
.top-bar > div {
  padding: 8px 16px; display: flex; flex-direction: column; justify-content: center;
}
.top-bar > div:not(:last-child) { border-right: 1px solid var(--border); }
.seat-summary { flex: 1; font-size: 11px; min-width: 0; }
.seat-summary strong { font-size: 13px; }
.floor-summary { flex: 0 0 auto; text-align: center; min-width: 180px; }
.scenario-summary { flex: 0 0 auto; text-align: right; min-width: 240px; }
.top-bar .big-num {
  font-family: 'DM Serif Display', serif; font-size: 24px; line-height: 1;
  letter-spacing: -.3px;
}
.top-bar .big-num.success { color: var(--success); }
.top-bar .big-num.warning { color: var(--warning); }
.top-bar .big-num.danger { color: var(--danger); }
.top-bar .sub { font-size: 10px; color: var(--text-muted); margin-top: 1px; }
.tcp-bar-sm { height: 18px; border-radius: 3px; overflow: hidden; display: flex;
  border: 1px solid var(--border); margin: 3px 0; }
.tcp-bar-sm > div { display: flex; align-items: center; padding: 0 5px;
  font-size: 10px; font-weight: 600; color: #fff; overflow: hidden; white-space: nowrap; }

/* ═══ Main two-column layout ═══ */
main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.col-wrap { flex: 1; display: flex; overflow: hidden; min-height: 0; }
.col-left, .col-right { overflow-y: auto; }
.col-left { width: 500px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--surface); }
.col-right { flex: 1; background: var(--bg); padding: 0 14px; }

/* ═══ Sections ═══ */
section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
section:last-child { border-bottom: none; }
.section-title {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); margin-bottom: 8px; display: flex; align-items: center; gap: 8px;
}
.section-title .tag { background: var(--surface2); color: var(--text-muted);
  padding: 1px 6px; border-radius: 3px; font-size: 9px; font-weight: 500;
  text-transform: none; letter-spacing: 0; }
.section-title .tag.good { background: rgba(16,185,129,.15); color: var(--success); }
.section-title .tag.warn { background: rgba(245,158,11,.15); color: var(--warning); }

/* ═══ Primary table ═══ */
.primary-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.primary-table th {
  font-weight: 600; color: var(--text-muted); font-size: 10px; text-transform: uppercase;
  letter-spacing: .04em; text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--border);
}
.primary-table th:first-child, .primary-table th:nth-child(2) { text-align: left; }
.primary-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.primary-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.primary-table td.swatch { width: 4px; padding: 0; }
.primary-table .swatch-bar { width: 4px; height: 18px; border-radius: 1px; }
.primary-table .cand { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.primary-table .cand-sub { color: var(--text-muted); font-size: 10px; }
.primary-table tr.total { font-weight: 600; }
.primary-table tr.total td { border-top: 1px solid var(--border); border-bottom: none; }
.primary-table input.shift {
  width: 70px; padding: 3px 6px; font-size: 12px; text-align: right;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 3px; color: var(--text);
}
.primary-table input.shift:focus { border-color: var(--accent); }
.primary-table .shifted { color: var(--accent); }
.primary-table .shifted-down { color: var(--danger); }

/* ═══ Flow matrix ═══ */
.flow-matrix { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
.flow-matrix th, .flow-matrix td { padding: 3px 6px; text-align: right; border-bottom: 1px solid var(--border); }
.flow-matrix th:first-child, .flow-matrix td:first-child { text-align: left; }
.flow-matrix th { font-size: 9px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .04em; font-weight: 600; background: var(--surface2); }
.flow-matrix .pc { display: inline-block; padding: 1px 4px; border-radius: 3px; font-size: 10px; min-width: 30px; cursor: pointer; }
.flow-matrix .pc:hover { background: var(--surface3); }
.flow-matrix .pc.edited { background: rgba(13,148,136,.18); color: var(--accent); }
.flow-matrix .overflow-warn { color: var(--warning); font-weight: 600; }

/* ═══ AEC-style Distribution of Preferences table ═══ */
.dop-table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
.dop-table th { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); text-align: right; padding: 4px 6px; border-bottom: 2px solid var(--border);
  background: var(--surface2); white-space: nowrap; }
.dop-table th:first-child { text-align: left; }
.dop-table td { padding: 3px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.dop-label { text-align: left !important; white-space: nowrap; }
.dop-num { text-align: right; }
.dop-pct { font-size: 9px; color: var(--text-muted); }
.dop-plus { color: var(--accent); }
.dop-elim { color: var(--danger); font-weight: 600; }
.dop-out { color: var(--text-dim); }
.dop-winner { color: var(--success); font-weight: 600; }
.dop-transfer { background: var(--surface); }
.dop-total td { border-bottom: 1px solid var(--surface3); }
.dop-first td { font-weight: 500; }
.dop-result { background: var(--surface2); }
.dop-result td { border-top: 2px solid var(--border); font-weight: 600; }

/* ═══ Flow cell inline editor ═══ */
.flow-edit-popover {
  display: inline-grid; grid-template-columns: 1fr; gap: 4px;
  background: var(--surface3); border: 1px solid var(--accent-dim); border-radius: 4px;
  padding: 6px 8px; font-size: 11px; min-width: 180px;
  box-shadow: 0 4px 16px rgba(0,0,0,.45);
}
.flow-edit-popover .fe-title { font-weight: 600; color: var(--text); white-space: nowrap; }
.flow-edit-popover .fe-body { display: flex; align-items: center; gap: 4px; }
.flow-edit-popover .fe-input { width: 60px; padding: 3px 6px; font-size: 11px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 3px; color: var(--text); text-align: right; }
.flow-edit-popover .fe-input:focus { border-color: var(--accent); outline: none; }
.flow-edit-popover .fe-unit { color: var(--text-muted); }
.flow-edit-popover .fe-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.flow-edit-popover .fe-actions button { font-size: 10px; padding: 2px 6px; }
.flow-edit-popover .fe-hint { margin-top: 2px; font-size: 10px; }

/* ═══ Warnings ═══ */
.warn-list { display: grid; gap: 3px; }
.warn-item { padding: 4px 8px; border-radius: 3px; font-size: 11px; background: var(--surface2);
  border-left: 2px solid var(--border); }
.warn-item.ok { border-left-color: var(--success); }
.warn-item.danger { border-left-color: var(--danger); }
.warn-item.warning { border-left-color: var(--warning); }

/* ═══ Comparators ═══ */
.comparators { display: flex; flex-wrap: wrap; gap: 4px; }
.comp-chip { padding: 3px 8px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; font-size: 11px; cursor: pointer; }
.comp-chip:hover { border-color: var(--accent-dim); }
.comp-chip .comp-score { color: var(--text-muted); font-size: 10px; margin-left: 4px; }

/* ═══ Badge ═══ */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 500; }
.badge.actual { background: rgba(16,185,129,.15); color: var(--success); }
.badge.model { background: rgba(245,158,11,.15); color: var(--warning); }

/* ═══ TCP bar ═══ */
.tcp-bar { height: 24px; border-radius: 4px; overflow: hidden; display: flex; margin: 4px 0;
  border: 1px solid var(--border); }
.tcp-bar > div { display: flex; align-items: center; padding: 0 6px; font-size: 11px;
  font-weight: 600; color: #fff; overflow: hidden; white-space: nowrap; }

/* ═══ Scenario controls ═══ */
.scenario-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.scenario-row label { font-size: 11px; color: var(--text-muted); min-width: 90px; }
.scenario-row input[type=range] { flex: 1; }
.scenario-row .val { font-size: 11px; font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }

/* ═══ Utility ═══ */
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mt-2 { margin-top: 6px; } .mt-4 { margin-top: 12px; }
.mb-2 { margin-bottom: 6px; } .mb-4 { margin-bottom: 12px; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.small { font-size: 11px; }
.tabular { font-variant-numeric: tabular-nums; }
.empty { padding: 20px; text-align: center; color: var(--text-muted); font-size: 12px; }

/* ═══ Focus outlines ═══ */
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pc:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; }

/* ═══ Range slider ═══ */
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: var(--surface2); border-radius: 2px; border: 1px solid var(--border); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; background: var(--accent); border-radius: 50%; margin-top: -6px; }

/* ═══ Modal ═══ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex;
  align-items: center; justify-content: center; z-index: 100; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 20px; max-width: 90vw; max-height: 85vh; overflow-y: auto; }
.modal h3 { font-family: 'DM Serif Display', serif; font-size: 20px; margin-bottom: 14px; }

kbd { display: inline-block; padding: 2px 6px; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 3px; font-size: 11px; color: var(--accent); min-width: 20px; text-align: center; }

/* ═══ Mode toggle + simple view ═══ */
.mode-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; margin-right: 8px; }
.mode-btn { border-radius: 0; border: none; padding: 5px 12px; font-weight: 500; }
.mode-btn:first-child { border-right: 1px solid var(--border); }
body:not(.mode-simple) #modeAdvancedBtn { background: var(--accent); color: #fff; }
body.mode-simple #modeSimpleBtn { background: var(--accent); color: #fff; }

/* Simple mode visibility. Default = advanced; .mode-simple flips it. */
.simple-view { display: none; }
body.mode-simple .advanced-only { display: none !important; }
body.mode-simple .simple-hide { display: none !important; }
body.mode-simple .simple-view { display: block; }
body.mode-simple main { padding-top: 24px; }
body.mode-simple .col-wrap { border-top: none; }

/* Simple view layout */
.simple-view { padding: 24px 32px; max-width: 760px; margin: 0 auto; }
.simple-view .sv-eyebrow { font-size: 12px; letter-spacing: 0.4px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 6px; }
.simple-view .sv-seat { font-family: "DM Serif Display", serif; font-size: 28px; line-height: 1.15; color: var(--text); margin: 0 0 18px; }
.simple-view .sv-headline { font-size: 18px; line-height: 1.45; color: var(--text); margin: 0 0 22px; }
.simple-view .sv-headline strong { color: var(--accent); font-weight: 600; }
.simple-view .sv-stat-row { display: flex; gap: 28px; align-items: baseline; margin: 0 0 14px; flex-wrap: wrap; }
.simple-view .sv-bignum { font-family: "DM Serif Display", serif; font-size: 56px; line-height: 1; color: var(--accent); letter-spacing: -1px; }
.simple-view .sv-bignum.already-won { color: var(--success); }
.simple-view .sv-bignum.hard { color: var(--warning); }
.simple-view .sv-bignum.impossible { color: var(--danger); }
.simple-view .sv-bignum-sub { font-size: 13px; color: var(--text-dim); line-height: 1.4; max-width: 320px; }
.simple-view .sv-source { margin: 0 0 22px; color: var(--text-dim); font-size: 14px; }
.simple-view .sv-source strong { color: var(--text); font-weight: 500; }
.simple-view .sv-apply { background: var(--accent); color: #fff; border: none; padding: 11px 20px; font-size: 14px; font-weight: 500; border-radius: 6px; cursor: pointer; transition: background 120ms; }
.simple-view .sv-apply:hover { background: var(--accent-dim); }
.simple-view .sv-apply:disabled { opacity: 0.5; cursor: default; }
.simple-view .sv-outcome { margin-top: 22px; padding: 12px 16px; background: var(--surface2); border-radius: 6px; border-left: 3px solid var(--accent); }
.simple-view .sv-outcome.loss { border-left-color: var(--danger); }
.simple-view .sv-outcome.win { border-left-color: var(--success); }
.simple-view .sv-outcome-title { font-size: 12px; letter-spacing: 0.3px; text-transform: uppercase; color: var(--text-dim); margin-bottom: 6px; }
.simple-view .sv-outcome-text { font-size: 15px; color: var(--text); }
.simple-view .sv-note { margin-top: 18px; font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.simple-view .sv-switch-advanced { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }
.simple-view .sv-switch-advanced a { color: var(--accent); cursor: pointer; }

/* ═══ Sankey ═══ */
.sankey-host { width: 100%; overflow-x: auto; }
svg.sankey { display: block; font-family: inherit; font-size: 11px; }
.sankey-round-label { fill: var(--text-dim, #9ca3af); font-size: 11px; font-weight: 500; letter-spacing: 0.3px; text-transform: uppercase; }
.sankey-node { cursor: pointer; transition: opacity 120ms; }
.sankey-node:hover { opacity: 0.85; }
.sankey-node-label { fill: var(--text, #e5e7eb); font-size: 11px; pointer-events: none; }
.sankey-node-sub { fill: var(--text-dim, #9ca3af); font-size: 10px; pointer-events: none; }
.sankey-help-marker { fill: #F59E0B; font-weight: 600; font-size: 11px; }
.sankey-link { cursor: pointer; transition: fill-opacity 120ms; }
.sankey-link:hover { fill-opacity: 0.7 !important; }
/* When any link is hovered, dim the rest. Sibling combinator would be ideal
   but plain :hover:not() works for the common case. */
svg.sankey:has(.sankey-link:hover) .sankey-link:not(:hover) { fill-opacity: 0.12; }
svg.sankey:has(.sankey-node:hover) .sankey-link { fill-opacity: 0.12; }
svg.sankey:has(.sankey-node:hover) .sankey-node:not(:hover) { opacity: 0.35; }

/* ═══ Responsive ═══ */
@media (max-width: 900px) {
  header { height: auto; padding: 8px; flex-wrap: wrap; gap: 6px; }
  .top-bar { flex-direction: column; }
  .win-summary { text-align: left; min-width: auto; }
  .col-left { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  main { flex-direction: column; }
  .col-left, .col-right { overflow-y: visible; }
}
