:root {
  color-scheme: light;
  --bg: #ffffff;
  --text: #222222;
  --muted: #5f5f5f;
  --border: #b5b5b5;
  --bar: #e6e6e6;
  --soft: #f0f0f0;
  --fol: #dedede;
  --accent: #3a3a3a;
  --on-accent: #ffffff;
  --err: #8a1c1c;
  --err-bg: #f6e3e3;
  --warn-bg: #f6efdc;
  --r: 0px;
  --scale: 1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #161616; --text: #ececec; --muted: #a5a5a5; --border: #4a4a4a; --bar: #242424; --soft: #1f1f1f;
    --fol: #343434; --accent: #e4e4e4; --on-accent: #161616; --err: #ffb4b4; --err-bg: #3a1f1f; --warn-bg: #3a331f;
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #161616; --text: #ececec; --muted: #a5a5a5; --border: #4a4a4a; --bar: #242424; --soft: #1f1f1f;
  --fol: #343434; --accent: #e4e4e4; --on-accent: #161616; --err: #ffb4b4; --err-bg: #3a1f1f; --warn-bg: #3a331f;
}
/* High contrast: pure black and white, one yellow accent, thick borders (WCAG AAA ratios). */
:root[data-theme='contrast'] {
  color-scheme: dark;
  --bg: #000000; --text: #ffffff; --muted: #f0f0f0; --border: #ffffff; --bar: #000000; --soft: #000000;
  --fol: #2b2b00; --accent: #ffe600; --on-accent: #000000; --err: #ffb3b3; --err-bg: #3d0000; --warn-bg: #2b2b00;
}
/* Kids blue: bright blues, big rounded shapes. */
:root[data-theme='kids'] {
  color-scheme: light;
  --bg: #f1f8ff; --text: #0a2a57; --muted: #35598c; --border: #6aa7ea; --bar: #bfdfff; --soft: #dcedff;
  --fol: #c4e0ff; --accent: #1565d8; --on-accent: #ffffff; --err: #8a1c1c; --err-bg: #ffe0e0; --warn-bg: #fff3c4;
  --r: 14px;
}

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--scale)); }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 0.9375rem/1.35 system-ui, -apple-system, 'Segoe UI', sans-serif; -webkit-text-size-adjust: 100%; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; padding-top: env(safe-area-inset-top); }

