/*
  Tallyho: web analytics app (Screenery template)
  Neo-brutalism as a working app: off-white paper, 2.5px black borders, flat lemon, mint, salmon and periwinkle fills,
  hard offset shadows that press in on click, Anybody stretched wide for headings and numbers, Victor Mono for data.

  Contents
   1. Tokens
   2. Base and browser surfaces
   3. Components: buttons, segmented control, popovers, fields, chips, tabs, toast
   4. Top bar: logo, site switcher, live counter, range, export
   5. Dashboard head and filters
   6. KPI tiles
   7. Chart
   8. Panels and tables (stacked cards on phones)
   9. Goals and funnel
  10. Drawer
  11. States: skeleton, error, onboarding, noscript
  12. Footer
  13. Motion
  14. Narrow screens
*/

/* ---------- 1. Tokens ---------- */
:root {
  /* Palette */
  --paper: #eff1ec;      /* page ground: a cool off-white */
  --paper-2: #e2e5de;    /* recessed */
  --card: #ffffff;       /* card surface */
  --ink: #121212;        /* borders, type, shadows */
  --ink-2: #45443e;      /* secondary text, 9:1 on paper */
  --lemon: #ffe14d;
  --mint: #7fe3b8;
  --salmon: #ff9d87;
  --peri: #a9b4ff;
  --lemon-2: #fff3b0;    /* light tints for mini bars */
  --mint-2: #c9f5e1;
  --salmon-2: #ffd5cb;
  --peri-2: #dde1ff;
  --focus: #2433e8;

  /* Type */
  --font: 'Anybody', 'Arial Narrow', sans-serif;
  --mono: 'Victor Mono', ui-monospace, monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.75rem;
  --fs-kpi: clamp(1.9rem, 1.2rem + 1.9vw, 3rem);

  /* Shape */
  --bw: 2.5px;
  --bw-thin: 2px;
  --r: 6px;
  --r-sm: 4px;
  --sh: 4px 4px 0 var(--ink);
  --sh-lg: 6px 6px 0 var(--ink);
  --sh-sm: 2px 2px 0 var(--ink);
  --line: var(--bw) solid var(--ink);

  /* Space */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --gutter: clamp(16px, 2.4vw, 32px);
  --max: 1380px;

  /* Motion */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --press: 90ms;
}

/* ---------- 2. Base and browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--ink) var(--paper-2); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 13%, transparent) 1px, transparent 1.3px);
  background-size: 22px 22px;
  accent-color: var(--ink);
  caret-color: var(--focus);
  overflow-x: hidden;
}
::selection { background: var(--lemon); color: var(--ink); }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--paper-2); }
::-webkit-scrollbar-thumb { background: var(--ink); border: 3px solid var(--paper-2); border-radius: 6px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 2px; }
h1, h2, h3 { margin: 0; text-wrap: balance; font-stretch: 125%; font-weight: 800; line-height: 1.1; letter-spacing: -0.01em; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.sr { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: var(--s4); top: -60px; z-index: 50; padding: var(--s2) var(--s4); background: var(--lemon); border: var(--line); border-radius: var(--r); box-shadow: var(--sh); font-weight: 700; text-decoration: none; }
.skip:focus { top: var(--s3); }
table, .num, .kpi-value, .live-num { font-variant-numeric: tabular-nums; }

/* ---------- 3. Components ---------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s4);
  background: var(--card); border: var(--line); border-radius: var(--r);
  box-shadow: var(--sh);
  font-weight: 700; font-stretch: 105%; white-space: nowrap;
  transition: transform var(--press) ease-out, box-shadow var(--press) ease-out, background-color 120ms;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { cursor: not-allowed; opacity: 1; background: var(--paper-2); color: var(--ink-2); box-shadow: none; border-style: dashed; transform: none; }
.btn-ink { background: var(--ink); color: var(--paper); box-shadow: 4px 4px 0 var(--lemon), 4px 4px 0 var(--bw) var(--ink); }
.btn-ink:hover { box-shadow: 5px 5px 0 var(--lemon), 5px 5px 0 var(--bw) var(--ink); }
.btn-ink:active { box-shadow: 0 0 0 var(--lemon); }
.btn-quiet { box-shadow: none; background: transparent; }
.btn-quiet:hover { background: var(--paper-2); box-shadow: none; transform: none; }
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--fs-sm); box-shadow: var(--sh-sm); }
.btn-sm:hover { box-shadow: 3px 3px 0 var(--ink); }
.btn-sm:active { transform: translate(2px, 2px); box-shadow: none; }
.btn-icon { width: 44px; padding: 0; justify-content: center; }
.btn.is-busy .i { animation: spin 0.8s linear infinite; }
.btn.is-done { background: var(--mint); }

/* Segmented control: one bordered block, pressed segment goes ink */
.seg { display: flex; border: var(--line); border-radius: var(--r); background: var(--card); box-shadow: var(--sh); overflow: hidden; }
.seg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 var(--s3);
  border: 0; border-left: var(--line); background: transparent;
  font-weight: 700; font-size: var(--fs-sm); font-stretch: 110%; white-space: nowrap;
  transition: background-color 120ms, color 120ms;
}
.seg-btn:first-child { border-left: 0; }
.seg-btn:hover { background: var(--lemon-2); }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg-btn:active { background: var(--lemon); color: var(--ink); }
.seg-btn:disabled { cursor: not-allowed; color: var(--ink-2); background: var(--paper-2); }
.seg-btn:focus-visible { outline-offset: -5px; outline-color: var(--lemon); }
.seg-btn:not([aria-pressed="true"]):focus-visible { outline-color: var(--focus); }

