/* Music player: an original retro handheld ("player") drawn in CSS. Semantic tokens only.
   Gloss colors come from --player-* tokens in styles/os9.css (retuned per theme);
   --player-gloss scales their strength (one knob for all of it; tested with CRT on, no trim needed).
   --player-scale sizes the whole device via CSS zoom (layout box shrinks too, no dead space).
   Platinum body (OS 9 tokens), recessed screen, circular click wheel.
   Pink (--accent-2) is the ONLY accent: the progress fill and the play indicator.
   Behavior: components/player.js. Markup: see the home sidebar in index.html. */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Size ---------- */
:root {
  --player-scale: 0.85; /* desktop: 15% smaller */
  --player-tilt: -9deg;  /* body tilt; the stickers rotate with it */
}

/* ---------- Body ---------- */
.player {
  /* gloss strengths, scaled by --player-gloss */
  --hl: color-mix(in srgb, var(--player-highlight) var(--player-gloss), transparent);
  --rf: color-mix(in srgb, var(--player-reflect) var(--player-gloss), transparent);
  --gl: color-mix(in srgb, var(--player-glare) var(--player-gloss), transparent);
  --sh: color-mix(in srgb, var(--player-sheen) var(--player-gloss), transparent);
  zoom: var(--player-scale);
  position: relative;
  z-index: 1; /* below the decorative stickers' layer is fine: stickers never take pointer events */
  display: grid;
  gap: 14px;
  width: 100%;
  max-width: 250px;
  margin: 6px auto 0;
  padding: 14px 14px 16px;
  background-color: var(--os-face);
  background-image: linear-gradient(to bottom, var(--player-body-top), var(--os-face) 55%, var(--player-body-bottom));
  color: var(--os-text);
  border: 1px solid var(--os-outline);
  border-radius: 22px;
  box-shadow:
    inset 0 0 0 1px var(--player-edge),   /* thin bright inner edge */
    inset 0 -2px 0 1px var(--os-lo),
    3px 3px 0 var(--shadow-small);
  transform: rotate(var(--player-tilt));
  font-family: var(--font-chrome);
  font-size: var(--os-size);
}

/* Gloss overlay: curved highlight + bottom reflection, painted OVER the stickers so they read as
   part of the glossy surface. Stack: body < under-wheel stickers (.player__deco--under) < wheel < stickers (.player__deco) < gloss < screen. */
.player::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 21px;
  background:
    radial-gradient(ellipse 125% 44% at 50% 0%, var(--hl) 0%, var(--hl) 30%, transparent 74%), /* curved highlight */
    linear-gradient(to top, transparent 2px, var(--rf) 6px, transparent 18px);       /* reflection near the bottom */
  /* the body's edge, redrawn over the stickers: anything crossing it looks wrapped around the side */
  box-shadow: inset 0 0 0 1px var(--player-edge), inset 0 -2px 0 1px var(--os-lo);
  pointer-events: none;
}

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

/* ---------- Screen ---------- */
.player__screen {
  position: relative;
  z-index: 3; /* above stickers + body gloss; it has its own glare */
  display: grid;
  align-content: start;
  gap: 5px;
  height: 158px; /* fixed (same outer size as before the bezel), so the wheel doesn't jump between views */
  padding: 5px 8px 5px;
  overflow: hidden;
  color: var(--os-text);
  border: 4px solid transparent; /* the bezel */
  border-radius: 8px;
  background:
    linear-gradient(var(--os-content), var(--os-content)) padding-box,
    linear-gradient(145deg, var(--player-bezel-a), var(--player-bezel-b) 55%, var(--player-bezel-a)) border-box;
  box-shadow:
    0 0 0 1px var(--os-outline),
    0 1px 0 1px var(--player-edge),
    inset 2px 2px 0 var(--os-lo-soft);
}

/* Glass glare: above the content, never blocks clicks */
.player__screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--gl) 0%, transparent 52%);
  pointer-events: none;
}

.player__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--os-lo-soft);
  font-size: 11px;
}

.player__state { color: var(--os-text-muted); }
.player__state svg { width: 9px; height: 9px; display: block; }
.player__state svg path { fill: currentColor; }
.player__state .player__state-pause { display: none; }
.player[data-playing="true"] .player__state { color: var(--accent-2); }      /* pink play indicator */
.player[data-playing="true"] .player__state .player__state-play { display: none; }
.player[data-playing="true"] .player__state .player__state-pause { display: block; }

/* Now Playing */
.player__now { display: grid; gap: 5px; }
.player__now[hidden],
.player__menu[hidden],
.player__volume[hidden] { display: none; }

