/* Shared look of the whole app: a crate of records you flip through, and a
   turntable for the record you open. Component styles reuse these tokens. */

:root {
  --room:       #1b1416;   /* the dark room behind everything */
  --room-up:    #251c1f;
  --line:       #3a2e31;
  --ink:        #f1e6dc;
  --ink-soft:   #b39c94;
  --ink-faint:  #7d6b66;
  --label:      #e9b9a0;   /* paper of a record label */
  --label-ink:  #3a2420;
  --groove-a:   #141012;
  --groove-b:   #211a1c;
  --metal:      #cfc6bd;
  --metal-dark: #8d8580;
  --live:       #8fe3a4;

  --font-title: "Fraunces", Georgia, serif;
  --font-body:  "Be Vietnam Pro", system-ui, sans-serif;
  --font-data:  "Space Grotesk", "Be Vietnam Pro", sans-serif;

  --gutter: 24px;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 70% at 50% 0%, var(--room-up), var(--room) 60%);
  background-color: var(--room);
  color: var(--ink);
  font: 300 16px/1.5 var(--font-body);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* film grain over everything */
.grain {
  position: fixed; inset: 0; z-index: 1000; pointer-events: none;
  opacity: .2; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.title {
  margin: 0;
  font: italic 300 clamp(38px, 11vw, 52px)/1.02 var(--font-title);
  letter-spacing: -0.01em;
}
.sub { margin: 6px 0 0; color: var(--ink-soft); font-size: 15px; }
.data { font: 400 13px var(--font-data); color: var(--ink-soft); }

/* ---------- home: the crate ---------- */

.home {
  max-width: 560px; margin: 0 auto; padding: 44px 0 32px;
  min-height: 100dvh; display: flex; flex-direction: column;
}
.home > #crate-mount { margin: auto 0; }
.home-head { padding: 0 var(--gutter); }
.home-head h1 { margin: 0; font: italic 300 clamp(40px, 12vw, 56px)/1 var(--font-title); letter-spacing: -0.015em; }
.home-head p { margin: 10px 0 0; color: var(--ink-soft); font-size: 15px; }

/* Records stand one behind the other, seen slightly from above. The front
   one is fully visible; flipping tips it forward and the next one shows. */
.crate { --sleeve: min(70vw, 290px); margin-top: 18px; }
.crate-stage {
  position: relative;
  height: calc(var(--sleeve) * 1.5);
  perspective: 1100px;
  perspective-origin: 50% -20%;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  outline: none;
}
.crate-item {
  position: absolute; left: 50%; bottom: calc(var(--sleeve) * 0.12);
  width: var(--sleeve); margin-left: calc(var(--sleeve) / -2);
  appearance: none; border: 0; padding: 0; background: none; color: inherit; text-align: left;
  cursor: pointer;
  transform-origin: 50% 100%;
  will-change: transform, opacity;
}
.crate-item[aria-disabled="true"] { cursor: default; }

/* the record inside: peeks out of the top of the front sleeve */
.sleeve-disc {
  position: absolute; left: 6%; right: 6%; top: 0; aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--label) 0 15%, transparent 15.5%),
    repeating-radial-gradient(circle, var(--groove-a) 0 1.5px, var(--groove-b) 1.5px 3.5px);
  box-shadow: 0 0 0 1px #2b2326;
  transform: translateY(0);
  transition: transform .5s var(--ease-out);
}
.crate-item.is-front .sleeve-disc { transform: translateY(-12%); }

.sleeve {
  position: relative;
  aspect-ratio: 1;
  border-radius: 2px;
  overflow: hidden;
  background: var(--room-up);
  box-shadow: 0 22px 40px rgba(0,0,0,.6), 0 2px 4px rgba(0,0,0,.4);
  transition: transform .45s var(--ease-out), box-shadow .45s var(--ease-out);
}
/* printed-cardboard feel shared by every sleeve: ring wear from the disc
   inside, a soft fold shadow at the open edge, worn corners */
