/* ============================================================
   MoodPlaylist TV: a 90s music TV after midnight.
   Layers, bottom to top: video → static → CRT glass → touch layer → buttons → guide.
   ============================================================ */

:root {
  --screen: #000;
  --bezel: #1d1a17;
  --ink: #fff;
  --dim: rgba(255, 255, 255, .72);
  --popup: #ffe14d;
  --heart: #ff3b6b;
  --skip: #fe5301;
  --knob: #2a2622;
  --glass-panel: rgba(10, 10, 14, .55);
  --vcr: "VT323", ui-monospace, monospace;
  --body: "Archivo", system-ui, sans-serif;
  --marker: "Permanent Marker", "Archivo", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--screen);
  color: var(--ink);
  font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- The picture ---------- */
#tube { position: fixed; inset: 0; overflow: hidden; background: var(--screen); animation: power-on .8s ease-out; }
#video { position: absolute; pointer-events: none; }
#video iframe, #yt { width: 100%; height: 100%; border: 0; display: block; }

/* The picture opens from a bright line, like a tube warming up */
@keyframes power-on {
  0% { transform: scale(.6, .004); filter: brightness(6); }
  45% { transform: scale(1, .004); filter: brightness(4); }
  100% { transform: scale(1, 1); filter: brightness(1); }
}

#static {
  position: fixed; inset: 0; width: 100%; height: 100%;
  image-rendering: pixelated; opacity: 0; transition: opacity .15s; pointer-events: none;
}
body.tuning #static { opacity: .85; }

/* CRT glass: scanlines, curved-tube vignette, the bezel's rounded corners */
#glass {
  position: fixed; inset: 0; pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, .22) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, .55) 100%);
  box-shadow: inset 0 0 0 10px var(--bezel), inset 0 0 60px 20px rgba(0, 0, 0, .7);
  border-radius: 18px;
  animation: flicker 6s infinite steps(1);
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  47% { opacity: .94; }
  48% { opacity: 1; }
}

#screen { position: fixed; inset: 0; z-index: 5; }

/* ---------- Channel bug, top left ---------- */
#bug {
  position: fixed; top: 22px; left: 26px; z-index: 10; width: 170px;
  opacity: .62; text-decoration: none; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .45));
}
#bug svg { display: block; width: 100%; height: auto; overflow: visible; }
.bug-mood { font-family: var(--body); font-stretch: 62%; font-weight: 900; font-size: 74px; fill: #fff; letter-spacing: -2px; }
.bug-playlist { font-family: var(--marker); font-size: 36px; fill: #fff; transform: rotate(-6deg); transform-origin: 40px 100px; }

/* ---------- On-screen display (VCR style), top right ---------- */
#osd {
  position: fixed; top: 24px; right: 108px; z-index: 10; pointer-events: none; text-align: right;
  font-family: var(--vcr); opacity: 0; transition: opacity .4s;
  text-shadow: 2px 0 rgba(255, 0, 70, .8), -2px 0 rgba(0, 220, 255, .8);
}
#osd.show, body.tuning #osd { opacity: 1; }
#osd-num { font-size: clamp(48px, 7vw, 84px); line-height: .85; }
#osd-name { font-size: clamp(22px, 2.6vw, 32px); }

#watching {
  position: fixed; top: 126px; right: 110px; z-index: 10; font-family: var(--vcr); font-size: 22px;
  opacity: 0; transition: opacity .4s; pointer-events: none;
}
#watching.show { opacity: 1; }

#stay-badge {
  position: fixed; top: 30px; left: 50%; transform: translateX(-50%); z-index: 10;
  font-family: var(--vcr); font-size: 22px; padding: 2px 12px; background: rgba(0, 0, 0, .55);
  opacity: 0; transition: opacity .4s; pointer-events: none; white-space: nowrap;
}
body.staying #stay-badge { opacity: 1; }

#ticker { display: none; }