.player__meta {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.player__cover {
  width: 52px;
  height: 52px;
  background: var(--os-face);
  border: 1px solid var(--os-outline);
}

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

.player__text { display: grid; gap: 1px; min-width: 0; }
.player__title,
.player__artist,
.player__count {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis; /* no scrolling text, ever */
}
.player__title { font-size: 12px; }
.player__artist { font-family: var(--font-chrome-text); font-size: 11px; color: var(--os-text-muted); }
.player__count { font-size: 10px; color: var(--os-text-muted); }

/* Progress (keyboard operable range) */
.player__seek {
  --p: 0%;
  width: 100%;
  height: 10px;
  margin: 2px 0 0;
  appearance: none;
  -webkit-appearance: none;
  background: linear-gradient(to right, var(--accent-2) var(--p), var(--os-field) var(--p)); /* pink fill */
  border: 1px solid var(--os-outline);
  border-radius: 0;
  cursor: pointer;
}
.player__seek::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 6px;
  height: 12px;
  background: var(--os-face);
  border: 1px solid var(--os-outline);
}
.player__seek::-moz-range-thumb {
  width: 6px;
  height: 12px;
  background: var(--os-face);
  border: 1px solid var(--os-outline);
  border-radius: 0;
}
.player__seek:disabled { cursor: default; opacity: 0.5; }

.player__times {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--os-text-muted);
  font-variant-numeric: tabular-nums;
}

/* Gentle "press play" cue until the first play this visit */
.player__cue {
  margin: 0;
  font-size: 11px;
  text-align: center;
  color: var(--os-text-muted);
  animation: player-breathe 3.5s ease-in-out infinite;
}
.player[data-started="true"] .player__cue { display: none; }
@keyframes player-breathe { 50% { opacity: 0.55; } }

