/* ==========================================================================
   MP-Beats — component vocabulary
   Every view composes from these. Views may add layout, never new button or
   input styles.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  --btn-bg: var(--surface-raised);
  --btn-fg: var(--text-primary);
  --btn-border: var(--border-default);
  --btn-h: 42px;

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--btn-h);
  min-width: var(--btn-h);
  padding-inline: var(--space-5);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  white-space: nowrap;
  isolation: isolate;
  transition:
    background-color var(--dur-fast) var(--ease-soft),
    border-color var(--dur-fast) var(--ease-soft),
    color var(--dur-fast) var(--ease-soft),
    transform var(--dur-instant) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}

/* Hover moves the TOKEN, never `background` itself.
   `.btn:hover:not(:disabled)` scores (0,3,0) and `.btn--primary` only (0,1,0),
   so setting `background` here beat every variant's own background: the primary
   button turned flat grey on hover and its near-black label became unreadable.
   Driving --btn-bg leaves any variant that paints its own background alone. */
.btn:hover:not(:disabled) {
  --btn-bg: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn:active:not(:disabled) {
  transform: scale(0.975);
}

.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  pointer-events: none;
}

/* Primary — the only element on a page allowed to be fully ember */
.btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-contrast);
  --btn-border: transparent;
  background: var(--gradient-ember);
  font-weight: var(--weight-bold);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.18) inset, 0 6px 18px color-mix(in oklab, var(--brand-accent) 24%, transparent);
}

.btn--primary:hover:not(:disabled) {
  --btn-bg: var(--accent-hover);
  filter: brightness(1.06);
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.22) inset, 0 10px 30px color-mix(in oklab, var(--brand-accent) 34%, transparent);
}

/* A slow specular sweep on hover — the "expensive product" cue */
.btn--primary::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background: var(--gradient-sheen);
  background-size: 220% 100%;
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-soft);
}

.btn--primary:hover::after {
  opacity: 1;
  animation: shimmer 1.1s var(--ease-soft);
}

.btn--secondary {
  --btn-bg: var(--glass-medium);
  --btn-border: var(--border-strong);
  backdrop-filter: blur(var(--glass-blur));
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-fg: var(--text-secondary);
}

.btn--ghost:hover:not(:disabled) {
  --btn-fg: var(--text-primary);
  background: var(--glass-thin);
  border-color: transparent;
}

.btn--outline {
  --btn-bg: transparent;
  --btn-border: var(--border-strong);
}

.btn--accent-outline {
  --btn-bg: var(--accent-softer);
  --btn-border: var(--border-accent);
  --btn-fg: var(--accent-text);
}

.btn--danger {
  --btn-bg: var(--danger-soft);
  --btn-border: color-mix(in oklab, var(--danger) 35%, transparent);
  --btn-fg: var(--danger);
}

.btn--danger:hover:not(:disabled) {
  --btn-bg: var(--danger);
  --btn-fg: #fff;
}

.btn--sm {
  --btn-h: 34px;
  padding-inline: var(--space-4);
  font-size: var(--text-xs);
}

.btn--lg {
  --btn-h: 52px;
  padding-inline: var(--space-8);
  font-size: var(--text-md);
}

.btn--xl {
  --btn-h: 60px;
  padding-inline: var(--space-10);
  font-size: var(--text-md);
}

.btn--block {
  width: 100%;
}

.btn--icon {
  padding: 0;
  aspect-ratio: 1;
  border-radius: var(--radius-circle);
}

.btn--square {
  padding: 0;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
}

/* Loading state: the label stays in place so the button never resizes */
.btn.is-loading {
  color: transparent;
  pointer-events: none;
}

.btn.is-loading::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--radius-circle);
  color: var(--btn-fg);
  animation: spin 0.6s linear infinite;
}

.btn--primary.is-loading::before {
  color: var(--accent-contrast);
}

@media (pointer: coarse) {
  .btn {
    --btn-h: var(--tap-min);
  }
  .btn--sm {
    --btn-h: var(--tap-min);
  }
}

/* --------------------------------------------------------------------------
   Play button — the single most-clicked control on the site
   -------------------------------------------------------------------------- */

