:root {
  --paper: #F3F4F6;
  --card: #FFFFFF;
  --ink: #1E2227;
  --muted: #5D6570;
  --line: #D9DDE2;
  --red: #C8102E;
  --blue: #0B5CC7;
  --win: #1F7A3A;
  --warn-bg: #FFF4D6;
  --warn-ink: #6B4E00;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --text: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16191D; --card: #1F2328; --ink: #E8EAED; --muted: #9AA2AC;
    --line: #30353C; --red: #FF5A6E; --blue: #5AA2FF; --win: #5CCB7E;
    --warn-bg: #3A3013; --warn-ink: #F5D98A;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--text); }
a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 3px; }
h1, h2 { font-family: var(--display); font-weight: 700; line-height: 1.1; margin: 0 0 .4rem; }
h1 { font-size: 2rem; }
h2 { font-size: 1.4rem; margin-top: 2rem; }
.muted { color: var(--muted); }
.tnum { font-family: var(--display); font-weight: 600; color: var(--muted); }

/* ---- header ---- */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .7rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--display); font-weight: 700; font-size: 1.35rem; text-decoration: none; }
.top nav { display: flex; gap: 1rem; flex-wrap: wrap; }
.top nav a { text-decoration: none; color: var(--muted); padding: .2rem 0; border-bottom: 2px solid transparent; }
.top nav a[aria-current="page"] { color: var(--ink); border-color: var(--ink); }
.lookup { margin-left: auto; }
.lookup input { width: 7.5rem; }
.logout { margin: 0; }

main { max-width: 760px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
section { margin-bottom: 1.5rem; }
.head { margin-bottom: 1rem; }

/* ---- forms ---- */
input, select, textarea, button { font: inherit; font-size: 16px; /* no iOS zoom */ }
input, select, textarea { width: 100%; padding: .55rem .65rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--card); color: var(--ink); }
textarea { resize: vertical; }
label { display: block; font-weight: 500; margin-bottom: .8rem; }
label input, label select { margin-top: .25rem; }
label small { display: block; font-weight: 400; color: var(--muted); }
button, .button { display: inline-block; padding: .55rem 1rem; border: 0; border-radius: 6px;
  background: var(--ink); color: var(--paper); font-weight: 600; cursor: pointer; text-decoration: none; }
button:disabled { opacity: .45; cursor: default; }
button.linkish { background: none; color: var(--muted); padding: 0; font-weight: 400; text-decoration: underline; text-underline-offset: 3px; }
button.danger { color: var(--red); }
.form-row { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; }
.form-row label { margin: 0; }
.form-row > input { flex: 1 1 14rem; width: auto; }
.settings-form { max-width: 26rem; }

.login { max-width: 22rem; margin: 12vh auto 0; }
.login button { width: 100%; }

/* ---- banners ---- */
.banner { padding: .6rem .8rem; border-radius: 6px; margin: 0 0 1rem; }
.banner.ok { background: color-mix(in srgb, var(--win) 14%, var(--card)); }
.banner.error { background: color-mix(in srgb, var(--red) 14%, var(--card)); }
.banner.warn, .banner.mock { background: var(--warn-bg); color: var(--warn-ink); }
.empty { padding: 1.5rem; background: var(--card); border: 1px dashed var(--line); border-radius: 8px; }

