:root {
  color-scheme: light dark;
  --bg: #f6f3ee;
  --card: #ffffff;
  --line: #e4ded4;
  --ink: #1f1b17;
  --muted: #74685b;
  --soft: #f0ebe3;
  --focus: #2f6fd0;
  --monkey: #d9622b;
  --celeb: #c8102e;
  --dog: #2f6fd0;
  --cat: #b8457e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f;
    --card: #1f1a16;
    --line: #342c25;
    --ink: #f1ebe3;
    --muted: #aa9c8c;
    --soft: #2a231d;
  }
}
:root[data-theme="dark"] {
  --bg: #15120f; --card: #1f1a16; --line: #342c25; --ink: #f1ebe3; --muted: #aa9c8c; --soft: #2a231d;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; }
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 1rem; margin: 0 0 12px; }
h2 small, h3 small { color: var(--muted); font-weight: 400; font-size: .85rem; margin-left: 6px; }
h3 { font-size: .9rem; margin: 0 0 6px; }
code { font-size: .85em; background: var(--soft); padding: 1px 5px; border-radius: 5px; }
.empty { color: var(--muted); margin: 0; }

/* ---- login */
.login {
  max-width: 380px; margin: 14vh auto 0; padding: 0 16px; display: flex; flex-direction: column; gap: 10px;
}
.login[hidden] { display: none; }
.login p { margin: 0; color: var(--muted); }
.login label { font-size: .85rem; color: var(--muted); margin-top: 10px; }
.login input {
  font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}
.login input:focus { outline: 2px solid var(--focus); outline-offset: 1px; }
.login .msg { color: var(--celeb); min-height: 1.4em; }
.primary {
  background: var(--ink); color: var(--bg); border: 0; border-radius: 10px; padding: 11px 16px; cursor: pointer; font-weight: 600;
}

/* ---- header */
.top {
  position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.top h1 { margin-right: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
}
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--muted)); opacity: .45; }
.chip[aria-pressed="true"] { color: var(--ink); border-color: var(--c, var(--ink)); background: color-mix(in srgb, var(--c, var(--ink)) 12%, var(--card)); }
.chip[aria-pressed="true"] i { opacity: 1; }
.range { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 3px; }
.range button { border: 0; background: none; padding: 5px 12px; border-radius: 99px; cursor: pointer; color: var(--muted); }
.range button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.tools { display: flex; align-items: center; gap: 10px; }
.ghost { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 14px; cursor: pointer; }
.ghost:disabled { opacity: .5; cursor: default; }
.ghost.small { padding: 4px 10px; font-size: .85rem; color: var(--muted); }
.updated { color: var(--muted); font-size: .85rem; }
.status { margin: 0; padding: 0 16px; color: var(--celeb); min-height: 0; }
.status:empty { display: none; }
.status:not(:empty) { padding: 10px 16px 0; }

/* ---- layout */
main { max-width: 1240px; margin: 0 auto; padding: 16px 16px 72px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; min-width: 0; }
.grid2, .grid3 { display: grid; gap: 14px; margin-bottom: 14px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid2 .card, .grid3 .card { margin: 0; }
@media (max-width: 980px) { .grid3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 680px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 980px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 480px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.tile .label { color: var(--muted); font-size: .8rem; }
.tile .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.tile .sub { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- chart */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--line); }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart rect:hover { filter: brightness(1.15); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: .85rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c); margin-right: 6px; vertical-align: -1px; }

/* ---- tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: right; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: baseline; }
th { color: var(--muted); font-weight: 500; font-size: .8rem; }
tbody th { text-align: left; color: var(--ink); }
tr:last-child td, tr:last-child th { border-bottom: 0; }
td b { font-weight: 600; }
td small { display: block; color: var(--muted); font-size: .75rem; }
.app { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.app::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--muted)); }

/* ---- bar lists */
.bar { display: grid; grid-template-columns: minmax(0, 1.3fr) 2fr auto; gap: 10px; align-items: center; padding: 4px 0; font-size: .9rem; }
.bar .k { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .track { height: 8px; background: var(--soft); border-radius: 99px; overflow: hidden; }
.bar .track i { display: block; height: 100%; background: var(--ink); border-radius: 99px; }
.bar .v { text-align: right; min-width: 3.5em; }
.bar .v small { color: var(--muted); margin-left: 5px; }

/* ---- top matches */
.tops { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.pill { display: inline-block; background: var(--soft); border-radius: 99px; padding: 3px 10px; margin: 0 6px 6px 0; font-size: .85rem; }
.pill b { color: var(--muted); font-weight: 500; margin-left: 4px; }

/* ---- errors */
.err { border-top: 1px solid var(--line); padding: 8px 0; }
.err:first-child { border-top: 0; }
.err summary { cursor: pointer; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.err .n { color: var(--muted); }
.err .when { color: var(--muted); font-size: .8rem; margin-left: auto; }
.errbody { color: var(--muted); font-size: .85rem; }
.errbody p { margin: 8px 0 4px; }
.errbody pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .78rem; background: var(--soft); padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; }

/* ---- runs */
.runs { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.run { margin: 0; background: var(--soft); border-radius: 14px; overflow: hidden; border-left: 4px solid var(--c); }
.run .pair { display: grid; grid-template-columns: 1fr 1fr; }
.run img, .run .nophoto { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--line); }
.run figcaption { padding: 8px 10px 10px; font-size: .85rem; }
.run figcaption b { font-weight: 600; }
.run .pct { color: var(--c); font-weight: 700; margin-left: 6px; }
.run small { display: block; color: var(--muted); font-size: .75rem; }
.center { text-align: center; margin-top: 14px; }

@media (prefers-reduced-motion: no-preference) {
  .chip, .range button { transition: background .15s, color .15s; }
}
