/* RunWithBeats design system
   Colour, type, spacing and radius tokens live in :root. Components below
   only use tokens, so a re-skin (or a native app theme) changes one block. */
:root {
  /* colour */
  --bg: #09090b;
  --surface: #131318;
  --surface-2: #1c1c23;
  --surface-3: #26262f;
  --border: #2c2c36;
  --text: #f6f6f8;
  --muted: #a5a5b3;
  --primary: #d9ff43;        /* volt */
  --primary-ink: #0d0f04;
  --secondary: #ff5c8a;      /* pulse */
  --danger: #ff7b72;
  --ok: #6ee7a8;

  /* type scale */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.75rem;
  --fs-2xl: clamp(2.5rem, 9vw, 5rem);

  /* spacing (4px base) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;

  /* radius */
  --r-sm: 8px; --r-md: 14px; --r-lg: 22px; --r-full: 999px;

  --page: 1040px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-md)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
body::before { /* soft glow behind the hero */
  content: ""; position: fixed; inset: -20% -10% auto; height: 70vh; z-index: -1; pointer-events: none;
  background:
    radial-gradient(40% 50% at 20% 30%, rgba(217, 255, 67, .10), transparent 70%),
    radial-gradient(35% 45% at 85% 20%, rgba(255, 92, 138, .10), transparent 70%);
}
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; border-radius: 4px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link {
  position: absolute; left: var(--s4); top: -60px; background: var(--primary); color: var(--primary-ink);
  padding: var(--s2) var(--s4); border-radius: var(--r-sm); font-weight: 700; z-index: 50;
}
.skip-link:focus { top: var(--s3); }

/* ---- header / footer -------------------------------------------------- */
.site-header {
  max-width: var(--page); margin: 0 auto; padding: var(--s4);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
}
.logo { display: inline-flex; align-items: center; gap: var(--s2); text-decoration: none; }
.logo-mark { width: 26px; height: 26px; fill: var(--primary); }
.logo-text { font-weight: 800; font-size: 1.2rem; letter-spacing: -.04em; }
.logo-thin { font-weight: 300; color: var(--muted); }
.site-header nav { display: flex; gap: var(--s4); }
.site-header nav a {
  color: var(--muted); text-decoration: none; font-size: var(--fs-sm); font-weight: 600; padding: var(--s2) 0;
}
.site-header nav a:hover { color: var(--text); }
.site-footer {
  max-width: var(--page); margin: var(--s8) auto 0; padding: var(--s6) var(--s4) 140px;
  border-top: 1px solid var(--border); color: var(--muted); font-size: var(--fs-sm);
  display: grid; gap: var(--s2);
}

/* ---- buttons ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s5); border-radius: var(--r-full); border: 1px solid transparent;
  font-weight: 700; font-size: var(--fs-sm); text-decoration: none; white-space: nowrap;
  transition: transform .15s var(--ease), background .15s, border-color .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #e6ff7a; }
.btn-secondary { background: var(--text); color: var(--bg); }
.btn-secondary:hover { background: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-lg { min-height: 56px; font-size: var(--fs-md); width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.link-btn {
  background: none; border: 0; padding: var(--s2); color: var(--muted); font-size: var(--fs-sm); font-weight: 600;
  text-decoration: underline; text-underline-offset: 3px; min-height: 36px;
}
.link-btn:hover { color: var(--text); }

.chip {
  display: inline-flex; align-items: baseline; gap: var(--s2); min-height: 40px; padding: 0 var(--s4);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-full);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; transition: border-color .15s, background .15s;
}
.chip small { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip[aria-pressed="true"] small { color: rgba(13, 15, 4, .7); }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-full); padding: 3px; }
.segmented button {
  border: 0; background: transparent; min-height: 36px; padding: 0 var(--s4); border-radius: var(--r-full);
  font-size: var(--fs-sm); font-weight: 600; color: var(--muted);
}
.segmented button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }

/* ---- hero + BPM selector --------------------------------------------- */
.hero {
  max-width: var(--page); margin: 0 auto; padding: var(--s6) var(--s4) var(--s7);
  display: grid; gap: var(--s6); transition: padding .3s var(--ease);
}
.hero h1 { font-size: var(--fs-2xl); line-height: .95; letter-spacing: -.05em; font-weight: 800; }
.hero > *, .bpm-card > * { min-width: 0; }
.accent { color: var(--primary); }
.lede { color: var(--muted); font-size: var(--fs-lg); max-width: 34ch; margin-top: var(--s4); }
.eyebrow { color: var(--secondary); font-size: var(--fs-xs); font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }

.bpm-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--s5); display: grid; gap: var(--s5);
}
.bpm-readout { display: flex; align-items: baseline; gap: var(--s2); white-space: nowrap; }
.bpm-field input {
  width: 3.2ch; box-sizing: content-box; background: transparent; border: 0; border-bottom: 2px solid var(--border);
  font-size: clamp(2.5rem, 13vw, 4rem); font-weight: 800; letter-spacing: -.04em; line-height: 1;
  font-variant-numeric: tabular-nums; text-align: center; padding: 0 2px 4px; border-radius: 0;
  -moz-appearance: textfield; appearance: textfield;
}
.bpm-field input::-webkit-outer-spin-button, .bpm-field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.bpm-field input:hover { border-bottom-color: var(--muted); }
.bpm-field input:focus-visible { outline: none; border-bottom-color: var(--primary); }
.bpm-dash { font-size: 2.5rem; color: var(--muted); font-weight: 300; }
.bpm-unit { color: var(--muted); font-weight: 700; letter-spacing: .1em; font-size: var(--fs-sm); }
.pulse {
  width: 14px; height: 14px; border-radius: 50%; background: var(--secondary); align-self: center; margin-right: var(--s2);
  --beat: .34s; animation: beat var(--beat) var(--ease) infinite alternate;
}
@keyframes beat {
  from { transform: scale(.7); box-shadow: 0 0 0 0 rgba(255, 92, 138, .55); }
  to { transform: scale(1.15); box-shadow: 0 0 0 10px rgba(255, 92, 138, 0); }
}

/* BPM scale: a window onto 60-220 that widens and narrows (see js/scale.js) */
.range { position: relative; height: 68px; padding: 0 18px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.rail { position: relative; height: 100%; cursor: pointer; }
.rail-track { position: absolute; left: 0; right: 0; top: 15px; height: 6px; border-radius: var(--r-full); background: var(--surface-3); }
.rail-fill { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--primary); border-radius: var(--r-full); }
.rail-ticks { position: absolute; left: 0; right: 0; top: 34px; height: 30px; pointer-events: none; }
.tick { position: absolute; top: 0; width: 1px; height: 6px; margin-left: -.5px; background: var(--border); opacity: 0; transition: opacity .25s; }
.tick.on { opacity: 1; }
.tick.major { height: 9px; background: var(--muted); }
.tick span {
  position: absolute; top: 13px; left: 50%; transform: translateX(-50%); opacity: 0; transition: opacity .25s;
  color: var(--muted); font-size: var(--fs-xs); font-variant-numeric: tabular-nums;
}
.tick.major span { opacity: 1; }
.thumb {
  position: absolute; top: 18px; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%;
  background: var(--text); border: 4px solid var(--bg); box-shadow: 0 0 0 2px var(--primary); cursor: grab;
  touch-action: pan-y; transition: scale .15s var(--ease), translate .2s var(--ease), box-shadow .15s;
}
.thumb::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; } /* roomier touch target */
.thumb:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--primary); }
.thumb[data-active] { scale: 1.15; cursor: grabbing; }
.range.together .thumb[data-which="min"] { translate: -9px 0; }
.range.together .thumb[data-which="max"] { translate: 9px 0; }
.edge {
  position: absolute; top: 4px; width: 18px; height: 28px; display: grid; place-items: center; z-index: 2;
  color: var(--primary); font-size: 22px; line-height: 1; opacity: 0; transition: opacity .3s; pointer-events: none;
}
.edge-l { left: 0; } .edge-r { right: 0; }
.range.can-left .edge-l, .range.can-right .edge-r { opacity: .95; }
.range.can-left .edge-l { animation: nudge-l 1.8s var(--ease) infinite; }
.range.can-right .edge-r { animation: nudge-r 1.8s var(--ease) infinite; }
@keyframes nudge-l { 50% { transform: translateX(-3px); } }
@keyframes nudge-r { 50% { transform: translateX(3px); } }
.fade { position: absolute; top: 30px; height: 36px; width: 44px; pointer-events: none; opacity: 0; transition: opacity .3s; }
.fade-l { left: 0; background: linear-gradient(90deg, var(--surface), transparent); }
.fade-r { right: 0; background: linear-gradient(270deg, var(--surface), transparent); }
.range.can-left .fade-l, .range.can-right .fade-r { opacity: 1; }
.presets { display: flex; gap: var(--s2); overflow-x: auto; margin: 0 calc(-1 * var(--s5)); padding: 2px var(--s5); scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
.hint { color: var(--muted); font-size: var(--fs-xs); text-align: center; }

/* compact hero once results are showing */
body.has-results .hero { padding-top: var(--s2); padding-bottom: var(--s5); gap: var(--s4); }
body.has-results .hero-copy, body.has-results .hint { display: none; }
body.has-results .bpm-field input { font-size: clamp(2rem, 8vw, 2.75rem); }
body.has-results .bpm-card { gap: var(--s4); padding: var(--s4) var(--s5); }
body.has-results .btn-lg { min-height: 48px; }

/* ---- results ---------------------------------------------------------- */
.results, .sessions { max-width: var(--page); margin: 0 auto; padding: var(--s5) var(--s4); }
.results-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s4); }
.results h2, .sessions h2 { font-size: var(--fs-xl); letter-spacing: -.03em; font-weight: 800; }
.results h2:focus { outline: none; }
.results-sub { color: var(--muted); font-size: var(--fs-sm); margin-top: var(--s1); }
.results-tools { display: flex; gap: var(--s2); flex-wrap: wrap; }
.genres { display: flex; gap: var(--s2); overflow-x: auto; margin: var(--s4) calc(-1 * var(--s4)) 0; padding: 2px var(--s4); scrollbar-width: none; }
.genres::-webkit-scrollbar { display: none; }
.genres .chip { min-height: 36px; }
.genres .chip-market { flex: none; border-style: dashed; }
.genres .chip-market[aria-pressed="true"] { border-style: solid; }
.select-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s1) var(--s2); margin-top: var(--s4);
  padding: var(--s2) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); font-weight: 600;
}
.spacer { flex: 1; }

