/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-soft: #86b6ef;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --seq-lo: #cde2fb;
  --seq-mid: #5598e7;
  --seq-hi: #104281;
  --empty-cell: #ecebe6;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-fill: #087f08;
  --good-wash: rgba(12, 163, 12, 0.07);
  --maybe: #fab219; --maybe-wash: rgba(250, 178, 25, 0.10);
  --scene-sky: #eef1f4; --scene-rail: #9b9a94; --crow-black: #151515; --crow-grey: #a7a7a2;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --idle: #898781;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.04);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-soft: #1c5cab;
    --accent-wash: rgba(57, 135, 229, 0.14);
    --seq-lo: #184f95;
    --seq-mid: #3987e5;
    --seq-hi: #b7d3f6;
    --empty-cell: #262624;
    --good: #0ca30c;
    --good-ink: #0ca30c;
    --good-fill: #087f08;
    --good-wash: rgba(12, 163, 12, 0.12);
    --maybe: #fab219; --maybe-wash: rgba(250, 178, 25, 0.10);
    --scene-sky: #4f5966; --scene-rail: #c3c2b7; --crow-black: #121212; --crow-grey: #b9b8b2;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --idle: #6b6a66;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-soft: #1c5cab;
  --accent-wash: rgba(57, 135, 229, 0.14);
  --seq-lo: #184f95;
  --seq-mid: #3987e5;
  --seq-hi: #b7d3f6;
  --empty-cell: #262624;
  --good: #0ca30c;
  --good-ink: #0ca30c;
  --good-fill: #087f08;
  --good-wash: rgba(12, 163, 12, 0.12);
  --maybe: #fab219; --maybe-wash: rgba(250, 178, 25, 0.10);
  --scene-sky: #4f5966; --scene-rail: #c3c2b7; --crow-black: #121212; --crow-grey: #b9b8b2;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --idle: #6b6a66;
  --shadow: none;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
button { font: inherit; color: inherit; }
.page { max-width: 1240px; margin: 0 auto; padding: 28px 24px 48px; }