/* ---------- Pop-Up Video bubbles: low on screen, a different colour each time ---------- */
#fact {
  --bubble: var(--popup);
  position: fixed; z-index: 9; max-width: min(340px, 80vw); pointer-events: none;
  background: var(--bubble); color: #111; border-radius: 24px; padding: 13px 18px;
  font-size: 17px; line-height: 1.32; font-weight: 700;
  box-shadow: 4px 6px 0 rgba(0, 0, 0, .55);
  transform: scale(0); transform-origin: 15% 100%; transition: transform .32s cubic-bezier(.3, 1.7, .5, 1);
}
#fact.show { transform: scale(1); }
#fact.tail-right { transform-origin: 85% 100%; }
#fact::after {
  content: ""; position: absolute; left: 28px; bottom: -13px;
  border: 14px solid transparent; border-top-color: var(--bubble); border-bottom: 0; border-left: 0;
}
#fact.tail-right::after { left: auto; right: 28px; border-left: 14px solid transparent; border-right: 0; }
#fact p { margin: 0; }

/* ---------- YouTube comments, drifting up the right side ---------- */
#comments {
  position: fixed; right: 108px; bottom: 120px; z-index: 8; width: 320px;
  display: flex; flex-direction: column; gap: 12px; pointer-events: none;
}
.comment {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--glass-panel); backdrop-filter: blur(6px); border-radius: 14px; padding: 10px 12px;
  font-size: 14px; line-height: 1.32; animation: rise .5s ease-out;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; flex: none; object-fit: cover; }
.avatar.letter { display: grid; place-items: center; color: #111; font-weight: 800; font-size: 14px; }
.comment p { margin: 0; }
.comment b { color: var(--popup); font-weight: 700; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- MTV-style credits ---------- */
#credits {
  position: fixed; left: 34px; bottom: 214px; z-index: 9; pointer-events: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .85); opacity: 0; transition: opacity .6s; max-width: 55vw;
}
#credits.show { opacity: 1; }
#credit-artist { font-stretch: 75%; font-weight: 800; font-size: clamp(22px, 2.6vw, 32px); line-height: 1.1; }
#credit-title { font-stretch: 75%; font-weight: 500; font-size: clamp(20px, 2.3vw, 28px); line-height: 1.15; }

#progress-bar { position: fixed; left: 0; right: 0; bottom: 0; height: 3px; z-index: 11; background: rgba(255, 255, 255, .12); }
#progress { height: 100%; width: 0; background: var(--popup); transition: width 1s linear; }

/* ---------- Tap for sound ---------- */
#sound {
  position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 20;
  border: 0; border-radius: 999px; padding: 16px 28px; font-size: 20px; font-weight: 800;
  background: var(--ink); color: #111; box-shadow: 0 0 0 8px rgba(255, 255, 255, .16), 0 10px 40px rgba(0, 0, 0, .5);
  animation: nudge 2.4s ease-in-out infinite;
}
#sound.gone { display: none; }
@keyframes nudge { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.06); } }

/* ---------- Live feed (desktop, left) ---------- */
#feed {
  position: fixed; left: 24px; top: 150px; z-index: 10; width: 290px; max-height: calc(100vh - 380px);
  overflow-y: auto; scrollbar-width: none;
}
#feed h2 { font-size: 15px; font-weight: 700; margin: 0 0 8px; color: var(--dim); }
#feed h2::before { content: "● "; color: var(--heart); }
.feed-item {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  background: var(--glass-panel); backdrop-filter: blur(6px); border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 14px; padding: 8px; margin-bottom: 8px;
}
.feed-item:hover { border-color: var(--popup); }
.feed-item img, .feed-blank { width: 72px; height: 40px; object-fit: cover; border-radius: 8px; flex: none; }
.feed-blank { display: grid; place-items: center; background: rgba(255, 255, 255, .08); }
.feed-item span { display: flex; flex-direction: column; min-width: 0; }
.feed-item b { font-size: 14px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.feed-item i { font-style: normal; font-size: 12px; color: var(--dim); }
.feed-empty { font-size: 14px; color: var(--dim); }

/* ---------- Remote control (right edge) ---------- */
#remote {
  position: fixed; right: 22px; top: 50%; transform: translateY(-50%); z-index: 12;
  display: flex; flex-direction: column; gap: 10px;
}
#remote button {
  width: 64px; min-height: 56px; border: 0; border-radius: 16px;
  background: var(--glass-panel); backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
}
#remote button i { font-style: normal; font-size: 12px; margin-top: 4px; color: var(--dim); }
#remote button:hover { background: rgba(255, 255, 255, .16); }
#btn-like span { color: var(--heart); }