.play-btn {
  --play-size: 46px;
  position: relative;
  display: grid;
  place-items: center;
  width: var(--play-size);
  height: var(--play-size);
  border-radius: var(--radius-circle);
  background: var(--gradient-ember);
  color: var(--accent-contrast);
  border: none;
  box-shadow: 0 4px 14px color-mix(in oklab, var(--brand-accent) 34%, transparent);
  /* Springs for ARRIVALS, expo-out for RESPONSES — that is the whole rule.
     --ease-spring overshoots to 1.56, so using it here made the site's
     most-clicked control wobble past its hover scale and, on press, spring
     *below* the pressed size before settling. A press must never bounce. */
  transition:
    transform var(--dur-instant) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}

.play-btn:hover {
  transform: scale(1.07);
  box-shadow: 0 6px 22px color-mix(in oklab, var(--brand-accent) 48%, transparent);
}

.play-btn:active {
  transform: scale(0.96);
}

.play-btn .icon {
  /* Optical centring: a triangle looks off-centre when geometrically centred */
  transform: translateX(1px);
}

.play-btn[data-playing='true'] .icon {
  transform: none;
}

.play-btn--live {
  background: var(--brand-live);
  color: #04120e;
  box-shadow: var(--glow-live);
}

.play-btn--lg {
  --play-size: 64px;
}
.play-btn--sm {
  --play-size: 36px;
}
.play-btn--xs {
  --play-size: 30px;
}

/* The compact sizes exist to fit a 48px thumbnail on a mouse-driven layout.
   On a finger they are simply too small to hit, so they resolve to the
   platform minimum instead. */
@media (pointer: coarse) {
  .play-btn--sm,
  .play-btn--xs {
    --play-size: var(--tap-min);
  }
}

/* --------------------------------------------------------------------------
   Now-playing equaliser
   -------------------------------------------------------------------------- */

.eq {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: var(--eq-size, 14px);
}

.eq i {
  width: 2.5px;
  height: 100%;
  border-radius: 2px;
  background: var(--live);
  transform-origin: bottom;
  animation: eq-bounce 0.9s var(--ease-in-out) infinite;
}

.eq i:nth-child(2) { animation-duration: 0.7s; animation-delay: -0.35s; }
.eq i:nth-child(3) { animation-duration: 1.1s; animation-delay: -0.6s; }

@media (prefers-reduced-motion: reduce) {
  .eq i {
    animation: none;
    height: 60%;
  }
  .eq i:nth-child(2) { height: 100%; }
  .eq i:nth-child(3) { height: 40%; }
}

/* --------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.field__error {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--danger);
}

/* A control whose only affordance is its boundary must clear WCAG 1.4.11's
   3:1 — so it gets --border-control (3.26:1), never a decorative border token,
   and its fill drops a step to --surface-void so the field is distinguishable
   from the page even before the border is considered. */
.input,
.textarea,
.select {
  width: 100%;
  min-height: max(46px, var(--tap-min));
  padding: var(--space-3) var(--space-4);
  background: var(--surface-void);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: var(--transition-colors), box-shadow var(--dur-fast) var(--ease-soft);
  /* iOS zooms the page when a focused input is under 16px */
  font-size: max(16px, var(--text-base));
}

@media (min-width: 861px) {
  .input,
  .textarea,
  .select {
    font-size: var(--text-base);
  }
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-quiet);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--border-control-hover);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface-raised);
}

.input[aria-invalid='true'],
.textarea[aria-invalid='true'] {
  border-color: var(--danger);
}

.input[aria-invalid='true']:focus {
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.textarea {
  min-height: 120px;
  resize: vertical;
  line-height: var(--leading-normal);
}

/* A data: URI cannot read a custom property, so this caret is the one colour
   in the system that has to be written twice. It mirrors --text-quiet
   (#838c9d); change both together. */
.select {
  appearance: none;
  padding-right: var(--space-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23838c9d' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  background-size: 16px;
  cursor: pointer;
}

.select option {
  background: var(--surface-overlay);
  color: var(--text-primary);
}

/* Input with a leading icon */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .icon {
  position: absolute;
  left: var(--space-4);
  color: var(--text-tertiary);
  pointer-events: none;
  transition: color var(--dur-fast) var(--ease-soft);
}

.input-group .input {
  padding-left: calc(var(--space-4) * 2 + 18px);
}

.input-group:focus-within .icon {
  color: var(--accent);
}

.input-group__clear {
  position: absolute;
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-circle);
  color: var(--text-tertiary);
}

.input-group__clear:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

@media (pointer: coarse) {
  .input-group__clear {
    width: var(--tap-min);
    height: var(--tap-min);
  }
}

/* Checkbox & radio */
.checkbox,
.radio {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  min-height: var(--tap-min);
  padding-block: var(--space-1);
}

.checkbox input,
.radio input {
  appearance: none;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-top: 1px;
  border: 1.5px solid var(--border-control);
  background: var(--surface-void);
  cursor: pointer;
  transition: var(--transition-colors), box-shadow var(--dur-fast) var(--ease-soft);
}

.checkbox input { border-radius: var(--radius-xs); }
.radio input { border-radius: var(--radius-circle); }

.checkbox input:checked,
.radio input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox input:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2314100a' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4.5 12.5 5 5 10-11'/%3E%3C/svg%3E");
  background-size: 13px;
  background-position: center;
  background-repeat: no-repeat;
}

