:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --border: #e1e0dc;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --series-1: #2a78d6;
  --track: #ebeae6;
  --danger-bg: #fdecec;
  --danger-text: #8f1d1d;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border: #2f2f2d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --series-1: #3987e5;
    --track: #262625;
    --danger-bg: #3a1a1a;
    --danger-text: #ffb4b4;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.5rem; margin-bottom: 16px; }
h3 { font-size: 1rem; margin-bottom: 16px; }
.muted { color: var(--text-muted); }

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-secondary); }
input, select {
  font: inherit; padding: 8px 10px; min-width: 0;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 6px;
}
button {
  font: inherit; font-weight: 600; padding: 9px 16px; cursor: pointer;
  background: var(--series-1); color: #fff; border: 0; border-radius: 6px;
}
button.link { background: none; color: var(--text-secondary); font-weight: 400; padding: 4px 0; }
button.link:hover { color: var(--text-primary); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; padding: 20px;
}
.alert { background: var(--danger-bg); color: var(--danger-text); padding: 10px 12px; border-radius: 6px; margin: 0 0 12px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login p { margin: 0; }

/* analytics layout */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.layout {
  max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start;
}
.content { min-width: 0; }
.rules { position: sticky; top: 16px; font-size: 0.875rem; }
.rules h3 { margin-bottom: 8px; }
.rules h4 { margin: 16px 0 4px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.rules dl { margin: 0; }
.rules dt { font-weight: 600; margin-top: 8px; }
.rules dd { margin: 0; color: var(--text-secondary); }
.rules mark { background: none; color: var(--series-1); font-weight: 700; }
.rules-intro, .rules-foot { margin: 0; font-size: 0.8rem; }
.rules-foot { margin-top: 16px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rules { position: static; }
}
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 28px; }
.filters input[type=number] { width: 100px; }
.empty { margin: 24px 0; }
.period-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin-bottom: 16px; }
.period-head h2 { margin: 0; }
.period-head a { color: var(--series-1); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; }
.tile-label { font-size: 0.8rem; color: var(--text-secondary); }
.tile-value { font-size: 1.6rem; font-weight: 600; line-height: 1.3; }
.tile-sub { font-size: 0.8rem; color: var(--text-muted); }

/* ranked bars */
.bars { list-style: none; margin: 0; padding: 0; }
.bar-row {
  position: relative; display: grid; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 6px;
  grid-template-columns: minmax(120px, 190px) 1fr minmax(140px, auto);
}
.bar-row:hover, .bar-row:focus-visible { background: var(--track); }
.bar-label { color: var(--text-primary); }
.bar-group { display: block; font-size: 0.75rem; color: var(--text-muted); }
.bar-track { height: 14px; }
.bar-fill { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.bar-sep { margin: 0 0.4em; }
.bar-pct { display: inline-block; min-width: 5ch; text-align: right; } /* fixed width keeps the | aligned across rows */
.bar-row::after {
  content: attr(data-tip); display: none; position: absolute; z-index: 1;
  left: 50%; bottom: calc(100% - 2px); transform: translateX(-50%); white-space: nowrap;
  padding: 6px 10px; border-radius: 6px; font-size: 0.8rem; pointer-events: none;
  background: var(--text-primary); color: var(--surface-1);
}
.bar-row:hover::after, .bar-row:focus-visible::after { display: block; }

.table-view { margin-top: 16px; }
.table-view summary { cursor: pointer; color: var(--text-secondary); }
table { width: 100%; border-collapse: collapse; margin-top: 10px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--text-secondary); font-size: 0.85rem; }
.num { text-align: right; }
.notes { font-size: 0.85rem; margin-top: 16px; }

@media (max-width: 560px) {
  .bar-row { grid-template-columns: 1fr auto; row-gap: 2px; }
  .bar-track { grid-column: 1 / -1; grid-row: 2; }
}