/* Popovers */
.pop {
  position: absolute; z-index: 30; top: calc(100% + 10px);
  background: var(--card); border: var(--line); border-radius: var(--r); box-shadow: var(--sh-lg);
}
.pop:focus-visible { outline-offset: 2px; }

/* Fields */
.field { display: grid; gap: 6px; }
.field-label { font-weight: 700; font-size: var(--fs-sm); }
.field input {
  min-height: 44px; padding: 0 var(--s3); width: 100%;
  background: var(--paper); border: var(--line); border-radius: var(--r-sm);
  font-family: var(--mono); font-size: var(--fs-sm);
}
.field input:focus-visible { outline-offset: 1px; background: #fff; }
.field input[aria-invalid="true"] { background: var(--salmon-2); border-style: dashed; }
.field-error { min-height: 1.3em; font-size: var(--fs-sm); font-weight: 700; color: #8a1d0c; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: 0; padding: 0; list-style: none; }
.chip {
  display: inline-flex; align-items: center; gap: var(--s1);
  min-height: 38px; padding-left: var(--s3);
  border: var(--line); border-radius: 999px; box-shadow: var(--sh-sm);
  font-size: var(--fs-sm); font-weight: 600;
}
.chip b { font-weight: 800; font-stretch: 110%; }
.chip-lemon { background: var(--lemon); }
.chip-mint { background: var(--mint); }
.chip-salmon { background: var(--salmon); }
.chip-peri { background: var(--peri); }
.chip-x { display: grid; place-items: center; width: 34px; height: 34px; margin-right: 1px; border: 0; border-radius: 50%; background: transparent; }
.chip-x:hover { background: color-mix(in srgb, var(--ink) 14%, transparent); }
.chip-x:active { background: var(--ink); color: var(--paper); }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs [role="tab"] {
  min-height: 36px; padding: 0 var(--s3);
  border: var(--bw-thin) solid var(--ink); border-radius: 999px; background: var(--card);
  font-weight: 700; font-size: var(--fs-sm); font-stretch: 105%;
}
.tabs [role="tab"]:hover { background: var(--lemon-2); }
.tabs [role="tab"][aria-selected="true"] { background: var(--ink); color: var(--paper); }

/* Toast */
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: var(--s5);
  max-width: min(560px, calc(100vw - 32px));
  padding: var(--s3) var(--s4);
  background: var(--ink); color: var(--paper);
  border: var(--line); border-radius: var(--r); box-shadow: 5px 5px 0 var(--lemon);
  font-weight: 600; font-size: var(--fs-sm);
  transform: translate(-50%, 160%); opacity: 0; pointer-events: none;
  transition: transform 380ms var(--ease), opacity 200ms;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* Card */
.card { background: var(--card); border: var(--line); border-radius: var(--r); box-shadow: var(--sh-lg); }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap;
  padding: var(--s3) var(--s4); border-bottom: var(--line);
}
.card-head h2 { font-size: var(--fs-lg); }

/* ---------- 4. Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap;
  padding: var(--s3) var(--gutter);
  background: var(--paper);
  border-bottom: 3px solid var(--ink);
}
.logo { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; text-decoration: none; }
.logo-mark { width: 36px; height: 36px; }
.logo-mark rect { fill: var(--lemon); stroke: var(--ink); stroke-width: 3; }
.logo-mark path { stroke: var(--ink); stroke-width: 3.5; stroke-linecap: square; }
.logo-word { font-size: 1.5rem; font-weight: 900; font-stretch: 150%; letter-spacing: -0.02em; }

.site-switch { position: relative; min-width: 0; }
.site-btn { max-width: 340px; padding-left: 8px; }
.site-btn-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.site-domain { font-family: var(--mono); font-weight: 700; font-size: var(--fs-sm); }
.favicon {
  display: inline-grid; place-items: center; flex: none;
  width: 26px; height: 26px; border: var(--bw-thin) solid var(--ink); border-radius: var(--r-sm);
  background: var(--salmon); font-weight: 900; font-size: 0.8rem; font-stretch: 100%;
}
.favicon[data-site="events"] { background: var(--peri); }
.favicon[data-site="zine"] { background: var(--mint); }
.site-btn[aria-expanded="true"] .i { transform: rotate(180deg); }
.site-list { left: 0; width: min(360px, calc(100vw - 32px)); margin: 0; padding: 6px; list-style: none; }
.site-list [role="option"] {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 52px; padding: 6px 10px; border: var(--bw-thin) solid transparent; border-radius: var(--r-sm);
  cursor: pointer;
}
.site-list [role="option"]:hover, .site-list .is-active { background: var(--lemon-2); border-color: var(--ink); }
.opt-text { display: grid; min-width: 0; flex: 1; }
.opt-domain { font-family: var(--mono); font-weight: 700; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.opt-sub { font-size: var(--fs-xs); color: var(--ink-2); }
.opt-check { visibility: hidden; }
[aria-selected="true"] > .opt-check { visibility: visible; }

.live {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 40px; padding: 4px var(--s3);
  border: var(--bw-thin) solid var(--ink); border-radius: 999px; background: var(--mint-2);
  font-size: var(--fs-sm); font-weight: 600;
}
.live[data-empty="true"] { background: var(--paper-2); }
.live-dot { position: relative; width: 12px; height: 12px; border: var(--bw-thin) solid var(--ink); border-radius: 50%; background: var(--mint); }
.live[data-empty="true"] .live-dot { background: var(--card); }
.live-num { display: inline-block; min-width: 1.2ch; font-size: var(--fs-lg); font-weight: 900; font-stretch: 120%; line-height: 1; }

.range { position: relative; margin-left: auto; }
.custom-short { display: none; }
.custom-pop { right: 0; width: min(380px, calc(100vw - 32px)); padding: var(--s4); display: grid; gap: var(--s3); }
.custom-title { font-weight: 700; font-size: var(--fs-sm); }
.custom-fields { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.custom-actions { display: flex; justify-content: flex-end; gap: var(--s2); }

/* ---------- 5. Dashboard head and filters ---------- */
.main { max-width: var(--max); margin: 0 auto; padding: var(--s5) var(--gutter) var(--s7); outline: none; }
.dash { display: grid; gap: var(--s5); }
.dash-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3) var(--s5); flex-wrap: wrap; }
.dash-title { font-size: var(--fs-xl); font-stretch: 120%; overflow-wrap: anywhere; }
.dash-title #dashSite { font-family: var(--font); }
.dash-range { display: inline-block; padding: 2px 10px; margin-left: 4px; border: var(--bw-thin) solid var(--ink); border-radius: var(--r-sm); background: var(--lemon); font-size: var(--fs-md); font-stretch: 110%; font-weight: 800; vertical-align: 0.3em; }
.filterbar { display: flex; align-items: center; gap: var(--s2) var(--s3); flex-wrap: wrap; }
.filter-hint { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--ink-2); }