.radio input:checked {
  box-shadow: inset 0 0 0 4px var(--surface-void);
}

.checkbox input:focus-visible,
.radio input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Switch */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  min-height: var(--tap-min);
}

.switch input {
  appearance: none;
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: var(--radius-pill);
  background: var(--surface-active);
  border: 1px solid var(--border-control);
  cursor: pointer;
  transition: background-color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}

.switch input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-circle);
  background: var(--text-secondary);
  transition: transform var(--dur-base) var(--ease-spring), background-color var(--dur-base) var(--ease-out);
}

.switch input:checked {
  background: var(--accent);
  border-color: transparent;
}

.switch input:checked::after {
  transform: translateX(18px);
  background: var(--accent-contrast);
}

.switch input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Cards & surfaces
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-inset);
}

.card--glass {
  background: var(--glass-thick);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-color: var(--border-default);
}

.card--pad {
  padding: var(--space-6);
}

/* Hover is a response to a pointer that has usually already moved on; at
   240ms it reads as lag. Responses run at --dur-fast, arrivals at --dur-base. */
.card--interactive {
  transition:
    border-color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out);
}

.card--interactive:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.panel {
  background: var(--surface-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
}

/* --------------------------------------------------------------------------
   Badges, pills, chips
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-2);
  border-radius: var(--radius-xs);
  background: var(--glass-medium);
  border: 1px solid var(--border-subtle);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-wide);
  color: var(--text-secondary);
  white-space: nowrap;
}

.badge--accent {
  background: var(--accent-soft);
  border-color: var(--border-accent);
  color: var(--accent-text);
}

.badge--live {
  background: var(--live-soft);
  border-color: color-mix(in oklab, var(--brand-live) 35%, transparent);
  color: var(--live);
}

.badge--success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge--warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge--info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.badge--exclusive {
  background: linear-gradient(135deg, #f5d99a, #c9a34e);
  color: #22190a;
  border-color: transparent;
  font-weight: var(--weight-bold);
}

/* Badges on artwork
   A translucent fill works over a known background. Over generated cover art
   it does not: the same "New" badge measured ~2.5:1 on a bright tile and
   ~8:1 on a dark one, so its legibility depended on whichever hue the
   generator happened to pick. A badge that only sometimes reads is not a
   component. Every badge over artwork therefore carries its own opaque scrim
   and renders identically on every cover. */
.beat-card__badges .badge {
  background: color-mix(in oklab, var(--surface-base) 72%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-color: var(--border-default);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

/* Amber is the site's scarcest signal — it means "this costs money / choose
   this". Over artwork exactly one badge is allowed to spend it: Featured. */
.beat-card__badges .badge--accent {
  background: color-mix(in oklab, var(--surface-base) 72%, transparent);
  border-color: var(--border-accent);
  color: var(--accent-text);
}

.beat-card__badges .badge--live {
  color: var(--live);
}

.beat-card__badges .badge--exclusive {
  background: linear-gradient(135deg, #f5d99a, #c9a34e);
  color: #22190a;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Interactive filter chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 34px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-default);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  transition: var(--transition-colors), transform var(--dur-fast) var(--ease-out);
}

.chip:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.chip[aria-pressed='true'],
.chip.is-active {
  background: var(--accent-soft);
  border-color: var(--border-accent);
  color: var(--accent-text);
}

.chip__count {
  font-variant-numeric: tabular-nums;
  color: var(--text-quiet);
  font-size: var(--text-2xs);
}

@media (pointer: coarse) {
  .chip {
    min-height: var(--tap-min);
  }
}

/* --------------------------------------------------------------------------
   Press vocabulary
   base.css strips the platform tap highlight from every button and link, so
   the site owes touch users a replacement. Without one, tapping a card, a
   chip, a tab, a nav link or a footer link produced no response at all until
   the next view painted — the app felt broken exactly where it is used most.

   One rule, applied everywhere: a press is a RESPONSE, so it runs at
   --dur-instant on --ease-out and never springs. Controls shrink slightly;
   large surfaces shrink less, because the same scale on a 300px tile reads as
   a glitch rather than a press.
   -------------------------------------------------------------------------- */

/* Only the timings for primitives this file owns are declared here; every
   other stylesheet composes the same two tokens into its own transition so
   nothing gets clobbered across load order. */
.chip,
.tab {
  transition:
    var(--transition-colors),
    transform var(--dur-instant) var(--ease-out);
}

/* Small controls — the press is the whole gesture, so it is the larger move. */
.chip:active,
.tab:active,
.page-btn:active:not(:disabled),
.queue-item__btn:active,
.social-link:active,
.footer__link:active,
.nav-link:active,
.tab-item:active,
.home-genre:active,
.home-license:active,
.lic-card:active,
.lic__card:active {
  transform: scale(0.97);
}

/* Large surfaces — a 300px tile at scale(0.97) reads as a glitch, not a press. */
.beat-card--row:active,
.beat-card--compact:active,
.beat-card--grid:active .beat-card__art,
.card--interactive:active {
  transform: scale(0.985);
}

/* Hover never fires on touch, so a press is the ONLY feedback these surfaces
   ever get. Give them the hover fill for the duration of the press. */
@media (hover: none) {
  .beat-card--row:active,
  .beat-card--compact:active,
  .queue-item__btn:active,
  .home-genre:active,
  .home-license:active,
  .tab:active {
    background: var(--surface-hover);
  }
}

/* --------------------------------------------------------------------------
   Skeletons
   -------------------------------------------------------------------------- */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgb(255 255 255 / 0.045) 45%,
    rgb(255 255 255 / 0.075) 50%,
    rgb(255 255 255 / 0.045) 55%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s var(--ease-in-out) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
  }
}

.skeleton--text { height: 0.85em; border-radius: var(--radius-xs); }
.skeleton--title { height: 1.4em; border-radius: var(--radius-xs); }
.skeleton--square { aspect-ratio: 1; border-radius: var(--radius-md); }
.skeleton--circle { aspect-ratio: 1; border-radius: var(--radius-circle); }

/* --------------------------------------------------------------------------
   Empty & error states
   -------------------------------------------------------------------------- */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: var(--space-16) var(--space-6);
  text-align: center;
}

.state__icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-circle);
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
}