.appbar { display: flex; align-items: center; gap: 4px; min-height: 56px; padding: 6px 8px 6px 12px; background: var(--bar); border-bottom: 1.5px solid var(--border); flex: none; }
.appbar .titles { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.appbar .title { font-size: 1.0625rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar .sub { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn { display: flex; align-items: center; justify-content: center; min-width: 44px; height: 44px; padding: 0 6px; font-size: 1.25rem; font-weight: 700; background: none; border: 0; cursor: pointer; }
.iconbtn.boxed { border: 1.5px solid var(--text); background: var(--bg); font-size: 1.5rem; }

.top { flex: none; border-bottom: 1px solid var(--border); }
.content { flex: 1; overflow-y: auto; padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.content > * { flex: none; }
.fn, .fol .fn { font-weight: 800; }
.content > .prow, .content > .rrow, .content > .srow { margin: 0 -14px; padding-left: 14px; padding-right: 14px; }

.label { font-size: 0.75rem; letter-spacing: 1px; font-weight: 700; color: var(--muted); margin-top: 4px; }
.label.inv { color: inherit; opacity: 0.85; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
.big { font-size: 1.0625rem; font-weight: 700; }
.pad { padding: 10px 0 0; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.link { text-decoration: underline; font-size: 0.8125rem; }
.chev { font-size: 1.375rem; color: var(--muted); }

.row { display: flex; align-items: center; gap: 6px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grow2 { flex: 2; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.textleft { text-align: left; }

.card { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1.5px solid var(--border); background: var(--bg); cursor: pointer; }
.card.row { flex-direction: row; }
.card.pinned { border-color: var(--text); }
.card.dashed { border-style: dashed; }
.card:focus-visible, .btn:focus-visible, .chip:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.nextgame { display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--fol); flex-wrap: wrap; }
.tag { display: inline-block; padding: 2px 8px; background: var(--accent); color: var(--on-accent); font-size: 0.6875rem; font-weight: 700; }

.banner { padding: 10px 12px; background: var(--soft); font-size: 0.8125rem; line-height: 1.4; }
.banner.err { background: var(--err-bg); color: var(--err); }
.banner.warn { background: var(--warn-bg); }
.banner a { text-decoration: underline; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 14px; border: 1.5px solid var(--text); background: var(--bg); font-weight: 700; text-align: center; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.8125rem; }
.btnrow { display: flex; gap: 8px; padding: 10px 12px 0; }
.btnrow .btn { flex: 1; min-height: 44px; font-size: 0.8125rem; }
.btnrow.pad { padding: 12px 14px; border-top: 1.5px solid var(--border); }

.chips { display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: flex; align-items: center; min-height: 36px; padding: 0 14px; border: 1.5px solid var(--border); white-space: nowrap; font-size: 0.8125rem; color: var(--muted); }
.subs .chip { font-size: 0.875rem; color: var(--text); }
.chip.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 700; }

.livestrip { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 4px 12px; background: var(--soft); font-size: 0.75rem; }
.live-l { min-width: 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--text); margin-right: 4px; vertical-align: middle; }
.dot.on { background: var(--accent); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.livebar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--bar); border-top: 1.5px solid var(--border); font-size: 0.875rem; }

.tabs { display: flex; border-bottom: 1.5px solid var(--border); }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 44px; font-size: 0.875rem; color: var(--muted); }
.tab.active { color: var(--text); font-weight: 700; border-bottom: 3px solid var(--accent); }

.thead { background: var(--bar); font-size: 0.6875rem; font-weight: 700; color: var(--muted); }
.prow { display: grid; grid-template-columns: 2.125rem minmax(0, 1fr) 2.125rem minmax(0, 1fr); gap: 6px; align-items: center; padding: 8px 14px; min-height: 48px; border-bottom: 1px solid var(--border); }
.prow.fol, .rrow.fol, .srow.fol, .gcard.fol { background: var(--fol); box-shadow: inset 4px 0 0 var(--accent); }
.prow.chg, .rrow.chg { animation: flash 3s ease-out 1; }
@keyframes flash { from { background: var(--accent); } to { background: transparent; } }
.prow .bo { font-size: 0.9375rem; }
.prow .res { text-align: center; font-weight: 700; font-size: 0.8125rem; }
.pl { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.pl .nm { overflow: hidden; text-overflow: ellipsis; }
.pl .rt { font-size: 0.6875rem; color: var(--muted); }
.thead.prow { min-height: 0; padding-top: 6px; padding-bottom: 6px; }

.sq { display: inline-block; width: 12px; height: 12px; border: 1.5px solid var(--text); flex: none; vertical-align: middle; }
.sq.w { background: #ffffff; }
.sq.b { background: #111111; }
.sq.u { border-style: dashed; background: transparent; }

.rrow { display: grid; grid-template-columns: 2rem minmax(0, 1fr) 2.875rem 2.5rem 2.75rem; gap: 6px; align-items: center; padding: 8px 14px; min-height: 44px; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.srow { display: grid; grid-template-columns: 2.125rem minmax(0, 1.5fr) 2.75rem 2.5rem minmax(0, 1fr); gap: 6px; align-items: center; padding: 8px 14px; min-height: 44px; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.srow .club { font-size: 0.75rem; color: var(--muted); }
.thead.rrow, .thead.srow { min-height: 0; font-size: 0.6875rem; }
.content > .rrow, .content > .srow { margin-top: -10px; }

.gcard { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1.5px solid var(--border); }
.rdn { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 44px; font-size: 1.25rem; }
.rdn .tag { font-size: 0.625rem; }
.ginfo { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.gres { display: flex; flex-direction: column; align-items: center; min-width: 36px; font-size: 1rem; }

.segment { display: flex; border-bottom: 1px solid var(--border); }
.seg { flex: 1; min-height: 40px; background: none; border: 0; cursor: pointer; font-size: 0.8125rem; color: var(--muted); }
.seg.active { color: var(--text); font-weight: 700; box-shadow: inset 0 -3px 0 var(--accent); }

.scrollx { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
table.data { border-collapse: collapse; font-size: 0.75rem; white-space: nowrap; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
table.data th { background: var(--bar); color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.8125rem; color: var(--muted); }
.field input { height: 48px; padding: 0 12px; border: 1.5px solid var(--text); background: var(--bg); color: var(--text); font-size: 1rem; }
.radio, .toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.radio input, .opt input { width: 20px; height: 20px; accent-color: var(--accent); }
.toggle { justify-content: space-between; padding: 0 12px; min-height: 52px; border-bottom: 1px solid var(--border); }
.toggle:last-child { border-bottom: 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.box { border: 1.5px solid var(--border); }
.optgrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.opt { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; border: 1.5px solid var(--border); cursor: pointer; font-size: 0.875rem; }
.opt.on { border: 2px solid var(--accent); background: var(--fol); font-weight: 700; }
.stack .opt { justify-content: flex-start; padding: 0 12px; }

.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-start; justify-content: center; padding: 72px 16px 16px; background: rgba(0, 0, 0, 0.55); overflow-y: auto; }
.modal { width: 100%; max-width: 520px; background: var(--bg); border: 2px solid var(--text); display: flex; flex-direction: column; }
.mhead { padding: 12px 14px; background: var(--accent); color: var(--on-accent); display: flex; flex-direction: column; gap: 2px; }
.mbody { max-height: 50vh; overflow-y: auto; }
.modal .prow { grid-template-columns: 2.125rem minmax(0, 1fr) 4.375rem minmax(0, 1fr); }
.modal .res.colr { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 0.625rem; letter-spacing: 0.5px; }
.thead .bo { font-size: 0.6875rem; }

/* ---- themes and accessibility ---- */
:root[data-theme='kids'] body { font-family: ui-rounded, 'Arial Rounded MT Bold', 'Segoe UI', system-ui, sans-serif; }
.card, .btn, .chip, .opt, .banner, .modal, .box, .gcard, .nextgame, .field input, .tag { border-radius: var(--r); }
.mhead { border-radius: calc(var(--r) - 2px) calc(var(--r) - 2px) 0 0; }
:root[data-theme='kids'] .tab.active, :root[data-theme='kids'] .seg.active { border-radius: 10px 10px 0 0; }
:root[data-theme='kids'] .btn, :root[data-theme='kids'] .chip { border-width: 2px; }

:root[data-theme='contrast'] .appbar, :root[data-theme='contrast'] .tabs, :root[data-theme='contrast'] .chips, :root[data-theme='contrast'] .livebar { border-bottom-width: 3px; }
:root[data-theme='contrast'] .card, :root[data-theme='contrast'] .btn, :root[data-theme='contrast'] .chip, :root[data-theme='contrast'] .opt, :root[data-theme='contrast'] .box, :root[data-theme='contrast'] .gcard, :root[data-theme='contrast'] .field input { border-width: 2.5px; }
:root[data-theme='contrast'] .prow, :root[data-theme='contrast'] .rrow, :root[data-theme='contrast'] .srow { border-bottom-width: 2px; }
:root[data-theme='contrast'] .prow.fol, :root[data-theme='contrast'] .rrow.fol, :root[data-theme='contrast'] .srow.fol, :root[data-theme='contrast'] .gcard.fol { box-shadow: inset 8px 0 0 var(--accent); }
:root[data-theme='contrast'] a:not(.btn):not(.chip):not(.tab):not(.iconbtn):not(.card) { text-decoration: underline; }
:root[data-theme='contrast'] .muted, :root[data-theme='contrast'] .label, :root[data-theme='contrast'] .rt { color: #ffffff; }
:root[data-theme='contrast'] .sq.u { border-style: dashed; }
:root[data-theme='contrast'] .chip.active, :root[data-theme='contrast'] .btn.primary { outline: 2px solid #ffffff; outline-offset: -5px; }

.chip { min-height: 44px; }
.seg { min-height: 44px; }
.btn.small { min-height: 44px; }
main:focus { outline: none; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 30; padding: 10px 14px; background: var(--accent); color: var(--on-accent); font-weight: 700; border: 2px solid var(--text); cursor: pointer; }
.skip:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
:root[data-theme='contrast'] :focus-visible { outline: 4px solid #ffffff; outline-offset: 3px; box-shadow: 0 0 0 7px #000000; }
:root[data-motion='reduce'] *, :root[data-motion='reduce'] *::before, :root[data-motion='reduce'] *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
.optgrid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