/* ---------- The deck: two knobs, a box, and the SkipVids button ---------- */
#deck {
  position: fixed; left: 24px; right: 108px; bottom: 20px; z-index: 12;
  display: flex; align-items: flex-end; gap: 18px;
}
#hint {
  position: absolute; left: 6px; bottom: 132px; font-weight: 800; font-size: 18px;
  background: var(--popup); color: #111; padding: 8px 14px; border-radius: 999px;
  animation: bob 1.4s ease-in-out infinite; pointer-events: none;
}
#hint.gone { display: none; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

.knobs { display: flex; gap: 10px; }
.knob-wrap { display: flex; flex-direction: column; align-items: center; min-width: 132px; }
/* A chunky bakelite knob with a white pointer line */
.knob {
  position: relative; width: 78px; height: 78px; border-radius: 50%; border: 0; padding: 0;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .28), transparent 45%),
    repeating-conic-gradient(from 0deg, #3a342e 0deg 6deg, #2a2622 6deg 12deg);
  box-shadow: 0 0 0 4px #14110f, 0 0 0 6px rgba(255, 255, 255, .12), 0 8px 18px rgba(0, 0, 0, .6);
  transition: transform .28s cubic-bezier(.3, 1.4, .5, 1);
  touch-action: none;
}
.knob:hover { box-shadow: 0 0 0 4px #14110f, 0 0 0 6px var(--popup), 0 8px 18px rgba(0, 0, 0, .6); }
.knob .pointer { position: absolute; left: 50%; top: 7px; width: 5px; height: 24px; margin-left: -2.5px; border-radius: 3px; background: var(--ink); }
.knob-label { font-size: 12px; color: var(--dim); margin-top: 8px; }
.knob-value {
  font-family: var(--vcr); font-weight: 400; font-size: 22px; line-height: 1; white-space: nowrap;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .9);
}
/* A typed vibe beats the knobs: dim them so that's obvious */
body.vibing .knobs { opacity: .55; }

#make {
  flex: 1; display: flex; align-items: center; gap: 8px; max-width: 520px; margin-bottom: 26px;
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(8px); border: 1px solid rgba(255, 255, 255, .2);
  border-radius: 999px; padding: 6px 6px 6px 18px;
}
#vibe { flex: 1; min-width: 0; background: none; border: 0; color: var(--ink); font: inherit; font-size: 16px; padding: 10px 0; outline: none; }
#vibe::placeholder { color: rgba(255, 255, 255, .6); }
#make-go { border: 0; border-radius: 999px; padding: 11px 20px; background: var(--popup); color: #111; font-weight: 800; }

#skipvids {
  margin-left: auto; margin-bottom: 26px; text-decoration: none;
  background: var(--skip); border-radius: 18px; padding: 10px 16px;
  box-shadow: 0 6px 24px rgba(254, 83, 1, .35);
}
#skipvids b { display: block; font-size: 16px; }
#skipvids span { display: block; font-size: 12px; opacity: .92; margin-top: 2px; white-space: nowrap; }

/* ---------- Tap to clean the screen ---------- */
#feed, #remote, #deck, #comments, #bug { transition: opacity .3s; }
body.clean #feed, body.clean #remote, body.clean #deck, body.clean #comments { opacity: 0; pointer-events: none; }

/* ---------- Hearts, toast, support ---------- */
.heart {
  position: fixed; z-index: 30; font-size: 64px; color: var(--heart); pointer-events: none;
  transform: translate(-50%, -50%); animation: heart-up 1.2s ease-out forwards;
  text-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}
@keyframes heart-up {
  0% { transform: translate(-50%, -50%) scale(.4); opacity: 1; }
  25% { transform: translate(-50%, -60%) scale(1.15); }
  100% { transform: translate(-50%, -180%) scale(1); opacity: 0; }
}

#toast {
  position: fixed; left: 50%; top: 84px; transform: translate(-50%, -12px); z-index: 70;
  background: var(--ink); color: #111; padding: 12px 18px; border-radius: 14px; font-weight: 600;
  max-width: 90vw; opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#support {
  display: none; position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 80;
  width: min(420px, 90vw); background: #fff; color: #111; border-radius: 18px; padding: 20px; line-height: 1.45;
}
#support.show { display: block; }
#support a { color: #1a4fd6; font-weight: 700; }
#support button { border: 0; background: #111; color: #fff; border-radius: 999px; padding: 9px 16px; }