.state__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.state__body {
  max-width: 44ch;
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */

.toast-root {
  position: fixed;
  right: var(--gutter);
  bottom: calc(var(--player-h) + var(--space-5));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(380px, calc(100vw - var(--gutter) * 2));
  pointer-events: none;
}

.toast-root > * {
  pointer-events: auto;
}

@media (max-width: 860px) {
  .toast-root {
    right: var(--space-3);
    left: var(--space-3);
    width: auto;
    bottom: calc(var(--player-h-mobile) + var(--tabbar-h) + var(--safe-b) + var(--space-3));
  }
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  padding-right: var(--space-10);
  overflow: hidden;
  background: var(--glass-thick);
  backdrop-filter: blur(var(--glass-blur-heavy));
  -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: fade-up var(--dur-slow) var(--ease-spring) both;
}

.toast.is-leaving {
  animation: toast-out var(--dur-base) var(--ease-soft) both;
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(24px) scale(0.96);
  }
}

.toast__icon { flex: 0 0 auto; margin-top: 1px; color: var(--text-secondary); }
.toast--success .toast__icon { color: var(--success); }
.toast--error .toast__icon { color: var(--danger); }
.toast--warning .toast__icon { color: var(--warning); }
.toast--cart .toast__icon { color: var(--accent); }

.toast__body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.toast__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.toast__message { font-size: var(--text-sm); color: var(--text-secondary); line-height: var(--leading-snug); }

.toast__action {
  flex: 0 0 auto;
  align-self: center;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--glass-medium);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--accent-text);
}

.toast__action:hover { background: var(--accent-soft); }