.tracks { list-style: none; margin: 0; padding: 0; }
.track {
  display: grid; grid-template-columns: auto 56px minmax(0, 1fr) auto; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s2); margin: 0 calc(-1 * var(--s2)); border-bottom: 1px solid var(--border);
  border-radius: var(--r-sm); transition: background .15s, opacity .2s;
  animation: rise .35s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.track:hover { background: var(--surface); }
.track.is-off .track-main, .track.is-off .art, .track.is-off .bpm-badge { opacity: .45; }
.track.is-playing { background: var(--surface); }

.check { position: relative; width: 28px; height: 44px; display: grid; place-items: center; }
.check input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.check span {
  width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--muted); display: grid; place-items: center;
  transition: background .12s, border-color .12s;
}
.check span::after {
  content: ""; width: 10px; height: 5px; border-left: 2.5px solid var(--primary-ink); border-bottom: 2.5px solid var(--primary-ink);
  transform: rotate(-45deg) translateY(-1px) scale(0); transition: transform .12s var(--ease);
}
.check input:checked + span { background: var(--primary); border-color: var(--primary); }
.check input:checked + span::after { transform: rotate(-45deg) translateY(-1px) scale(1); }
.check input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 3px; }

.art {
  position: relative; width: 56px; height: 56px; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2);
  border: 0; padding: 0; display: block;
}
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.art .play {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(9, 9, 11, .5);
  opacity: 0; transition: opacity .15s;
}
.art .play svg { width: 24px; height: 24px; fill: #fff; }
.art:hover .play, .art:focus-visible .play, .track.is-playing .play, .track.is-loading .play { opacity: 1; }
@media (hover: none) { .art .play { opacity: 1; background: rgba(9, 9, 11, .3); } }
.art .progress { position: absolute; left: 0; bottom: 0; height: 3px; width: var(--p, 0%); background: var(--primary); }
.art[disabled] { cursor: default; }
.art[disabled] .play { display: none; }
.track.is-loading .play svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.track-main { min-width: 0; }
.track-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-artist { color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 2px var(--s3); margin-top: 2px; color: var(--muted); font-size: var(--fs-xs); }
.track-meta a { text-underline-offset: 2px; }
.track-meta a:hover { color: var(--text); }
.pop { display: inline-flex; align-items: center; gap: 6px; }
.pop i { display: block; width: 44px; height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.pop i::after { content: ""; display: block; height: 100%; width: var(--w, 0%); background: var(--secondary); }
.tag-off { color: var(--danger); }

.bpm-badge { text-align: right; line-height: 1.05; }
.bpm-badge b { display: block; font-size: 1.35rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.bpm-badge span { color: var(--muted); font-size: 0.65rem; font-weight: 700; letter-spacing: .1em; }
.bpm-badge .verified { color: var(--ok); }

.state { text-align: center; color: var(--muted); padding: var(--s7) var(--s4); display: grid; gap: var(--s3); justify-items: center; }
.state:empty { display: none; }
.state strong { color: var(--text); font-size: var(--fs-lg); }
.more-row { display: flex; justify-content: center; padding: var(--s5) 0; }

.skeleton { display: grid; grid-template-columns: 28px 56px 1fr 48px; gap: var(--s3); align-items: center; padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.skeleton i { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.skeleton i:nth-child(2) { height: 56px; border-radius: var(--r-sm); }
.skeleton i:nth-child(3) { width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- sticky action bar ------------------------------------------------- */
.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(19, 19, 24, .92); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border); padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
  animation: slide-up .3s var(--ease);
}
@keyframes slide-up { from { transform: translateY(100%); } }
.action-inner { max-width: var(--page); margin: 0 auto; display: grid; gap: var(--s2); }
.action-count { font-weight: 700; font-size: var(--fs-sm); }
.action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.action-buttons .btn { padding: 0 var(--s3); }
.action-buttons .btn .wide { display: none; }

/* ---- sessions ------------------------------------------------------------ */
.sessions { margin-top: var(--s7); }
.sessions .lede { margin-top: var(--s2); font-size: var(--fs-md); }
.sessions-list { margin-top: var(--s5); display: grid; gap: var(--s3); }
.session-card, .empty-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s5);
}
.empty-card { border-style: dashed; color: var(--muted); }
.empty-card strong { color: var(--text); display: block; margin-bottom: var(--s1); }
.session-card h3 { font-size: var(--fs-md); }
.session-card p { color: var(--muted); font-size: var(--fs-sm); }
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--r-full); font-size: var(--fs-xs); font-weight: 700; background: var(--surface-3); margin-bottom: var(--s2); }
.badge.live { background: var(--secondary); color: #1a0410; }

/* ---- modal + toasts -------------------------------------------------------- */
.modal {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--r-lg);
  padding: 0; width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
}
.modal::backdrop { background: rgba(0, 0, 0, .7); }
.modal[open] { animation: pop .2s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-body { padding: var(--s6) var(--s5); display: grid; gap: var(--s4); justify-items: center; text-align: center; }
.modal-body h2 { font-size: var(--fs-lg); letter-spacing: -.02em; }
.modal-body p { color: var(--muted); font-size: var(--fs-sm); }
.modal-body .btn { width: 100%; }
.modal-body ul { text-align: left; color: var(--muted); font-size: var(--fs-sm); padding-left: var(--s5); margin: 0; display: grid; gap: var(--s2); }
.modal-body ul b { color: var(--text); }
.modal-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); }
.modal-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.modal-icon.ok { background: var(--primary); color: var(--primary-ink); }
.modal-icon.bad { background: rgba(255, 123, 114, .15); color: var(--danger); }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--surface-3); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.share-url {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: var(--s3); font-size: var(--fs-sm); color: var(--text); text-overflow: ellipsis;
}
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 150px; z-index: 40; display: grid; gap: var(--s2); width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  background: var(--text); color: var(--bg); padding: var(--s3) var(--s4); border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: 600; text-align: center; animation: pop .2s var(--ease);
}