/* ---------- Masthead ---------- */
.masthead { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 44px; height: 44px; flex: none; }
.logo-tile { fill: var(--scene-sky); stroke: var(--border); stroke-width: 1; }
h1 { font-size: 26px; line-height: 1.15; }
.tagline { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; fill: var(--ink-2); }
.icon-btn:hover { background: var(--surface-2); }
.masthead { flex-wrap: wrap; }
.masthead-actions { display: flex; align-items: center; gap: 10px; }
.yt-link {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px 0 10px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.yt-link:hover { background: var(--surface-2); }
.yt-link svg { width: 24px; height: 24px; flex: none; }
.yt-bg { fill: #e62117; }
.yt-play { fill: #fff; }
.yt-link:focus-visible, .footer a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Cards & grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  min-width: 0;
}
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.span-12 { grid-column: span 12; }
.span-6 { grid-column: span 6; }
@media (max-width: 900px) { .span-6 { grid-column: span 12; } }

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head.compact { margin-bottom: 8px; }
.card-head h2 { font-size: 16px; }
.card-head .sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.chart { width: 100%; height: 240px; }
.chart.h-260 { height: 260px; }
.chart.h-280 { height: 280px; }
.chart.h-340 { height: 340px; }
.chart-scroll { overflow-x: auto; overflow-y: hidden; }

/* table view toggle */
.table-view { display: none; max-height: 420px; overflow: auto; }
.card.show-table .chart, .card.show-table .chart-scroll { display: none; }
.card.show-table .table-view { display: block; }
.table-btn {
  border: 1px solid var(--border); background: transparent; color: var(--ink-2);
  border-radius: 8px; padding: 4px 10px; font-size: 12.5px; cursor: pointer;
}
.table-btn:hover { background: var(--surface-2); color: var(--ink); }
.card.show-table .table-btn { background: var(--surface-2); color: var(--ink); }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--ink-3); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
table.data td { font-variant-numeric: tabular-nums; }
table.data tbody tr:hover td { background: var(--accent-wash); }
.table-wrap { overflow-x: auto; }
.chart.yoy { margin-top: 22px; }

/* ---------- Live status block ---------- */
.live {
  display: flex; align-items: center; gap: 14px 22px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 20px 14px 14px; margin-bottom: 22px;
  transition: background-color .4s, border-color .4s;
}
.live[data-state="here"] { background: var(--good-wash); border-color: var(--good); }
.live[data-state="maybe"] { background: var(--maybe-wash); border-color: var(--maybe); }

/* the schematic balcony */
.scene { width: 150px; height: auto; flex: none; display: block; }
.scene .sky { fill: var(--scene-sky); }
.scene .railing { fill: var(--scene-rail); transition: opacity .4s; }
.scene .perched {
  opacity: 0; transform: translateY(-16px);
  transition: opacity .5s ease, transform .6s cubic-bezier(.2, .9, .3, 1.25);
}
/* hooded crow parts (inside the <use> clone, so plain class selectors only) */
.hc-k { fill: var(--crow-black); }
.hc-g { fill: var(--crow-grey); }
.hc-leg { fill: none; stroke: var(--crow-black); stroke-width: 1.9; stroke-linecap: round; }
.hc-eye { fill: #e9e8e3; }
.live[data-state="here"] .scene .perched { opacity: 1; transform: none; }
.live[data-state="maybe"] .scene .perched { opacity: .35; transform: none; }  /* fading: maybe still there */
.scene .unknown { fill: var(--scene-rail); font: 600 34px var(--font); opacity: 0; transition: opacity .4s; }
.live[data-state="offline"] .scene .unknown { opacity: 1; }
.live[data-state="offline"] .scene .railing, .live[data-state="loading"] .scene .railing { opacity: .45; }
@media (prefers-reduced-motion: reduce) { .scene .perched, .live { transition: none; } }

/* the light + answer */
.live-text { flex: 1 1 auto; min-width: 0; }
.indicator {
  display: inline-flex; align-items: center; gap: 9px; margin-bottom: 8px;
  padding: 6px 14px 6px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--ink); font-weight: 600; font-size: 14.5px; white-space: nowrap;
}
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--idle); flex: none; position: relative; }
.live[data-state="here"] .indicator { background: var(--good-fill); border-color: transparent; color: #fff; }
.live[data-state="here"] .status-dot { background: #7dff7d; box-shadow: 0 0 0 2px rgba(255,255,255,.35), 0 0 10px 3px rgba(125,255,125,.75); }
.live[data-state="here"] .status-dot::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  border: 2px solid #fff; opacity: 0; animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(0.5); opacity: 0.9; } 100% { transform: scale(1.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .live[data-state="here"] .status-dot::after { animation: none; opacity: 0.5; } }
.live[data-state="maybe"] .indicator { background: var(--maybe); border-color: transparent; color: #0b0b0b; }
.live[data-state="maybe"] .status-dot { background: #fff3c4; box-shadow: 0 0 0 2px rgba(0,0,0,.12), 0 0 9px 3px rgba(255,214,90,.8); }
.live[data-state="offline"] .indicator, .live[data-state="loading"] .indicator { background: transparent; border-style: dashed; color: var(--ink-2); }
.live[data-state="offline"] .status-dot, .live[data-state="loading"] .status-dot { background: transparent; border: 2px solid var(--idle); }
.status-label { font-size: 19px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
.status-detail { margin-top: 2px; color: var(--ink-2); font-size: 14px; }
.live-updated { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; align-self: flex-start; margin-top: 4px; }
@media (max-width: 700px) {
  .live { flex-wrap: wrap; }
  .scene { width: 112px; }
  .live-text { flex-basis: calc(100% - 130px); }
  .live-updated { width: 100%; margin-top: 0; }
}

/* ---------- Recent days card ---------- */
.recent { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 28px; margin: 18px 0 16px; }
.recent h2 { font-size: 16px; margin-bottom: 12px; }
.today-stats { display: flex; flex-direction: column; gap: 14px; margin: 0; }
.today-stats div { display: flex; flex-direction: column; }
.today-stats dt { color: var(--ink-3); font-size: 12px; order: 2; }
.today-stats dd { margin: 0; font-size: 20px; font-weight: 600; order: 1; }
@media (max-width: 760px) {
  .recent { grid-template-columns: 1fr; gap: 20px; }
  .today-stats { flex-direction: row; flex-wrap: wrap; gap: 12px 28px; }
}

/* 7-day strip */
.strip { display: grid; grid-template-columns: 84px 1fr; row-gap: 6px; column-gap: 10px; align-items: center; }
.strip .day { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; }
.strip .day.today { color: var(--ink); font-weight: 600; }
.strip .track { position: relative; height: 18px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.strip .block { position: absolute; top: 3px; bottom: 3px; min-width: 3px; border-radius: 2px; background: var(--accent); cursor: default; }
.strip .block:hover, .strip .block:focus { background: var(--seq-hi); outline: none; }
.strip .now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--good); }
.strip .axis { grid-column: 2; position: relative; height: 16px; color: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.strip .axis span { position: absolute; transform: translateX(-50%); }
.strip .axis span:first-child { transform: none; }
.strip .axis span:last-child { transform: translateX(-100%); }

/* ---------- Filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: flex-end; margin: 4px 0 16px; }
.filter { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: 100%; }
.filter-label { color: var(--ink-3); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.seg {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; max-width: 100%;
}
.seg button {
  border: 0; background: transparent; color: var(--ink-2); cursor: pointer;
  padding: 6px 12px; border-radius: 7px; font-size: 13.5px; white-space: nowrap;
}
.seg button:hover { color: var(--ink); background: var(--accent-wash); }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 0 0 1px var(--border); }
.seg button:focus-visible, .table-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg.small button { padding: 4px 10px; font-size: 12.5px; }
.range-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.custom-range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; color: var(--ink-2); font-size: 13.5px; }
.custom-range[hidden] { display: none; }
.custom-range label { display: inline-flex; align-items: center; gap: 6px; }
.custom-range input {
  font: inherit; font-size: 13.5px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px; min-height: 34px;
}
.custom-range input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: 1.35fr repeat(4, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpis .tile.hero { grid-column: span 2; } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; margin-top: 4px; }
.tile .value small { font-size: 16px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
.tile .note { color: var(--ink-3); font-size: 12.5px; margin-top: 4px; text-wrap: pretty; }
.tile.hero .value { font-size: 52px; line-height: 1.05; }

/* ---------- Records ---------- */
.records { margin: 0; display: grid; grid-template-columns: 1fr; }
.records > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 16px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.records > div:last-child { border-bottom: 0; }
.records dt { color: var(--ink-2); font-size: 13.5px; }
.records dd { margin: 0; font-weight: 600; text-align: right; }
.records dd.when { grid-column: 1 / -1; color: var(--ink-3); font-size: 12.5px; margin-top: -2px; font-weight: 400; text-align: left; }

.empty { color: var(--ink-3); font-size: 13.5px; }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 6px 24px rgba(0,0,0,.14);
}
.tt-value { font-weight: 600; font-size: 13.5px; }
.tt-label { color: var(--ink-2); }
.tt-row { display: flex; align-items: center; gap: 8px; }
.tt-key { width: 10px; height: 2px; border-radius: 1px; background: var(--accent); flex: none; }

/* ---------- Footer ---------- */
.footer { margin-top: 32px; padding-top: 20px; border-top: 1px solid var(--grid); }
.footer a { display: inline-flex; align-items: center; gap: 10px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.footer a:hover { color: var(--ink); }
.footer a:hover span { text-decoration: underline; text-underline-offset: 3px; }
.footer b { font-weight: 600; color: var(--ink); }
.logo-sm { width: 28px; height: 28px; flex: none; }

/* ---------- Loading state ---------- */
.is-loading .grid { opacity: 0.5; }

@media (max-width: 600px) {
  .page { padding: 18px 16px 40px; }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .live { padding: 12px 14px 12px 12px; }
  .status-label { font-size: 17px; }
  .indicator { font-size: 13.5px; }
  .masthead-actions { width: 100%; }
  .yt-link { flex: 1; justify-content: center; }
  .tile.hero .value { font-size: 44px; }
  .tile .value { font-size: 24px; }
  .strip { grid-template-columns: 64px 1fr; }
}
