/* app.css — Cadence design system.
 * Premium dark analytics aesthetic (Linear/Vercel/Stripe-grade restraint):
 * flat surfaces + hairline borders, ONE accent (aqua), Inter + tabular numerals,
 * strict 8pt spacing, a real type scale. No gradients/glows/heavy shadows.
 */
@font-face {
  font-family: 'Inter';
  src: url('/assets/fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* surface ladder (elevation by lightness, not shadow) */
  --bg: #0a0e12;
  --surface-1: #11161d;
  --surface-2: #1b232c;   /* nudged up so nested tiles separate from --surface-1 */
  --surface-3: #243039;   /* widened the ladder one more step for deeply-nested tiles */
  --border: rgba(255, 255, 255, .07);
  --border-strong: rgba(255, 255, 255, .13);
  /* 1px top-sheen for inset surface depth (theme-tunable; lighter themes lower/darken it) */
  --sheen: rgba(255, 255, 255, .045);

  /* text */
  --txt: #e9eef4;
  --dim: #a9b8c6;
  --dimmer: #8a9fb3;   /* AA: clears >=4.5:1 even on the lightest nested --surface-3 */

  /* the ONE accent + semantic-only colors */
  --acc: #22d3c5;
  --acc-2: #16b3a6;
  --acc-ink: #04201d;
  --pos: #3ddc97;
  --neg: #ff6b9d;
  --warn: #f5c451;

  /* categorical palette — ONLY for multi-series charts, never UI chrome */
  --violet: #8b7bff;
  --amber: #f5b942;
  --rose: #ff6f91;
  --sky: #4ea8ff;
  --slate: #9bb0c3;

  /* spacing (8pt) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s12: 48px;
  --gap: 24px;

  /* radii (role-based, tight) */
  --rad: 12px;
  --rad-sm: 8px;

  /* type scale */
  --fs-over: 11px; --fs-cap: 12px; --fs-label: 13px; --fs-body: 15px;
  --fs-emph: 17px; --fs-h: 20px; --fs-stat: 26px; --fs-hero: 34px; --fs-display: 46px;

  /* one soft shadow, popovers/tooltips only */
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 28px -14px rgba(0, 0, 0, .6);
  --ease: cubic-bezier(.2, .6, .2, 1);
  --dur: .16s;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--txt);
  font: 400 var(--fs-body)/1.5 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums lining-nums;
  font-optical-sizing: auto;
  font-variation-settings: "opsz" 16;   /* text optical size; display tiers raise opsz below */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  padding-bottom: 64px;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }
::selection { background: color-mix(in srgb, var(--acc) 25%, transparent); }
/* designed focus ring: 2px accent + 2px offset + a soft 25%-accent halo */
:focus-visible {
  outline: 2px solid var(--acc); outline-offset: 2px; border-radius: 4px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--acc) 25%, transparent);
}
/* radius-matched focus so the halo hugs each component shape */
.row:focus-visible, .card:focus-visible { border-radius: var(--rad-sm); }
.chip:focus-visible { border-radius: 30px; }
/* round targets get a halo, not a square outline */
.hero .avatar:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--acc); }
input, textarea, [contenteditable] { caret-color: var(--acc); }
:disabled, [disabled], [aria-disabled="true"] { color: var(--dimmer); cursor: not-allowed; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 8px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2c3a49; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 var(--s6); }