/* Menu (track list) */
.player__list {
  display: grid;
  gap: 1px;
  max-height: 118px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.player__item {
  display: grid;
  width: 100%;
  padding: 3px 6px;
  text-align: left;
  background: transparent;
  color: var(--os-text);
  border: 0;
  font: inherit;
  cursor: pointer;
}
.player__item-title,
.player__item-artist { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.player__item-title { font-size: 12px; }
.player__item-artist { font-family: var(--font-chrome-text); font-size: 11px; color: var(--os-text-muted); }
.player__item:hover { background: var(--os-face); }
.player__item[aria-current="true"],
.player__item[aria-current="true"] .player__item-artist { background: var(--os-select-bg); color: var(--os-select-text); }
.player__item:disabled { cursor: default; opacity: 0.6; }
.player__item:focus-visible { outline-offset: -2px; }

/* Volume overlay */
.player__volume {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: var(--os-face);
  border: 1px solid var(--os-outline);
  box-shadow: inset 1px 1px 0 var(--os-hi);
  font-size: 11px;
}
.player__volume svg { width: 14px; height: 12px; flex: none; }
.player__volume svg path:first-child { fill: currentColor; }
.player__volbar {
  --v: 35%;
  flex: 1;
  height: 8px;
  background: var(--os-field);
  border: 1px solid var(--os-outline);
}
.player__volbar i { display: block; width: var(--v); height: 100%; background: var(--fill); }
.player__volnum { min-width: 3.2ch; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Click wheel ---------- */
.player__wheel {
  position: relative;
  z-index: 0; /* stickers may overlap its rim (never its buttons) */
  width: 160px;
  height: 160px;
  margin: 0 auto;
  border-radius: 50%;
  background-color: var(--os-btn-face);
  background-image:
    radial-gradient(ellipse 80% 55% at 50% 18%, var(--sh), transparent 70%),
    linear-gradient(to bottom, var(--player-body-top), var(--player-body-bottom));
  border: 1px solid var(--os-outline);
  box-shadow: inset 0 0 0 1px var(--player-edge), inset 0 -2px 0 1px var(--os-lo);
}

.player__btn,
.player__center {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--os-text);
  background: transparent;
  border: 0;
  cursor: pointer;
  font: inherit;
}

/* 44px tap targets on every wheel button */
.player__btn { width: 48px; height: 44px; border-radius: 8px; }
.player__btn svg { width: 16px; height: 12px; fill: currentColor; }
.player__btn--menu { top: 4px; left: 50%; margin-left: -24px; font-size: 11px; letter-spacing: 0.04em; }
.player__btn--vol { bottom: 4px; left: 50%; margin-left: -24px; }
.player__btn--left { left: 2px; top: 50%; margin-top: -22px; width: 44px; }
.player__btn--right { right: 2px; top: 50%; margin-top: -22px; width: 44px; }
.player__btn:hover { color: var(--os-text-muted); }
.player__btn:active { background: var(--os-face-pressed); }
.player__btn--vol[aria-pressed="true"],
.player__btn--menu[aria-expanded="true"] { background: var(--os-face-pressed); }

.player__center {
  top: 50%;
  left: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background-color: var(--os-face);
  background-image:
    radial-gradient(circle at 50% 28%, var(--sh), transparent 62%),
    linear-gradient(to bottom, var(--player-body-top), var(--player-body-bottom));
  border: 1px solid var(--os-outline);
  box-shadow: inset 0 1px 0 var(--player-edge), 0 2px 0 var(--os-lo); /* slightly raised */
}
.player__center svg { width: 16px; height: 16px; fill: currentColor; }
.player__center:active {
  background-image: linear-gradient(to top, var(--player-body-top), var(--player-body-bottom)); /* pressed in */
  box-shadow: inset 0 2px 0 var(--os-lo);
  transform: translateY(1px);
}
.player__icon-pause { display: none; }
.player[data-playing="true"] .player__icon-play { display: none; }
.player[data-playing="true"] .player__icon-pause { display: block; }

/* ---------- Stickers glued to the body ---------- */
/* Children of .player, so they tilt + scale with it. Under the gloss overlay. Never take clicks.
   A collage: stickers cluster and overlap each other, may overlap the wheel's rim, and may run off the
   body's edge, where the layer clips them to the rounded outline so they read as wrapped around it.
   They always stay off the screen and >= 5px from every wheel button.
   Placement comes from custom properties on each sticker:
   --s-x / --s-y  the sticker's CENTER, % of the body's width / height (.player__deco = the body's inner box)
   --s-w          width, % of the body's width (height follows the image's aspect ratio)
   --s-r          rotation, on top of the body's own --player-tilt
   --s-z          stack order among the stickers in the same layer (each .player__deco is its own stacking
                  context, so a sticker can never rise above the gloss or the screen)
   The values live in the "Sticker placement" block below. */
.player__deco {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  border-radius: 21px;
  pointer-events: none;
}

/* Under-wheel layer (the rainbow flag): same box, but under the click wheel (z-index 0);
   still above the body's own fill, and the gloss still passes over it */
.player__deco--under { z-index: -1; }

.player__sticker {
  position: absolute;
  left: var(--s-x, 50%);
  top: var(--s-y, 50%);
  z-index: var(--s-z, auto);
  width: var(--s-w, 20%);
  height: auto;
  transform: translate(-50%, -50%) rotate(var(--s-r, 0deg)); /* centered on (--s-x, --s-y), spins around its center */
  /* white sticker border + a tight, faint, hard shadow so it sits flat on the surface */
  filter:
    drop-shadow(2px 0 0 var(--player-sticker-border))
    drop-shadow(-2px 0 0 var(--player-sticker-border))
    drop-shadow(0 2px 0 var(--player-sticker-border))
    drop-shadow(0 -2px 0 var(--player-sticker-border))
    drop-shadow(1px 1px 0 var(--player-sticker-shadow));
}

/* ---------- Sticker placement ----------
   One line per sticker (data-sticker in index.html). Body stickers: % of the player body.
   camera: % of its own container (.home-stickers, styles/site.css). */
[data-sticker="starburst"]    { --s-x: 6.03%;  --s-y: 57.25%; --s-w: 24.92%; --s-r: -12deg;   --s-z: 2; }
[data-sticker="bandaid"]      { --s-x: 6.21%;  --s-y: 66.43%; --s-w: 20.1%;  --s-r: -11deg;   --s-z: 1; }
[data-sticker="smiley"]       { --s-x: 95.26%; --s-y: 56.25%; --s-w: 14.4%;  --s-r: 27deg;    --s-z: 3; }
[data-sticker="orange"]       { --s-x: 86.88%; --s-y: 96.43%; --s-w: 26.52%; --s-r: 14deg;    --s-z: 5; }
[data-sticker="rainbow-flag"] { --s-x: 90.07%; --s-y: 83.36%; --s-w: 19.04%; --s-r: 46deg;    --s-z: 4; }
[data-sticker="dice"]         { --s-x: 6.77%;  --s-y: 93.29%; --s-w: 15.71%; --s-r: -27.5deg; --s-z: 6; }
[data-sticker="camera"]       { --s-x: 87.17%; --s-y: -3.15%; --s-w: 40.4%;  --s-r: 15.5deg;  --s-z: 1; }

/* ---------- Narrow desktop windows (min-width sidebar): the -9deg tilt pushes the top-left
   corner past the window edge, so nudge the device right a little ---------- */
@container (44rem < width <= 64rem) {
  .player { translate: 10px 0; }
}

/* ---------- Phones: exactly the previous size (44px+ tap targets) ---------- */
@container (max-width: 44rem) {
  .player { --player-scale: 1; }
}

/* ---------- Reduced motion: nothing moves ---------- */
@media (prefers-reduced-motion: reduce) {
  .player__cue { animation: none; }
}