/* ---------- 6. KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s4); }
.kpi {
  display: grid; align-content: start; gap: var(--s2); text-align: left;
  min-height: 150px; padding: var(--s4);
  background: var(--card); border: var(--line); border-radius: var(--r); box-shadow: var(--sh-lg);
  transition: transform var(--press) ease-out, box-shadow var(--press) ease-out, background-color 160ms;
}
.kpi:hover { transform: translate(-1px, -1px); box-shadow: 7px 7px 0 var(--ink); }
.kpi:active { transform: translate(6px, 6px); box-shadow: 0 0 0 var(--ink); }
/* The chosen tile stays pressed in and takes its metric's fill */
.kpi[aria-pressed="true"] { transform: translate(4px, 4px); box-shadow: 2px 2px 0 var(--ink); }
.kpi[data-metric="visitors"][aria-pressed="true"] { background: var(--lemon); }
.kpi[data-metric="pageviews"][aria-pressed="true"] { background: var(--peri); }
.kpi[data-metric="bounce"][aria-pressed="true"] { background: var(--salmon); }
.kpi[data-metric="duration"][aria-pressed="true"] { background: var(--mint); }
.kpi-label { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: var(--fs-sm); font-stretch: 110%; }
.kpi-value { font-size: var(--fs-kpi); font-weight: 900; font-stretch: 112%; line-height: 1; letter-spacing: -0.02em; white-space: nowrap; }
.kpi-delta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: var(--fs-sm); font-weight: 800; }
.kpi-delta[data-tone] > span:not(.kpi-vs) { padding: 1px 8px; border: var(--bw-thin) solid var(--ink); border-radius: 999px; font-family: var(--mono); font-weight: 700; }
.kpi-delta { --chip: var(--paper-2); }
.kpi-delta[data-tone="good"] { --chip: var(--mint); }
.kpi-delta[data-tone="bad"] { --chip: var(--salmon); }
.kpi-delta > span:not(.kpi-vs) { background: var(--chip); }
.kpi-delta > .i { width: 18px; height: 18px; padding: 1px; border: var(--bw-thin) solid var(--ink); border-radius: 50%; background: var(--chip); stroke-width: 2.4; }
.kpi[data-metric="duration"][aria-pressed="true"] .kpi-delta[data-tone="good"],
.kpi[data-metric="bounce"][aria-pressed="true"] .kpi-delta[data-tone="bad"] { --chip: var(--card); }
.kpi-vs { flex-basis: 100%; font-family: var(--mono); font-weight: 400; font-size: var(--fs-xs); color: var(--ink-2); }
.kpi[aria-pressed="true"] .kpi-vs { color: var(--ink); }