/* ---------- top bar + tabs ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(10, 14, 18, .82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .wrap { display: flex; align-items: center; gap: var(--s4); height: 58px; }
.brand { display: flex; align-items: center; gap: var(--s3); font-weight: 700; font-size: var(--fs-emph); letter-spacing: -.01em; white-space: nowrap; }
.brand .logo { width: 24px; height: 24px; flex: none; color: var(--acc); display: flex; align-items: center; justify-content: center; }
.brand .logo svg { display: block; }
.brand .who { color: var(--dim); font-weight: 500; font-size: var(--fs-label); }
.tabs { display: flex; gap: var(--s1); margin-left: auto; overflow-x: auto; scrollbar-width: none; flex: 0 1 auto; min-width: 0; }
.tabs button { flex: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: transparent; border: 0; color: var(--dim); cursor: pointer;
  font-weight: 500; font-size: var(--fs-label); padding: var(--s2) var(--s3); border-radius: var(--rad-sm);
  white-space: nowrap; transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.tabs button:hover { color: var(--txt); background: var(--surface-2); }
.tabs button.on { color: var(--txt); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--acc); }

/* ---------- page sections ---------- */
.page { padding-top: var(--s6); min-height: 62vh; animation: fade .3s var(--ease); }
.page[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-title { font-size: var(--fs-over); text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 600; margin: 0 0 var(--s4); display: flex; align-items: center; gap: var(--s2); }
.page-title .accent { color: var(--acc); }
.page-title .sub { text-transform: none; letter-spacing: 0; color: var(--dim); }

/* ---------- hero ---------- */
.hero { display: flex; align-items: center; gap: var(--s5); padding: var(--s5) 0 var(--s4); flex-wrap: wrap; }
.hero .avatar { width: 84px; height: 84px; border-radius: 50%; border: 1px solid var(--border-strong); object-fit: cover; background: var(--surface-1); }
.hero h1 { font-size: var(--fs-hero); font-weight: 800; letter-spacing: -.022em; font-variation-settings: "opsz" 34; display: flex; align-items: center; gap: var(--s3); }
.hero .sub { color: var(--dim); font-size: var(--fs-label); margin-top: var(--s1); }
.badge { font-size: var(--fs-over); font-weight: 700; letter-spacing: .04em; color: var(--acc); background: color-mix(in srgb, var(--acc) 12%, transparent); border: 1px solid color-mix(in srgb, var(--acc) 25%, transparent); border-radius: 30px; padding: 2px 9px; }
.badge.gold { color: var(--warn); background: rgba(245, 196, 81, .1); border-color: rgba(245, 196, 81, .25); }
.badge.ghost { color: var(--dim); background: transparent; border-color: var(--border-strong); }

/* ---------- stat strip ---------- */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: var(--s4); margin: var(--s2) 0 var(--s6); }
.stat { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--rad); padding: var(--s4); box-shadow: inset 0 1px 0 var(--sheen); }
.stat .n { font-size: var(--fs-stat); font-weight: 700; color: var(--txt); font-variant-numeric: tabular-nums; font-variation-settings: "opsz" 26; letter-spacing: -.015em; font-feature-settings: "tnum" 1, "zero" 1; }
.stat .n.acc { color: var(--acc); }            /* aqua reserved for a single hero metric */
.stat .n.gold, .stat .n.violet, .stat .n.pink, .stat .n.blue, .stat .n.green, .stat .n.orange { color: var(--txt); } /* neutralize old rainbow */
.stat .l { font-size: var(--fs-cap); color: var(--dim); margin-top: var(--s1); }
.stat .hint { font-size: var(--fs-cap); color: var(--dimmer); margin-top: 2px; }

/* ---------- grid ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.grid.cols-1 { grid-template-columns: 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.auto { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 900px) { .grid, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } .span-2 { grid-column: auto; } }

/* ---------- panels ---------- */
.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--rad); padding: var(--s5); min-width: 0; box-shadow: inset 0 1px 0 var(--sheen); }
.panel.glow { border-color: color-mix(in srgb, var(--acc) 30%, transparent); }
.panel-head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s4); }
.panel h2 { font-size: var(--fs-label); font-weight: 600; color: var(--dim); display: flex; align-items: center; gap: var(--s2); }
.panel h2 .dot { width: 6px; height: 6px; border-radius: 2px; background: var(--dimmer); flex: none; }
.panel.glow h2 .dot { background: var(--acc); }
.panel .sub { font-size: var(--fs-cap); color: var(--dimmer); margin: calc(-1 * var(--s3)) 0 var(--s4); }
.panel .stat { background: var(--surface-2); }   /* nested tiles read as cards on the panel surface */
.panel-head .right { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }

/* ---------- list rows ---------- */
.row { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--rad-sm); transition: background var(--dur) var(--ease); }
.row:hover { background: var(--surface-2); }
.row .pos { width: 22px; text-align: center; font-weight: 600; color: var(--dimmer); font-size: var(--fs-cap); flex: none; font-variant-numeric: tabular-nums; }
.row .pos.top { color: var(--txt); }
.row .art { width: 44px; height: 44px; border-radius: var(--rad-sm); object-fit: cover; flex: none; background: var(--surface-2); }
.row .art.circ { border-radius: 50%; }
.row .meta { min-width: 0; flex: 1; }
.row .meta .t { font-weight: 600; font-size: var(--fs-body); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta .s { font-size: var(--fs-cap); color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .val { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.row .val .p { font-weight: 600; color: var(--txt); font-size: var(--fs-body); }
.row .val .h { font-size: var(--fs-cap); color: var(--dimmer); }

/* ---------- segmented control / chips ---------- */
.seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--rad-sm); padding: 3px; }
.seg button { background: transparent; border: 0; color: var(--dim); cursor: pointer; font-weight: 500; font-size: var(--fs-cap); padding: 5px 12px; border-radius: 6px; transition: var(--dur) var(--ease); white-space: nowrap; }
.seg button:hover { color: var(--txt); }
.seg button.on { background: var(--acc); color: var(--acc-ink); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: var(--s1); background: var(--surface-2); border: 1px solid var(--border); color: var(--dim); border-radius: 30px; padding: 5px 12px; font-size: var(--fs-cap); font-weight: 500; cursor: pointer; transition: var(--dur) var(--ease); }
.chip:hover { color: var(--txt); border-color: var(--border-strong); }
.chip.on { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); font-weight: 600; }
.tag { display: inline-block; background: var(--surface-2); color: var(--dim); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-size: var(--fs-cap); font-weight: 500; }

