@tailwind base;
@tailwind components;
@tailwind utilities;

/* ── Self-hosted fonts (no CDN — see Ethos threat model) ─────────────────── */
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Light.woff2') format('woff2');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-SemiBold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/GeistMono-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/GeistMono-Medium.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* ── Ethos Design Tokens (default dark) ────────────────────────────────────── */
:root {
  /* warm brown-tinted neutral ramp — Ethos law, not cool grey */
  --ethos-bg0: #14110D;
  --ethos-bg1: #1B1712;
  --ethos-bg2: #221D17;
  --ethos-surface0: #2C261D;
  --ethos-surface1: #372F24;
  --ethos-surface2: #423927;
  --ethos-border: rgba(244,234,220,0.09);
  --ethos-border-hi: rgba(244,234,220,0.16);
  --ethos-text: #F4EEE4;
  --ethos-secondary: #B4AA98;
  --ethos-muted: #756C5C;
  --ethos-disabled: #5a5347;
  /* Mono default (Ethos law 1) — machine values sit a step above `muted` so a
     count or a duration stays legible without competing with the human label. */
  --ethos-machine: #9C917D;

  /* muzick fingerprint: honey amber */
  --ethos-accent: #EDA24E;
  --ethos-accent-hover: #E08F32;
  --ethos-on-accent: #14110D;

  /* semantic colors */
  --ethos-green: #22c55e;
  --ethos-amber: #eab308;
  --ethos-red: #ef4444;
  --ethos-purple: #a855f7;
  --ethos-cyan: #22d3ee;
  --ethos-orange: #f97316;
}

/* ── Base reset ───────────────────────────────────────────────────────────── */
body {
  margin: 0;
  padding: 0;
  background-color: var(--ethos-bg0);
  color: var(--ethos-text);
  font-family: 'Geist', -apple-system, BlinkMacSystemFont,
    'Segoe UI', 'Roboto', sans-serif;
  font-size: 14px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#root {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
}

button,
a,
input[type='range'] {
  -webkit-tap-highlight-color: transparent;
}

/* ── Safe area ────────────────────────────────────────────────────────────────
   Installed on Android the app paints edge to edge (viewport-fit=cover), so the
   gesture bar and any display cutout sit on top of the layout. These add the
   inset on top of whatever padding the element already carries. */
.safe-b {
  padding-bottom: calc(var(--safe-b-base, 0px) + env(safe-area-inset-bottom));
}

.safe-x {
  padding-left: calc(var(--safe-x-base, 0px) + env(safe-area-inset-left));
  padding-right: calc(var(--safe-x-base, 0px) + env(safe-area-inset-right));
}

@media (pointer: coarse) {
  input[type='range']::-webkit-slider-thumb {
    width: 18px;
    height: 18px;
    margin-top: -7px;
  }
  input[type='range']::-moz-range-thumb {
    width: 18px;
    height: 18px;
  }
}