/* ---------- Guide ---------- */
#guide {
  display: none; position: fixed; inset: 0; z-index: 60; overflow-y: auto;
  background: rgba(6, 6, 10, .94); backdrop-filter: blur(10px); padding: 24px 28px 40px;
}
body.guide-open #guide { display: block; }
#guide header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
#guide h2 { font-family: var(--vcr); font-size: 44px; font-weight: 400; margin: 0; }
#guide-live { margin: 0; color: var(--popup); font-weight: 600; flex: 1; }
#guide-search {
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .2); color: var(--ink);
  border-radius: 999px; padding: 10px 16px; font: inherit; width: min(320px, 100%);
}
#guide-close { border: 0; background: rgba(255, 255, 255, .1); border-radius: 50%; width: 44px; height: 44px; font-size: 18px; }
#guide h3 { font-size: 16px; color: var(--dim); font-weight: 600; margin: 22px 0 10px; }
.feed-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.feed-row .feed-item { width: 260px; flex: none; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile {
  position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-height: 86px;
  text-decoration: none; border-radius: 14px; overflow: hidden; padding: 10px 12px;
  background: #16151c; border: 2px solid transparent;
}
.tile:hover, .tile:focus-visible { border-color: var(--popup); outline: none; }
.tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .55; }
.tile .tile-emoji { position: relative; font-size: 28px; line-height: 1; }
.tile b { position: relative; font-size: 15px; margin-top: 4px; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
.guide-foot { margin-top: 26px; font-size: 14px; color: var(--dim); }

/* ---------- Phones: TikTok-style layout ---------- */
@media (max-width: 760px) {
  #glass { box-shadow: inset 0 0 40px 10px rgba(0, 0, 0, .7); border-radius: 0; }
  #bug { top: max(14px, env(safe-area-inset-top)); left: 14px; width: 118px; }
  #osd { top: max(16px, env(safe-area-inset-top)); right: 16px; }
  #watching { top: 96px; right: 16px; font-size: 18px; }
  #stay-badge { top: auto; bottom: 268px; left: 16px; transform: none; font-size: 18px; }
  #feed { display: none; }
  #ticker {
    display: block; position: fixed; z-index: 12; left: 14px; right: 14px; top: max(96px, calc(env(safe-area-inset-top) + 82px));
    text-align: left; border: 0; border-radius: 999px; padding: 9px 14px; font-size: 14px; font-weight: 600;
    background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transform: translateY(-8px); transition: opacity .4s, transform .4s;
  }
  #ticker.show { opacity: 1; transform: none; }
  body.clean #ticker { opacity: 0; pointer-events: none; }

  #remote { right: 10px; top: auto; bottom: 206px; transform: none; gap: 6px; }
  #remote button { width: 52px; min-height: 48px; font-size: 19px; background: rgba(0, 0, 0, .35); }
  #remote #btn-full { display: none; }

  #credits { left: 16px; bottom: 214px; max-width: calc(100vw - 90px); }
  #comments { left: 16px; right: 74px; width: auto; bottom: 300px; gap: 8px; }
  .comment:nth-last-child(n+3) { display: none; }

  /* Deck: knobs side by side, the box underneath, SkipVids on top */
  #deck {
    left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom));
    flex-wrap: wrap; gap: 10px; align-items: center;
  }
  /* Row 1: the two knobs + a compact SkipVids button. Row 2: the box, full width */
  .knobs { order: 1; gap: 2px; }
  .knob-wrap { min-width: 0; width: 88px; }
  #skipvids { order: 2; flex: 1; min-width: 0; margin: 0; padding: 9px 12px; border-radius: 14px; }
  #skipvids b { font-size: 14px; line-height: 1.2; }
  #skipvids span { white-space: normal; font-size: 11px; }
  .knob { width: 58px; height: 58px; }
  .knob .pointer { top: 5px; height: 18px; }
  .knob-value { font-size: 18px; }
  #make { order: 3; flex: 1 1 100%; margin: 0; padding-left: 16px; }
  #vibe { font-size: 15px; }
  #make-go { padding: 10px 14px; }
  #hint { bottom: 186px; font-size: 15px; }
  #sound { top: 40%; font-size: 18px; }

  #fact { font-size: 15px; max-width: 76vw; }
  #guide { padding: 16px; }
  #guide h2 { font-size: 34px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  #glass, #tube, #sound, #hint { animation: none; }
  .heart, .comment { animation: none; }
}