/* ---------- big metric ---------- */
.metric { padding: var(--s2) 0; }
.metric .big { font-size: var(--fs-hero); font-weight: 800; letter-spacing: -.022em; line-height: 1.05; color: var(--txt); font-variant-numeric: tabular-nums; font-variation-settings: "opsz" 34; font-feature-settings: "tnum" 1, "zero" 1; }
.metric .big.acc { color: var(--acc); }
.metric .big.gold, .metric .big.violet { color: var(--txt); }
.metric .lab { font-size: var(--fs-cap); color: var(--dim); margin-top: var(--s2); }
.metric .note { font-size: var(--fs-cap); color: var(--dimmer); margin-top: var(--s1); }

/* ---------- score / spectrum meters ---------- */
.scorebar { margin: var(--s3) 0; }
.scorebar .top { display: flex; justify-content: space-between; font-size: var(--fs-label); margin-bottom: var(--s1); }
.scorebar .top .lab { font-weight: 500; }
.scorebar .top .v { color: var(--dim); font-size: var(--fs-cap); font-variant-numeric: tabular-nums; }
.scorebar .track { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.scorebar .fill { height: 100%; background: var(--acc); border-radius: 4px; transition: width .5s var(--ease); }
.spectrum { margin: var(--s4) 0; }
.spectrum .ends { display: flex; justify-content: space-between; font-size: var(--fs-cap); color: var(--dim); margin-bottom: var(--s1); }
.spectrum .bar { position: relative; height: 6px; border-radius: 4px; background: var(--surface-2); }
.spectrum .marker { position: absolute; top: -5px; width: 3px; height: 16px; border-radius: 2px; background: var(--acc); transform: translateX(-50%); transition: left .5s var(--ease); }

/* ---------- callouts / cards ---------- */
.callout { display: flex; gap: var(--s3); align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--rad-sm); padding: var(--s3) var(--s4); }
.callout .ic { flex: none; color: var(--acc); display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: var(--rad-sm); background: color-mix(in srgb, var(--acc) 10%, transparent); }
.callout .art { width: 52px; height: 52px; border-radius: var(--rad-sm); object-fit: cover; flex: none; background: var(--surface-1); }
.callout .art.circ { border-radius: 50%; }
.callout .body { min-width: 0; }
.callout .body .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.callout .body .s { color: var(--dim); font-size: var(--fs-label); margin-top: 2px; }
.ic-svg { display: block; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: var(--s4); }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--rad-sm); padding: var(--s4); box-shadow: inset 0 1px 0 var(--sheen); }
.card .art { width: 100%; aspect-ratio: 1; border-radius: var(--rad-sm); object-fit: cover; background: var(--surface-1); margin-bottom: var(--s3); }
.card .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .s { color: var(--dim); font-size: var(--fs-cap); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- charts ---------- */
.chart { width: 100%; }
.chart.h-sm { height: 200px; }
.chart.h-md { height: 300px; }
.chart.h-lg { height: 380px; }
.chart.square { aspect-ratio: 1 / 1; max-width: 360px; margin: 0 auto; }
.chart-svg { display: block; overflow: visible; }
.c-axis { fill: var(--dimmer); font-size: 11px; font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1, "zero" 1; }
.c-lab { fill: var(--dim); font-size: 12px; }
.c-val { fill: var(--txt); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1, "zero" 1; }
.c-center-top { fill: var(--txt); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; font-variation-settings: "opsz" 26; letter-spacing: -.015em; font-feature-settings: "tnum" 1, "zero" 1; }
.c-center-sub { fill: var(--dim); font-size: 11px; }
.c-quad { fill: var(--dimmer); font-size: 11px; }
.c-hit { cursor: pointer; }
.chart-tip { position: fixed; z-index: 999; pointer-events: none; opacity: 0; transition: opacity .1s; background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--rad-sm); padding: var(--s2) var(--s3); font-size: var(--fs-cap); line-height: 1.45; color: var(--txt); box-shadow: var(--shadow); max-width: 240px; font-variant-numeric: tabular-nums; }
.chart-tip b { color: var(--acc); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); margin-top: var(--s3); justify-content: center; }
.legend .it { display: flex; align-items: center; gap: var(--s1); font-size: var(--fs-cap); color: var(--dim); }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- search ---------- */
.searchbar { position: relative; margin-bottom: var(--s5); }
.search-input { width: 100%; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--rad); color: var(--txt); font: inherit; font-size: var(--fs-emph); padding: var(--s4) var(--s5) var(--s4) 48px; transition: border var(--dur) var(--ease); }
.search-input:focus { border-color: var(--acc); } .search-input:focus:not(:focus-visible) { outline: none; }
.search-input::placeholder { color: var(--dimmer); }
.searchbar .search-ic { position: absolute; left: var(--s4); top: 50%; transform: translateY(-50%); color: var(--dimmer); display: flex; }
.searchbar .search-clear { position: absolute; right: var(--s4); top: 50%; transform: translateY(-50%); color: var(--dimmer); background: none; border: 0; cursor: pointer; display: flex; }
.searchbar .search-clear:hover { color: var(--txt); }
.results .result-group + .result-group { margin-top: var(--s5); }
.result-group h3 { font-size: var(--fs-over); text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 600; margin-bottom: var(--s2); }