/* ── Focus ring: 2px accent, for keyboard users only ──────────────────────── */
:focus-visible {
  outline: 2px solid var(--ethos-accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── Selection ────────────────────────────────────────────────────────────── */
::selection {
  background: color-mix(in srgb, var(--ethos-accent) 35%, transparent);
  color: var(--ethos-text);
}

/* ── Scrollbars (thin, themed) ────────────────────────────────────────────── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--ethos-border) transparent;
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--ethos-border) 80%, transparent);
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--ethos-muted) 60%, transparent);
  background-clip: padding-box;
}

/* ── Smooth scroll for main content ───────────────────────────────────────── */
html { scroll-behavior: smooth; }

/* ── Utility classes ──────────────────────────────────────────────────────── */

/* Surfaced bar (top bar / playback bar) — depth from light, not blur */
.glass {
  background: var(--ethos-bg1);
  border-top: 1px solid var(--ethos-border);
  box-shadow: 0 2px 8px rgba(0,0,0,.35), 0 12px 32px rgba(0,0,0,.28);
}

/* Hide scrollbars but keep scroll behavior */
.scrollbar-hide {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.scrollbar-hide::-webkit-scrollbar { display: none; }

/* Skeleton shimmer */
@keyframes shimmer {
  0% { opacity: 0.4; }
  50% { opacity: 0.8; }
  100% { opacity: 0.4; }
}
.skeleton {
  animation: shimmer 1.5s ease-in-out infinite;
  background: var(--ethos-surface1);
  border-radius: 4px;
}

/* Vibe's profile aura: a small, old-player-inspired creature whose color and
   movement come from the active recommendation state. */
@keyframes vibe-aura-pulse {
  0%, 100% { transform: scale(var(--vibe-scale)) rotate(-7deg); filter: brightness(.9); }
  50% { transform: scale(calc(var(--vibe-scale) * 1.12)) rotate(8deg); filter: brightness(1.28); }
}
@keyframes vibe-aura-orbit {
  to { transform: rotate(360deg); }
}
@keyframes vibe-aura-spark {
  0%, 100% { transform: translateY(0) scale(.75); opacity: .38; }
  50% { transform: translateY(-5px) scale(1.15); opacity: 1; }
}
.vibe-aura-halo {
  position: absolute;
  inset: 7px;
  border-radius: 9999px;
  background: hsl(var(--vibe-hue) 88% 62% / .22);
  filter: blur(12px);
  animation: vibe-aura-pulse var(--vibe-pulse) ease-in-out infinite;
}
.vibe-aura-core {
  position: relative;
  width: 30px;
  height: 36px;
  border: 1px solid hsl(var(--vibe-hue) 95% 86% / .72);
  border-radius: 46% 54% 58% 42% / 43% 45% 55% 57%;
  background: radial-gradient(circle at 36% 28%, hsl(var(--vibe-hue) 100% 93%), hsl(var(--vibe-hue) 88% 61%) 38%, hsl(calc(var(--vibe-hue) + 35) 68% 31%) 100%);
  box-shadow: inset 3px 2px 8px hsl(0 0% 100% / .34), 0 0 17px hsl(var(--vibe-hue) 92% 59% / .78);
  animation: vibe-aura-pulse var(--vibe-pulse) ease-in-out infinite;
}
.vibe-aura-orbit {
  position: absolute;
  width: 47px;
  height: 47px;
  border: 1px solid hsl(var(--vibe-hue) 90% 76% / .36);
  border-radius: 47% 53% 43% 57%;
  animation: vibe-aura-orbit var(--vibe-orbit) linear infinite;
}
.vibe-aura-orbit-two {
  width: 56px;
  height: 37px;
  border-color: hsl(calc(var(--vibe-hue) + 55) 90% 76% / .24);
  animation-direction: reverse;
  animation-duration: calc(var(--vibe-orbit) * 1.45);
}
.vibe-aura-heart,
.vibe-aura-spark {
  position: absolute;
  display: block;
  border-radius: 9999px;
  background: hsl(0 0% 100% / .9);
  box-shadow: 0 0 8px hsl(0 0% 100% / .92);
}
.vibe-aura-heart { width: 7px; height: 7px; left: 11px; top: 15px; }
.vibe-aura-spark { width: 4px; height: 4px; animation: vibe-aura-spark 2.1s ease-in-out infinite; }
.vibe-aura-spark-one { left: -4px; top: 5px; }
.vibe-aura-spark-two { right: -3px; bottom: 7px; animation-delay: -1s; }
/* Ambient variant: a plasma in the page background, in the lineage of a media
   player visualizer. Three layers — a hot core, a cooler counter-rotating
   companion, and a fan of rays — stacked and pushed through one SVG turbulence
   displacement pass (see VibeAura.tsx), which is what turns clean gradients
   into churning flame. Centering lives on the wrapper, never here: these
   keyframes animate `transform` and would overwrite it. */
/* Anchor lives here, not in utility classes: the offsets differ per breakpoint
   and the -50% centering pair sits on the same element, so keeping both in one
   place is what stops the two from fighting. Off to the right on purpose — the
   reading column stays clear and the plasma bleeds past the track rows. */
.vibe-aura-blob {
  left: 62%;
  top: 52%;
}
@media (min-width: 640px) {
  .vibe-aura-blob { left: 80%; top: 56%; }
}
.vibe-aura-stack {
  position: absolute;
  inset: 0;
  /* Blur alone is the cheap variant, and the only one phones get. The
     displacement pass is added by .vibe-aura-stack-plasma, which VibeAura
     applies only when it has also mounted the filter it names. */
  filter: blur(14px);
}
.vibe-aura-stack-plasma {
  filter: url(#vibe-plasma) blur(14px);
}
.vibe-aura-layer {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  mix-blend-mode: screen;
}
@keyframes vibe-aura-churn {
  0%   { transform: scale(var(--vibe-scale)) translate3d(-7%, -4%, 0) rotate(0deg); }
  33%  { transform: scale(calc(var(--vibe-scale) * 1.22)) translate3d(6%, -8%, 0) rotate(120deg); }
  66%  { transform: scale(calc(var(--vibe-scale) * 0.9)) translate3d(8%, 7%, 0) rotate(240deg); }
  100% { transform: scale(var(--vibe-scale)) translate3d(-7%, -4%, 0) rotate(360deg); }
}
@keyframes vibe-aura-spin {
  from { transform: rotate(0deg) scale(var(--vibe-scale)); }
  to   { transform: rotate(-360deg) scale(var(--vibe-scale)); }
}
@keyframes vibe-aura-breathe {
  from { opacity: .55; transform: scale(.86); }
  to   { opacity: 1; transform: scale(1.12); }
}
/* Hot core — near-white centre falling to the profile hue. */
.vibe-aura-core-layer {
  background:
    radial-gradient(closest-side at 47% 44%, hsl(calc(var(--vibe-hue) + 24) 100% 82% / .95), hsl(var(--vibe-hue) 100% 58% / .75) 38%, transparent 70%),
    radial-gradient(closest-side at 58% 58%, hsl(calc(var(--vibe-hue) - 12) 100% 50% / .8), transparent 66%);
  animation: vibe-aura-churn var(--vibe-orbit) ease-in-out infinite;
}
/* Companion — turns the other way so the two shear against each other. */
.vibe-aura-swirl-layer {
  background:
    radial-gradient(closest-side at 62% 40%, hsl(calc(var(--vibe-hue) - 20) 100% 54% / .7), transparent 68%),
    radial-gradient(closest-side at 36% 66%, hsl(calc(var(--vibe-hue) - 44) 96% 50% / .58), transparent 72%);
  animation: vibe-aura-churn calc(var(--vibe-orbit) * 1.6) ease-in-out infinite reverse;
}
/* Ray fan — the spikes the displacement pass bends into filaments. Masked to a
   ring so the centre stays a clean hot core. */
.vibe-aura-rays-layer {
  background: repeating-conic-gradient(
    from 0deg,
    transparent 0deg 5deg,
    hsl(calc(var(--vibe-hue) + 8) 100% 66% / .5) 5deg 7.5deg
  );
  -webkit-mask-image: radial-gradient(closest-side, transparent 18%, #000 46%, transparent 82%);
  mask-image: radial-gradient(closest-side, transparent 18%, #000 46%, transparent 82%);
  animation: vibe-aura-spin calc(var(--vibe-orbit) * 2.4) linear infinite;
}
/* Pulse at the profile's tempo. This lives on the stack, not on the outer
   .vibe-aura-blob: that element carries the -translate-x-1/2 -translate-y-1/2
   centering, and an animation setting `transform` overwrites it, which anchors
   the plasma by its top-left corner instead of its middle. */
.vibe-aura-stack {
  animation: vibe-aura-breathe var(--vibe-pulse) ease-in-out infinite alternate;
}
@media (min-width: 640px) {
  .vibe-aura-stack { filter: blur(20px); }
  .vibe-aura-stack-plasma { filter: url(#vibe-plasma) blur(20px); }
}
@media (prefers-reduced-motion: reduce) {
  .vibe-aura-halo, .vibe-aura-core, .vibe-aura-orbit, .vibe-aura-spark,
  .vibe-aura-stack, .vibe-aura-layer { animation: none; }
}

/* ── Component base classes ────────────────────────────────────────────────── */

/* Card surface — standard container */
.card-surface {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-radius: 8px;
  border: 1px solid var(--ethos-border);
  background: var(--ethos-surface0);
  padding: 12px;
  transition: background 150ms ease, border-color 150ms ease;
}
.card-surface:hover {
  background: var(--ethos-surface1);
  border-color: color-mix(in srgb, var(--ethos-accent) 40%, transparent);
}

/* Track list — one dense, hairline-separated column everywhere a list of tracks
   appears. Replaces the per-page `space-y-1` around bordered row cards, which
   cost 90px per track and fit only 7 rows on a 900px screen. */
.track-list > * + * {
  border-top: 1px solid color-mix(in srgb, var(--ethos-border) 60%, transparent);
}

/* Row hover: light falling off to the right, not a filled slab. A flat
   770px-wide rectangle with a hard right edge is the ugly version, and it also
   squares off the Vibe timeline's stacked artwork. */
.track-row:hover {
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--ethos-surface1) 85%, transparent) 0%,
    color-mix(in srgb, var(--ethos-surface1) 40%, transparent) 38%,
    transparent 78%
  );
}

/* Artwork frame */
.artwork-frame {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
}

/* Play button overlay */
.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.5), transparent 60%);
  opacity: 0;
  transition: opacity 150ms ease;
}
.group:hover .play-overlay { opacity: 1; }
.play-overlay-btn {
  width: 44px;
  height: 44px;
  border-radius: 9999px;
  background: var(--ethos-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ethos-on-accent);
  box-shadow: 0 8px 24px -4px color-mix(in srgb, var(--ethos-accent) 40%, transparent);
  transform: translateY(8px);
  transition: transform 150ms ease;
}
.group:hover .play-overlay-btn { transform: translateY(0); }

/* Settings library actions use a compact, stateful button rather than an
   unstyled native control. */
.admin-btn {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--ethos-border-hi);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--ethos-surface1);
  color: var(--ethos-text);
  font-size: 13px;
  font-weight: 500;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}
