/* Crypt TV. Pixel-art CRT + VHS shelf. Every art position is in art pixels times --px. */
.ctv {
  --px: 2px;                 /* set by crypt-tv.js to an integer device-pixel scale */
  --ctv-ink: #f2efe6;        /* label paper, also UI text */
  --ctv-dim: #b9b3a6;
  --ctv-red: #e9161f;        /* Tim's mark */
  --ctv-void: #0d0c0e;
  --ctv-plastic: #2a292c;
  --ctv-focus: #f2efe6;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-width: 0;
  color: var(--ctv-ink);
  font: 400 14px/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  -webkit-tap-highlight-color: transparent;
}
.ctv *, .ctv *::before, .ctv *::after { box-sizing: border-box; }
.ctv canvas, .ctv-cabinet, .ctv-knob, .ctv-plank { image-rendering: pixelated; image-rendering: crisp-edges; }
.ctv canvas { image-rendering: pixelated; }

/* ------------------------------------------------------------ the set */
.ctv-set {
  position: relative;
  flex: none;
  width: calc(176 * var(--px));
  height: calc(148 * var(--px));
}
.ctv-set::before {           /* the screen's light on the wall behind the set */
  content: "";
  position: absolute;
  left: calc(4 * var(--px)); right: calc(30 * var(--px));
  top: calc(20 * var(--px)); bottom: calc(10 * var(--px));
  background: radial-gradient(closest-side, rgba(120, 170, 220, .16), rgba(120, 170, 220, 0));
  filter: blur(calc(10 * var(--px)));
  z-index: 0;
  pointer-events: none;
}
.ctv-cabinet {
  position: absolute; inset: 0;
  background: var(--ctv-tv) 0 0 / 100% 100% no-repeat;
  z-index: 3;
  pointer-events: none;
}
.ctv-screen {
  position: absolute;
  left: calc(17 * var(--px)); top: calc(36 * var(--px));
  width: calc(112 * var(--px)); height: calc(84 * var(--px));
  background: #050607;
  overflow: hidden;
  z-index: 1;
  border-radius: calc(6 * var(--px));
}
.ctv-tube { position: absolute; inset: 0; }
.ctv-video {
  position: absolute; inset: -2%;
  width: 104%; height: 104%;
  object-fit: cover;
  opacity: 0;
  filter: url(#ctv-fringe) saturate(1.15) contrast(1.06) brightness(1.04);
  background: #050607;
}
.ctv-video.is-on { opacity: 1; z-index: 1; }
.ctv-static {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  z-index: 2;
  pointer-events: none;
}
.ctv-osd {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  z-index: 3;
  pointer-events: none;
}
.ctv-glass {                 /* scanlines, curvature falloff, glare: the CRT face */
  position: absolute; inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
    linear-gradient(158deg, rgba(255, 255, 255, .10) 0%, rgba(255, 255, 255, .03) 26%, rgba(255, 255, 255, 0) 42%),
    radial-gradient(120% 118% at 50% 48%, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, .55) 100%),
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, .26) 0, rgba(0, 0, 0, .26) calc(var(--px) / 3), rgba(0, 0, 0, 0) calc(var(--px) / 3), rgba(0, 0, 0, 0) var(--px));
  box-shadow: inset 0 0 calc(6 * var(--px)) rgba(0, 0, 0, .7), inset 0 0 calc(2 * var(--px)) rgba(140, 200, 255, .12);
}
.ctv-glass::after {          /* slow refresh band */
  content: "";
  position: absolute; left: 0; right: 0; top: -20%;
  height: 18%;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, .045), rgba(255, 255, 255, 0));
  animation: ctv-band 7.5s linear infinite;
}
@keyframes ctv-band { to { transform: translateY(700%); } }

