/* ==========================================================================
   MP-Beats — reset, document, typography, primitives
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Header + player are fixed, so anchors must not land underneath them */
  scroll-padding-top: calc(var(--header-h) + var(--space-6));
  scroll-padding-bottom: calc(var(--player-h) + var(--space-6));
  background: var(--surface-void);
  color-scheme: dark;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  min-height: 100svh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background: var(--surface-void);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-synthesis-weight: none;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

/* The whole app sits above a fixed atmospheric backdrop */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(1200px 800px at 12% -8%, color-mix(in oklab, var(--brand-accent) 11%, transparent), transparent 62%),
    radial-gradient(1000px 700px at 92% 4%, color-mix(in oklab, var(--brand-accent-2) 8%, transparent), transparent 60%),
    var(--surface-void);
  pointer-events: none;
}

/* Fine film grain — the single cheapest trick for making flat dark UI feel
   like a physical object instead of a PNG. Kept under 3% opacity. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.028;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

/* ---- Media & form defaults ------------------------------------------ */

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

img {
  height: auto;
  /* Prevents the alt-text flash before artwork resolves */
  color: transparent;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

/* Suppressing the platform tap highlight is only legitimate if something
   replaces it. The shared press vocabulary in components.css (`.pressable`
   and the `:active` block that applies it to every interactive surface) is
   that replacement — do not remove one without the other, or touch users get
   no feedback at all until the next paint. */
button {
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

ul,
ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  width: 100%;
}

hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
}

/* ---- Typography ------------------------------------------------------ */

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-display);
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

.t-hero {
  font-family: var(--font-display);
  font-size: var(--text-hero);
  font-weight: var(--weight-black);
  line-height: 0.92;
  letter-spacing: var(--tracking-hero);
  text-wrap: balance;
}

.t-display {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-display);
  line-height: var(--leading-tight);
}

.t-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-display);
}

.t-heading {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
}

.t-body {
  font-size: var(--text-base);
  color: var(--text-secondary);
  line-height: var(--leading-normal);
}

.t-lead {
  font-size: var(--text-md);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

.t-small {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

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

/* Section eyebrow — small caps label above a heading */
.t-eyebrow {
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.t-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-normal);
}

/* Numbers that update live (timecodes, prices, counters) must not reflow */
.t-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.t-gradient {
  background: var(--gradient-ember);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* Guarantees legibility if background-clip is unsupported */
  -webkit-text-fill-color: transparent;
}

.t-accent { color: var(--accent-text); }
.t-secondary { color: var(--text-secondary); }
.t-tertiary { color: var(--text-tertiary); }

.t-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.t-clamp-2,
.t-clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.t-clamp-2 { -webkit-line-clamp: 2; line-clamp: 2; }
.t-clamp-3 { -webkit-line-clamp: 3; line-clamp: 3; }

/* ---- Selection & focus ----------------------------------------------- */

::selection {
  background: color-mix(in oklab, var(--brand-accent) 32%, transparent);
  color: var(--text-primary);
}

/* Mouse users never see a focus ring; keyboard users always do. */
:focus {
  outline: none;
}

/* No `border-radius` here. It would mutate the *element's* geometry, not the
   outline's — browsers already round an outline to follow the element's own
   radius — so any focusable element whose radius is set at equal-or-lower
   specificity would visibly snap to 4px the instant it took keyboard focus.
   If a component needs a rounder ring, it sets `outline-offset` on itself. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: var(--z-max);
  padding: var(--space-3) var(--space-5);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-sm);
  transform: translateY(-160%);
  transition: transform var(--dur-base) var(--ease-out);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

/* ---- Scrollbars ------------------------------------------------------ */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-active) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-active);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-quiet);
  background-clip: content-box;
}

/* ---- Layout primitives ----------------------------------------------- */

.container {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container--narrow { max-width: var(--content-narrow); }
.container--wide { max-width: var(--content-wide); }

.section {
  padding-block: var(--section-y);
}

.stack { display: flex; flex-direction: column; }
.row { display: flex; flex-direction: row; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { display: flex; align-items: center; justify-content: center; }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }
.gap-10 { gap: var(--space-10); }
.gap-12 { gap: var(--space-12); }

/* ---- Accessibility helpers ------------------------------------------- */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.no-scroll {
  overflow: hidden;
  /* Preserve the scrollbar gutter so opening a modal does not shift layout */
  scrollbar-gutter: stable;
}

/* ---- Section header pattern ------------------------------------------ */

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
}