.toast__close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
}

.toast__close:hover { background: var(--surface-hover); color: var(--text-primary); }

@media (pointer: coarse) {
  .toast__close {
    width: var(--tap-min);
    height: var(--tap-min);
  }
}

.toast__timer {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2px;
  width: 100%;
  transform-origin: left;
  background: var(--accent);
  animation: toast-timer var(--toast-duration, 4000ms) linear forwards;
}

.toast.is-paused .toast__timer { animation-play-state: paused; }

@keyframes toast-timer {
  from { transform: scaleX(1); }
  to { transform: scaleX(0); }
}

/* --------------------------------------------------------------------------
   Modal & drawer
   -------------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: rgb(4 5 8 / 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in var(--dur-base) var(--ease-soft);
}

.modal {
  position: relative;
  width: min(560px, 100%);
  max-height: min(86svh, 780px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  animation: modal-in var(--dur-slow) var(--ease-spring) both;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
}

.modal__head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  background: var(--surface-overlay);
  border-bottom: 1px solid var(--border-subtle);
}

.modal__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
.modal__body { padding: var(--space-6); }
.modal__foot {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  padding: var(--space-5) var(--space-6);
  background: var(--surface-overlay);
  border-top: 1px solid var(--border-subtle);
}

/* On phones a modal becomes a bottom sheet — thumb-reachable, native-feeling */
@media (max-width: 640px) {
  .overlay {
    padding: 0;
    place-items: end stretch;
  }
  .modal {
    width: 100%;
    max-height: 92svh;
    border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
    padding-bottom: var(--safe-b);
    animation: sheet-in var(--dur-slow) var(--ease-out) both;
  }
  @keyframes sheet-in {
    from { transform: translateY(100%); }
  }
  .modal::before {
    content: '';
    display: block;
    width: 38px;
    height: 4px;
    margin: var(--space-3) auto 0;
    border-radius: var(--radius-pill);
    background: var(--border-strong);
  }
}

/* --------------------------------------------------------------------------
   Tooltip
   -------------------------------------------------------------------------- */

[data-tip] {
  position: relative;
}

[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  z-index: var(--z-tooltip);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--surface-overlay);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-md);
  color: var(--text-primary);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 4px);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease-soft), transform var(--dur-fast) var(--ease-out);
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Touch devices have no hover, so tooltips would stick after a tap */
@media (pointer: coarse) {
  [data-tip]::after {
    display: none;
  }
}

/* --------------------------------------------------------------------------
   Progress & meters
   -------------------------------------------------------------------------- */

.progress {
  position: relative;
  height: 4px;
  width: 100%;
  border-radius: var(--radius-pill);
  background: var(--surface-active);
  overflow: hidden;
}

.progress__bar {
  /* The bar is a <span>. Without display:block it stays inline, where height
     and width do not apply — so it had no box, and scaleX() animated nothing.
     Uploads showed a permanently empty track. */
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--gradient-ember);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform var(--dur-fast) linear;
}

.progress--indeterminate .progress__bar {
  width: 40%;
  animation: indeterminate 1.2s var(--ease-in-out) infinite;
}

@keyframes indeterminate {
  from { transform: translateX(-100%); }
  to { transform: translateX(320%); }
}

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-1);
  background: var(--surface-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  padding: var(--space-2) var(--space-5);
  min-height: 36px;
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: var(--transition-colors);
}

.tab:hover { color: var(--text-primary); }

.tab[aria-selected='true'],
.tab.is-active {
  background: var(--surface-hover);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}

@media (pointer: coarse) {
  .tab {
    min-height: var(--tap-min);
  }
}

/* --------------------------------------------------------------------------
   Table
   -------------------------------------------------------------------------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface-base);
}

.table {
  min-width: 640px;
  font-size: var(--text-sm);
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border-default);
  text-align: left;
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color var(--dur-fast) var(--ease-soft); }
.table tbody tr:hover { background: var(--glass-thin); }

/* --------------------------------------------------------------------------
   Artwork
   -------------------------------------------------------------------------- */

.art {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  isolation: isolate;
}

.art img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--dur-slower) var(--ease-out), opacity var(--dur-base) var(--ease-soft);
}

.art img[data-loaded='false'] { opacity: 0; }

