/* Mobile first. Base styles target a phone; min-width queries add room for bigger screens. */

:root {
  --navy: #0b2545;
  --navy-2: #13315c;
  --red: #c8102e;
  --red-2: #a50d26;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --text: #0f172a;
  --muted: #5b6678;
  --border: #d9e0ea;
  --accent: #1d4ed8;
  --good: #15803d;
  --good-bg: #e7f6ec;
  --bad: #b91c1c;
  --bad-bg: #fdecec;
  --live: #dc2626;
  --radius: 14px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1220;
    --surface: #111b2e;
    --surface-2: #16223a;
    --text: #e8edf5;
    --muted: #9aa7bb;
    --border: #243350;
    --accent: #60a5fa;
    --good: #4ade80;
    --good-bg: #0f2a1b;
    --bad: #f87171;
    --bad-bg: #2d1414;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: .5rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top));
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; font-weight: 700; margin-right: auto; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.topnav { display: none; }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.avatar {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--red); color: #fff; font-weight: 700;
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.2); padding: .4rem; z-index: 40;
}
.menu-panel a, .menu-panel .linklike {
  display: block; width: 100%; text-align: left; padding: .7rem .8rem; border-radius: 10px; color: var(--text);
}
.menu-panel a:hover, .menu-panel .linklike:hover { background: var(--surface-2); text-decoration: none; }
.menu-who { padding: .6rem .8rem; border-bottom: 1px solid var(--border); margin-bottom: .3rem; display: grid; }