/* ---- match list: the alliance band is the one loud element ---- */
.actions { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.matches { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.match { display: grid; grid-template-columns: 5.2rem 1fr; background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.match.red  { --alliance: var(--red); }
.match.blue { --alliance: var(--blue); }
.qnum { background: var(--alliance); color: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: .6rem .3rem; }
.qnum .q { font-family: var(--display); font-weight: 700; font-size: 2.1rem; line-height: 1; }
.qnum .time { font-size: .85rem; opacity: .9; margin-top: .2rem; }
.match .body { padding: .7rem .9rem; min-width: 0; }
.match.next { border: 2px solid var(--alliance); box-shadow: 0 0 0 3px color-mix(in srgb, var(--alliance) 18%, transparent); }
.match.played .qnum { background: color-mix(in srgb, var(--alliance) 65%, var(--card)); }
.alliance { margin: 0 0 .35rem; font-weight: 600; color: var(--alliance); display: flex; flex-wrap: wrap; gap: .4rem .7rem; align-items: baseline; }
.nextflag { background: var(--alliance); color: #fff; font-size: .8rem; padding: .05rem .5rem; border-radius: 99px; }
.res { color: var(--muted); font-weight: 500; }
.res.W { color: var(--win); }
.row { margin: .15rem 0; display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; }
.role { color: var(--muted); font-size: .9rem; min-width: 5.3rem; }
.opps { display: flex; flex-direction: column; gap: .1rem; }
.team { text-decoration: none; }
.team:hover .tname { text-decoration: underline; }
.tname { font-weight: 600; }
.meta { color: var(--muted); font-size: .85rem; }
.tag { font-size: .8rem; border: 1px solid var(--line); border-radius: 4px; padding: 0 .3rem; color: var(--muted); }
.notes-badge { font-size: .8rem; color: var(--win); white-space: nowrap; }

/* ---- tables ---- */
.scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 500; color: var(--muted); font-size: .9rem; }
tbody tr:last-child td { border-bottom: 0; }
tr.us td { background: color-mix(in srgb, var(--blue) 9%, var(--card)); }
td form { margin: 0; }
td button { padding: .3rem .7rem; font-size: .9rem; }

/* ---- team page ---- */
.stats { display: flex; flex-wrap: wrap; gap: .5rem 2rem; color: var(--muted); }
.stats .big { display: block; font-family: var(--display); font-weight: 700; font-size: 2rem; color: var(--ink); line-height: 1.1; }
ul.plain { padding-left: 1.1rem; margin: 0; }
.red-text { color: var(--red); }
.blue-text { color: var(--blue); }
.note-form { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .9rem; margin-bottom: 1rem; }
.note-form textarea { margin: .3rem 0 .7rem; }
.note { border-left: 3px solid var(--line); padding: .3rem 0 .3rem .9rem; margin-bottom: 1.1rem; }
.note header { display: flex; flex-wrap: wrap; gap: .1rem .6rem; align-items: baseline; }
.note-body { white-space: pre-wrap; margin: .3rem 0; overflow-wrap: anywhere; }
.stars { color: #D4A017; letter-spacing: 1px; }
.stars .off { color: var(--line); }
.note-actions { display: flex; gap: 1rem; font-size: .9rem; }
.note-actions form { margin: 0; }

@media (max-width: 520px) {
  h1 { font-size: 1.7rem; }
  .match { grid-template-columns: 4.2rem 1fr; }
  .qnum .q { font-size: 1.8rem; }
  .lookup { margin-left: 0; }
  .role { min-width: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---- all matches list ---- */
.small { font-size: .9rem; }
.crumb { margin: 0 0 .4rem; font-size: .95rem; }
.qlist { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.qrow { display: grid; grid-template-columns: 3.4rem 1fr 5.2rem 1fr; gap: .5rem; align-items: center;
  padding: .5rem .7rem; border-bottom: 1px solid var(--line); }
.qrow:last-child { border-bottom: 0; }
.qrow.is-ours { background: color-mix(in srgb, var(--ink) 5%, var(--card)); }
.qlink { font-family: var(--display); font-weight: 700; font-size: 1.3rem; text-decoration: none; line-height: 1.05; }
.qlink small { display: block; font-family: var(--text); font-weight: 400; font-size: .75rem; color: var(--muted); }
.side { display: flex; flex-direction: column; min-width: 0; font-size: .95rem; }
.red-side { border-left: 3px solid var(--red); padding-left: .45rem; }
.blue-side { border-right: 3px solid var(--blue); padding-right: .45rem; text-align: right; align-items: flex-end; }
.side .team { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.side .tname { font-weight: 500; }
.side.won .tname { font-weight: 700; }
.team.ours .tname { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.score { text-align: center; font-family: var(--display); font-weight: 600; font-size: 1.25rem; white-space: nowrap; }
.score .w, .smatch .w { font-weight: 700; }
.dash { color: var(--muted); padding: 0 .2rem; }

/* ---- match detail ---- */
.scoreboard { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.sb { background: var(--card); border: 1px solid var(--line); border-top: 6px solid var(--c); border-radius: 8px; padding: .7rem .9rem; min-width: 0; }
.sb.red { --c: var(--red); }
.sb.blue { --c: var(--blue); }
.sb.won { border-color: var(--c); border-width: 2px 2px 2px 2px; border-top-width: 6px; }
.sb-label { margin: 0; color: var(--c); font-weight: 600; }
.sb-score { margin: 0 0 .3rem; font-family: var(--display); font-weight: 700; font-size: 3.2rem; line-height: 1; }
.sb-teams div { margin: .1rem 0; overflow-wrap: anywhere; }
table.bd th[scope="row"] { font-weight: 500; color: var(--ink); white-space: normal; }
table.bd td { font-variant-numeric: tabular-nums; width: 5.5rem; }
table.bd td.better { font-weight: 700; }
table.bd tr.total th, table.bd tr.total td { border-top: 2px solid var(--line); font-size: 1.1rem; }
table.bd tr.total th { font-weight: 700; }
.all-fields summary { cursor: pointer; font-weight: 600; padding: .4rem 0; }
.all-fields .scroll { margin-top: .5rem; }

/* ---- playoffs ---- */
td.picks { white-space: normal; }
td.picks .team { display: inline-block; margin-right: .7rem; }
.status { font-size: .85rem; padding: .05rem .5rem; border-radius: 99px; border: 1px solid var(--line); }
.st-champion .status { background: #D4A017; border-color: #D4A017; color: #1E2227; font-weight: 600; }
.st-finalist .status { border-color: var(--ink); }
.st-eliminated td { color: var(--muted); }
.st-eliminated .tname { font-weight: 500; }
.series-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.series { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; }
.series-head { margin: 0 0 .3rem; display: flex; flex-wrap: wrap; gap: .2rem .8rem; align-items: baseline; }
.smatch { display: flex; flex-wrap: wrap; gap: .3rem; align-items: baseline; padding: .3rem 0;
  text-decoration: none; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.smatch:hover .mlabel { text-decoration: underline; }
.mlabel { min-width: 5.5rem; color: var(--muted); }
.mlabel small { font-size: .8rem; }

@media (max-width: 520px) {
  .qrow { grid-template-columns: 2.9rem 1fr 4.3rem 1fr; gap: .35rem; padding: .5rem; }
  .side { font-size: .85rem; }
  .side .tnum { display: none; }
  .score { font-size: 1.1rem; }
  .sb-score { font-size: 2.6rem; }
}
.score { text-decoration: none; }
.alliance-list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
.al { display: flex; gap: .8rem; align-items: flex-start; padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
.al:last-child { border-bottom: 0; }
.al.us { background: color-mix(in srgb, var(--blue) 9%, var(--card)); }
.al-num { font-family: var(--display); font-weight: 700; font-size: 1.8rem; line-height: 1; min-width: 1.4rem; }
.al-teams { margin: 0; }
.al-teams .team { white-space: nowrap; }
.al-meta { margin: .25rem 0 0; display: flex; gap: .6rem; align-items: baseline; }
.st-eliminated .tname, .st-eliminated .al-num { color: var(--muted); font-weight: 500; }
