/* Crate view: layout and motion only. Colours come from designsystem roles;
   the detail tint is sampled from the cover at runtime (content, not a token). */

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--text-primary);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

.crate-bar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: calc(env(safe-area-inset-top) + var(--space-2)) var(--space-4) var(--space-2);
}

.crate-bar .ds-segmented {
  margin-inline: auto;
}

.crate-count {
  min-width: 5.5rem;
  text-align: right;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.crate-stage {
  /* Covers fill the height between the bar and the dock, like a wall of sleeves;
     on a phone the width caps them so the records either side stay in view. */
  --cover: min(calc((100dvh - 10rem) * 0.86), 42rem, 46vw);
  --thick: calc(var(--cover) * 0.055);
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: grab;
  outline: none;
}

.crate-stage.is-dragging {
  cursor: grabbing;
}

.crate-track {
  position: absolute;
  left: 50%;
  top: calc(50% - 1.5rem);
}

.crate-track,
.crate-flight-lane {
  width: 0;
  height: 0;
  perspective: 3200px;
  perspective-origin: 0 0;
}

/* The sleeve in flight between its slot and the detail view, above the detail backdrop. */
.crate-flight {
  position: fixed;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.crate-flight-lane {
  position: absolute;
}

.crate-flight-shadow {
  position: absolute;
  inset: 0;
  box-shadow: var(--shadow-floating);
  opacity: var(--lift, 0);
}

.crate-item {
  position: absolute;
  left: calc(var(--cover) / -2);
  top: calc(var(--cover) / -2);
  width: var(--cover);
  height: var(--cover);
  transform-origin: 50% 50%;
  transform-style: preserve-3d;
  will-change: transform;
  cursor: pointer;
}

/* A sleeve that is open in the detail view: front and sides fly out together. */
.crate-item.is-out > * {
  visibility: hidden;
}

.crate-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--surface-sunken);
  /* 4.0 has no shadows and near-page surfaces: a hairline keeps plain sleeves visible; cover art paints over it. */
  box-shadow: inset 0 0 0 var(--border-hairline) var(--border-strong);
  backface-visibility: hidden;
}

.crate-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Discogs only has photos of the label: a plain sleeve with the label showing through
   a die-cut centre hole, as white labels and promos actually come. */
.crate-face-diecut {
  background: var(--surface-raised);
}

.crate-face-diecut img {
  position: absolute;
  inset: 27%;
  width: 46%;
  height: 46%;
  border-radius: 50%;
}

.crate-face-diecut::after {
  content: "";
  position: absolute;
  inset: 27%;
  border-radius: 50%;
  box-shadow: var(--shadow-raised);
  outline: 1px solid var(--border-subtle);
  pointer-events: none;
}

.crate-face-missing {
  display: grid;
  place-items: center;
  padding: var(--space-4);
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--font-size-sm, 0.875rem);
}

/* The sleeve's sides: each runs back from an edge of the front, so the sleeve's depth sits
   behind the cover as on a real record, and carries the title.
   A printed sleeve shows the edge of its artwork there; plain and die-cut sleeves stay card. */
.crate-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  width: var(--thick);
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  backface-visibility: hidden;
}

.crate-spine-left {
  left: 0;
  transform-origin: left center;
  transform: translateZ(calc(var(--thick) * -1)) rotateY(-90deg);
}

.crate-spine-right {
  right: 0;
  transform-origin: right center;
  transform: translateZ(calc(var(--thick) * -1)) rotateY(90deg);
}

/* No border on printed sides: it left a strip of page showing at the fold. The extra pixel
   tucks the side under the front so the fold closes at every angle. */
.has-art .crate-spine {
  border: 0;
  width: calc(var(--thick) + 1px);
  background-origin: border-box;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--text-primary) 18%, transparent), transparent 30%, transparent 70%, color-mix(in srgb, var(--text-primary) 18%, transparent)),
    var(--art);
  background-size: 100% 100%, var(--cover) 100%;
  background-repeat: no-repeat;
}

.has-art .crate-spine-left {
  background-position: 0 0, left center;
}

.has-art .crate-spine-right {
  background-position: 0 0, right center;
}

/* The title is printed straight onto the artwork; the ink follows the edge colour
   (data-theme on the spine, set from the cover), with a soft halo for busy prints. */
.has-art .crate-spine span {
  color: var(--text-primary);
  text-shadow: 0 0 3px var(--surface), 0 0 1px var(--surface);
}

.crate-spine span {
  position: absolute;
  left: 50%;
  top: var(--space-3);
  writing-mode: vertical-rl;
  transform: translateX(-50%) rotate(180deg);
  max-height: calc(100% - var(--space-6));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(0.625rem, calc(var(--thick) * 0.5), 0.8125rem);
  line-height: 1;
  color: var(--text-secondary);
}