/* ---------- share button + export modal ---------- */
.share-btn { display: inline-flex; align-items: center; gap: var(--s1); background: var(--surface-2); border: 1px solid var(--border); color: var(--dim); border-radius: var(--rad-sm); padding: 6px 12px; font-size: var(--fs-cap); font-weight: 500; cursor: pointer; transition: var(--dur) var(--ease); }
.share-btn:hover { color: var(--txt); border-color: var(--border-strong); }
.modal-overlay { position: fixed; inset: 0; z-index: 200; background: rgba(5, 8, 11, .75); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: var(--s6); animation: fade .2s var(--ease); }
.modal { background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--rad); padding: var(--s5); max-width: min(92vw, 460px); box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; margin-bottom: var(--s4); }
.modal-head h3 { font-size: var(--fs-emph); font-weight: 700; }
.modal-head .x { margin-left: auto; background: none; border: 0; color: var(--dim); cursor: pointer; display: flex; }
.modal-head .x:hover { color: var(--txt); }
.modal img.preview { width: 100%; border-radius: var(--rad-sm); display: block; border: 1px solid var(--border); }
.modal .actions { display: flex; gap: var(--s2); margin-top: var(--s4); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s1); border-radius: var(--rad-sm); padding: var(--s3) var(--s4); font-weight: 600; font-size: var(--fs-label); cursor: pointer; border: 1px solid var(--border); background: var(--surface-2); color: var(--txt); transition: var(--dur) var(--ease); }
.btn:hover { border-color: var(--border-strong); }
.btn.primary { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.btn.primary:hover { background: var(--acc-2); }
.export-stage { position: fixed; left: -9999px; top: 0; }

/* ---------- taste identity (aura / archetype) ---------- */
.archetype { display: flex; align-items: center; gap: var(--s4); }
.aura { width: 64px; height: 64px; border-radius: 50%; flex: none; box-shadow: 0 0 24px -6px var(--acc); }
.archetype .name { font-size: var(--fs-h); font-weight: 800; letter-spacing: -.01em; }
.archetype .desc { color: var(--dim); font-size: var(--fs-label); margin-top: 2px; }

/* ---------- Aura: album-art colour identity (window.Aura, color-engine.js) ----------
   A recurring visual signature — a soft colour glow pulled from the cover art on
   screen, threaded behind detail-modal headers, Wrapped heroes and card art.
   --aura-a / --aura-b are painted per-element by color-engine.js and default to
   transparent, so an un-tagged element is byte-identical to before. These are
   STATIC gradients: no element's visibility is gated on an animation, so the
   whole system renders correctly under prefers-reduced-motion (only the fade of
   the colour swap-in is a transition, and the content shows regardless). */
.has-aura { --aura-a: transparent; --aura-b: transparent; }

/* detail-modal header becomes a self-contained aura card (no layout bleed) */
.detail-hero.has-aura {
  padding: var(--s4);
  border-radius: var(--rad);
  border: 1px solid var(--border);
  background:
    radial-gradient(74% 120% at 6% -12%, var(--aura-a), transparent 66%),
    radial-gradient(64% 120% at 103% 6%, var(--aura-b), transparent 70%),
    var(--surface-2);
  transition: background .45s var(--ease);
}

/* reusable aura backdrop for big-number heroes (Wrapped, cards) */
.aura-hero { position: relative; isolation: isolate; }
.aura-hero.has-aura::before {
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background:
    radial-gradient(58% 92% at 16% 8%, var(--aura-a), transparent 60%),
    radial-gradient(52% 84% at 94% 92%, var(--aura-b), transparent 64%);
  transition: opacity .45s var(--ease);
  pointer-events: none;
}
/* a strip of aura swatches (detail modal / personality panel) */
.aura-swatches { display: flex; gap: var(--s1); margin-top: var(--s3); }
.aura-swatches i { width: 26px; height: 26px; border-radius: 6px; flex: none; border: 1px solid var(--border); box-shadow: inset 0 1px 0 var(--sheen); }

/* ---------- states ---------- */
.loading, .empty { color: var(--dim); padding: var(--s6) var(--s2); font-size: var(--fs-label); text-align: center; }
.skel { background: var(--surface-2); border-radius: var(--rad-sm); position: relative; overflow: hidden; }
.skel::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .04), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border-strong); border-top-color: var(--acc); border-right-color: var(--acc); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