.admin-btn:hover:not(:disabled) {
  background: var(--ethos-surface2);
  border-color: color-mix(in srgb, var(--ethos-accent) 50%, transparent);
}
.admin-btn:disabled { cursor: wait; opacity: 0.65; }
.admin-btn--done { border-color: color-mix(in srgb, var(--ethos-green) 60%, transparent); color: var(--ethos-green); }
.admin-btn--error { border-color: color-mix(in srgb, var(--ethos-red) 60%, transparent); color: var(--ethos-red); }

/* Keep row actions available on touch. On pointer-and-hover devices, reveal
   them when the row is hovered or any of its controls receives focus. */
.track-row-actions { opacity: 1; transition: opacity 150ms ease; }
@media (hover: hover) and (pointer: fine) {
  .track-row-actions { opacity: 0; }
  .group:hover .track-row-actions,
  .group:focus-within .track-row-actions { opacity: 1; }
}

/* Transport button */
.transport-btn {
  width: 40px;
  height: 40px;
  border-radius: 9999px;
  background: var(--ethos-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ethos-on-accent);
  transition: background 150ms ease, transform 150ms ease;
}
.transport-btn:hover { background: var(--ethos-accent-hover); transform: scale(1.06); }
.transport-btn:active { transform: scale(0.94); }
.transport-btn:disabled { opacity: 0.4; }

/* Gradient text — used sparingly for page headings */
.text-gradient {
  background: linear-gradient(120deg, var(--ethos-text), color-mix(in srgb, var(--ethos-accent) 75%, var(--ethos-text)));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Range slider styling */
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--ethos-border) 90%, transparent);
}
input[type='range']::-moz-range-track {
  height: 4px;
  border-radius: 9999px;
  background: color-mix(in srgb, var(--ethos-border) 90%, transparent);
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 9999px;
  background: var(--ethos-accent);
  margin-top: -4px;
  transition: transform 150ms ease;
}
input[type='range']:hover::-webkit-slider-thumb { transform: scale(1.15); }
input[type='range']::-moz-range-thumb {
  width: 12px; height: 12px; border: none;
  border-radius: 9999px; background: var(--ethos-accent);
}
input[type='range']:focus-visible {
  outline: none;
}
input[type='range']:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--ethos-accent) 30%, transparent);
}
input[type='range']:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--ethos-accent) 30%, transparent);
}
