:root {
  --page: #fefefc;
  --surface: transparent;
  --surface-2: #f1f1ef;
  --border: #303030;
  --text: #161616;
  --muted: #4b4b4b;
  --subtle: #737373;
  --ui-accent: #1f2328;
  --data-accent: #1f2328;
  --theme-label: #1f2328;
  --focus: #1f2328;
  --empty: #e8e8e6;
  --lv1: #dedede;
  --lv2: #bcbcbc;
  --lv3: #8c8c8c;
  --lv4: #5d5d5d;
  --lv5: #242424;
  --tip-bg: #1b1b1b;
  --tip-text: #ffffff;
  --tip-muted: #d4d4d4;
  --cell: 15px;
  --cell-gap: 3px;
  color-scheme: light;
}

:root[data-activity-palette="cobalt"] {
  --page: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --border: #1f2328;
  --text: #1f2328;
  --muted: #57606a;
  --subtle: #6e7781;
  --ui-accent: #1f2328;
  --data-accent: #ffd700;
  --theme-label: #0969da;
  --focus: #1f2328;
  --empty: #eaeef2;
  --tip-bg: #1f2328;
  --tip-text: #ffffff;
  --tip-muted: #d0d7de;
}

:root[data-activity-palette="magenta"] {
  --page: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --border: #1f2328;
  --text: #1f2328;
  --muted: #57606a;
  --subtle: #6e7781;
  --ui-accent: #1f2328;
  --data-accent: #c2185b;
  --theme-label: #c2185b;
  --focus: #1f2328;
  --empty: #eaeef2;
  --tip-bg: #24121b;
  --tip-text: #ffffff;
  --tip-muted: #d0d7de;
}

:root[data-activity-palette="newsprint"] {
  --page: #f7f6f1;
  --surface: transparent;
  --surface-2: #f1f1ef;
  --border: #303030;
  --text: #161616;
  --muted: #4b4b4b;
  --subtle: #737373;
  --ui-accent: #1f2328;
  --data-accent: #1f2328;
  --theme-label: #1f2328;
  --focus: #1f2328;
  --empty: #e8e8e6;
  --tip-bg: #1b1b1b;
  --tip-text: #ffffff;
  --tip-muted: #d4d4d4;
}

[data-theme="dark"] {
  --page: #11100f;
  --surface: #171513;
  --surface-2: #1e1b18;
  --border: #5b5750;
  --text: #f2eee8;
  --muted: #b7b0a8;
  --subtle: #918b83;
  --ui-accent: #f2eee8;
  --data-accent: #f2eee8;
  --theme-label: #f2eee8;
  --focus: #f2eee8;
  --empty: #24211e;
  --tip-bg: #f2eee8;
  --tip-text: #171513;
  --tip-muted: #675e56;
  color-scheme: dark;
}

