/* Page frame, type, forms and tables. Written phone-first; wider layouts are
   added in min-width queries. */

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 5rem; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 400 1rem/1.5 var(--text); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px));
}
a { color: inherit; text-underline-offset: 3px; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; font-family: var(--display); line-height: 1.05; }
h1 { font-size: clamp(2.5rem, 9vw, 3.75rem); font-weight: 800; font-style: italic; text-transform: uppercase; letter-spacing: -.01em; }
h2 { font-size: 1.6rem; font-weight: 700; letter-spacing: .005em; }
h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: .7rem; }
p { margin: 0 0 .8rem; }
p:last-child { margin-bottom: 0; }
.lede { color: var(--muted); margin: .5rem 0 0; max-width: 62ch; font-size: 1.02rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.up, .down { white-space: nowrap; }
.up { color: var(--good); font-weight: 700; }
.down { color: var(--bad); font-weight: 700; }

/* ---------- forms ---------- */
button, select, input, textarea {
  font: inherit; font-variant-numeric: tabular-nums; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: .6rem .85rem;
}
button { cursor: pointer; font-weight: 600; }
button:disabled { opacity: .4; cursor: default; }
select { color-scheme: inherit; }
textarea { width: 100%; min-height: 12rem; line-height: 1.55; border-radius: var(--r); padding: 1rem 1.1rem; }
.btn {
  display: inline-flex; align-items: center; gap: .45rem; text-decoration: none; font-weight: 700;
  border-radius: 999px; padding: .65rem 1.2rem; background: var(--brand); color: var(--on-brand); border: 0;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; background: var(--night); color: var(--on-night);
  padding-top: env(safe-area-inset-top, 0px); border-bottom: 3px solid var(--flag);
}
.topbar-in { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 1rem; padding: .7rem var(--pad); min-height: 3.6rem; }
.brand { display: flex; align-items: center; flex: none; }
.brand img { display: block; height: 30px; width: auto; }
.nav { display: none; gap: .25rem; margin-left: 1rem; }
.nav a {
  text-decoration: none; font: 700 1.15rem/1 var(--display); letter-spacing: .02em; text-transform: uppercase;
  padding: .55rem .9rem; border-radius: 999px; color: var(--on-night-muted);
}
.nav a:hover { color: #fff; }
.nav a[aria-current="page"] { color: var(--night); background: var(--flag); }
.scan { margin-left: auto; font-size: .82rem; display: flex; align-items: center; gap: .6rem; color: var(--on-night-muted); white-space: nowrap; }
.scan progress { width: 70px; height: 6px; accent-color: var(--flag); }
.update { background: var(--flag); color: var(--flag-ink); border: 0; border-radius: 999px; padding: .4rem .9rem; font-size: .88rem; }
.theme {
  flex: none; width: 2.5rem; height: 2.5rem; padding: 0; border-radius: 50%; display: grid; place-items: center;
  background: var(--night-2); color: var(--on-night); border: 1px solid rgb(255 255 255 / .18);
}
.theme svg { width: 1.2rem; height: 1.2rem; }
.theme .moon, .theme[aria-pressed="true"] .sun { display: none; }
.theme[aria-pressed="true"] .moon { display: block; }

/* ---------- phone tab bar ---------- */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--night); border-top: 1px solid rgb(255 255 255 / .12);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; height: var(--tabbar);
  text-decoration: none; color: var(--on-night-muted); font: 600 .78rem/1 var(--text);
}
.tabbar svg { width: 1.45rem; height: 1.45rem; }
.tabbar a[aria-current="page"] { color: var(--flag); }

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .nav { display: flex; }
  .brand img { height: 34px; }
}

main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 1.4rem var(--pad) 3.5rem; }
.pagehead { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; justify-content: space-between; align-items: flex-end; margin-bottom: 1.2rem; }
.back { display: inline-flex; align-items: center; gap: .45rem; margin-bottom: 1rem; font-weight: 600; text-decoration: none; color: var(--muted); }
.back:hover { color: var(--ink); }
.back::before { content: ""; width: .5rem; height: .5rem; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }

.sec { margin: 2.4rem 0 .9rem; }
.sec h2 { display: flex; align-items: center; gap: .55rem; }
.sec p { color: var(--muted); margin: .3rem 0 0; max-width: 70ch; }
.pane > .sec:first-child { margin-top: 1.6rem; }

/* ---------- tables ---------- */
.scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .94rem; }
th, td { padding: .7rem .8rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th.l, td.l { text-align: left; }
thead th { font-size: .8rem; font-weight: 600; color: var(--muted); background: var(--panel); border-bottom-color: var(--line-strong); }
tr.vs td { background: var(--warn-bg); }
.sticky-first th:first-child, .sticky-first td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
.sticky-first thead th:first-child { background: var(--panel); }
th button.sort { border: 0; background: none; padding: 0; font: inherit; color: inherit; border-radius: 0; }
th button.sort::after { content: " ↕"; opacity: .45; }
th button.sort[aria-pressed="true"] { color: var(--ink); }
th button.sort[aria-pressed="true"]::after { content: " ↓"; opacity: 1; }

/* Phones: tighter cells and short names in the player column, so more stats fit on screen. */
.tight { display: none; }
@media (max-width: 619px) {
  table { font-size: .88rem; }
  th, td { padding: .55rem .5rem; }
  th:first-child, td:first-child { padding-left: .65rem; }
  td .wide { display: none; }
  td .tight { display: inline; }
  td .pl { gap: .5rem; }
  td .av-sm { width: 2.1rem; height: 2.1rem; border-radius: 8px; font-size: .7rem; }
  td .pl-name { font-size: .9rem; white-space: nowrap; }
  td .pl-meta { font-size: .76rem; }
  td .tag { font-size: .68rem; padding: 0 .35rem; }
  td .spark { width: 64px; height: auto; }
  td .meter-track { width: 40px; }
  td .small { font-size: .76rem; }
}

/* ---------- states ---------- */
.status { padding: 2.5rem 0; color: var(--muted); display: flex; align-items: center; gap: .7rem; }
.spinner { width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 2.5px solid var(--line-strong); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.building { max-width: 620px; padding: 2rem 0; }
.building progress { width: 100%; height: 10px; accent-color: var(--brand); }
.error { background: var(--surface); border: 1px solid var(--bad); border-left-width: 5px; border-radius: var(--r); padding: 1.2rem 1.3rem; }
.error h2 { margin-bottom: .5rem; }
details.explain { margin-top: 1.6rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: .9rem 1.1rem; }
details.explain summary { font-weight: 700; cursor: pointer; }
details.explain p { color: var(--muted); max-width: 78ch; margin-top: .7rem; }

/* ---------- footer ---------- */
.footer { background: var(--night); color: var(--on-night-muted); font-size: .9rem; }
.footer-in { max-width: 1240px; margin: 0 auto; padding: 2.2rem var(--pad) 2.4rem; display: grid; gap: 1.4rem; }
.footer img { display: block; }
.footer p { max-width: 74ch; margin: 0; }
.footer a { color: var(--on-night); }
.footer .rp { color: var(--on-night); }
.footer-base { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; padding-top: 1.4rem; border-top: 1px solid rgb(255 255 255 / .12); }
.dd { display: inline-flex; align-items: center; gap: .7rem; text-decoration: none; color: var(--on-night-muted); }
.dd b { display: block; font: 700 1.25rem/1 var(--display); letter-spacing: .06em; text-transform: uppercase; color: var(--on-night); }
.dd small { display: block; font-size: .78rem; margin-bottom: .15rem; }
@media (min-width: 760px) { .footer-in { grid-template-columns: auto 1fr; column-gap: 3rem; } .footer-base { grid-column: 1 / -1; } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