.section-head__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-display);
  line-height: var(--leading-tight);
}

.section-head__sub {
  margin-top: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-base);
  max-width: 56ch;
}

/* ---- Divider with a hairline gradient -------------------------------- */

.rule {
  height: 1px;
  border: 0;
  background: linear-gradient(
    to right,
    transparent,
    var(--border-default) 15%,
    var(--border-default) 85%,
    transparent
  );
}

/* ---- Scroll reveal --------------------------------------------------- */
/* Elements marked [data-reveal] start hidden and are released by the
   IntersectionObserver in core/reveal.js. If JS fails, the fallback below
   keeps everything visible rather than hiding the whole page. */

/* Reveal is opt-IN, enabled only once the app boots. If a script fails or is
   blocked, `js-ready` never lands and every element simply stays visible —
   a broken bundle must never produce a blank page. */
/* No blanket `will-change`. Promoting every unrevealed element at once puts a
   48-card catalogue on 48 compositor layers before a single one animates — the
   exact anti-pattern the hint exists to avoid, and real GPU memory on low-end
   Android. A transform/opacity transition promotes the element for its own
   duration anyway; reveal.js may set the hint per-element just before it
   releases one, and clear it on transitionend. */
html.js-ready [data-reveal] {
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition:
    opacity var(--dur-slower) var(--ease-out),
    transform var(--dur-slower) var(--ease-out);
  transition-delay: var(--reveal-delay, 0ms);
}

html.js-ready [data-reveal].is-revealed {
  opacity: 1;
  transform: none;
  will-change: auto;
}

html.reveal-off [data-reveal] {
  opacity: 1 !important;
  transform: none !important;
}

/* The reduced-motion escape hatch has to out-specify the hiding rule or it is
   dead code. `html.js-ready [data-reveal]` scores (0,2,1); a bare
   `[data-reveal]` scores (0,1,0) and loses, which left reduced-motion users
   looking at a permanently blank page whenever the observer missed an element.
   Matching the selector exactly restores the safety net. */
@media (prefers-reduced-motion: reduce) {
  html.js-ready [data-reveal],
  [data-reveal] {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ---- App scaffold ----------------------------------------------------- */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100svh;
}

#view {
  flex: 1 1 auto;
  /* Room for the fixed player, plus the mobile tab bar and the notch */
  padding-bottom: calc(var(--player-h) + var(--space-8));
}

@media (max-width: 860px) {
  #view {
    padding-bottom: calc(var(--player-h-mobile) + var(--tabbar-h) + var(--safe-b) + var(--space-6));
  }
}

/* ---- View transitions ------------------------------------------------- */

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) {
    animation: vt-out var(--dur-base) var(--ease-soft) both;
  }
  ::view-transition-new(root) {
    animation: vt-in var(--dur-slow) var(--ease-out) both;
  }
}

@keyframes vt-out {
  to { opacity: 0; transform: translateY(-6px); }
}

@keyframes vt-in {
  from { opacity: 0; transform: translateY(10px); }
}

/* The persistent chrome must never take part in a page transition — the player
   owns the audio and the header owns the user's place in the site.
   `view-transition-name: none` is the DEFAULT: it means "do not capture me as
   my own named element", which leaves the element inside the root snapshot and
   fades + slides it with the page — the precise opposite of what is wanted.
   Giving each one a unique name lifts it OUT of the root capture; killing the
   group animation then holds it perfectly still across the swap.
   (Descendants of a named element cannot be named individually, so there is no
   `.player-bar *` rule — it never did anything but confirm the default.) */
.player-bar {
  view-transition-name: player;
}

.header {
  view-transition-name: header;
}

::view-transition-group(player),
::view-transition-group(header) {
  animation: none;
}

/* ---- Shared keyframes -------------------------------------------------- */

@keyframes shimmer {
  from { background-position: -160% 0; }
  to { background-position: 260% 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 color-mix(in oklab, var(--brand-live) 45%, transparent); }
  70% { box-shadow: 0 0 0 12px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes eq-bounce {
  0%, 100% { transform: scaleY(0.28); }
  50% { transform: scaleY(1); }
}

@keyframes float-slow {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-14px) rotate(1.2deg); }
}

@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