:root[data-theme="dark"][data-activity-palette="cobalt"] { --data-accent: #ffd700; --theme-label: #7cb7ff; }
:root[data-theme="dark"][data-activity-palette="magenta"] { --data-accent: #f26ca8; --theme-label: #f26ca8; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #11100f;
    --surface: #171513;
    --surface-2: #1e1b18;
    --border: #5b5750;
    --text: #f2eee8;
    --muted: #b7b0a8;
    --subtle: #918b83;
    --ui-accent: #f2eee8;
    --data-accent: #f2eee8;
    --theme-label: #f2eee8;
    --focus: #f2eee8;
    --empty: #24211e;
    --tip-bg: #f2eee8;
    --tip-text: #171513;
    --tip-muted: #675e56;
    color-scheme: dark;
  }
  :root:not([data-theme="light"])[data-activity-palette="cobalt"] { --data-accent: #ffd700; --theme-label: #7cb7ff; }
  :root:not([data-theme="light"])[data-activity-palette="magenta"] { --data-accent: #f26ca8; --theme-label: #f26ca8; }
}

:root[data-theme="dark"][data-activity-palette] {
  --page: #11100f;
  --surface: #171513;
  --surface-2: #1e1b18;
  --border: #5b5750;
  --text: #f2eee8;
  --muted: #b7b0a8;
  --subtle: #918b83;
  --ui-accent: #f2eee8;
  --focus: #f2eee8;
  --empty: #24211e;
}
:root[data-theme="dark"][data-activity-palette="cobalt"] { --data-accent: #ffd700; --theme-label: #7cb7ff; }
:root[data-theme="dark"][data-activity-palette="magenta"] { --data-accent: #f26ca8; --theme-label: #f26ca8; }
:root[data-theme="dark"][data-activity-palette="newsprint"] { --data-accent: #f2eee8; --theme-label: #f2eee8; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"])[data-activity-palette] {
    --page: #11100f;
    --surface: #171513;
    --surface-2: #1e1b18;
    --border: #5b5750;
    --text: #f2eee8;
    --muted: #b7b0a8;
    --subtle: #918b83;
    --ui-accent: #f2eee8;
    --focus: #f2eee8;
    --empty: #24211e;
  }
  :root:not([data-theme="light"])[data-activity-palette="cobalt"] { --data-accent: #ffd700; --theme-label: #7cb7ff; }
  :root:not([data-theme="light"])[data-activity-palette="magenta"] { --data-accent: #f26ca8; --theme-label: #f26ca8; }
  :root:not([data-theme="light"])[data-activity-palette="newsprint"] { --data-accent: #f2eee8; --theme-label: #f2eee8; }
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
  background-color: var(--page);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

:root[data-activity-palette="newsprint"] body {
  background-image: url("./newsprint-surface.jpg");
  background-repeat: repeat;
  background-size: 560px auto;
  background-position: 0 0;
  background-blend-mode: normal;
}
:root[data-theme="dark"][data-activity-palette="newsprint"] body { background-image: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"])[data-activity-palette="newsprint"] body { background-image: none; }
}

button,
a { font: inherit; touch-action: manipulation; }

button:focus-visible,
a:focus-visible,
.cell:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip { position: absolute; left: -999px; }
.skip:focus {
  left: 10px;
  top: 10px;
  z-index: 10;
  padding: 6px 9px;
  background: var(--tip-bg);
  color: var(--tip-text);
}

.top {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.top-inner {
  max-width: 1120px;
  min-height: 54px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand strong {
  font: 600 16px/1.2 ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  letter-spacing: -0.02em;
}

.brand span,
.freshness,
.gh { color: var(--muted); font-size: 12px; }

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

.freshness { margin: 0; white-space: nowrap; }
.gh { text-decoration: none; border-bottom: 1px solid transparent; }
.gh:hover { color: var(--text); border-color: currentColor; }

.theme { display: flex; align-items: center; gap: 9px; }
.theme button {
  min-height: 30px;
  padding: 3px 0 2px;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.theme button[aria-pressed="true"] { color: var(--text); border-color: currentColor; }

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 30px 24px 76px;
}

.identity {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 12px;
}

.overview { margin: 0 0 26px; }
.hero { display: flex; align-items: baseline; gap: 10px; }
.hero-value {
  margin: 0;
  font: 600 clamp(34px, 4vw, 42px)/1 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
}
.hero-label {
  margin: 0;
  color: var(--muted);
  font: 500 14px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.coverage-note {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}
.coverage-note[hidden] { display: none; }
.coverage-link {
  min-height: 26px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--ui-accent);
  cursor: pointer;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 0;
  margin: 20px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
  color: var(--muted);
  font-size: 12px;
}
.hero-meta li { padding: 0 18px; border-left: 1px solid var(--border); }
.hero-meta li:first-child { padding-left: 0; border-left: 0; }
.hero-meta strong {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 13px;
}
h2 {
  margin: 0;
  font: 600 16px/1.25 ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  letter-spacing: -0.015em;
}
h1,
h2 { text-wrap: balance; scroll-margin-top: 16px; }
.series-heading,
.range-readout,
.wall-hint { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.range-readout { text-align: right; font-variant-numeric: tabular-nums; }
.mobile-only { display: none; }

.activity { margin: 0 0 50px; }
.activity-head { margin-bottom: 7px; }
.activity-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 24px;
  margin-bottom: 15px;
  border-bottom: 1px solid var(--border);
}

.seg { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.seg button {
  min-height: 34px;
  margin-bottom: -1px;
  padding: 5px 0 6px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg button[aria-selected="true"] { border-color: var(--ui-accent); color: var(--text); }
.palette-seg button[aria-selected="true"] { color: var(--theme-label); }
.palette-seg { margin-left: auto; }

.heat-panel { padding-top: 2px; }
.heat-layout {
  display: grid;
  grid-template-columns: 29px minmax(0, 1fr);
  gap: 10px;
}
.weekdays {
  display: grid;
  grid-template-rows: 16px repeat(7, var(--cell));
  gap: var(--cell-gap);
  color: var(--subtle);
  font-size: 10px;
}
.weekdays span { display: flex; align-items: center; height: var(--cell); }
.heat-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  touch-action: pan-x;
  scrollbar-color: var(--border) transparent;
  scrollbar-width: thin;
}
.months {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: calc(var(--cell) + var(--cell-gap));
  height: 16px;
  color: var(--subtle);
  font-size: 10px;
}
.months span { white-space: nowrap; }
.wall {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cell));
  grid-auto-columns: var(--cell);
  gap: var(--cell-gap);
  width: max-content;
  padding: 0 0 4px;
}
.cell {
  width: var(--cell);
  height: var(--cell);
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--empty);
  cursor: pointer;
}
.cell.future { background: var(--surface-2); }
.cell.unknown {
  background: repeating-linear-gradient(-45deg, var(--empty), var(--empty) 2px, var(--surface-2) 2px, var(--surface-2) 4px);
}
.cell.lv1 { background: var(--lv1); }
.cell.lv2 { background: var(--lv2); }
.cell.lv3 { background: var(--lv3); }
.cell.lv4 { background: var(--lv4); }
.cell.lv5 { background: var(--lv5); }
.cell.newsprint { background-image: none; }
.cell.peak { box-shadow: inset 0 0 0 1px var(--text); }
@media (hover: hover) {
  .cell:hover { box-shadow: inset 0 0 0 1px var(--text); }
  .seg button:hover,
  .theme button:hover,
  .coverage-link:hover { color: var(--text); }
  .rank-row:hover .rank-name { text-decoration: underline; text-underline-offset: 3px; }
}

.heat-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 9px;
}
.legend { display: flex; align-items: center; gap: 4px; color: var(--subtle); font-size: 11px; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 2px; }
.wall-empty {
  margin-top: 12px;
  padding: 16px 0;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
  color: var(--muted);
}
.wall-empty p { margin: 0; }
.wall-empty button {
  margin-top: 8px;
  padding: 0 0 2px;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--ui-accent);
  cursor: pointer;
}

.trend-strip {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.trend-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.trend { height: 54px; }
.trend svg { display: block; width: 100%; height: 54px; }
.trend .area { display: none; }
.trend .line { fill: none; stroke: var(--data-accent); stroke-width: 1.7; vector-effect: non-scaling-stroke; }
.trend .dot { fill: var(--page); stroke: var(--data-accent); stroke-width: 1.8; vector-effect: non-scaling-stroke; }

.tip {
  position: fixed;
  z-index: 6;
  min-width: min(132px, calc(100vw - 16px));
  max-width: min(220px, calc(100vw - 16px));
  padding: 7px 9px 8px;
  border: 1px solid var(--tip-bg);
  border-radius: 3px;
  background: var(--tip-bg);
  color: var(--tip-text);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
}
.tip.is-on { opacity: 1; }
.tip b { display: block; margin-bottom: 1px; font-size: 12px; font-weight: 600; }
.tip .muted { color: var(--tip-muted); }

.break { margin: 0 0 52px; }
.break .section-head {
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}
.rows { border-top: 0; }
.rank-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  padding: 13px 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.rank-row[aria-pressed="true"] { box-shadow: inset 2px 0 0 var(--ui-accent); padding-left: 10px; }
.rank-n { padding-top: 1px; color: var(--subtle); font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.rank-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.rank-name { font-weight: 600; }
.rank-value { font: 600 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; font-variant-numeric: tabular-nums; }
.rank-bar {
  display: block;
  height: 2px;
  margin: 8px 0 6px;
  overflow: hidden;
  background: var(--empty);
}
.rank-bar i { display: block; width: 0; height: 100%; background: var(--data-accent); }
.rank-meta,
.rank-note { display: block; color: var(--muted); font-size: 12px; }
.rank-note { margin-top: 3px; }

.technical {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.technical summary {
  padding: 13px 0;
  cursor: pointer;
  font-weight: 600;
}
.technical summary span { margin-left: 8px; color: var(--muted); font-weight: 400; font-size: 12px; }
.technical-body { display: grid; gap: 32px; padding: 14px 0 28px; }
.technical-body h2 { margin-bottom: 11px; }
.coverage-table { width: 100%; overflow-x: auto; }
.coverage-table table { width: 100%; min-width: 620px; border-collapse: collapse; font-size: 13px; }
.coverage-table th,
.coverage-table td { padding: 8px 6px; border-top: 1px solid var(--border); text-align: left; }
.coverage-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ok { color: var(--text); }
.miss { color: var(--muted); }
.about { max-width: 68ch; color: var(--muted); }
.about p { margin: 0 0 10px; }
.about a { color: var(--ui-accent); }
.banner {
  max-width: 1072px;
  margin: 14px auto 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
@media (prefers-reduced-motion: no-preference) {
  .rank-bar i { transition: width 160ms ease; }
  .tip { transition: opacity 80ms linear; }
}

@media (min-width: 721px) and (max-width: 1050px) {
  :root { --cell: 13px; }
}

@media (max-width: 720px) {
  :root { --cell: 14px; }
  .top-inner { padding: 9px 16px; align-items: flex-start; flex-direction: column; }
  .header-actions { width: 100%; justify-content: space-between; gap: 8px 12px; }
  main { padding: 24px 16px 64px; }
  .hero-value { font-size: 34px; }
  .hero-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-meta li { padding: 0; border-left: 0; }
  .hero-meta li:nth-child(even) { padding-left: 12px; border-left: 1px solid var(--border); }
  .section-head { align-items: start; }
  .activity-controls { align-items: flex-start; flex-direction: column; gap: 0; }
  .activity-controls .seg { width: 100%; gap: 13px; }
  .activity-controls .seg + .seg { border-top: 1px solid var(--border); }
  .palette-seg { margin-left: 0; }
  .heat-layout { grid-template-columns: 22px minmax(0, 1fr); gap: 7px; }
  .weekdays { font-size: 9px; }
  .wall-hint { max-width: 24ch; }
  .mobile-only { display: inline; }
  .rank-top { flex-wrap: wrap; }
  .technical summary span { display: block; margin: 2px 0 0; }
  .banner { margin: 12px 16px 0; }
}