/* ---------- 7. Chart ---------- */
.chart-card { --m: var(--lemon); }
.chart-card[data-metric="pageviews"] { --m: var(--peri); }
.chart-card[data-metric="bounce"] { --m: var(--salmon); }
.chart-card[data-metric="duration"] { --m: var(--mint); }
.chart-card .card-head { background: var(--lemon); }
.chart-card[data-metric="pageviews"] .card-head { background: var(--peri); }
.chart-card[data-metric="bounce"] .card-head { background: var(--salmon); }
.chart-card[data-metric="duration"] .card-head { background: var(--mint); }
.legend { display: flex; gap: var(--s4); margin: 0; padding: 0; list-style: none; font-size: var(--fs-sm); font-weight: 600; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 18px; height: 14px; }
.key-now { background: var(--card); border: var(--bw-thin) solid var(--ink); }
.key-prev { height: 0; border-top: 2.5px dashed var(--ink); }
.chart-wrap { position: relative; margin: var(--s4); margin-top: var(--s5); border-radius: var(--r-sm); touch-action: pan-y; }
.chart-wrap:focus-visible { outline-offset: 6px; }
.chart { display: block; width: 100%; overflow: visible; }
.chart .grid { stroke: color-mix(in srgb, var(--ink) 16%, transparent); stroke-width: 1.5; stroke-dasharray: 3 5; }
.chart .grid.base { stroke: var(--ink); stroke-width: 2.5; stroke-dasharray: none; }
.chart .ylab, .chart .xlab { font-family: var(--mono); font-size: 11.5px; fill: var(--ink-2); }
.chart .bar { --fill: var(--lemon); fill: var(--fill); stroke: var(--ink); stroke-width: 2; transform-box: fill-box; transform-origin: 50% 100%; }
.chart-card[data-metric="pageviews"] .bar { --fill: var(--peri); }
.chart-card[data-metric="bounce"] .bar { --fill: var(--salmon); }
.chart-card[data-metric="duration"] .bar { --fill: var(--mint); }
.chart.dense .bar { stroke-width: 1; }
.chart .bar.on { fill: var(--ink); }
.chart .bar-future { fill: none; stroke: color-mix(in srgb, var(--ink) 35%, transparent); stroke-width: 1.5; stroke-dasharray: 3 3; }
.chart .prev { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-dasharray: 6 5; stroke-linejoin: round; }
.chart .hover-col { fill: color-mix(in srgb, var(--ink) 7%, transparent); }
.tip {
  position: absolute; top: -14px; z-index: 2; pointer-events: none;
  min-width: 170px; padding: var(--s2) var(--s3);
  background: var(--ink); color: var(--paper);
  border: var(--line); border-radius: var(--r-sm); box-shadow: 4px 4px 0 var(--lemon);
  font-size: var(--fs-sm);
}
.tip-date { font-family: var(--mono); font-size: var(--fs-xs); }
.tip-val { font-size: var(--fs-lg); font-weight: 900; font-stretch: 115%; line-height: 1.2; }
.tip-val span { font-size: var(--fs-sm); font-weight: 600; font-stretch: 100%; }
.tip-prev { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-xs); }
.tip-prev b, .goal-d { font-family: var(--mono); padding: 0 6px; border-radius: 999px; background: var(--paper-2); color: var(--ink); font-weight: 800; }
[data-tone="good"]:is(b, .goal-d) { background: var(--mint); }
[data-tone="bad"]:is(b, .goal-d) { background: var(--salmon); }