.crate-spine b {
  color: var(--text-primary);
  font-weight: 600;
}

.crate-empty {
  position: absolute;
  inset: 40% var(--space-6) auto;
  text-align: center;
}

.crate-dock {
  position: fixed;
  inset: auto var(--space-4) calc(env(safe-area-inset-bottom) + var(--space-4));
  z-index: 3;
  max-width: 24rem;
  margin: 0 auto;
  display: grid;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-6);
  border-radius: var(--radius-sheet);
  background: var(--glass-chrome-bg);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  border: var(--border-hairline) solid var(--border-strong);
  box-shadow: var(--shadow-floating);
}

.crate-now {
  display: grid;
  min-height: 2.25rem;
  text-align: center;
  font-size: 0.875rem;
}

.crate-now-artist,
.crate-now-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crate-now-artist {
  font-weight: 600;
}

.crate-now-title {
  color: var(--text-secondary);
}

/* Glass slider: a thin track filled up to a glass capsule thumb that swells while held. */
.crate-scrub {
  --fill: 0%;
  /* The thumb stays a bright capsule in both themes, like a glass lens catching light. */
  --crate-thumb: var(--surface-raised);
  --crate-thumb-edge: var(--border-strong);
  width: 100%;
  height: 1.75rem;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

[data-theme="dark"] .crate-scrub {
  --crate-thumb: var(--text-primary);
  --crate-thumb-edge: var(--border-strong);
}

.crate-scrub::-webkit-slider-runnable-track {
  height: 0.3125rem;
  border-radius: var(--radius-pill);
  background: linear-gradient(to right, var(--text-primary) var(--fill), var(--surface-selected) var(--fill));
}

.crate-scrub::-moz-range-track {
  height: 0.3125rem;
  border-radius: var(--radius-pill);
  background: var(--surface-selected);
}

.crate-scrub::-moz-range-progress {
  height: 0.3125rem;
  border-radius: var(--radius-pill);
  background: var(--text-primary);
}

.crate-scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 2.375rem;
  height: 1.5rem;
  margin-top: -0.59375rem;
  border: 1px solid var(--crate-thumb-edge);
  border-radius: var(--radius-pill);
  background: var(--crate-thumb);
  box-shadow: var(--shadow-floating);
  transition: transform var(--motion-duration-fast) var(--motion-ease-standard);
}

.crate-scrub::-moz-range-thumb {
  width: 2.375rem;
  height: 1.5rem;
  border: 1px solid var(--crate-thumb-edge);
  border-radius: var(--radius-pill);
  background: var(--crate-thumb);
  box-shadow: var(--shadow-floating);
  transition: transform var(--motion-duration-fast) var(--motion-ease-standard);
}

.crate-scrub:active::-webkit-slider-thumb {
  transform: scale(1.18);
}

.crate-scrub:active::-moz-range-thumb {
  transform: scale(1.18);
}

.crate-scrub:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-pill);
}

/* Now playing: shown in the dock while a track plays and its record is not open. */
.crate-playing {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  padding-bottom: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
}

.crate-playing[hidden] {
  display: none;
}

.crate-playing-open {
  display: grid;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}

.crate-playing-title,
.crate-playing-artist {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crate-playing-title {
  font-weight: 600;
}

.crate-playing-artist {
  color: var(--text-secondary);
}

/* Detail: the tapped cover flies here; the whole screen takes the cover's main colour.
   The backdrop fades on its own layer so the flying cover stays fully visible. */
.crate-detail {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: calc(env(safe-area-inset-top) + var(--space-12)) var(--space-6) calc(env(safe-area-inset-bottom) + var(--space-8));
  color: var(--text-primary);
  overflow-y: auto;
}

.crate-detail::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--tint, var(--surface-sunken));
  opacity: 0;
  transition: opacity var(--motion-duration-moderate) var(--motion-ease-standard);
}

.crate-detail.is-open::before {
  opacity: 1;
}

.crate-detail-close {
  position: fixed;
  z-index: 1;
  top: calc(env(safe-area-inset-top) + var(--space-3));
  left: var(--space-4);
  border-radius: var(--radius-pill);
  background: color-mix(in oklab, var(--text-primary) 10%, transparent);
  opacity: 0;
  transition: opacity var(--motion-duration-moderate) var(--motion-ease-standard);
}

.crate-detail-close:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.crate-detail.is-open .crate-detail-close {
  opacity: 1;
}

.crate-detail-body {
  display: grid;
  gap: var(--space-8);
  max-width: 68rem;
  width: 100%;
}

.crate-detail-side {
  display: grid;
  gap: var(--space-6);
  justify-items: center;
  align-content: start;
}