/* Generated fallback: a deterministic DUOTONE per beat.
   The old version fed --art-hue straight into hsl(), which meant a catalogue
   of four beats came out amber, blue, cyan and green — a full-spectrum set
   that belongs to no palette and actively fights "Obsidian & Ember". Hue is
   also the wrong axis: it made the cover art look like four different sites
   rather than four records from one studio.

   Instead --art-hue only chooses a POSITION along the brand ramp, between
   --brand-accent (ember) and --brand-accent-2 (flare). Every generated cover
   therefore lands inside the ~22° arc the brand already owns, still unique
   per beat, and still follows the admin theme editor for free. */
.art--fallback {
  /* --art-hue is a stable 0–359 hash of the slug. Four independent folds of it
     give four independent axes of variation, so two beats that share a palette
     still get different artwork: where the light falls, how far it spreads,
     how deep the shadow runs, and which way the base gradient rakes. Records
     in a series differ by COMPOSITION, not by hue — that is what makes them
     read as one catalogue instead of four unrelated tiles. */
  --art-pos: clamp(0%, calc(var(--art-hue, 28) / 3.6 * 1%), 100%);
  --art-x: calc(50% + sin(var(--art-hue, 28) * 1deg) * 30%);
  --art-y: calc(50% + cos(var(--art-hue, 28) * 1deg) * 30%);
  --art-spread: calc(95% + sin(var(--art-hue, 28) * 2.9deg) * 35%);
  --art-depth: calc(26% + (1 + cos(var(--art-hue, 28) * 3.1deg)) * 15%);
  --art-rake: calc(140deg + sin(var(--art-hue, 28) * 1.7deg) * 55deg);

  /* Position on the ember ramp — a ~22° arc the brand already owns. */
  --art-tint: color-mix(in oklab, var(--brand-accent) calc(100% - var(--art-pos)), var(--brand-accent-2));
  --art-shade: color-mix(in oklab, var(--art-tint) var(--art-depth), var(--surface-void));

  background:
    radial-gradient(var(--art-spread) var(--art-spread) at var(--art-x) var(--art-y), var(--art-tint), transparent 62%),
    radial-gradient(
      130% 130% at calc(100% - var(--art-x)) calc(100% - var(--art-y)),
      var(--art-shade),
      transparent 70%
    ),
    linear-gradient(var(--art-rake), var(--surface-raised), var(--surface-void));
}

/* Film grain, not blur. At 0.35 the gradients underneath read as an image
   that failed to load; at 0.6 the surface acquires a texture and the whole
   tile stops looking like a placeholder. */
.art--fallback::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)' opacity='0.4'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
  opacity: 0.6;
}

/* Fallback cover art: the beat's own waveform, so no two are alike.
   crisp-edges keeps the bars from anti-aliasing into a soft picket fence at
   small sizes, so the silhouette reads as a spectrum. */
/* The bar data comes from the audio, but its framing is part of the cover:
   varying the height and the optical centre per beat means two tracks with
   similar envelopes still crop to different silhouettes. */
.art__glyph {
  --glyph-h: calc(52% + (1 + sin(var(--art-hue, 28) * 2.3deg)) * 9%);
  position: absolute;
  inset: calc((100% - var(--glyph-h)) / 2) 12%;
  width: 76%;
  height: var(--glyph-h);
  fill: rgb(255 255 255 / 0.88);
  shape-rendering: crispEdges;
  filter: drop-shadow(0 2px 14px rgb(0 0 0 / 0.5));
  transition: fill var(--dur-fast) var(--ease-soft);
}

.art--fallback:hover .art__glyph {
  fill: rgb(255 255 255 / 1);
}

.art__initials {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 22cqi, 4rem);
  font-weight: var(--weight-black);
  letter-spacing: var(--tracking-hero);
  color: rgb(255 255 255 / 0.9);
  text-shadow: 0 2px 20px rgb(0 0 0 / 0.4);
  container-type: inline-size;
}

/* --------------------------------------------------------------------------
   Misc
   -------------------------------------------------------------------------- */

.divider-label {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--text-quiet);
  font-size: var(--text-xs);
}

.divider-label::before,
.divider-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--surface-raised);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  text-align: center;
  color: var(--text-secondary);
}

.scroll-x {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  /* Bleed to the viewport edge on mobile so cards look like a native carousel */
  margin-inline: calc(var(--gutter) * -1);
  padding-inline: var(--gutter);
  padding-bottom: var(--space-2);
}

.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x > * { scroll-snap-align: start; }