/* ---------- 8. Panels and tables ---------- */
.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s5); align-items: start; }
.panel[data-dim="page"] .card-head { background: var(--lemon); }
.panel[data-dim="source"] .card-head { background: var(--mint); }
.panel[data-dim="country"] .card-head { background: var(--peri); }
.panel[data-dim="device"] .card-head { background: var(--salmon); }
.table-host { padding: var(--s2) var(--s4) var(--s3); }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { padding: 0; text-align: left; font-weight: 400; }
.tbl th.num { text-align: right; padding-left: var(--s3); }
.sort {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 40px; padding: 0 6px; margin: 0 -6px;
  border: 0; border-radius: var(--r-sm); background: transparent;
  font-family: var(--mono); font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2);
}
.sort .i { width: 13px; height: 13px; opacity: 0.55; }
.sort:hover { background: var(--paper-2); color: var(--ink); }
[aria-sort="ascending"] .sort, [aria-sort="descending"] .sort { color: var(--ink); }
[aria-sort="ascending"] .sort .i, [aria-sort="descending"] .sort .i { opacity: 1; }
.tbl td { padding: 3px 0; border-top: var(--bw-thin) dashed color-mix(in srgb, var(--ink) 22%, transparent); }
.tbl tbody tr:first-child td { border-top-color: var(--ink); border-top-style: solid; }
.tbl td.num { padding-left: var(--s3); text-align: right; font-family: var(--mono); font-size: var(--fs-sm); white-space: nowrap; width: 1%; }
.tbl td.name { width: auto; max-width: 0; }
.rowbtn {
  position: relative; display: flex; align-items: center; gap: var(--s2); width: 100%;
  min-height: 38px; padding: 0 10px;
  border: 0; background: transparent; text-align: left;
  font-size: var(--fs-sm); font-weight: 600;
}
.rowbtn .lbl { position: relative; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel[data-dim="page"] .rowbtn .lbl, .drawer[data-tint="lemon"] .rowbtn .lbl { font-family: var(--mono); font-size: 0.82rem; }
.mbar {
  position: absolute; left: 0; top: 4px; bottom: 4px; width: var(--w);
  min-width: 4px; border-radius: 3px; background: var(--tint, var(--lemon-2));
  box-shadow: inset 0 -3px 0 var(--tint-on, var(--lemon));
  transition: width 420ms var(--ease);
}
.tint-lemon { --tint: var(--lemon-2); --tint-on: var(--lemon); }
.tint-mint { --tint: var(--mint-2); --tint-on: var(--mint); }
.tint-peri { --tint: var(--peri-2); --tint-on: var(--peri); }
.tint-salmon { --tint: var(--salmon-2); --tint-on: var(--salmon); }
.rowbtn:hover .mbar { background: var(--tint-on); outline: var(--bw-thin) solid var(--ink); }
.rowbtn:active .mbar { outline-width: 3px; }
.is-filter .mbar { background: var(--tint-on); background-image: repeating-linear-gradient(-45deg, transparent 0 6px, color-mix(in srgb, var(--ink) 16%, transparent) 6px 8px); }
.is-filter .lbl { font-weight: 800; }
.cc {
  position: relative; flex: none; display: inline-grid; place-items: center;
  width: 30px; height: 20px; border: var(--bw-thin) solid var(--ink); border-radius: 3px; background: var(--card);
  font-family: var(--mono); font-size: 0.7rem; font-weight: 700;
}
.tbl .none td { padding: var(--s5) var(--s2); text-align: center; color: var(--ink-2); font-weight: 600; border-top: var(--bw-thin) solid var(--ink); }
.tbl-foot { padding-top: var(--s2); font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-2); }

.device-split { display: flex; height: 34px; margin: var(--s4) var(--s4) 0; border: var(--line); border-radius: var(--r-sm); overflow: hidden; box-shadow: var(--sh-sm); }
.device-split span { display: grid; place-items: center; min-width: 0; border-left: var(--line); font-family: var(--mono); font-size: var(--fs-xs); font-weight: 700; transition: flex-basis 420ms var(--ease); }
.device-split span:first-child { border-left: 0; }
.seg-desktop { background: var(--salmon); }
.seg-mobile { background: var(--salmon-2); }
.seg-tablet { background: var(--card); }

