:root {
  color-scheme: light dark;
  --canvas: #f5f5f9;
  --surface: #fff;
  --ink: #252336;
  --muted: #686579;
  --line: #dedde6;
  --purple: #5140a5;
  --purple-soft: #eeebf8;
  --ochre: #8a5b0c;
  --focus: #315dd8;
  --display: "Barlow Condensed", Impact, "Arial Narrow", sans-serif;
  --body: "Manrope", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@font-face { font-family: "Barlow Condensed"; src: url("assets/fonts/barlow-condensed-bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Manrope"; src: url("assets/fonts/manrope-regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Manrope"; src: url("assets/fonts/manrope-semibold.ttf") format("truetype"); font-weight: 600 800; font-display: swap; }
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); font: 16px/1.45 var(--body); }
button, input, select { font: inherit; }
button, select, summary { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.shell { width: min(100% - 48px, 1120px); margin: 0 auto; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-size: 18px; font-weight: 720; letter-spacing: -.04em; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 32px; background: var(--purple); color: white; font: 16px/1 var(--display); letter-spacing: .015em; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.season { color: var(--muted); font-size: 13px; font-weight: 650; }
.top-cta { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; background: var(--purple); color: white; border-radius: 4px; text-decoration: none; font-weight: 650; }
.top-cta:hover, .primary-button:hover { background: #40317f; }
.settings-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 6px; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; }
.settings-link:hover { color: var(--purple); }
.top-actions > * { white-space: nowrap; }
.controls { display: flex; justify-content: space-between; align-items: end; gap: 20px; padding: 22px 0 18px; }
.pair-selectors { display: flex; align-items: end; gap: 10px; }
.pair-selectors label, .mode-filter, .field { display: grid; gap: 5px; color: var(--muted); font-size: 13px; font-weight: 600; }
.pair-selectors select, .mode-filter select, .field select, .date-field input, .score-person select { min-width: 0; height: 44px; padding: 0 34px 0 11px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); }
.pair-selectors select { width: clamp(150px, 21vw, 235px); }
.control-vs { padding: 0 2px 11px; color: var(--muted); font-size: 14px; }
.mode-filter select { min-width: 158px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 330px; grid-template-areas: "score entry" "history entry"; align-items: start; gap: 16px 20px; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
.scoreboard { grid-area: score; padding: 22px 26px 0; }
.scoreboard-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 13px; font-weight: 550; }
.scoreboard-head h1, .section-head h2 { margin: 0; font-size: 22px; line-height: 1.2; font-weight: 680; letter-spacing: -.035em; }
.matches-count { color: var(--muted); font-size: 13px; }
.score-strip { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr); align-items: center; gap: 18px; min-height: 112px; padding: 15px 0 16px; border-bottom: 1px solid var(--line); }
.side-name { min-width: 0; display: grid; gap: 3px; }
.side-two { text-align: right; }
.player-name { overflow: hidden; color: var(--ink); font-weight: 700; font-size: clamp(17px, 2.1vw, 23px); text-overflow: ellipsis; white-space: nowrap; }
.side-caption { color: var(--muted); font-size: 13px; }
.wins-score { position: relative; display: flex; align-items: center; gap: clamp(12px, 2vw, 22px); padding-bottom: 15px; color: var(--purple); font: 62px/.95 var(--display); letter-spacing: .01em; }
.wins-score small { position: absolute; right: 0; bottom: 0; left: 0; color: var(--muted); text-align: center; font: 12px/1.2 var(--body); letter-spacing: 0; }
.wins-score span { color: #a6a3b1; font: 29px/1 var(--body); }
.comparison-wrap { overflow-x: auto; }
.comparison-details > summary { display: none; }
.comparison { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.comparison th, .comparison td { height: 37px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.comparison thead th { height: 38px; color: var(--muted); font-size: 13px; font-weight: 600; }
.comparison thead th:first-child, .comparison tbody td:first-child { text-align: left; padding-left: 2px; }
.comparison thead th:last-child, .comparison tbody td:last-child { text-align: right; padding-right: 2px; }
.comparison thead th:nth-child(2), .comparison tbody th { width: 38%; text-align: center; }
.comparison tbody td { font-size: 15px; font-weight: 600; }
.comparison tbody th { color: var(--muted); font-size: 13px; font-weight: 500; }
.shared-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; margin: 0 -26px; padding: 0 26px; border-top: 0; }
.shared-stats div { min-width: 0; display: grid; gap: 2px; padding: 13px 12px 15px 0; }
.shared-stats div + div { border-left: 1px solid var(--line); padding-left: 14px; }
.shared-stats span { color: var(--muted); font-size: 12px; }
.shared-stats strong { font-size: 16px; font-weight: 680; font-variant-numeric: tabular-nums; }
.entry { grid-area: entry; position: sticky; top: 16px; padding: 22px 20px 18px; }
.entry form#match-form { margin-top: 17px; }
.field label, .score-person > label { color: var(--muted); font-size: 13px; font-weight: 600; }
.field select, .date-field input { width: 100%; }
.score-entry { display: grid; grid-template-columns: minmax(0,1fr) 16px minmax(0,1fr); align-items: end; gap: 5px; margin: 20px 0; }
.score-person { min-width: 0; text-align: center; }
.score-person > label { display: block; margin-bottom: 5px; }
.score-person select { width: 100%; padding-right: 24px; }
.score-control { display: flex; align-items: center; justify-content: center; gap: 2px; margin-top: 8px; }
.score-control input { width: 58px; height: 58px; padding: 0; border: 1px solid var(--line); border-radius: 4px; appearance: textfield; background: var(--canvas); color: var(--ink); text-align: center; font: 38px/1 var(--display); }
.score-control input::-webkit-inner-spin-button, .score-control input::-webkit-outer-spin-button { appearance: none; margin: 0; }
.nudge { flex: 0 0 36px; min-width: 36px; min-height: 44px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 24px; }
.nudge:hover { background: var(--purple-soft); color: var(--purple); }
.score-colon { padding-bottom: 11px; color: var(--muted); text-align: center; font-size: 22px; }
.score-p1 > label { color: var(--purple); }
.score-p2 > label { color: var(--ochre); }
.form-row { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: end; gap: 10px; }
.primary-button { min-height: 44px; padding: 0 15px; border: 0; border-radius: 4px; background: var(--purple); color: #fff; font-size: 14px; font-weight: 650; white-space: nowrap; }
.primary-button:disabled { opacity: .65; cursor: wait; }
.form-message { min-height: 19px; margin: 9px 0 0; color: var(--ochre); font-size: 13px; }
.cancel-edit { min-height: 44px; padding: 0 10px; border: 0; background: transparent; color: var(--muted); }
.cancel-edit[hidden] { display: none; }
.history { grid-area: history; padding: 21px 24px 8px; }
.export-button { min-height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--ink); font-size: 13px; font-weight: 600; }
.export-button:hover { border-color: var(--purple); color: var(--purple); }
.history-list { max-height: 420px; overflow: auto; margin-top: 9px; }
.match-row { display: grid; grid-template-columns: 65px minmax(0,1fr) 74px auto; align-items: center; gap: 10px; min-height: 70px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.match-row:last-child { border-bottom: 0; }
.match-date { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.match-teams { min-width: 0; }
.match-mode { display: block; overflow: hidden; margin-bottom: 2px; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.match-summary { overflow: hidden; font-size: 14px; font-weight: 620; text-overflow: ellipsis; white-space: nowrap; }
.match-summary .p1 { color: var(--purple); }
.match-summary .p2 { color: var(--ochre); }
.match-score { text-align: center; font: 24px/1 var(--display); font-variant-numeric: tabular-nums; white-space: nowrap; }
.match-actions { display: flex; gap: 2px; }
.icon-button { display: grid; place-items: center; min-width: 40px; min-height: 44px; padding: 0 5px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; }
.icon-button:hover { background: var(--canvas); color: var(--ink); }
.icon-button.delete:hover { color: #9a3d32; }
.empty-state, .loading-state { padding: 34px 12px; color: var(--muted); text-align: center; font-size: 14px; }
.empty-state strong { display: block; margin-bottom: 4px; color: var(--ink); font-size: 16px; }
.empty-state span { display: block; }
.retry-button { margin: 14px auto 0; min-height: 44px; }
.settings { margin: 16px 0 32px; padding: 0 20px; }
.settings summary { display: flex; align-items: center; gap: 12px; min-height: 58px; list-style: none; font-size: 15px; font-weight: 680; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary::after { content: "+"; margin-left: auto; color: var(--purple); font-size: 20px; font-weight: 400; }
.settings[open] summary::after { content: "−"; }
.settings-hint { color: var(--muted); font-size: 13px; font-weight: 450; }
.settings-content { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; padding: 5px 0 20px; }
.settings-content section { min-width: 0; }
.settings-content h2 { margin: 0 0 12px; font-size: 16px; }
.players-list, .modes-list { display: grid; gap: 8px; }
.player-edit-row, .mode-edit-row { display: grid; grid-template-columns: minmax(70px,.7fr) minmax(0,1fr) auto; align-items: center; gap: 8px; }
.player-edit-row > span, .mode-edit-row > span { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.player-edit-row input, .mode-edit-row input, .add-form input { min-width: 0; width: 100%; height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); }
.quiet-button, .add-form button { min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--purple); font-size: 13px; font-weight: 620; white-space: nowrap; }
.quiet-button:hover, .add-form button:hover { background: var(--purple-soft); }
.add-form { display: flex; gap: 8px; margin-top: 10px; }
.settings-message { min-height: 19px; margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.toast { position: fixed; z-index: 10; bottom: 20px; left: 50%; max-width: calc(100vw - 32px); padding: 11px 16px; transform: translate(-50%, 10px); border-radius: 4px; background: var(--ink); color: white; opacity: 0; pointer-events: none; transition: opacity .15s ease, transform .15s ease; font-size: 14px; }
.toast.visible { transform: translate(-50%, 0); opacity: 1; }
.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; }

@media (max-width: 800px) {
  .shell { width: min(100% - 36px, 650px); }
  .workspace { grid-template-columns: 1fr; grid-template-areas: "score" "entry" "history"; gap: 13px; }
  .entry { position: static; }
  .scoreboard { padding-right: 20px; padding-left: 20px; }
  .shared-stats { margin-right: -20px; margin-left: -20px; padding-right: 20px; padding-left: 20px; }
  .entry { padding: 18px 20px 13px; }
  .entry form#match-form { margin-top: 11px; }
  .score-entry { margin: 13px 0; }
  .score-person { display: grid; grid-template-columns: minmax(0,1fr); gap: 5px; align-items: center; }
  .score-person > label { grid-column: 1; text-align: left; }
  .score-person > select { grid-column: 1; }
  .score-control { grid-column: 1; margin-top: 2px; }
  .score-control input { width: 48px; height: 48px; font-size: 32px; }
  .nudge { flex-basis: 44px; min-width: 44px; }
  .score-colon { padding-bottom: 0; align-self: center; }
}
@media (max-width: 520px) {
  .shell { width: calc(100% - 28px); }
  .topbar { height: 62px; }
  .brand { font-size: 17px; }
  .top-actions { gap: 11px; }
  .settings-link { padding: 0 2px; font-size: 13px; }
  .top-cta { padding: 0 13px; }
  .controls { align-items: stretch; flex-direction: column; gap: 10px; padding: 15px 0 12px; }
  .pair-selectors { display: grid; grid-template-columns: minmax(0,1fr) 18px minmax(0,1fr); gap: 7px; align-items: end; }
  .pair-selectors select { width: 100%; padding-right: 24px; }
  .pair-selectors label, .mode-filter { font-size: 13px; }
  .control-vs { padding: 0 0 11px; text-align: center; }
  .mode-filter { display: flex; align-items: center; justify-content: space-between; }
  .mode-filter select { min-width: 0; width: 66%; }
  .scoreboard { padding: 16px 15px 0; }
  .scoreboard-head h1, .section-head h2 { font-size: 20px; }
  .score-strip { min-height: 82px; gap: 8px; padding: 9px 0; }
  .comparison-details:not([open]) .comparison-wrap { display: none; }
  .comparison-details > summary { display: flex; align-items: center; min-height: 44px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 13px; font-weight: 600; list-style: none; cursor: pointer; }
  .comparison-details > summary::-webkit-details-marker { display: none; }
  .comparison-details > summary::after { content: "+"; margin-left: auto; color: var(--purple); font-size: 19px; font-weight: 400; }
  .comparison-details[open] > summary::after { content: "−"; }
  .wins-score { gap: 11px; font-size: 52px; }
  .wins-score span { font-size: 23px; }
  .player-name { font-size: 16px; }
  .comparison th, .comparison td { height: 35px; padding-right: 5px; padding-left: 5px; }
  .comparison thead th:nth-child(2), .comparison tbody th { width: 43%; }
  .shared-stats { margin-right: -15px; margin-left: -15px; padding: 0 15px; }
  .shared-stats div { padding-right: 5px; }
  .shared-stats div + div { padding-left: 9px; }
  .shared-stats span { font-size: 12px; }
  .shared-stats strong { font-size: 15px; }
  .entry { padding: 16px 15px 10px; }
  .score-entry { grid-template-columns: minmax(0,1fr) 12px minmax(0,1fr); gap: 4px; }
  .score-person { gap: 6px; }
  .score-control { gap: 0; }
  .score-control input { width: 44px; }
  .form-row { grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
  .date-field { min-width: 0; }
  .date-field input { padding: 0 7px; }
  .primary-button { padding: 0 11px; }
  .history { padding: 16px 14px 6px; }
  .history-list { max-height: 480px; }
  .match-row { grid-template-columns: 48px minmax(0,1fr) 52px; gap: 6px; min-height: 66px; }
  .match-actions { grid-column: 2 / 4; justify-content: flex-end; margin-top: -2px; }
  .match-row { position: relative; padding-bottom: 42px; }
  .match-actions { position: absolute; right: 0; bottom: 0; }
  .match-score { font-size: 22px; }
  .settings { margin-top: 13px; padding: 0 14px; }
  .settings summary { min-height: 54px; }
  .settings-content { grid-template-columns: 1fr; gap: 17px; padding-bottom: 15px; }
  .player-edit-row, .mode-edit-row { grid-template-columns: minmax(60px,.7fr) minmax(0,1fr) auto; gap: 6px; }
  .quiet-button, .add-form button { padding: 0 9px; }
}
@media (max-width: 360px) {
  .shell { width: calc(100% - 22px); }
  .season { display: none; }
  .scoreboard { padding-right: 11px; padding-left: 11px; }
  .shared-stats { margin-right: -11px; margin-left: -11px; padding-right: 11px; padding-left: 11px; }
  .wins-score { gap: 8px; font-size: 47px; }
  .player-name { font-size: 15px; }
  .score-control input { width: 40px; }
  .entry { padding-right: 11px; padding-left: 11px; }
  .score-entry { gap: 2px; }
  .score-person select { padding-left: 7px; padding-right: 20px; }
}
@media (prefers-color-scheme: dark) {
  :root { --canvas: #181722; --surface: #242330; --ink: #f2f0f8; --muted: #b0adbf; --line: #3b3948; --purple: #b3a7ff; --purple-soft: #38334f; --ochre: #e0b55e; --focus: #a99aff; }
  .brand-mark { color: #201d32; }
  .top-cta, .primary-button { color: #201d32; }
  .top-cta:hover, .primary-button:hover { background: #c8bfff; }
  .wins-score { color: var(--purple); }
  .icon-button.delete:hover { color: #ff998e; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
