:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #14171c;
  --muted: #5f6672;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --win: #1f9d55;
  --loss: #d64045;
  --pending: #9aa1ac;
  --push: #b08a1e;
  --hot: #e0611f;
  --cold: #2b7bd3;
  --warn-bg: #fff6e0;
  --warn-text: #6b4c00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaee;
    --muted: #9aa2b1;
    --accent: #6d8dff;
    --accent-text: #0b0d12;
    --win: #34c172;
    --loss: #ff6b6f;
    --pending: #6b7280;
    --push: #d8b04a;
    --hot: #ff8a4c;
    --cold: #5aa2ff;
    --warn-bg: #2b2412;
    --warn-text: #f3d68a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaee;
  --muted: #9aa2b1;
  --accent: #6d8dff;
  --accent-text: #0b0d12;
  --win: #34c172;
  --loss: #ff6b6f;
  --pending: #6b7280;
  --push: #d8b04a;
  --hot: #ff8a4c;
  --cold: #5aa2ff;
  --warn-bg: #2b2412;
  --warn-text: #f3d68a;
  --shadow: none;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}
h2 {
  font-size: 1.15rem;
}
h3 {
  font-size: 1rem;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
.muted {
  color: var(--muted);
}
.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  background: var(--surface);
  padding: 8px 12px;
  border-radius: 8px;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- top bar & tabs ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand h1 {
  font-size: 1.05rem;
}
.sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tabs {
  position: sticky;
  top: calc(57px + env(safe-area-inset-top));
  z-index: 9;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tablist {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 8px max(12px, env(safe-area-inset-left));
  max-width: 1280px;
  margin: 0 auto;
}
.tablist::-webkit-scrollbar {
  display: none;
}
.tab {
  flex: none;
  border: 0;
  background: transparent;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}
.tab[aria-selected="true"] {
  background: var(--text);
  color: var(--bg);
}
.tab .count {
  margin-left: 6px;
  font-size: 0.75rem;
  opacity: 0.8;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
  outline: none;
}

/* ---------- primitives ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 12px;
  min-height: 36px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover {
  border-color: var(--muted);
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
.btn[disabled] {
  opacity: 0.55;
  cursor: progress;
}
.btn.small {
  min-height: 30px;
  padding: 4px 10px;
  font-size: 0.85rem;
}
.spin svg {
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .spin svg {
    animation: none;
  }
}
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill.hot {
  color: var(--hot);
  border-color: color-mix(in srgb, var(--hot) 40%, transparent);
}
.pill.cold {
  color: var(--cold);
  border-color: color-mix(in srgb, var(--cold) 40%, transparent);
}
.pill.over {
  color: var(--win);
}
.pill.under {
  color: var(--cold);
}
.pill.warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border-color: transparent;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.banner {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-text);
}
.error {
  color: var(--loss);
  min-height: 1.2em;
}

/* ---------- view header ---------- */
.viewhead {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
}
.viewhead p {
  margin: 4px 0 0;
}
.stamps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.78rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 12px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  min-height: 32px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}
.filters input[type="search"],
.filters select {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 6px 10px;
  min-height: 34px;
  max-width: 100%;
}
.toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.sep {
  width: 1px;
  height: 22px;
  background: var(--border);
}

/* ---------- summary cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
}
.stat[aria-pressed="true"] {
  outline: 2px solid var(--accent);
}
.stat .label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}
.stat .value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 2px 0;
}
.stat .meta {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

/* ---------- tables (become cards on phones) ---------- */
.tablewrap {
  overflow-x: auto;
}
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
table.data th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 700;
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--surface);
}
table.data td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  white-space: nowrap;
}
table.data td.wide {
  white-space: normal;
  min-width: 220px;
}
table.data tr:last-child td {
  border-bottom: 0;
}
table.data td.num {
  text-align: right;
  white-space: nowrap;
}
table.data th.num {
  text-align: right;
}
table.data tr.dim td {
  opacity: 0.55;
}
.strong {
  font-weight: 700;
}
.small {
  font-size: 0.8rem;
}
.nowrap {
  white-space: nowrap;
}