/* ---------- 9. Goals and funnel ---------- */
.goals .card-head { background: var(--peri); }
.goals-body { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.funnel { padding: var(--s4) var(--s5) var(--s5); border-right: var(--line); }
.fsteps { display: grid; gap: var(--s4); margin: 0; padding: 0; list-style: none; }
.fstep-top { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: 6px; }
.fstep-label { font-weight: 800; font-stretch: 110%; }
.fstep-n { display: inline-flex; align-items: baseline; gap: var(--s2); font-family: var(--mono); font-weight: 700; font-size: var(--fs-sm); }
.fstep-pct { padding: 0 6px; border: var(--bw-thin) solid var(--ink); border-radius: var(--r-sm); background: var(--peri-2); font-size: var(--fs-xs); }
.fbar { height: 30px; border: var(--line); border-radius: var(--r-sm); background: var(--paper-2); overflow: hidden; }
.fbar span { display: block; height: 100%; width: var(--w); min-width: 3px; background: var(--peri); border-right: var(--line); transition: width 520ms var(--ease); }
.fstep:first-child .fbar span { border-right: 0; }
.fdrop { margin-top: 4px; font-size: var(--fs-xs); color: var(--ink-2); font-family: var(--mono); }
.goal-list { padding: var(--s4) var(--s5) var(--s5); }
.goal-list h3 { font-size: var(--fs-md); margin-bottom: var(--s3); }
.goal-list ul { display: grid; margin: 0; padding: 0; list-style: none; }
.goal-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; gap: var(--s3);
  padding: var(--s3) 0; border-top: var(--bw-thin) dashed color-mix(in srgb, var(--ink) 22%, transparent);
}
.goal-list li:first-child { border-top: var(--bw-thin) solid var(--ink); }
.goal-label { font-weight: 700; font-size: var(--fs-sm); }
.goal-n, .goal-cr { font-family: var(--mono); font-size: var(--fs-sm); text-align: right; }
.goal-cr { color: var(--ink-2); }
.goal-d { border: var(--bw-thin) solid var(--ink); font-size: var(--fs-xs); white-space: nowrap; }
.goal-note { margin-top: var(--s4); padding: var(--s3); border: var(--bw-thin) dashed var(--ink); border-radius: var(--r-sm); font-size: var(--fs-sm); color: var(--ink-2); max-width: 60ch; }
.chart .bar.partial { fill: url(#hatch); }

/* ---------- 10. Drawer ---------- */
.drawer {
  width: min(600px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh;
  margin: 0 0 0 auto; padding: 0;
  background: var(--card); color: var(--ink);
  border: 0; border-left: 3px solid var(--ink); box-shadow: -8px 0 0 var(--ink);
}
.drawer::backdrop { background: color-mix(in srgb, var(--ink) 45%, transparent); }
.drawer-inner { display: grid; grid-template-rows: auto auto auto 1fr; height: 100%; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: var(--line); background: var(--lemon); }
.drawer[data-tint="mint"] .drawer-head { background: var(--mint); }
.drawer[data-tint="peri"] .drawer-head { background: var(--peri); }
.drawer[data-tint="salmon"] .drawer-head { background: var(--salmon); }
.drawer-head h2 { font-size: var(--fs-xl); }
.drawer-sub { padding: var(--s3) var(--s4) 0; font-size: var(--fs-sm); color: var(--ink-2); }
.search { position: relative; display: block; margin: var(--s3) var(--s4) 0; }
.search .i { position: absolute; left: 12px; top: 14px; }
.search input {
  width: 100%; min-height: 44px; padding: 0 var(--s3) 0 38px;
  border: var(--line); border-radius: var(--r-sm); background: var(--paper); box-shadow: var(--sh-sm);
}
.search input::placeholder { color: var(--ink-2); }
.drawer-table { overflow: auto; padding-bottom: var(--s6); }

/* ---------- 11. States ---------- */
.skeleton { display: grid; gap: var(--s5); }
.sk { border: var(--bw-thin) dashed color-mix(in srgb, var(--ink) 45%, transparent); border-radius: var(--r); background: var(--paper-2); }
.sk-title { width: min(420px, 70%); height: 40px; }
.sk-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s4); }
.sk-row-2 { grid-template-columns: 1fr 1fr; gap: var(--s5); }
.sk-tile { height: 150px; }
.sk-chart { height: 360px; }
.sk-panel { height: 340px; }

.state-card { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: var(--s6); align-items: center; padding: var(--s6); max-width: 1040px; margin: var(--s5) auto; }
.state-art { width: 100%; height: auto; }
.art-paper { fill: var(--card); stroke: var(--ink); stroke-width: 3; }
.art-line { stroke: var(--ink); stroke-width: 3; }
.art-dot { fill: var(--salmon); stroke: var(--ink); stroke-width: 2; }
.art-bar { stroke: var(--ink); stroke-width: 3; }
.art-bar.a { fill: var(--lemon); } .art-bar.b { fill: var(--mint); } .art-bar.c { fill: var(--peri); } .art-bar.d { fill: var(--salmon); }
.art-x { stroke: var(--ink); stroke-width: 5; stroke-linecap: square; }
.state-copy { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s4); max-width: 62ch; }
.state-copy h2 { overflow-wrap: anywhere; font-size: clamp(1.6rem, 1.1rem + 1.6vw, 2.4rem); }
.state-actions { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; margin-top: var(--s2); }
.state-note { font-size: var(--fs-sm); color: var(--ink-2); }
.error-card { background: var(--card); }