footer { color: var(--dimmer); font-size: var(--fs-cap); text-align: center; margin-top: var(--s12); padding-top: var(--s5); border-top: 1px solid var(--border); }
footer a { color: var(--dim); }
footer a:hover { color: var(--txt); }

/* ---------- motion: hover + scroll reveal ---------- */
.stat, .card, .callout { transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease); }
.stat:hover, .card:hover, .callout:hover { transform: translateY(-2px); border-color: var(--border-strong); background: var(--surface-2); }
.panel { transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease); }
.panel:hover { border-color: var(--border-strong); }
.chip, .btn, .share-btn { transition: transform var(--dur) var(--ease), color var(--dur) var(--ease), background var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.chip:hover, .btn:hover, .share-btn:hover { transform: translateY(-1px); }
/* press microstates — tiny, so they compose with fx.js hover transforms */
.btn:active, .tabs button:active, .seg button:active, .share-btn:active { transform: translateY(.5px); }
.stat:active, .card:active, .chip:active { transform: scale(.985); }
.row .art, .card .art, .callout .art { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
/* subtle hover + bounce on clickable thumbnails (user-requested) */
@keyframes thumbBounce { 0% { transform: translateY(0) scale(1); } 35% { transform: translateY(-5px) scale(1.07); } 65% { transform: translateY(0) scale(1.03); } 100% { transform: translateY(-2px) scale(1.05); } }
.row:hover .art, .card:hover .art, .callout:hover .art { animation: thumbBounce .5s var(--ease) forwards; box-shadow: 0 8px 20px -8px rgba(0, 0, 0, .6); }
[data-detail] { cursor: pointer; }
.hero .avatar { transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.hero .avatar:hover { transform: scale(1.04); border-color: var(--acc); }

/* scroll-reveal (JS adds .reveal then .in) */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .5s var(--ease), transform .5s var(--ease); transition-delay: var(--reveal-delay, 0ms); }
.reveal.in { opacity: 1; transform: none; }

/* sticky-header shadow + scroll progress */
.topbar { transition: box-shadow var(--dur) var(--ease); }
.topbar.scrolled { box-shadow: 0 1px 0 var(--border), 0 8px 22px -14px rgba(0, 0, 0, .8); }
.scroll-progress { position: fixed; top: 0; left: 0; height: 2px; width: 0; background: var(--acc); z-index: 60; pointer-events: none; transition: width .08s linear; }

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1 !important; transform: none !important; }
  .stat:hover, .card:hover, .callout:hover, .chip:hover, .btn:hover, .share-btn:hover,
  .hero .avatar:hover, .panel:hover,
  .btn:active, .tabs button:active, .seg button:active, .share-btn:active,
  .stat:active, .card:active, .chip:active { transform: none !important; }
  /* keep functional + explicitly-requested motion alive even under reduced-motion */
  .spinner { animation: spin .7s linear infinite !important; }
}

