:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8987;
  --line: #d9dbe0;
  --accent: #0f172a;
  --accent-text: #ffffff;
  --point: #e34948;
  --point-text: #ffffff;
  --us: #1baf7a;
  --them: #2a78d6;
  --warn: #eda100;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.05);
  --tabbar-h: 62px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111113;
    --surface: #1a1a19;
    --surface-2: #26262a;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8d8c86;
    --line: #34343a;
    --accent: #e8e8ea;
    --accent-text: #111113;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; user-select: none; -webkit-user-select: none; cursor: pointer; }
a { color: inherit; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--accent); color: var(--accent-text);
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: .2px; }
.status { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--warn); color: #111; }
.status.offline { background: var(--point); color: #fff; }
.app {
  padding: 14px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 720px; margin: 0 auto;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none;
}
.tabbar a .ico { font-size: 20px; }
.tabbar a.active { color: var(--text); }

/* Cards & lists */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 14px; overflow-x: auto; }
.card h2, .card h3 { margin: 0 0 10px; font-size: 17px; }
h1 { font-size: 22px; margin: 4px 0 12px; }
.sub { color: var(--text-2); font-size: 14px; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list a.item { display: flex; align-items: center; gap: 12px; flex: 1; text-decoration: none; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--text-2); text-decoration: none; font-size: 14px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 13px; color: var(--text-2); font-weight: 600; }
input, select {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 16px; /* 16px stops iOS zooming on focus */
}
input[type=date] { -webkit-appearance: none; min-height: 46px; }
.form-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.form-grid .span2 { grid-column: 1 / -1; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 16px; border-radius: 12px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 15px;
  min-height: 46px;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--text-2); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--point); border-color: var(--point); }
.btn.small { padding: 8px 12px; min-height: 36px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:active { transform: scale(.98); }

/* Chips / badges */
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge.school { border-left: 4px solid var(--series-color, var(--muted)); }
.num { font-weight: 800; font-size: 18px; min-width: 38px; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-weight: 600; }
.pill.live { background: var(--us); color: #fff; }
.pill.final { background: var(--accent); color: var(--accent-text); }
.pill.pending { background: var(--surface-2); }

/* Game tabs */
.gametabs { display: flex; gap: 8px; margin: 10px 0 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.gametabs a, .gametabs button {
  flex: 1; min-width: 84px; text-align: center; padding: 10px 8px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); text-decoration: none; font-weight: 700; font-size: 14px;
}
.gametabs a.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.gametabs a small { display: block; font-weight: 500; font-size: 11px; opacity: .8; }

/* Lineup picker */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.pick {
  padding: 10px 8px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface-2);
  text-align: center; min-height: 68px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.pick .num { font-size: 22px; min-width: 0; }
.pick .nm { font-size: 12px; color: var(--text-2); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick.on { border-color: var(--us); background: color-mix(in srgb, var(--us) 18%, var(--surface)); }
.pick:disabled { opacity: .4; }
.school-head { display: flex; align-items: center; gap: 8px; margin: 12px 0 6px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.school-head:first-child { margin-top: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--series-color, var(--muted)); flex: none; }

/* Big point button */
.pointwrap { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.pointbtn {
  width: 100%; min-height: 38vh; border-radius: 22px; border: 0;
  background: var(--point); color: var(--point-text);
  font-size: clamp(40px, 12vw, 72px); font-weight: 900; letter-spacing: 2px;
  box-shadow: 0 8px 0 color-mix(in srgb, var(--point) 70%, black), var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: transform .06s ease, box-shadow .06s ease;
}
.pointbtn small { font-size: 16px; font-weight: 600; letter-spacing: 0; opacity: .9; }
.pointbtn:active, .pointbtn.pressed { transform: translateY(6px); box-shadow: 0 2px 0 color-mix(in srgb, var(--point) 70%, black); }
.pointbtn:disabled { opacity: .5; box-shadow: none; }
.pointrow { display: flex; gap: 10px; }
.pointrow .pointbtn { min-height: 30vh; font-size: clamp(22px, 7vw, 40px); }
.pointbtn.us { background: var(--us); box-shadow: 0 8px 0 color-mix(in srgb, var(--us) 70%, black); }
.pointbtn.them { background: var(--them); box-shadow: 0 8px 0 color-mix(in srgb, var(--them) 70%, black); }
.pointbtn.us:active, .pointbtn.them:active { box-shadow: 0 2px 0 rgba(0,0,0,.4); }
.scoreline { display: flex; align-items: baseline; justify-content: center; gap: 14px; font-size: 15px; color: var(--text-2); }
.scoreline b { font-size: 26px; color: var(--text); }

/* Court / bench */
.court li { cursor: pointer; }
.court li:active { background: var(--surface-2); }
.pts { font-weight: 800; font-size: 18px; min-width: 34px; text-align: right; }
.pts small { font-weight: 500; font-size: 11px; color: var(--muted); display: block; }
.swap { font-size: 12px; color: var(--muted); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--text-2); font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.barcell { min-width: 90px; }
.bar { position: relative; height: 10px; background: var(--surface-2); border-radius: 0 4px 4px 0; overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-color, var(--series-1)); border-radius: 0 4px 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 13px; color: var(--text-2); margin: 6px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* School comparison */
.schoolcard { border-left: 5px solid var(--series-color, var(--muted)); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--text-2); }
.sharebar { display: flex; height: 22px; border-radius: 6px; overflow: hidden; margin: 8px 0 4px; gap: 2px; background: var(--surface-2); }
.sharebar > i { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; background: var(--series-color); min-width: 0; overflow: hidden; }

/* Modal & toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 720px; max-height: 85vh; overflow: auto;
  background: var(--surface); border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet h3 { margin: 0 0 12px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%);
  background: var(--accent); color: var(--accent-text); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 60;
  max-width: 90vw; box-shadow: var(--shadow);
}
.details summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.log { font-size: 14px; color: var(--text-2); }
.log li { display: block; padding: 8px 0; }
.log b { color: var(--text); }
.inline-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.notice { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border: 1px solid var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