.onboard { display: block; padding: 0; overflow: hidden; }
.onboard-head { display: grid; gap: var(--s3); padding: var(--s6); background: var(--mint); border-bottom: var(--line); }
.onboard-head h2 { font-size: clamp(1.6rem, 1.1rem + 1.8vw, 2.6rem); max-width: 26ch; overflow-wrap: anywhere; }
.onboard-head p { max-width: 64ch; }
.steps { display: grid; margin: 0; padding: 0; list-style: none; }
.step { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: var(--s5); padding: var(--s5) var(--s6); border-top: var(--bw-thin) dashed color-mix(in srgb, var(--ink) 30%, transparent); }
.step:first-child { border-top: 0; }
.step-n {
  display: grid; place-items: center; width: 56px; height: 56px;
  border: var(--line); border-radius: var(--r); box-shadow: var(--sh);
  font-size: 1.6rem; font-weight: 900; font-stretch: 130%;
}
.step:nth-child(1) .step-n { background: var(--lemon); }
.step:nth-child(2) .step-n { background: var(--peri); }
.step:nth-child(3) .step-n { background: var(--salmon); }
.step-body { display: grid; gap: var(--s3); align-content: start; max-width: 72ch; }
.step-body h3 { font-size: var(--fs-lg); }
.snippet { position: relative; border: var(--line); border-radius: var(--r); background: var(--ink); box-shadow: var(--sh); }
.snippet pre { margin: 0; padding: var(--s4); padding-right: 150px; overflow-x: auto; }
.snippet code { font-family: var(--mono); font-size: var(--fs-sm); color: var(--lemon-2); line-height: 1.6; }
.copy-btn { position: absolute; top: 10px; right: 10px; box-shadow: 2px 2px 0 var(--lemon); }
.setup-panel { padding: var(--s3) var(--s4); border: var(--bw-thin) solid var(--ink); border-radius: var(--r-sm); background: var(--paper); }
.check-row { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.check-result { font-weight: 600; font-size: var(--fs-sm); }
.check-result[data-tone="bad"] { padding: var(--s2) var(--s3); border: var(--bw-thin) solid var(--ink); border-radius: var(--r-sm); background: var(--salmon-2); }

.noscript { padding: var(--s6); margin-bottom: var(--s5); background: var(--lemon); display: grid; gap: var(--s3); }
.noscript h1 { font-size: var(--fs-xl); }
.noscript p { max-width: 64ch; }

/* ---------- 12. Footer ---------- */
.foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3) var(--s5); flex-wrap: wrap;
  max-width: var(--max); margin: 0 auto; padding: var(--s5) var(--gutter) var(--s7);
  border-top: 3px solid var(--ink);
  font-size: var(--fs-sm);
}
.foot-privacy { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 600; max-width: 70ch; }
.foot-actions { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.foot-meta { font-family: var(--mono); font-size: var(--fs-xs); color: var(--ink-2); }

/* ---------- 13. Motion ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: no-preference) {
  /* Signature: bars drop into place like blocks, left to right, when the metric or range changes */
  .chart.grow .bar { animation: drop 560ms var(--ease) both; animation-delay: calc(min(var(--i), 40) * 14ms); }
  @keyframes drop { from { transform: scaleY(0); } 60% { transform: scaleY(1.06); } to { transform: scaleY(1); } }
  .live-dot::after { content: ''; position: absolute; inset: -6px; border: 2px solid var(--ink); border-radius: 50%; animation: ping 2.4s var(--ease) infinite; }
  .live[data-empty="true"] .live-dot::after { content: none; }
  @keyframes ping { from { transform: scale(0.4); opacity: 0.9; } to { transform: scale(1.4); opacity: 0; } }
  .live-num.bump { animation: bump 380ms var(--ease); }
  @keyframes bump { 30% { transform: translateY(-4px) scale(1.18); } }
  .sk { animation: shimmer 1.2s ease-in-out infinite alternate; }
  @keyframes shimmer { to { background: var(--lemon-2); } }
  .pop:not([hidden]) { animation: popin 180ms var(--ease); }
  @keyframes popin { from { transform: translate(-3px, -6px); opacity: 0; } }
  .drawer[open] { animation: slide 340ms var(--ease); }
  @keyframes slide { from { transform: translateX(40px); opacity: 0; } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------- 14. Narrow screens ---------- */
@media (max-width: 1180px) {
  .topbar { gap: var(--s3); }
  .live-text { display: none; }
  .live::after { content: 'now'; }
}
@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panels { grid-template-columns: minmax(0, 1fr); }
  .goals-body { grid-template-columns: minmax(0, 1fr); }
  .funnel { border-right: 0; border-bottom: var(--line); }
  .state-card { grid-template-columns: minmax(0, 1fr); }
  .state-art { max-width: 260px; }
  .sk-row-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  :root { --sh-lg: 4px 4px 0 var(--ink); }
  .topbar {
    position: relative;
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "logo site live" "range range export";
    gap: var(--s2) var(--s2); padding-top: var(--s2); padding-bottom: var(--s3);
  }
  .logo { grid-area: logo; }
  .logo-word { display: none; }
  .site-switch { grid-area: site; }
  .site-btn { width: 100%; max-width: none; }
  .site-btn .i { margin-left: auto; }
  .live { grid-area: live; padding: 0 10px; }
  .range { grid-area: range; margin: 0; min-width: 0; }
  .seg { width: 100%; }
  .seg-btn { flex: 1 1 auto; padding: 0 8px; font-size: 0.8rem; font-stretch: 100%; }
  .seg-btn .i { display: none; }
  .custom-long { display: none; }
  .custom-short { display: inline; }
  .export-btn { grid-area: export; width: 44px; padding: 0; justify-content: center; }
  .export-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .custom-pop { left: 0; right: auto; width: calc(100vw - 2 * var(--gutter)); }
  .main { padding-top: var(--s4); }
  .dash { gap: var(--s4); }
  .dash-title { font-size: var(--fs-lg); }
  .dash-range { font-size: var(--fs-sm); }
  .filter-hint { font-size: var(--fs-xs); }
  .kpis { gap: var(--s3); }
  .kpi { min-height: 0; padding: var(--s3); gap: 6px; box-shadow: var(--sh); }
  .kpi[aria-pressed="true"] { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
  .kpi-value { font-size: 1.65rem; font-stretch: 95%; }
  .kpi-label { font-size: var(--fs-xs); }
  .kpi-delta { font-size: var(--fs-xs); }
  .kpi-vs { font-size: 0.68rem; }
  .card-head { padding: var(--s3); }
  .legend { gap: var(--s3); font-size: var(--fs-xs); }
  .chart-wrap { margin: var(--s3); margin-top: var(--s5); }
  .tip { min-width: 150px; }

  /* Tables become stacked cards: the header row turns into sort chips */
  .table-host { padding: var(--s3); }
  .tbl, .tbl tbody, .tbl tr, .tbl td { display: block; }
  .tbl thead tr { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--s3); }
  .tbl th { display: block; }
  .tbl th.num { text-align: left; }
  .sort { margin: 0; min-height: 34px; padding: 0 10px; border: var(--bw-thin) solid var(--ink); border-radius: 999px; background: var(--card); }
  [aria-sort="ascending"] .sort, [aria-sort="descending"] .sort { background: var(--ink); color: var(--paper); }
  .tbl tbody { display: grid; gap: var(--s2); }
  .tbl tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 6px 8px 8px; border: var(--bw-thin) solid var(--ink); border-radius: var(--r-sm); background: var(--card); }
  .tbl tbody tr.is-filter { box-shadow: var(--sh-sm); }
  .tbl td, .tbl tbody tr:first-child td { border: 0; padding: 0; }
  .tbl td.name { grid-column: 1 / -1; max-width: none; margin-bottom: 4px; }
  .tbl td.num { width: auto; padding: 0 6px 0 0; text-align: left; font-size: var(--fs-sm); }
  .tbl td.num::before { content: attr(data-label); display: block; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-2); }
  .rowbtn { padding: 0 8px; min-height: 34px; }
  .tbl .none { display: block; }
  .tbl .none td { border: 0; padding: var(--s4) var(--s2); }
  .device-split { margin: var(--s3) var(--s3) 0; }

  .funnel, .goal-list { padding: var(--s4); }
  .goal-list li { grid-template-columns: auto auto minmax(0, 1fr); gap: 4px var(--s3); }
  .goal-label { grid-column: 1 / -1; }
  .goal-n, .goal-cr { text-align: left; }
  .goal-d { justify-self: end; }
  .state-card { padding: var(--s5); gap: var(--s4); margin-top: 0; }
  .state-card.onboard { padding: 0; }
  .onboard-head { padding: var(--s5); }
  .step { padding: var(--s4); }
  .step { grid-template-columns: minmax(0, 1fr); gap: var(--s3); padding: var(--s5); }
  .step-n { width: 44px; height: 44px; font-size: 1.25rem; }
  .snippet pre { padding-right: var(--s4); padding-bottom: 64px; }
  .copy-btn { top: auto; bottom: 10px; }
  .sk-row { grid-template-columns: 1fr 1fr; }
  .sk-chart { height: 260px; }
  .foot { padding-bottom: var(--s6); }
  .toast { bottom: var(--s3); }
}
@media (max-width: 380px) {
  .live-dot { display: none; }
  .seg-btn { font-size: 0.75rem; padding: 0 4px; }
}

/* Lead review fix: at phone width the range control ran past its edge and clipped "Custom".
   Keep the calendar icon and move the word to screen readers only. */
@media (max-width: 430px) {
  .range .seg-btn:has(> .i) > .i { display: block; }
  .range .seg-btn:has(> .i) > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