/* utility */
.muted { color: var(--dim); }
.right { margin-left: auto; }
.flex { display: flex; align-items: center; gap: var(--s3); }
.wrap-flex { display: flex; flex-wrap: wrap; gap: var(--s2); }
.mt { margin-top: var(--s4); }
.center { text-align: center; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- song / artist detail modal ---------- */
.modal.detail { max-width: min(95vw, 780px); width: 780px; max-height: 88vh; overflow-y: auto; padding: var(--s5) var(--s5) var(--s6); }
.detail-hero { display: flex; gap: var(--s4); align-items: center; }
.detail-hero .cover { width: 104px; height: 104px; border-radius: var(--rad-sm); object-fit: cover; flex: none; border: 1px solid var(--border); background: var(--surface-2); }
.detail-hero .cover.circ { border-radius: 50%; }
.detail-hero .who { min-width: 0; flex: 1; }
.detail-hero .kicker { font-size: var(--fs-over); text-transform: uppercase; letter-spacing: .08em; color: var(--acc); font-weight: 600; }
.detail-hero .ttl { font-size: var(--fs-h); font-weight: 800; letter-spacing: -.01em; line-height: 1.12; margin-top: 2px; }
.detail-hero .by { color: var(--dim); margin-top: 3px; }
.detail-hero .tags { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s2); }
.detail-sec-title { font-size: var(--fs-over); text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 600; margin: var(--s5) 0 var(--s3); display: flex; align-items: center; gap: var(--s2); }
.detail-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(116px, 1fr)); gap: var(--s3); }
.fact { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--rad-sm); padding: var(--s3) var(--s4); }
.fact .n { font-size: var(--fs-emph); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; font-variation-settings: "opsz" 26; letter-spacing: -.015em; font-feature-settings: "tnum" 1, "zero" 1; }
.fact .n.acc { color: var(--acc); }
.fact .l { font-size: var(--fs-cap); color: var(--dim); margin-top: 3px; }
.detail-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); align-items: start; }
@media (max-width: 660px) { .detail-grid2 { grid-template-columns: 1fr; } .modal.detail { width: auto; } .detail-hero { flex-direction: column; text-align: center; } }
.meta-row { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-label); }
.meta-row:last-child { border-bottom: 0; }
.meta-row .k { color: var(--dim); }
.meta-row .v { color: var(--txt); text-align: right; font-variant-numeric: tabular-nums; }
.pop-badge { display: inline-flex; align-items: baseline; gap: 6px; }
.pop-badge .num { font-size: var(--fs-h); font-weight: 800; color: var(--acc); font-variant-numeric: tabular-nums; font-variation-settings: "opsz" 26; letter-spacing: -.015em; font-feature-settings: "tnum" 1, "zero" 1; }
.pop-badge .den { color: var(--dim); font-size: var(--fs-cap); }
.detail-chart { width: 100%; }
.detail-actions { display: flex; gap: var(--s2); margin-top: var(--s5); flex-wrap: wrap; }
.detail-actions .right { margin-left: auto; }

/* hide affordance on list rows */
.row { position: relative; }
.row-hide { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); opacity: 0; background: var(--surface-2); border: 1px solid var(--border); color: var(--dim); border-radius: var(--rad-sm); padding: 4px 6px; cursor: pointer; display: inline-flex; align-items: center; transition: opacity var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease); z-index: 3; }
.row:hover .row-hide, .row-hide:focus-visible { opacity: 1; }
.row-hide:hover { color: #ff6f91; border-color: var(--border-strong); }

/* profile / hidden songs */
.hidden-empty { color: var(--dim); padding: var(--s5) var(--s2); text-align: center; }
.unhide-btn { margin-left: auto; }

/* x-axis zoom control for time-series charts */
.chart-zoom { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s3); color: var(--dim); font-size: var(--fs-cap); }
.chart-zoom input[type=range] { accent-color: var(--acc); height: 3px; cursor: pointer; }
.chart-zoom .rng { font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 0; }
.chart-zoom .seg { margin-left: auto; }
.chart-zoom .reset { background: none; border: 0; color: var(--acc); cursor: pointer; font-size: var(--fs-cap); padding: 0; }