@media (max-width: 760px) {
  table.data,
  table.data tbody,
  table.data tr,
  table.data td {
    display: block;
    width: 100%;
  }
  table.data thead {
    display: none;
  }
  table.data tr {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
  }
  table.data tr:last-child {
    border-bottom: 0;
  }
  table.data td {
    border: 0;
    padding: 3px 0;
    white-space: normal;
    min-width: 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    text-align: right;
  }
  table.data td.num {
    text-align: right;
  }
  table.data td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-align: left;
    flex: none;
    max-width: 45%;
  }
  table.data td.primary {
    font-size: 1rem;
    font-weight: 700;
    text-align: left;
    padding-bottom: 6px;
  }
  table.data td.primary::before {
    display: none;
  }
  table.data td.wide {
    display: block;
    text-align: left;
  }
  table.data td.wide::before {
    display: block;
    max-width: none;
  }
  .topbar .btn span {
    display: none;
  }
  .tabs {
    top: calc(55px + env(safe-area-inset-top));
  }
}

/* ---------- result circles ---------- */
.dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 600;
}
.dot::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  background: var(--pending);
}
.dot.won::before {
  background: var(--win);
}
.dot.lost::before {
  background: var(--loss);
}
.dot.push::before,
.dot.void::before {
  background: var(--push);
}
.dot.pending::before {
  background: transparent;
  border: 2px solid var(--pending);
}
.dot.none::before {
  background: transparent;
  border: 2px dashed var(--border);
}

/* ---------- sparkline bars (last N games) ---------- */
.spark {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 26px;
  vertical-align: middle;
}
.spark i {
  display: block;
  width: 6px;
  border-radius: 2px;
  background: var(--loss);
  min-height: 2px;
}
.spark i.hit {
  background: var(--win);
}

/* ---------- misc blocks ---------- */
details.box {
  margin-top: 12px;
  padding: 10px 14px;
}
details.box summary {
  cursor: pointer;
  font-weight: 600;
}
details.box ul {
  margin: 8px 0 0;
  padding-left: 18px;
}
details.box li {
  margin: 2px 0;
  font-size: 0.85rem;
}
.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}
.empty strong {
  display: block;
  font-size: 1.6rem;
  color: var(--text);
  margin-bottom: 4px;
}
.ladder {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ladder span {
  font-size: 0.75rem;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
}
.ladder span.x {
  text-decoration: line-through;
  opacity: 0.55;
}
.ladder span.best {
  outline: 1px solid var(--accent);
}
.checks {
  font-size: 0.8rem;
  color: var(--muted);
}
.bets {
  display: grid;
  gap: 10px;
}
.bet {
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: center;
  justify-content: space-between;
}
.bet .text {
  font-family: var(--mono);
  font-weight: 700;
}
.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}
.section {
  margin-top: 18px;
}
.section > h3 {
  margin-bottom: 8px;
}
.statusdot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--win);
}
.statusdot.bad {
  background: var(--loss);
}
.statusdot.warn {
  background: var(--push);
}
.skeleton {
  height: 120px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ---------- login ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(360px, calc(100vw - 32px));
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.login {
  display: grid;
  gap: 10px;
  padding: 22px;
}
.login input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  font-size: 16px; /* prevents iOS zoom */
}

@media (max-width: 760px) {
  /* 16px inputs stop iOS Safari from zooming on focus */
  .filters input[type="search"],
  .filters select {
    font-size: 16px;
    flex: 1 1 160px;
  }
}

/* ---------- alert bar (e.g. StatMuse blocked) ---------- */
.alertbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 14px;
  border: 1px solid color-mix(in srgb, var(--warn-text) 35%, transparent);
}
