:root {
  --bg: #f5f7fb;
  --card: #fff;
  --text: #003e80;
  --muted: #667085;
  --line: #dce2ea;
  --blue: #003e80;
  --blue2: #002d5e;
  --red: #b42318;
  --green: #067647;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  --page-pad: 12px;
  --control-h: 44px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}
button, input, select, textarea, .file-button { font: inherit; }
button, .file-button, input, select, textarea {
  border: 1px solid #cfd7e3;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
button, .file-button {
  min-height: var(--control-h);
  padding: 9px 12px;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover, .file-button:hover { background: #f8fafc; }
input, select, textarea { min-height: var(--control-h); padding: 8px 10px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid #bfdbfe;
  outline-offset: 1px;
  border-color: #60a5fa;
}
.primary, .run { background: var(--blue); color: #fff; border-color: var(--blue); font-weight: 700; }
.primary:hover, .run:hover { background: var(--blue2); }
.danger { color: var(--red); }
.ghost { background: transparent; }
.file-button input { display: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
code { background: #f2f4f7; padding: 2px 4px; border-radius: 4px; }

/* Header: mobile layout is the default. League selector remains upper-right. */
.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(145px, 52vw);
  align-items: start;
  gap: 10px;
  padding: 12px var(--page-pad);
  background: #003e80;
  color: #fff;
}
.topbar > div:first-child { min-width: 0; }
.topbar h1 { margin: 4px 0 0; font-size: clamp(19px, 5vw, 24px); line-height: 1.05; }
.topbar p { margin: 4px 0 0; color: #cbd5e1; }
.topbar select, .topbar input {
  width: 100%;
  min-width: 0;
  color: #003e80;
  background: #fff;
  border-color: rgba(255,255,255,.75);
  font-weight: 700;
}
.scenario-picker, .topbar-league, .league-switch {
  min-width: 0;
  margin-left: auto;
  width: 100%;
}
.scenario-picker {
  display: grid;
  gap: 6px;
}
.scenario-picker label, .topbar-league label, .league-switch label {
  display: grid;
  gap: 3px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.scenario-picker select, .topbar-league select, .league-switch select, .scenario-name { display: block; margin: 0; min-width: 0; }
.scenario-name { min-height: 38px; }
.league-name { display: none; }

/* Shared Vipps support strip directly below the top banner. */
.support-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px var(--page-pad);
  background: #0a5b53;
  color: #fff;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}
.support-strip:hover, .support-strip:focus-visible {
  background: #084b45;
  color: #fff;
}

/* Primary action bars */
.toolbar {
  padding: 8px var(--page-pad);
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.full-toolbar { display: grid; gap: 8px; }
.toolbar-primary {
  display: grid;
  grid-template-columns: auto minmax(108px, 1fr) auto;
  gap: 8px;
  align-items: end;
}
.toolbar-primary .sim-control {
  display: grid;
  gap: 3px;
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}
.toolbar-primary .sim-control input { width: 100%; min-width: 0; }
.toolbar-primary .run { white-space: nowrap; }
.toolbar-export { width: 100%; }
.toolbar-actions {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.toolbar-actions summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 7px 10px;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}
.toolbar-action-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 0 8px 8px;
}
.toolbar-action-list > * { width: 100%; text-align: center; }
.toolbar .spacer { display: none; }
.toolbar label { color: var(--muted); }
.toolbar input { min-width: 0; }
.public-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}
.public-toolbar .save-state { grid-column: 1 / -1; justify-self: start; }
.public-toolbar label {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3px;
  min-width: 0;
  font-size: 11px;
  font-weight: 700;
}
.public-toolbar label input { width: 100%; min-width: 0; }
.public-toolbar .run { white-space: nowrap; }

.save-state {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.save-state.saved { background: #ecfdf3; color: #067647; }
.save-state.saving { background: #eff6ff; color: #1e40af; }
.save-state.dirty { background: #fff7ed; color: #9a3412; }
.save-state.error { background: #fef3f2; color: #b42318; }

.status {
  margin: 10px var(--page-pad) 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}
.status.error { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.status.success { background: #ecfdf3; border-color: #abefc6; color: #067647; }


/* Simulation lock: keep the current scenario stable while the Worker is running. */
body.simulation-busy { overflow: hidden; }
.simulation-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .42);
}
.simulation-overlay[hidden] { display: none; }
.simulation-dialog {
  width: min(360px, 100%);
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .22);
  text-align: center;
}
.simulation-spinner {
  width: 38px;
  height: 38px;
  border: 4px solid #dce2ea;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: simulation-spin .8s linear infinite;
}
.simulation-dialog strong { font-size: 16px; }
.simulation-dialog .muted { font-size: 12px; }
@keyframes simulation-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .simulation-spinner { animation-duration: 1.8s; } }

/* Navigation */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  padding: 10px var(--page-pad) 0;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: 0 0 auto;
  min-height: 42px;
  border-radius: 9px 9px 0 0;
  padding: 9px 12px;
  color: var(--muted);
  white-space: nowrap;
}
.tabs button.active { background: #fff; color: var(--text); font-weight: 700; border-bottom-color: #fff; }

main { margin: 0 var(--page-pad) 18px; }
.tab-panel {
  display: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0 10px 10px 10px;
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.tab-panel.active { display: block; }
.section-head {
  display: grid;
  gap: 10px;
  align-items: start;
  margin-bottom: 14px;
}
.section-head h2, .card h2 { margin: 0 0 4px; font-size: 18px; }
.section-head h3 { margin: 0 0 4px; }
.section-head p, .card p { margin: 0; color: var(--muted); }
.section-head > div:last-child:not(:first-child) {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.section-head > div:last-child:not(:first-child) > button { flex: 1 1 140px; }
.compact { align-items: start; }

.settings-row {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}
.settings-row label { display: grid; gap: 5px; }
.settings-row input, .settings-row select { width: 100%; }
.split, .three-col { display: grid; grid-template-columns: 1fr; gap: 14px; }
.probability-stack { display: grid; grid-template-columns: 1fr; gap: 18px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 14px; min-width: 0; }
.explain { margin-top: 14px; padding: 12px; background: #f8fafc; border-radius: 8px; color: #475467; }

/* Team cards */
.team-card-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 2px 0 16px; }
.team-card { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 12px; min-width: 0; }
.team-card-head { display: block; }
.team-card-title { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 15px; font-weight: 700; color: var(--text); }
.team-card-title strong { min-width: 0; overflow-wrap: anywhere; }
.team-card-name { min-width: 0; width: 100%; font-weight: 700; color: var(--text); background: transparent; border-color: transparent; padding-left: 4px; }
.team-card-name:focus { background: #fff; border-color: #60a5fa; }
.team-card-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; margin-top: 12px; }
.team-card-controls > label:not(.dq-toggle) { display: grid; gap: 4px; flex: 0 1 180px; min-width: 110px; font-size: 11px; color: var(--muted); font-weight: 700; }
.team-card-controls select { width: 100%; min-width: 0; color: var(--text); font-weight: 700; }
.dq-toggle { display: inline-flex; align-items: center; gap: 7px; min-height: var(--control-h); color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.dq-toggle input { width: 20px; height: 20px; min-height: 20px; accent-color: #b42318; }
.disqualified-card { background: #fff7f6; border-color: #fecdca; }
.disqualified-card .team-card-title { color: #912018; }
.team-stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #eef2f6; }
.team-stat-grid label, .team-stat-readonly { display: grid; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.team-stat-grid input { width: 100%; min-width: 0; color: var(--text); font-weight: 600; }
.team-stat-readonly strong { min-height: var(--control-h); display: flex; align-items: center; color: var(--text); font-size: 14px; }
.remove-btn { min-width: 40px; color: var(--red); }

/* Tables. Most interactive tables become cards below 700px. */
.table-wrap { overflow: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; -webkit-overflow-scrolling: touch; }
.table-wrap.wide { max-width: 100%; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th { background: #f8fafc; text-align: left; font-size: 12px; color: var(--text); border-bottom: 1px solid var(--line); padding: 8px; white-space: nowrap; }
td { border-bottom: 1px solid #eef2f6; padding: 7px 8px; vertical-align: middle; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td input[type=number] { width: 74px; }
td input.team-name { width: 180px; }
td input.date { width: 100%; }
td input.time { width: 90px; }
td select.team-select, td select.mode-select, td select.state-select { width: 100%; min-width: 0; }
.small-input { width: 100% !important; min-width: 0; }
.prob-preview { font-variant-numeric: tabular-nums; color: var(--text); }
.matrix-cell select { width: 100%; min-width: 72px; }

#categoryMatrix { min-width: 430px; }
#categoryMatrix th:first-child, #categoryMatrix td:first-child { position: sticky; left: 0; z-index: 2; background: #f8fafc; }
#resultsTable { min-width: max-content; }
#resultsTable th:first-child, #resultsTable td:first-child { position: sticky; left: 0; z-index: 3; background: #fff; box-shadow: 1px 0 0 var(--line); }
#resultsTable th:first-child { background: #f8fafc; }
#resultsTable th.result-head { text-align: center; }
#resultsTable th.position-head { min-width: 56px; }
#resultsTable th.team-head { text-align: left; min-width: 140px; }
#resultsTable .expected { text-align: center; }
.prob-cell { text-align: center; font-variant-numeric: tabular-nums; }
.prob-cell.high { font-weight: 700; }
.expected { text-align: right; font-variant-numeric: tabular-nums; }
.zone-head { min-width: 112px; max-width: 160px; white-space: normal; line-height: 1.15; }
.zone-cell { background: #f2f4f7; font-weight: 600; }
.zone-name { width: 100%; min-width: 0; }

@media (max-width: 699px) {
  #matchesTable thead,
  #playedMatchesTable thead,
  #presetsTable thead,
  #resultZonesTable thead { display: none; }

  #matchesTable,
  #playedMatchesTable,
  #presetsTable,
  #resultZonesTable,
  #matchesTable tbody,
  #playedMatchesTable tbody,
  #presetsTable tbody,
  #resultZonesTable tbody { display: block; width: 100%; }

  #matchesTable tr,
  #playedMatchesTable tr,
  #presetsTable tr,
  #resultZonesTable tr {
    display: block;
    margin: 0 0 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
  }
  #matchesTable tr:last-child,
  #playedMatchesTable tr:last-child,
  #presetsTable tr:last-child,
  #resultZonesTable tr:last-child { margin-bottom: 0; }

  #matchesTable td,
  #playedMatchesTable td,
  #presetsTable td,
  #resultZonesTable td {
    display: grid;
    grid-template-columns: 92px minmax(0,1fr);
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 43px;
    padding: 7px 9px;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #matchesTable td[data-label]::before,
  #playedMatchesTable td[data-label]::before,
  #presetsTable td[data-label]::before,
  #resultZonesTable td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
  }
  #matchesTable td:not([data-label]),
  #playedMatchesTable td:not([data-label]),
  #presetsTable td:not([data-label]),
  #resultZonesTable td:not([data-label]) { display: block; }

  #matchesTable td input,
  #matchesTable td select,
  #playedMatchesTable td input,
  #playedMatchesTable td select,
  #presetsTable td input,
  #presetsTable td select,
  #resultZonesTable td input,
  #resultZonesTable td select { width: 100% !important; min-width: 0 !important; max-width: none; }

  #matchesTable .fixed-score-inputs,
  #playedMatchesTable .fixed-score-inputs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }

  .table-wrap:has(#matchesTable),
  .table-wrap:has(#playedMatchesTable),
  .table-wrap:has(#presetsTable),
  .table-wrap:has(#resultZonesTable) { border: 0; overflow: visible; }
}

/* Match states and source */
.fixed-match td { background: #f6fef9; }
.fixed-badge { display: inline-block; padding: 4px 8px; border-radius: 999px; background: #ecfdf3; color: #067647; font-weight: 700; font-size: 12px; }
.fixed-score-inputs { display: inline-flex; align-items: center; gap: 5px; }
.score-input { width: 58px !important; text-align: center; }
.match-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.match-tools label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.match-tools select { min-width: 100px; }
.round-input { width: 58px !important; }
.source-panel { margin: 0 0 14px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.source-grid { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: end; }
.source-grid label, .proxy-label { display: grid; gap: 5px; color: #475467; font-size: 12px; }
.source-grid input, .source-grid select, .source-grid button, .proxy-label input { width: 100%; }
.source-advanced { margin-top: 8px; }
.source-advanced summary { min-height: 40px; display: flex; align-items: center; cursor: pointer; color: #475467; font-weight: 700; }
.source-advanced textarea { width: 100%; margin-top: 8px; }
.source-url { min-width: 0; }
.proxy-label { margin-top: 10px; }
.disqualified-team td { background: #fef3f2; color: #912018; }
.disqualified-team input, .disqualified-team select { opacity: .72; }
.dq-cell { text-align: center; }
.dq-cell input { width: 18px; height: 18px; accent-color: #b42318; }
.excluded-match td { background: #f9fafb; color: #667085; }
.excluded-match input, .excluded-match select { opacity: .68; }
.excluded-badge { display: inline-block; padding: 4px 8px; border-radius: 999px; background: #f2f4f7; color: #475467; font-weight: 700; font-size: 12px; }
.browser-badge { display: inline-flex; align-items: center; padding: 3px 7px; border-radius: 999px; background: #eaf2fb; color: #003e80; font-size: 11px; font-weight: 700; white-space: nowrap; }

/* Probability and score views */
.bulk-box { margin: 0 0 14px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.bulk-box summary { min-height: 38px; display: flex; align-items: center; cursor: pointer; font-weight: 700; }
.bulk-box textarea { display: block; width: 100%; margin: 10px 0; }
.score-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-width: 0; }
.score-card h3 { margin: 0 0 8px; }
.score-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto minmax(0,1fr) 42px;
  gap: 6px;
  align-items: end;
  margin-bottom: 8px;
}
.score-row > input:nth-child(1) { grid-column: 1; grid-row: 1; width: 100%; min-width: 0; }
.score-row > span { grid-column: 2; grid-row: 1; align-self: center; text-align: center; }
.score-row > input:nth-child(3) { grid-column: 3; grid-row: 1; width: 100%; min-width: 0; }
.score-weight { grid-column: 1 / 4; grid-row: 2; display: grid; gap: 3px; color: var(--muted); font-size: 10px; font-weight: 700; }
.score-weight input { width: 100%; min-width: 0; }
.score-row > .remove-btn { grid-column: 4; grid-row: 1 / 3; align-self: stretch; }
.score-total { color: var(--muted); font-size: 12px; margin: 8px 0; }
.prob-source-badge { display: inline-block; margin-right: 6px; padding: 2px 6px; border-radius: 999px; background: #eaf2fb; color: #003e80; font-size: 10px; font-weight: 700; vertical-align: 1px; }

/* Results */
.result-actions { display: grid !important; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; width: 100%; }
.result-meta { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; margin-bottom: 12px; }
.metric { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #f8fafc; min-width: 0; }
.metric span { color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin-top: 2px; font-size: 15px; overflow-wrap: anywhere; }
.dq-metric { background: #fef3f2; border-color: #fecdca; }
.dq-metric strong { color: #b42318; font-size: 12px; }
.result-zone-panel { margin: 0 0 16px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #f8fafc; }
.result-zone-panel h3 { margin: 0 0 4px; font-size: 16px; }
.result-zone-panel .table-wrap { background: #fff; }

/* Played matches in public edition */
.played-matches { margin-top: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.played-matches summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; padding: 9px 11px; font-weight: 700; color: var(--text); background: #f8fafc; border-radius: 8px; }
.played-matches[open] summary { border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.played-matches .table-wrap { border: 0; border-radius: 0 0 8px 8px; padding: 8px; }
.played-matches .muted { font-weight: 400; margin-left: 5px; }

footer { padding: 0 var(--page-pad) 22px; color: var(--muted); font-size: 12px; }

.site-footer {
  display: grid;
  gap: 18px;
  justify-items: center;
  text-align: center;
}
.site-footer > p { margin: 0; max-width: 760px; }

.footer-credit { margin-top: -8px !important; }
.footer-credit a { color: var(--text); font-weight: 700; text-decoration: none; }
.footer-credit a:hover, .footer-credit a:focus-visible { text-decoration: underline; }

.footer-version { margin-top: -10px !important; font-size: 9px; opacity: 0.6; letter-spacing: 0.02em; }

/* Progressive enhancement for larger screens. */
@media (min-width: 700px) {
  :root { --page-pad: 20px; }
  .topbar { grid-template-columns: minmax(0,1fr) auto; align-items: center; padding-top: 16px; padding-bottom: 16px; }
  .topbar h1 { margin-top: 0; }
  .scenario-picker { width: auto; min-width: 430px; display: grid; grid-template-columns: minmax(220px,1fr) minmax(180px,.8fr); align-items: end; gap: 10px; }
  .scenario-picker label { font-size: 12px; }
  .topbar-league, .league-switch { width: auto; min-width: 240px; }
  .topbar-league label, .league-switch label { font-size: 12px; }

  .public-toolbar { display: flex; align-items: center; gap: 8px; }
  .public-toolbar .save-state { grid-column: auto; margin-right: auto; }
  .public-toolbar label { display: flex; align-items: center; gap: 6px; font-size: 12px; }
  .public-toolbar label input { width: 110px; }

  .full-toolbar { display: flex; align-items: center; gap: 8px; }
  .toolbar-actions { order: 0; border: 0; background: transparent; }
  .toolbar-actions > summary { display: none; }
  .toolbar-actions > .toolbar-action-list { display: flex !important; gap: 8px; padding: 0; }
  .toolbar-action-list > * { width: auto; white-space: nowrap; }
  .toolbar-primary { order: 1; margin-left: auto; display: flex; align-items: center; gap: 8px; }
  .toolbar-primary .sim-control { display: flex; align-items: center; gap: 6px; font-size: 12px; }
  .toolbar-primary .sim-control input { width: 105px; }
  .toolbar-export { width: auto; order: 0; white-space: nowrap; }

  .tabs { padding-top: 14px; gap: 2px; }
  main { margin-bottom: 28px; }
  .tab-panel { padding: 18px; }
  .section-head { grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 16px; }
  .section-head > div:last-child:not(:first-child) { justify-content: flex-end; }
  .section-head > div:last-child:not(:first-child) > button { flex: 0 0 auto; }
  .settings-row { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
  .settings-row label { display: flex; gap: 8px; align-items: center; }
  .settings-row input, .settings-row select { width: auto; }

  .team-card-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
  .team-stat-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .split { grid-template-columns: 1fr 1fr; gap: 18px; }
  .result-actions { width: auto; display: flex !important; }
  .result-meta { display: flex; flex-wrap: wrap; gap: 12px; }
  .metric { padding: 8px 12px; }
  .metric strong { font-size: 16px; }
  .source-grid { grid-template-columns: 150px minmax(280px,1fr) auto; }
  .source-grid button { width: auto; white-space: nowrap; }
  .match-tools label { display: flex; align-items: center; gap: 5px; font-size: 12px; }

  th { position: sticky; top: 0; z-index: 1; }
  td input.date { width: 125px; }
  td select.team-select { min-width: 145px; }
  td select.mode-select { min-width: 105px; }
  td select.state-select { min-width: 112px; }
  .small-input { width: 70px !important; }
  .zone-name { min-width: 190px; }

  .score-row { grid-template-columns: minmax(0,1fr) auto minmax(0,1fr) minmax(90px,1.2fr) 42px; align-items: center; }
  .score-row > input:nth-child(1) { grid-column: 1; grid-row: 1; }
  .score-row > span { grid-column: 2; grid-row: 1; }
  .score-row > input:nth-child(3) { grid-column: 3; grid-row: 1; }
  .score-weight { grid-column: 4; grid-row: 1; display: block; font-size: 0; }
  .score-weight input { width: 100%; }
  .score-row > .remove-btn { grid-column: 5; grid-row: 1; }
}

@media (min-width: 1000px) {
  :root { --page-pad: 28px; }
  .topbar { padding-top: 18px; padding-bottom: 18px; }
  .topbar h1 { font-size: 24px; }
  .tab-panel { padding: 20px; }
  .team-card-grid { grid-template-columns: repeat(auto-fit, minmax(250px,1fr)); }
  .three-col { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
}

@media (max-width: 390px) {
  .topbar { grid-template-columns: minmax(0,1fr) minmax(132px,49vw); gap: 8px; }
  .topbar h1 { font-size: 18px; }
  .toolbar-primary { grid-template-columns: auto minmax(92px,1fr); }
  .toolbar-primary .run { grid-column: 1 / -1; width: 100%; }
  .dq-toggle { justify-self: start; }
  .team-card-controls .remove-btn { width: 100%; }
  .result-actions { grid-template-columns: 1fr; }
  #matchesTable td,
  #playedMatchesTable td,
  #presetsTable td,
  #resultZonesTable td { grid-template-columns: 80px minmax(0,1fr); }
}

/* Compact match cards */
.match-summary-head,
.match-summary-cell { display: none; }
.match-input-triple {
  display: inline-grid;
  grid-template-columns: repeat(3, 70px);
  gap: 5px;
  align-items: center;
}
.match-input-triple .small-input { width: 70px !important; min-width: 0; text-align: center; }
.prob-values { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.match-mobile-edit { display: none; }

@media (max-width: 699px) {
  #matchesTable td.match-date-cell,
  #matchesTable td.match-home-cell,
  #matchesTable td.match-away-cell,
  #playedMatchesTable td.match-date-cell,
  #playedMatchesTable td.match-home-cell,
  #playedMatchesTable td.match-away-cell { display: none; }

  #matchesTable td.match-summary-cell,
  #playedMatchesTable td.match-summary-cell {
    display: block;
    min-height: 0;
    padding: 10px 9px 8px;
    color: var(--text);
    font-size: 14px;
    font-weight: 800;
    line-height: 1.3;
    border-bottom: 1px solid var(--line);
    white-space: normal;
  }
  #matchesTable td.match-summary-cell::before,
  #playedMatchesTable td.match-summary-cell::before,
  #matchesTable td.match-probability-cell::before,
  #playedMatchesTable td.match-probability-cell::before { display: none; }

  .match-summary-line { overflow-wrap: anywhere; }
  .match-mobile-edit { display: block; margin-top: 6px; }
  .match-mobile-edit summary {
    width: max-content;
    cursor: pointer;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }
  .match-mobile-edit-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin-top: 7px;
  }
  .match-mobile-edit-grid input,
  .match-mobile-edit-grid select { width: 100% !important; min-width: 0 !important; }

  #matchesTable .match-input-triple,
  #playedMatchesTable .match-input-triple {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: flex-start;
    width: auto;
  }
  #matchesTable .match-input-triple .small-input,
  #playedMatchesTable .match-input-triple .small-input {
    width: 6.8ch !important;
    min-width: 6.8ch !important;
    max-width: 6.8ch !important;
    padding-left: 6px;
    padding-right: 6px;
    text-align: center;
  }

  #matchesTable td.match-probability-cell,
  #playedMatchesTable td.match-probability-cell {
    display: block;
    min-height: 0;
    padding-top: 7px;
    padding-bottom: 9px;
    white-space: normal;
  }
  #matchesTable td.match-probability-cell:empty,
  #playedMatchesTable td.match-probability-cell:empty { display: none; }
}

/* Public edition specifics */
.public-team-cards .team-card-controls > label:not(.dq-toggle) { flex-basis: 180px; }
.fixed-match td strong { font-variant-numeric: tabular-nums; }

.public-config-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.public-config-actions button { width: 100%; }

@media (min-width: 700px) {
  .public-config-actions {
    grid-column: auto;
    display: flex;
    gap: 8px;
  }
  .public-config-actions button { width: auto; white-space: nowrap; }
}

/* Local temporary result method */
.result-input-pair {
  display: inline-grid;
  grid-template-columns: 84px 18px 84px;
  column-gap: 6px;
  align-items: end;
  white-space: nowrap;
}
.result-input-pair label {
  display: grid;
  grid-template-rows: 14px var(--control-h);
  gap: 4px;
  align-items: end;
  width: 84px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}
.result-score-input {
  width: 84px !important;
  min-width: 84px;
  height: var(--control-h);
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.result-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--control-h);
  padding: 0;
  font-weight: 700;
}
.local-result-match td {
  background: rgba(0,62,128,.035);
  vertical-align: bottom;
}
.local-result-match .match-input-cell { min-width: 210px; }