/* ---------- themes (set data-theme on <html>; absent = default "aqua") ---------- */
html { transition: background-color .25s var(--ease); }
[data-theme="midnight"] {
  --bg: #080b16; --surface-1: #0f1424; --surface-2: #171d33; --surface-3: #202844;
  --border: rgba(255,255,255,.07); --border-strong: rgba(255,255,255,.14);
  --acc: #6ea8ff; --acc-2: #4f8be8; --acc-ink: #06122b;
}
[data-theme="sunset"] {
  --bg: #150d0c; --surface-1: #1e1413; --surface-2: #2b1d1a; --surface-3: #392623;
  --acc: #ff8a5b; --acc-2: #f0673a; --acc-ink: #2a0d05; --warn: #ffce6b;
}
[data-theme="grape"] {
  --bg: #100c1a; --surface-1: #181226; --surface-2: #221a36; --surface-3: #2e2447;
  --acc: #b388ff; --acc-2: #9a6cf0; --acc-ink: #1a0d33;
}
[data-theme="mono"] {
  --bg: #0c0d0f; --surface-1: #15171a; --surface-2: #1f2226; --surface-3: #2a2e33;
  --acc: #e6ebf2; --acc-2: #c3ccd6; --acc-ink: #15171a;
}
[data-theme="light"] {
  --bg: #f3f6fa; --surface-1: #ffffff; --surface-2: #eef2f7; --surface-3: #e3e9f0;
  --border: rgba(12,22,32,.10); --border-strong: rgba(12,22,32,.18);
  /* darker accent + dim so text on the light surfaces meets WCAG AA (~4.5:1) */
  --txt: #0e1820; --dim: #3e4f60; --dimmer: #586979;
  --acc: #0a7a70; --acc-2: #086158; --acc-ink: #ffffff;
  /* darker pos/neg so YoY deltas (wrapped) meet WCAG AA (~4.5:1) on the light bg */
  --pos: #0a7d52; --neg: #c11d54;
  /* a white top-sheen is invisible on light surfaces — use a faint dark top hairline instead */
  --sheen: rgba(12, 22, 32, .05);
  --shadow: 0 1px 2px rgba(20,30,40,.08), 0 12px 28px -16px rgba(20,30,40,.22);
}
/* the topbar is hardcoded dark elsewhere; in the light theme make it light too so
   the (darkened-for-AA) nav labels stay readable on it */
[data-theme="light"] .topbar { background: rgba(243, 246, 250, .85); }

/* user-chosen custom accent overrides the theme accent when set */
html[style*="--acc"] { }

/* ======================================================================
   CUSTOMIZATION SUBSTRATE  (density · font scale · contrast · hit targets)
   All gated by data-* attrs / vars on <html>. With no attrs set and
   --scale=1 every value below computes to today's design — byte-identical.
   ====================================================================== */

/* ---- (2) Font scale ------------------------------------------------------
   Single source of truth: base px sizes, then --fs-* = base × --scale.
   This :root comes AFTER the original :root, so (equal specificity) it wins
   and rebinds the type scale through calc(). --scale defaults to 1, so the
   computed sizes are unchanged. JS sets --scale on <html> (Prefs 'fontScale',
   clamped ~0.85..1.3); density (below) re-points the *-b base vars, so the
   two controls multiply cleanly (density base × user scale). */
:root {
  --scale: 1;
  --fs-over-b: 11px; --fs-cap-b: 12px; --fs-label-b: 13px; --fs-body-b: 15px;
  --fs-emph-b: 17px; --fs-h-b: 20px; --fs-stat-b: 26px; --fs-hero-b: 34px; --fs-display-b: 46px;

  --fs-over:    calc(var(--fs-over-b)    * var(--scale, 1));
  --fs-cap:     calc(var(--fs-cap-b)     * var(--scale, 1));
  --fs-label:   calc(var(--fs-label-b)   * var(--scale, 1));
  --fs-body:    calc(var(--fs-body-b)    * var(--scale, 1));
  --fs-emph:    calc(var(--fs-emph-b)    * var(--scale, 1));
  --fs-h:       calc(var(--fs-h-b)       * var(--scale, 1));
  --fs-stat:    calc(var(--fs-stat-b)    * var(--scale, 1));
  --fs-hero:    calc(var(--fs-hero-b)    * var(--scale, 1));
  --fs-display: calc(var(--fs-display-b) * var(--scale, 1));
}

/* ---- (1) Density: compact -----------------------------------------------
   <html data-density="compact">. Tighten the 8pt spacing scale (~25-30%) and
   re-point the font base vars (~8-12% smaller) so more fits on screen.
   Placed after the :root font-scale block → wins by source order; because it
   only moves the *-b base vars, the --fs-* calc() still applies --scale on
   top, so compact + larger font compose. Comfortable (no attr) = unchanged. */