.sleeve::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 50% 50%, transparent 41%, rgba(255,255,255,.09) 42.5%, transparent 44.5%),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.05) 0 13%, transparent 13.5%),
    linear-gradient(180deg, rgba(0,0,0,.28), transparent 7%),
    linear-gradient(90deg, rgba(255,255,255,.06), transparent 3%, transparent 97%, rgba(0,0,0,.2));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06), inset 0 0 22px rgba(0,0,0,.25);
}
.sleeve-art { position: absolute; inset: 0; overflow: hidden; }
.sleeve-name {
  position: absolute; left: 18px; right: 18px; top: 16px; z-index: 1;
  font: italic 300 30px/1.02 var(--font-title); color: #fff;
}
.sleeve-meta {
  position: absolute; left: 18px; right: 18px; bottom: 15px; z-index: 1;
  display: flex; justify-content: space-between; gap: 10px;
  font: 400 12px var(--font-data); color: rgba(255,255,255,.78);
}

/* hover and press: the sleeve swells a little and the record rises */
@media (hover: hover) {
  .crate-item.is-front:hover .sleeve { transform: scale(1.045); box-shadow: 0 30px 60px rgba(0,0,0,.65), 0 2px 4px rgba(0,0,0,.4); }
  .crate-item.is-front:hover .sleeve-disc { transform: translateY(-26%); }
}
.crate-item.is-front:active .sleeve { transform: scale(1.03); }
.crate-item.is-front:active .sleeve-disc { transform: translateY(-22%); }

/* blank: a plain white-label sleeve with the centre cut out */
.sleeve.is-blank { background: #e9e2d8; }
.sleeve.is-blank .sleeve-art {
  background: radial-gradient(circle, transparent 0 17%, rgba(0,0,0,.18) 17.5%, transparent 19%);
}
.sleeve.is-blank .sleeve-art::before {
  content: ""; position: absolute; left: 50%; top: 50%; width: 34%; height: 34%; transform: translate(-50%, -50%);
  border-radius: 50%; background: radial-gradient(circle, var(--room) 0 4%, var(--label) 5%);
}
.sleeve.is-blank .sleeve-name { color: #3a2e2a; }
.sleeve.is-blank .sleeve-meta { color: rgba(58,46,42,.7); }

.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--ink-faint); vertical-align: 1px; }
.dot.on { background: var(--live); box-shadow: 0 0 8px var(--live); }

.crate-caption { padding: 0 var(--gutter); text-align: center; min-height: 76px; }
.crate-caption b { display: block; font: italic 300 26px var(--font-title); }
.crate-caption span { display: block; color: var(--ink-soft); font-size: 14px; }
.crate-count { margin-top: 10px; display: flex; justify-content: center; gap: 7px; }
.crate-count i { width: 5px; height: 5px; border-radius: 50%; background: var(--line); transition: background-color .3s, transform .3s; }
.crate-count i.on { background: var(--ink); transform: scale(1.3); }

/* ---------- player: the turntable ---------- */