@media (min-width: 48rem) and (orientation: landscape) {
  .crate-detail-body {
    grid-template-columns: minmax(0, 26rem) minmax(0, 1fr);
    align-items: start;
    gap: var(--space-12);
  }
}

.crate-detail-cover {
  width: min(78vw, 46vh, 26rem);
  aspect-ratio: 1;
  overflow: hidden;
  box-shadow: var(--shadow-floating);
  background: var(--surface-sunken);
  transform-origin: 50% 50%;
  will-change: transform;
}

.crate-detail-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.crate-detail-cover.crate-face-diecut {
  position: relative;
  background: var(--surface-raised);
}

.crate-detail-cover.crate-face-diecut img {
  position: absolute;
  inset: 27%;
  width: 46%;
  height: 46%;
}

.crate-detail-reveal {
  opacity: 0;
  transform: translateY(var(--motion-distance-short));
  transition: opacity var(--motion-duration-moderate) var(--motion-ease-decelerate) var(--motion-duration-fast),
              transform var(--motion-duration-moderate) var(--motion-ease-decelerate) var(--motion-duration-fast);
}

.crate-detail.is-open .crate-detail-reveal {
  opacity: 1;
  transform: none;
}

.crate-detail-head {
  display: grid;
  gap: var(--space-1);
  text-align: center;
  max-width: 26rem;
}

.crate-detail-title,
.crate-detail-artist,
.crate-detail-meta {
  margin: 0;
}

.crate-detail-title {
  font-size: 1.25rem;
  line-height: 1.25;
  font-weight: 700;
}

.crate-detail-artist {
  font-size: 1.0625rem;
  font-weight: 500;
}

.crate-detail-meta {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.crate-detail-link {
  color: inherit;
  text-underline-offset: 0.2em;
}

.crate-detail-link::before {
  content: "· ";
}

.crate-detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  width: min(78vw, 46vh, 26rem);
}

.crate-pill {
  min-height: 2.75rem;
  padding: 0 var(--space-6);
  border: 1.5px solid currentColor;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.crate-pill:hover:not(:disabled) {
  background: color-mix(in oklab, var(--text-primary) 10%, transparent);
}

.crate-pill:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.crate-pill:disabled {
  opacity: 0.4;
  cursor: default;
}

.crate-detail-tracks {
  display: grid;
  gap: var(--space-3);
  align-content: start;
  -webkit-user-select: text;
  user-select: text;
}

.crate-player-wrap {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--surface-sunken);
  box-shadow: var(--shadow-floating);
}

.crate-player-wrap[hidden] {
  display: none;
}

/* Mini player: the same iframe, pinned above the dock so the track keeps playing. */
.crate-player-wrap.is-mini {
  position: fixed;
  z-index: 4;
  right: var(--space-4);
  bottom: calc(env(safe-area-inset-bottom) + 10rem);
  width: min(13rem, 42vw);
  border-radius: var(--radius-control);
  border: var(--border-hairline) solid var(--border-strong);
  visibility: visible;
  pointer-events: auto;
}

/* Closed detail that still holds a playing track: invisible and click-through. */
.crate-detail.is-idle {
  visibility: hidden;
  pointer-events: none;
  overflow: hidden;
}

/* The reveal fade and slide would hide or offset the pinned player inside it. */
.crate-detail.is-idle .crate-detail-reveal {
  opacity: 1;
  transform: none;
  transition: none;
}

.crate-player {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.crate-tracklist {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.crate-track-play,
.crate-track-row[data-playable="false"] {
  display: grid;
  grid-template-columns: 2.25rem 1fr auto;
  align-items: baseline;
  gap: var(--space-3);
  width: 100%;
  min-height: 2.875rem;
  padding: var(--space-3) var(--space-3);
  text-align: left;
  font: inherit;
  font-weight: 500;
  color: inherit;
}

.crate-track-play {
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  cursor: pointer;
}

.crate-track-play:hover {
  background: color-mix(in oklab, var(--text-primary) 8%, transparent);
}

.crate-track-play:focus-visible {
  outline: 2px solid var(--text-primary);
  outline-offset: -2px;
}

.crate-track-play[aria-pressed="true"] {
  font-weight: 700;
  background: color-mix(in oklab, var(--text-primary) 12%, transparent);
}

.crate-track-row[data-playable="false"] {
  opacity: 0.5;
}

.crate-track-pos,
.crate-track-time {
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.crate-tracks-note:empty {
  display: none;
}

.crate-tracks-note {
  margin: 0;
  padding-inline: var(--space-3);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

@media (prefers-reduced-motion: reduce) {
  .crate-detail::before,
  .crate-detail-close,
  .crate-detail-reveal {
    transition: none;
  }
}

.crate-detail[hidden] {
  display: none;
}