[data-density="compact"] {
  /* spacing — only the larger steps shrink; --s1/--s2/--s3 keep fine detail */
  --s4: 12px; --s5: 14px; --s6: 17px; --s8: 24px; --s12: 36px;
  --gap: 17px;
  /* slightly smaller type */
  --fs-over-b: 10px; --fs-cap-b: 11px; --fs-label-b: 12px; --fs-body-b: 14px;
  --fs-emph-b: 15px; --fs-h-b: 18px; --fs-stat-b: 22px; --fs-hero-b: 29px; --fs-display-b: 39px;
}
/* compact: tighten panel/stat padding, row padding + row height */
[data-density="compact"] .panel { padding: var(--s4); }
[data-density="compact"] .stat,
[data-density="compact"] .card,
[data-density="compact"] .callout { padding: var(--s3); }
[data-density="compact"] .row { padding: var(--s1) var(--s2); gap: var(--s2); }
[data-density="compact"] .row .art { width: 36px; height: 36px; }   /* shorter rows */
[data-density="compact"] .topbar .wrap { height: 50px; }
[data-density="compact"] .panel-head { margin-bottom: var(--s3); }
[data-density="compact"] .strip { gap: var(--s3); }

/* ---- (3) High-contrast theme --------------------------------------------
   <html data-theme="contrast">. Mirrors the structure of the theme blocks
   above. Near-black surfaces, pure-white text, borders bumped to rgba .3+,
   a bright high-contrast accent. Body/dim text clears WCAG AA (>=4.5:1)
   on the near-black bg (#e6e6e6 ≈ 18:1, #c4c4c4 ≈ 12:1). */
[data-theme="contrast"] {
  --bg: #000000; --surface-1: #0a0a0a; --surface-2: #161616; --surface-3: #232323;
  --border: rgba(255,255,255,.32); --border-strong: rgba(255,255,255,.55);
  --txt: #ffffff; --dim: #e6e6e6; --dimmer: #c4c4c4;
  --acc: #2ce6d6; --acc-2: #19c2b4; --acc-ink: #00100e;
  --pos: #5cffb0; --neg: #ff90b5; --warn: #ffd75e;
  --shadow: 0 1px 2px rgba(0,0,0,.6), 0 12px 28px -14px rgba(0,0,0,.85);
}

/* ---- (4) Large hit targets -----------------------------------------------
   <html data-hit="large">. Bring interactive targets to >=44px (WCAG 2.5.5).
   Buttons get min-height + vertical padding and center their label; small
   icon affordances get a 44x44 square. The hover-only row hide button is
   also surfaced at a higher resting opacity so it's reachable without hover. */
[data-hit="large"] .tabs button {
  min-height: 44px; display: inline-flex; align-items: center;
  padding-top: var(--s2); padding-bottom: var(--s2);
}
[data-hit="large"] .seg button {
  min-height: 44px; display: inline-flex; align-items: center;
  padding-top: var(--s1); padding-bottom: var(--s1);
}
[data-hit="large"] .btn,
[data-hit="large"] .chip,
[data-hit="large"] .share-btn {
  min-height: 44px; display: inline-flex; align-items: center;
}
[data-hit="large"] .row-hide {
  min-width: 44px; min-height: 44px; justify-content: center;
  opacity: .5;                         /* reveal at rest, not just on hover */
}
[data-hit="large"] .row:hover .row-hide,
[data-hit="large"] .row-hide:focus-visible { opacity: 1; }
[data-hit="large"] .modal-head .x,
[data-hit="large"] .searchbar .search-clear {
  min-width: 44px; min-height: 44px; justify-content: center;
}
/* fatter, easier-to-grab range thumbs + taller track hit area */
[data-hit="large"] input[type=range] { height: 22px; }
[data-hit="large"] input[type=range]::-webkit-slider-thumb { width: 22px; height: 22px; }
[data-hit="large"] input[type=range]::-moz-range-thumb { width: 22px; height: 22px; border: 0; }

/* ---- (5) Rangebar handle focus ring --------------------------------------
   The scrubber handles (rangebar.js, role="slider") sit inside
   .rb-track{overflow:hidden}, which clips the global :focus-visible outline.
   Draw the keyboard-focus ring INSIDE the clip — on the handle's knob (::after) —
   so it stays visible instead of being cut off by the track's overflow. */
.rb-handle:focus-visible { outline: none; }
.rb-handle:focus-visible::after {
  height: 42px;                                          /* echo the :hover lift */
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--acc), 0 2px 6px rgba(0, 0, 0, .4);
}