.player {
  position: fixed; inset: 0; z-index: 500;
  overflow-y: auto;
  background: radial-gradient(120% 70% at 50% 0%, var(--room-up), var(--room) 60%);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.player[hidden] { display: none; }
.player { opacity: 0; transition: opacity .35s var(--ease-out); }
.player.is-visible { opacity: 1; }
.player-inner { max-width: 480px; margin: 0 auto; padding: 18px var(--gutter) 40px; }

.player-back {
  appearance: none; border: 0; background: none; color: var(--ink-soft);
  font: 400 15px var(--font-body); padding: 10px 0; margin-bottom: 14px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.player-back svg { width: 9px; height: 15px; }

/* the deck: record + glow ring + tonearm. Sizes in % of the deck width. */
.deck { position: relative; width: 100%; aspect-ratio: 1 / 0.92; margin-top: 18px; touch-action: none; }
.record {
  position: absolute; left: 1%; top: 7%; width: 78%; aspect-ratio: 1;
  border-radius: 50%;
}
.record-glow { position: absolute; inset: -5%; border-radius: 50%; filter: blur(18px); opacity: 0; transition: opacity .5s; }
.record-disc {
  position: absolute; inset: 0; border-radius: 50%;
  background: repeating-radial-gradient(circle, var(--groove-a) 0 1.5px, var(--groove-b) 1.5px 3.5px);
  box-shadow: 0 0 0 1px #2b2326, 0 30px 60px rgba(0,0,0,.6);
  animation: spin var(--spin, 0s) linear infinite;
  animation-play-state: var(--spin-state, paused);
}
/* fixed light reflection: makes the spin visible on a round disc */
.record-sheen {
  position: absolute; inset: 0; border-radius: 50%; pointer-events: none;
  background: conic-gradient(from 20deg, transparent 0 8%, rgba(255,255,255,.07) 12%, transparent 18% 58%, rgba(255,255,255,.05) 62%, transparent 68%);
}
.record-label {
  position: absolute; left: 50%; top: 50%; width: 40%; height: 40%; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--label); color: var(--label-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.record-label b { font: 300 clamp(30px, 10vw, 44px)/1 var(--font-title); letter-spacing: -0.02em; }
.record-label span { font: 400 11px var(--font-data); margin-top: 4px; opacity: .8; }
.record-mark { position: absolute; left: 50%; top: 4%; width: 2px; height: 7%; margin-left: -1px; background: var(--label-ink); opacity: .35; border-radius: 1px; }

.tonearm { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.tonearm-base {
  position: absolute; width: 34px; height: 34px; margin: -17px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #efe8e1, var(--metal-dark));
  box-shadow: 0 6px 14px rgba(0,0,0,.5);
}
.tonearm-rod {
  position: absolute; width: 6px; margin-left: -3px; border-radius: 3px;
  background: linear-gradient(90deg, var(--metal-dark), #f3ede6 50%, var(--metal-dark));
  transform-origin: 50% 0;
  transition: transform .45s var(--ease-out);
  box-shadow: 4px 8px 10px rgba(0,0,0,.35);
  pointer-events: auto; cursor: grab; touch-action: none;
}
.tonearm-rod::after {   /* cartridge */
  content: ""; position: absolute; left: -7px; bottom: -6px; width: 20px; height: 28px; border-radius: 3px;
  background: linear-gradient(#e6ddd5, var(--metal-dark));
}
.tonearm-rod::before {  /* wider invisible grab area */
  content: ""; position: absolute; left: -22px; right: -22px; top: 30%; bottom: -20px;
}
.deck.is-dragging .tonearm-rod { transition: none; cursor: grabbing; }
.tonearm-rod:focus-visible { outline: 3px solid var(--label); outline-offset: 4px; }

.deck-hint { margin: 6px 0 0; text-align: right; }

/* pills */
.pills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 26px; }
.pill {
  appearance: none; cursor: pointer;
  border: 1px solid #4a3a3d; border-radius: 999px; background: none;
  padding: 12px 0; color: var(--ink-soft);
  font: 400 16px var(--font-body);
  transition: background-color .25s, color .25s, border-color .25s;
  touch-action: manipulation;
}
.pill.is-active { background: var(--ink); color: var(--room); border-color: var(--ink); }
.pill.is-pending { border-color: var(--ink); color: var(--ink); animation: breathe 1s ease-in-out infinite; }
.pill:disabled { cursor: default; opacity: .45; }

.player-note { margin: 18px 0 0; color: var(--ink-soft); font-size: 14px; min-height: 1.5em; }

:focus-visible { outline: 2px solid var(--label); outline-offset: 3px; }
.crate-stage:focus-visible { outline: none; }
.crate-stage:focus-visible .crate-item.is-front .sleeve { outline: 2px solid var(--label); outline-offset: 4px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { opacity: .45; } }

/* the record slides out of its sleeve onto the deck */
.player.is-opening .record { animation: slide-out .7s var(--ease-out) both; }
.player.is-opening .tonearm-rod { transition-delay: .45s; }
@keyframes slide-out { from { transform: translateX(-70%) rotate(-40deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