/* ---- Bottom tab bar (phones) ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 58px; font-size: .7rem; font-weight: 600; color: var(--muted);
}
.tab:hover { text-decoration: none; }
.tab.is-active { color: var(--red); }
.tab-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Layout ---- */
.page { width: 100%; max-width: 1100px; margin: 0 auto; padding: 1rem; flex: 1; }
.footer { text-align: center; padding: 1rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 1rem; }
.card-flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* ---- Alerts & badges ---- */
.alert { padding: .8rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 500; overflow-wrap: anywhere; }
.alert-success { background: var(--good-bg); color: var(--good); }
.alert-error { background: var(--bad-bg); color: var(--bad); }
.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle;
}
.badge-live { background: var(--live); color: #fff; border-color: var(--live); }
.badge-accent { background: var(--navy); color: #fff; border-color: var(--navy); }
.badge-muted { opacity: .8; }

/* ---- Buttons ---- */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .6rem 1.1rem; border-radius: 12px; border: 1px solid transparent;
  background: var(--navy); color: #fff; font: inherit; font-weight: 700; cursor: pointer; text-align: center;
}
.btn:hover { text-decoration: none; filter: brightness(1.1); }
.btn-red { background: var(--red); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost-light { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.btn-small { min-height: 36px; padding: .35rem .8rem; font-size: .9rem; border-radius: 10px; }
.btn-block { display: flex; width: 100%; }
.btn-huge { min-height: 64px; font-size: 1.1rem; border-radius: 16px; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.icon-btn.icon-edit { color: var(--accent); text-decoration: none; }
.icon-btn.icon-edit:hover { text-decoration: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--bad); font-size: 1.2rem; cursor: pointer;
}
form.inline { display: inline; }

/* ---- Forms ---- */
label { display: block; font-weight: 600; margin-bottom: .3rem; }
.field { margin-bottom: 1rem; }
.field-hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time],
input[type=number], input[type=color], select, textarea {
  width: 100%; min-height: var(--tap); padding: .6rem .75rem; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
input[type=color] { padding: .25rem; width: 64px; }
input:focus, select:focus, textarea:focus { outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
.check { display: flex; align-items: center; gap: .6rem; font-weight: 500; min-height: var(--tap); }
.check input { width: 22px; height: 22px; }
input.jersey-input { width: 4.2rem; min-height: 40px; text-align: center; padding: .3rem; }

/* Chip pickers: radio buttons styled as big tap targets */
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; border: 0; padding: 0; margin: 0 0 1.2rem; }
.chips legend { font-weight: 700; margin-bottom: .5rem; padding: 0; }
.chips-4 { grid-template-columns: repeat(4, 1fr); }
.chip { margin: 0; font-weight: 500; position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.chip span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 56px; padding: .35rem .4rem; border-radius: 12px; line-height: 1.15;
  border: 2px solid var(--border); background: var(--surface); cursor: pointer; font-size: .9rem;
}
.chip span b { font-size: 1.15rem; }
.chip input:checked + span { border-color: var(--red); background: var(--red); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.chip-none span { color: var(--muted); }

/* ---- Games ---- */
.games { display: grid; gap: .6rem; }
.game {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem .9rem; color: var(--text); box-shadow: var(--shadow);
}
a.game:hover { text-decoration: none; border-color: var(--accent); }
.game-when { font-size: .8rem; color: var(--muted); font-weight: 600; margin-bottom: .35rem; display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.game-team { display: flex; align-items: center; gap: .5rem; padding: .15rem 0; font-weight: 500; }
.game-team.is-winner { font-weight: 800; }
.game-team.is-mine .game-team-name { text-decoration: underline; text-decoration-color: var(--red); text-underline-offset: 3px; }
.game-team-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-score { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.game-note { font-size: .85rem; color: var(--muted); margin-top: .25rem; }
.game-off { background: transparent; box-shadow: none; border-style: dashed; }
.swatch { width: 12px; height: 12px; border-radius: 4px; background: var(--c); flex: none; display: inline-block; }
.team-chip { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; color: var(--text); }
.week-head { font-size: .8rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.2rem 0 .5rem; }
.week-head:first-child { margin-top: 0; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .6rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; background: var(--surface-2); position: sticky; top: 0; }
th.num, td.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
td.strong, th.strong { font-weight: 800; }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }
th.sticky-col { background: var(--surface-2); z-index: 2; }
.rank { color: var(--muted); width: 1.5rem; }

/* ---- Segmented control / filters ---- */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.segmented a { padding: .45rem .9rem; border-radius: 9px; color: var(--muted); font-weight: 700; font-size: .9rem; }
.segmented a.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented a:hover { text-decoration: none; }
.filter { display: flex; gap: .5rem; align-items: center; }
.filter select { width: auto; min-width: 180px; }

/* ---- Scoreboard (scorekeeper) ---- */
.scoreboard {
  position: sticky; top: calc(52px + env(safe-area-inset-top)); z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .5rem;
  background: var(--navy); color: #fff; border-radius: var(--radius); padding: .8rem; margin-bottom: 1rem;
}
.sb-team { text-align: center; min-width: 0; }
.sb-name { font-weight: 700; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-side { font-size: .7rem; opacity: .7; text-transform: uppercase; letter-spacing: .08em; }
.sb-score { font-size: 2.6rem; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.sb-mid { text-align: center; font-size: .8rem; opacity: .85; }
.score-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.score-actions .col { display: grid; gap: .6rem; }
.event-list { list-style: none; margin: 0; padding: 0; }
.event-list li { display: flex; align-items: center; gap: .6rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.event-list li:last-child { border-bottom: 0; }
.event-main { flex: 1; min-width: 0; }
.event-main .muted { font-size: .85rem; }
.period-tag { font-size: .72rem; font-weight: 800; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: .15rem .4rem; flex: none; }

/* Lineup checklist */
.lineup { list-style: none; margin: 0; padding: 0; }
.lineup li { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.lineup li:last-child { border-bottom: 0; }
.lineup .check { flex: 1; margin: 0; min-width: 0; }
.lineup .goalie-pick { font-size: .8rem; font-weight: 600; display: flex; align-items: center; gap: .3rem; color: var(--muted); margin: 0; }
.lineup .goalie-pick input { width: 20px; height: 20px; }

.sticky-submit {
  position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 10;
  padding: .75rem 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.box-teams { display: grid; gap: 1rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.statline { display: grid; grid-template-columns: repeat(5, 1fr); text-align: center; gap: .3rem; }
.statline b { display: block; font-size: 1.4rem; }
.statline span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
code.link { display: block; padding: .5rem; background: var(--surface-2); border-radius: 8px; font-size: .8rem; overflow-wrap: anywhere; user-select: all; }

/* ---- Larger screens ---- */
@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .topnav { display: flex; gap: .25rem; }
  .topnav .tab { flex-direction: row; min-height: 40px; padding: 0 .8rem; font-size: .95rem; color: rgba(255,255,255,.75); border-radius: 10px; }
  .topnav .tab.is-active { color: #fff; background: rgba(255,255,255,.12); }
  .topnav .tab-icon { display: none; }
  .page { padding: 1.5rem; }
  h1 { font-size: 1.75rem; }
  .games-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .75rem; }
  .split { display: grid; grid-template-columns: 3fr 2fr; gap: 1rem; align-items: start; }
  .split > .card + .card, .split > * + * { margin-top: 0; }
  .box-teams { grid-template-columns: 1fr 1fr; }
  .scoreboard { top: 64px; }
  .sticky-submit { bottom: 0; }
  .score-page .page { max-width: 720px; }
}