/* channel change: roll and colour tear while the static runs */
.ctv-screen.is-glitching .ctv-tube { animation: ctv-roll .42s cubic-bezier(.2, .7, .3, 1) both; }
.ctv-screen.is-glitching .ctv-video.is-on { filter: url(#ctv-tear) saturate(1.6) contrast(1.2); }
@keyframes ctv-roll {
  0%   { transform: translateY(0) skewX(0); }
  18%  { transform: translateY(-34%) skewX(-6deg); }
  19%  { transform: translateY(66%) skewX(5deg); }
  46%  { transform: translateY(12%) skewX(-2deg); }
  70%  { transform: translateY(-3%) skewX(0); }
  100% { transform: translateY(0) skewX(0); }
}

.ctv-led {
  position: absolute;
  left: calc(141 * var(--px)); top: calc(40 * var(--px));
  width: calc(18 * var(--px)); height: calc(9 * var(--px));
  z-index: 4;
  filter: drop-shadow(0 0 calc(1.5 * var(--px)) rgba(255, 59, 47, .55));
}
.ctv-power {
  position: absolute;
  left: calc(154 * var(--px)); top: calc(127 * var(--px));
  width: calc(4 * var(--px)); height: calc(2 * var(--px));
  z-index: 4;
  border-radius: 50%;
  box-shadow: 0 0 calc(3 * var(--px)) calc(1 * var(--px)) rgba(255, 59, 47, .45);
  pointer-events: none;
}
.ctv-knob {
  position: absolute;
  z-index: 5;
  padding: 0; margin: 0; border: 0;
  background: var(--ctv-knobs) 0 0 / calc(136 * var(--px)) calc(30 * var(--px)) no-repeat;
  border-radius: 50%;
  cursor: pointer;
}
.ctv-knob--ch {
  left: calc(141 * var(--px)); top: calc(56 * var(--px));
  width: calc(17 * var(--px)); height: calc(17 * var(--px));
  background-position: calc(var(--frame, 0) * -17 * var(--px)) 0;
}
.ctv-knob--vol {
  left: calc(143 * var(--px)); top: calc(80 * var(--px));
  width: calc(13 * var(--px)); height: calc(13 * var(--px));
  background-position: calc(var(--frame, 0) * -17 * var(--px)) calc(-17 * var(--px));
}
.ctv-knob:hover { filter: brightness(1.15); }

/* ------------------------------------------------------------ the shelf */
.ctv-shelf {
  position: relative;
  width: calc(176 * var(--px));
  max-width: 100%;
  margin-top: calc(4 * var(--px));
}
.ctv-tapes {
  display: flex;
  align-items: flex-end;
  /* the hit area pads small tapes out to 44px; the gap shrinks by that padding so the drawn spacing barely moves */
  gap: max(0px, calc(3 * var(--px) - max(0px, 44px - 16 * var(--px))));
  padding: calc(14 * var(--px)) calc(6 * var(--px)) 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.ctv-tapes::-webkit-scrollbar { display: none; }
.ctv-tapes > :first-child { margin-left: auto; }
.ctv-tapes > :last-child { margin-right: auto; }
.ctv-tape {
  flex: none;
  position: relative;
  width: max(44px, calc(16 * var(--px)));
  min-height: 44px;
  height: calc(72 * var(--px));
  padding: 0; margin: 0; border: 0;
  background: none;
  cursor: pointer;
  scroll-snap-align: center;
  will-change: transform;
}
.ctv-tape canvas { display: block; width: calc(16 * var(--px)); height: 100%; margin: 0 auto; }
.ctv-tape:focus { outline: none; }
.ctv-tape:focus-visible canvas {
  outline: var(--px) solid var(--ctv-focus);
  outline-offset: var(--px);
}
.ctv-tape[aria-pressed="true"] canvas { filter: drop-shadow(0 calc(2 * var(--px)) 0 rgba(0, 0, 0, .55)); }
.ctv-plank {
  height: calc(10 * var(--px));
  background: var(--ctv-shelf) 0 0 / calc(32 * var(--px)) calc(10 * var(--px)) repeat-x;
}

/* ------------------------------------------------------------ caption + controls */
.ctv-info {
  width: calc(176 * var(--px));
  max-width: 100%;
  margin-top: 12px;
  padding: 0 calc(2 * var(--px));
  min-height: 3.6em;
}
.ctv-now { margin: 0; color: var(--ctv-ink); font-weight: 700; letter-spacing: .01em; }
.ctv-credit { margin: 2px 0 0; color: var(--ctv-dim); font-size: 12px; max-width: 70ch; }
.ctv-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: calc(176 * var(--px));
  max-width: 100%;
  margin-top: 10px;
  padding: 0 calc(2 * var(--px));
}
.ctv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 calc(4 * var(--px));
  border: var(--px) solid #120a07;
  background: var(--ctv-plastic);
  box-shadow: inset var(--px) var(--px) 0 #55545a, inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 #1b1a1c;
  color: var(--ctv-ink);
  cursor: pointer;
}
.ctv-btn canvas { display: block; }
.ctv-btn:hover { background: #3b3a3e; }
.ctv-btn:active, .ctv-btn[aria-pressed="true"] {
  box-shadow: inset var(--px) var(--px) 0 #1b1a1c, inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 #55545a;
}
.ctv-btn[aria-pressed="true"] { background: #a80f16; }
.ctv-btn:focus { outline: none; }
.ctv-btn:focus-visible, .ctv-knob:focus-visible {
  outline: var(--px) solid var(--ctv-focus);
  outline-offset: var(--px);
}
.ctv-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.ctv-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------ reduced motion: no wave, no roll, crossfade */
@media (prefers-reduced-motion: reduce) {
  .ctv-glass::after { animation: none; display: none; }
  .ctv-screen.is-glitching .ctv-tube { animation: none; }
  .ctv-video { transition: opacity 0s linear .5s; }
  .ctv-video.is-on { transition: opacity .45s ease; }
  .ctv-tape { will-change: auto; }
}

/* ------------------------------------------------------------ the tape-box shelves (clips.json with "shelf") */
.ctv-shelf.has-racks > .ctv-plank { display: none; }
.ctv-tapes.ctv-racks { display: block; padding: 0; overflow: visible; gap: 0; }
.ctv-tapes.ctv-racks > :first-child, .ctv-tapes.ctv-racks > :last-child { margin: 0; }
.ctv-rack + .ctv-rack { margin-top: calc(5 * var(--px)); }
.ctv-rack-h {
  margin: 0 0 calc(1 * var(--px)); padding: 0 calc(3 * var(--px));
  font: 400 max(9px, calc(3.4 * var(--px)))/1.4 "Press Start 2P", "Courier New", monospace;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold, #f7ec3c);
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.ctv-rack-n { font-size: max(7px, calc(2.4 * var(--px))); color: #f2efe6; opacity: .75; }
/* a soft fade on the right edge says the shelf keeps going */
.ctv-rack-row { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent); }
.ctv-rack-row {
  display: flex; align-items: flex-end; gap: calc(3 * var(--px));
  padding: calc(4 * var(--px)) calc(3 * var(--px)) 0;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x proximity; scrollbar-width: thin; scrollbar-color: var(--gold, #f7ec3c) transparent;
  overscroll-behavior-x: contain;
}
.ctv-box {
  flex: none; position: relative; display: flex; flex-direction: column;
  width: max(78px, calc(27 * var(--px))); height: auto; min-height: 0;
  padding: calc(1 * var(--px)); margin: 0;
  background: #0d0c0e; border: calc(0.67 * var(--px)) solid #3a3a3a; border-bottom-width: 0;
  box-shadow: inset 0 0 0 1px #000;
  cursor: pointer; scroll-snap-align: start; text-align: left;
}
.ctv-box-art { display: block; position: relative; aspect-ratio: 3 / 4; overflow: hidden; background: #222; }
.ctv-box-art img { display: block; width: 100%; height: 100%; object-fit: cover; image-rendering: auto; }
.ctv-box-title {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  min-height: 2.7em; margin-top: calc(1 * var(--px)); padding: calc(1 * var(--px)) calc(1.2 * var(--px));
  font: 400 max(7px, calc(2.4 * var(--px)))/1.35 "Press Start 2P", "Courier New", monospace;
  color: #0d0c0e; background: #f2efe6; overflow-wrap: break-word; word-break: normal;
}
.ctv-rack--up .ctv-box-title { background: var(--gold, #f7ec3c); }
.ctv-box-ch {
  position: absolute; top: calc(2 * var(--px)); left: calc(2 * var(--px));
  padding: 2px 3px; font: 400 max(6px, calc(2 * var(--px)))/1 "Press Start 2P", "Courier New", monospace;
  color: #f2efe6; background: rgba(0, 0, 0, .78);
}
.ctv-box-date {
  position: absolute; right: calc(-1 * var(--px)); top: calc(22 * var(--px)); rotate: -6deg;
  padding: calc(1 * var(--px)) calc(1.5 * var(--px));
  font: 400 max(6px, calc(2.2 * var(--px)))/1.2 "Press Start 2P", "Courier New", monospace;
  color: #000; background: var(--gold, #f7ec3c); border: 2px solid #000; box-shadow: 2px 2px 0 #000; white-space: nowrap;
}
.ctv-box:hover .ctv-box-art img { filter: brightness(1.12); }
.ctv-box:focus { outline: none; }
.ctv-box:focus-visible { outline: 3px solid var(--gold, #f7ec3c); outline-offset: 2px; }
.ctv-box[aria-pressed="true"] { border-color: var(--gold, #f7ec3c); box-shadow: 0 0 0 2px #000, 0 calc(2 * var(--px)) 0 rgba(0, 0, 0, .55); }
.ctv-box[aria-pressed="true"] .ctv-box-ch { background: var(--gold, #f7ec3c); color: #000; }
@media (prefers-reduced-motion: reduce) { .ctv-box { transition: none; } }

/* a flyer tape (no video): the poster fills the screen and slowly scrolls top to bottom and back */
.ctv-video.is-still { object-position: 50% 0%; animation: ctv-flyer-pan 14s ease-in-out 1s infinite alternate; }
@keyframes ctv-flyer-pan { 0%, 12% { object-position: 50% 0%; } 88%, 100% { object-position: 50% 100%; } }
@media (prefers-reduced-motion: reduce) { .ctv-video.is-still { animation: none; object-position: 50% 0%; } }