/* ---- larger screens ---------------------------------------------------------- */
@media (min-width: 760px) {
  .site-header { padding: var(--s5) var(--s5); }
  .hero { grid-template-columns: 1fr 1fr; align-items: center; padding: var(--s7) var(--s5) var(--s8); gap: var(--s7); }
  body.has-results .hero { grid-template-columns: 1fr; }
  body.has-results .bpm-card { grid-template-columns: auto minmax(200px, 1fr) auto; align-items: center; column-gap: var(--s6); }
  body.has-results .presets { grid-column: 1 / -1; grid-row: 2; }
  body.has-results .btn-lg { width: auto; padding: 0 var(--s6); }
  .bpm-card { padding: var(--s6); }
  .bpm-field input { font-size: clamp(2.5rem, 5.2vw, 4.5rem); }
  .presets { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
  .results, .sessions { padding-left: var(--s5); padding-right: var(--s5); }
  .genres { flex-wrap: wrap; overflow: visible; margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .track { grid-template-columns: auto 64px minmax(0, 1fr) auto; gap: var(--s4); padding: var(--s3) var(--s3); margin: 0 calc(-1 * var(--s3)); }
  .art { width: 64px; height: 64px; }
  .action-inner { grid-template-columns: 1fr auto; align-items: center; }
  .action-buttons { display: flex; }
  .action-buttons .btn { padding: 0 var(--s5); }
  .action-buttons .btn .wide { display: inline; }
  .sessions-list { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
  .toasts { bottom: 100px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  html { scroll-behavior: auto; }
}
