/* A small CRT sits below the shelf in the page's own video archive. */
.tape-player[hidden] { display: none; }
.tape-player {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: 0;
  scroll-margin-top: 6rem;
  overflow-anchor: none;
  transition: grid-template-rows 650ms cubic-bezier(.22,.7,.25,1), margin-top 650ms cubic-bezier(.22,.7,.25,1);
}
.tape-player.is-expanded { grid-template-rows: 1fr; margin-top: clamp(1.75rem, 4vw, 3rem); }
/* The archive opens like a shallow compartment; release the clip after it settles so the TV's shadow survives. */
.tape-player__reveal { min-height: 0; overflow: hidden; }
.tape-player.is-expanded:not(.is-revealing) .tape-player__reveal { overflow: visible; }
.tape-player__stage { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; }
/* The shelf clones this slot's cover; keep the source out of the layout. */
.tape-player__case { display: none; }
.tape-player__tv { min-width: 0; padding: clamp(.65rem, 1.6vw, 1.1rem); border: 1px solid #80736a; border-radius: 25px; background: linear-gradient(135deg, #79706a 0%, #514b49 18%, #302e32 68%, #51494a 100%); box-shadow: inset 1px 1px 0 #ffffff55, inset -3px -4px 0 #17141a99, 0 12px 26px #0006; opacity: 1; transform: translateY(0); transition: opacity 480ms ease, transform 650ms cubic-bezier(.22,.7,.25,1); }
.tape-player:not(.is-expanded) .tape-player__tv { opacity: 0; transform: translateY(-14px); }
.tape-player__screen { position: relative; isolation: isolate; overflow: hidden; min-width: 0; color: #f4f3ee; background: radial-gradient(ellipse at 45% 18%, #313c50 0%, #202a3b 55%, #131b28 100%); border: clamp(5px, .8vw, 9px) solid #161a20; border-radius: 28px / 22px; box-shadow: inset 0 0 0 1px #b9c9da30, inset 0 0 35px #000a, 0 0 0 1px #ddd5c528; }
.tape-player__screen::before, .tape-player__screen::after { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: inherit; }
.tape-player__screen::before { opacity: .12; background: repeating-linear-gradient(0deg, #02070b 0 1px, transparent 1px 4px); }
.tape-player__screen::after { opacity: .16; background: linear-gradient(108deg, #e7f7ff14, transparent 33%), linear-gradient(transparent 0 47%, #b5e5ff 49%, transparent 51%); background-size: auto, 100% 190%; animation: tape-tv-tracking 9s linear infinite; }
@keyframes tape-tv-tracking { from { background-position: 0 0, 0 -140%; } to { background-position: 0 0, 0 240%; } }
.tape-player__screen .card__body { position: relative; z-index: 1; min-width: 0; padding: clamp(1.3rem, 3.5vw, 2.5rem); }
.tape-player__screen .badge { background: #d9efff12; border-color: #bed8e35c; color: #dbeaf3; }
.tape-player__screen h3 { color: #fffdf8; font-size: clamp(1.5rem, 3vw, 2.3rem); margin: .8rem 0; }
.tape-player__screen p { color: #e1e6e9; line-height: 1.7; }
.tape-player__screen a { color: #b8f0ff; text-decoration-color: #b8f0ff88; }
.tape-player__screen a:focus-visible { outline: 2px solid #ffdf8c; outline-offset: 3px; }
.tape-player__screen .card__links { margin-top: .5rem; }
.tape-player__screen .tape-preview figcaption { color: #cbd7df; }
.tape-player__controls { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 3.3rem; padding: .7rem .6rem .15rem; color: #f2e8d6; font: 600 .65rem/1.4 var(--font-mono); letter-spacing: .08em; }
.tape-player__controls::before { content: ""; flex: 0 0 30px; height: 30px; border-radius: 50%; background: radial-gradient(circle at 36% 30%, #746d67 0 10%, #343137 16% 54%, #161419 57% 68%, #bdb3a3 70% 73%, #4b4544 76%); box-shadow: 0 1px 2px #0009; }
.tape-player__close { cursor: pointer; flex: 0 0 auto; padding: .55rem .7rem; border: 1px solid #cbbfaf80; border-radius: 4px; background: #211f23; color: #fff4de; font: 600 .65rem/1 var(--font-mono); letter-spacing: .04em; transition: border-color .18s, background .18s, box-shadow .18s, transform .12s; }
.tape-player__close:focus-visible { outline: 2px solid #ffe391; outline-offset: 3px; }
.tape-player__close:disabled { opacity: .4; cursor: default; }
.tape-player__status { flex: 1 1 auto; min-width: 0; }
.tape-player__power {
  flex: 0 0 33px; width: 33px; height: 33px; padding: 0; cursor: pointer;
  display: grid; place-items: center; border: 1px solid #b9aaa088; border-radius: 50%;
  background: radial-gradient(circle at 35% 25%, #615b59, #29262b 70%);
  color: #f2ddbd; box-shadow: inset 0 1px 1px #ffffff30, 0 2px 3px #0008;
  font: 600 1.05rem/1 Arial, sans-serif; transition: border-color .18s, box-shadow .18s, color .18s, transform .12s;
}
.tape-player__power:focus-visible { outline: 2px solid #ffe391; outline-offset: 3px; }
@media (hover: hover) and (pointer: fine) {
  .tape-player__close:not(:disabled):hover, .tape-player__power:hover {
    color: #fff5dc; border-color: #e4c58c; box-shadow: inset 0 0 8px #e8b76933, 0 0 9px -4px #e8b76988;
  }
  .tape-player__close:not(:disabled):hover { background: #3b3032; }
}
.tape-player__close:not(:disabled):active, .tape-player__power:active { transform: translateY(1px); }
@media (max-width: 680px) {
  .tape-player__tv { border-radius: 20px; }
  .tape-player__screen { border-radius: 22px / 18px; }
  .tape-player__screen .card__body { padding: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) { .tape-player__screen::after { animation: none; background: linear-gradient(108deg, #e7f7ff14, transparent 33%); } }
.tape-player__screen .tape-preview img { width: min(100%, 430px); }

/* The compartment opens gently while the picture powers up. */
.tape-player__controls::before { content: none; }
.tape-player__controls { gap: clamp(.45rem, 1.5vw, 1rem); }
.tape-player__screen { clip-path: inset(0 round 20px); filter: brightness(1); transition: clip-path 510ms cubic-bezier(.22,.7,.25,1), filter 510ms ease; }
.tape-player:not(.is-expanded) .tape-player__screen { clip-path: inset(49% 1% 49% 1% round 20px); filter: brightness(1.3); }
.tape-player.is-playing .tape-player__screen::after { animation: tape-tv-interference 720ms ease-out, tape-tv-tracking 9s linear 720ms infinite; }
@keyframes tape-tv-interference {
  0% { opacity: .22; background: repeating-linear-gradient(0deg, transparent 0 4px, #d2f2ff99 5px 6px, transparent 8px 13px); }
  100% { opacity: .08; background: repeating-linear-gradient(0deg, transparent 0 6px, #c9e8ff66 7px 8px, transparent 9px 15px); }
}
/* A global tape pause or reduced motion must never freeze the player mid-transition. */
html.is-tape-paused .tape-player .tape-player__tv,
html.is-tape-paused .tape-player .tape-player__screen,
html.is-tape-paused .tape-player .tape-player__screen::after { animation: none !important; }
html.is-tape-paused .tape-player, html.is-tape-paused .tape-player__tv, html.is-tape-paused .tape-player__screen { transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .tape-player, .tape-player__tv, .tape-player__screen { transition: none; }
  .tape-player__close, .tape-player__power { transition: none; }
  .tape-player__close:not(:disabled):active, .tape-player__power:active { transform: none; }
  .tape-player.is-playing .tape-player__tv,
  .tape-player.is-playing .tape-player__screen,
  .tape-player.is-ejecting .tape-player__tv,
  .tape-player.is-ejecting .tape-player__screen,
  .tape-player.is-playing .tape-player__screen::after { animation: none; }
}
/* A labelled control makes the hidden card collection feel like part of the TV. */
.tape-player__screen .card__deck {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  padding: .65rem .85rem;
  border: 1px solid #ffd274;
  border-radius: 3px;
  background: linear-gradient(#ffdc8d, #f4ae52);
  color: #261c2b;
  box-shadow: 0 3px 0 #8d4d36, inset 0 1px #fff8;
  font: 700 .76rem/1.2 var(--font-mono);
  letter-spacing: .03em;
  text-decoration: none;
  text-transform: uppercase;
  transition: transform .15s, box-shadow .15s;
}
.tape-player__screen .card__deck::before { content: '▶'; font-size: .7rem; }
.tape-player__screen .card__deck:hover { color: #261c2b; text-decoration: none; transform: translateY(-2px); box-shadow: 0 5px 0 #8d4d36, inset 0 1px #fff8; }
.tape-player__screen .card__deck:focus-visible { outline: 2px solid #fff; outline-offset: 4px; }
@media (prefers-reduced-motion: reduce) { .tape-player__screen .card__deck { transition: none; } }
/* A quiet foil sheen on the artwork, separate from the cassette sleeves. */
.tape-art-preview--art { position: relative; width: fit-content; max-width: 100%; overflow: hidden; border-radius: 4px; }
.tape-art-preview--art::after { content: ''; position: absolute; inset: 4px; border-radius: 2px; pointer-events: none; opacity: .1; background: linear-gradient(125deg, transparent 20%, #f978d4 40%, #80e5ff 49%, #f8d769 58%, transparent 76%); mix-blend-mode: screen; transition: opacity .25s; }
@media (hover: hover) { .tape-art-preview--art:hover::after { opacity: .42; } }
@media (prefers-reduced-motion: reduce) { .tape-art-preview--art::after { transition: none; } }

/* Only the picture retunes on a change; the television stays put. */
.tape-player.is-changing .tape-player__screen .card__body { animation: tape-picture-change 300ms ease-out both; }
@keyframes tape-picture-change {
  0% { opacity: .55; filter: brightness(1.3); transform: translateY(5px); }
  100% { opacity: 1; filter: brightness(1); transform: translateY(0); }
}
html.is-tape-paused .tape-player .tape-player__screen .card__body { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  .tape-player.is-changing .tape-player__screen .card__body { animation: none; }
}
.tape-player__tv { width: 100%; max-width: 720px; }
@media (max-width: 480px) {
  .tape-player__controls { flex-wrap: nowrap; gap: .35rem; padding-inline: .25rem; }
  .tape-player__status { font-size: .52rem; letter-spacing: .03em; }
  .tape-player__close { padding: .48rem .5rem; font-size: .57rem; }
  .tape-player__power { flex-basis: 30px; width: 30px; height: 30px; }
}
/* On a narrow handset, a squarer tube gives text and controls room to breathe. */
@media (max-width: 680px) {
  .tape-player__screen { aspect-ratio: 1 / 1; }
}

/* The television is part of the archive even before a tape is selected.
   Only the picture changes; the cabinet keeps its place in the page. */
.tape-player, .tape-player.is-expanded {
  grid-template-rows: 1fr;
  margin-top: clamp(1.75rem, 4vw, 3rem);
  transition: none;
}
.tape-player .tape-player__reveal { overflow: visible; }
.tape-player:not(.is-expanded) .tape-player__tv { opacity: 1; transform: none; }
.tape-player:not(.is-expanded) .tape-player__screen { clip-path: inset(0 round 20px); filter: none; }
.tape-player.is-off .tape-player__screen { background: #080a0c; }
.tape-player.is-off .tape-player__screen::before,
.tape-player.is-off .tape-player__screen::after { visibility: hidden; }

/* The picture collapses inside a fixed, dark tube; the cabinet never moves. */
.tape-player__tube { position: relative; overflow: hidden; border-radius: 9% / 8%; background: #080a0e; }
.tape-player__tube::after {
  content: ''; position: absolute; z-index: 5; left: 50%; top: 50%; width: 90%; height: 2px;
  pointer-events: none; opacity: 0; transform: translate(-50%, -50%) scaleX(0);
  background: #fff; border-radius: 50%; box-shadow: 0 0 8px 2px #c8e5ff, 0 0 24px 4px #8aafff99;
}
.tape-player.is-powering-off .tape-player__screen { animation: crt-power-off 650ms ease-in both; }
.tape-player.is-powering-on .tape-player__screen { animation: crt-power-on 700ms ease-out both; }
.tape-player.is-powering-off .tape-player__tube::after { animation: crt-beam-off 650ms ease-out both; }
.tape-player.is-powering-on .tape-player__tube::after { animation: crt-beam-on 700ms ease-out both; }
@keyframes crt-power-off {
  0%, 12% { clip-path: inset(0 round 20px); filter: brightness(1); }
  52% { clip-path: inset(49.5% 1% 49.5% round 2px); filter: brightness(2); }
  76%, 100% { clip-path: inset(49.9% 49.9% round 1px); filter: brightness(1.2); }
}
@keyframes crt-power-on {
  0%, 10% { clip-path: inset(49.9% 49.9% round 1px); filter: brightness(1.8); }
  35% { clip-path: inset(49.5% 1% 49.5% round 2px); filter: brightness(2); }
  75%, 100% { clip-path: inset(0 round 20px); filter: brightness(1); }
}
@keyframes crt-beam-off {
  0%, 22% { opacity: 0; transform: translate(-50%, -50%) scaleX(.95); }
  52% { opacity: .9; transform: translate(-50%, -50%) scaleX(.95); }
  76% { opacity: .9; transform: translate(-50%, -50%) scaleX(.008); }
  100% { opacity: 0; transform: translate(-50%, -50%) scaleX(.008); }
}
@keyframes crt-beam-on {
  0% { opacity: 0; transform: translate(-50%, -50%) scaleX(.008); }
  12% { opacity: .8; transform: translate(-50%, -50%) scaleX(.008); }
  35% { opacity: .7; transform: translate(-50%, -50%) scaleX(.95); }
  58%, 100% { opacity: 0; transform: translate(-50%, -50%) scaleX(.95); }
}
html.is-tape-paused .tape-player .tape-player__tube::after { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  .tape-player.is-powering-on .tape-player__screen,
  .tape-player.is-powering-off .tape-player__screen,
  .tape-player.is-powering-on .tape-player__tube::after,
  .tape-player.is-powering-off .tape-player__tube::after { animation: none; }
}
/* Apply after the playback animation shorthand, which otherwise resets the
   play state. The tracking line rests while the picture cannot be seen. */
html.deck-open .tape-player .tape-player__screen::after,
.tape-player:is(.is-tv-offscreen, .is-off) .tape-player__screen::after { animation-play-state: paused; }
