:root {
  --green: #39ff5c;
  --green-dim: #1fa83c;
  --bg: #000;
  --panel: rgba(16, 16, 16, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f2f2f2;
  --muted: #9a9a9a;
  --mono: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* The screen. The iframe never takes pointer events; our UI does. */
#screen {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

#player, #screen iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  pointer-events: none;
}

/* iOS: YouTube's own controls take the taps (fullscreen, then picture-in-picture). */
body.native-controls #screen iframe { pointer-events: auto; }

#static {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms linear;
}
#static.on { opacity: 1; }

/* On-screen display */
#osd { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#channel-badge {
  position: absolute;
  top: 24px;
  left: 28px;
  font-family: var(--mono);
  font-size: clamp(20px, 3vw, 32px);
  font-weight: 700;
  color: var(--green);
  text-shadow: 0 0 6px rgba(57, 255, 92, 0.6), 0 0 2px #000;
  opacity: 0;
  transition: opacity 400ms ease;
}
#channel-badge.show { opacity: 1; }
#channel-badge .name { display: block; margin-top: 2px; font-size: 0.45em; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--green-dim); }

#lower-third {
  position: absolute;
  left: 28px;
  bottom: 48px;
  max-width: min(70vw, 640px);
  padding: 14px 20px 14px 18px;
  border-left: 4px solid var(--green);
  background: linear-gradient(90deg, rgba(0,0,0,0.85), rgba(0,0,0,0.55) 80%, transparent);
  transform: translateX(-16px);
  opacity: 0;
  transition: opacity 350ms ease, transform 350ms ease;
}
#lower-third.show { opacity: 1; transform: none; }
.lt-title { font-size: clamp(16px, 2.4vw, 24px); font-weight: 600; line-height: 1.2; }
.lt-artist { margin-top: 4px; font-size: clamp(13px, 1.8vw, 17px); color: #ddd; }
.lt-meta { margin-top: 8px; font-family: var(--mono); font-size: 13px; color: var(--green); letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }

#toast {
  position: absolute;
  top: 24px;
  right: 28px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 13px;
  opacity: 0;
  transition: opacity 250ms;
}
#toast.show { opacity: 1; }

#unmute {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  padding: 14px 22px;
  border: 1px solid var(--green-dim);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.75);
  color: var(--green);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  animation: breathe 2.4s ease-in-out infinite;
}
#unmute { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; }
#unmute svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#unmute[hidden] { display: none; }
#unmute:hover { background: rgba(57, 255, 92, 0.12); }
@keyframes breathe { 50% { box-shadow: 0 0 0 10px rgba(57, 255, 92, 0.12); } }
@media (prefers-reduced-motion: reduce) { #unmute { animation: none; } }

/* Remote: a round D-pad cut into four wedges (channels up/down, volume -/+)
   with the guide in the middle, and icon buttons in rows of three below. */
#remote {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 190px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
  opacity: 0.25;
  transition: opacity 250ms;
}
#remote:hover, #remote:focus-within, body.idle-off #remote { opacity: 1; }
#remote button {
  color: #d8d8d8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
#remote button:focus-visible { outline: 2px solid var(--green); outline-offset: 1px; }
#remote button.active { color: var(--green); }
/* Minimized: only the little handle stays, at the corner. */
#remote .minimize {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 36px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 0 24px 0 12px;
  background: #1c1c1c;
}
#remote .minimize:hover { background: #2a2a2a; }
#remote.minimized { width: auto; padding: 0; gap: 0; border-radius: 14px; }
#remote.minimized > :not(.minimize) { display: none; }
#remote.minimized .minimize { position: static; width: 44px; height: 44px; border: 0; border-radius: 14px; }
#remote.minimized .minimize svg { transform: rotate(180deg); }
#remote svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#remote .glyph { font-family: var(--mono); font-weight: 700; font-size: 13px; letter-spacing: 0.02em; }
#remote [data-action="info"] .glyph { font-size: 16px; font-style: italic; font-family: Georgia, serif; }

.pad {
  position: relative;
  width: 156px;
  height: 156px;
  border-radius: 50%;
  overflow: hidden;
  background: #1a1a1a;
  border: 1px solid var(--line);
}
/* the two diagonal seams between wedges */
.pad::before, .pad::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -10%;
  width: 1px;
  height: 120%;
  background: var(--line);
  transform: rotate(45deg);
  pointer-events: none;
}
.pad::after { transform: rotate(-45deg); }
.wedge {
  position: absolute;
  inset: 0;
  background: transparent;
}
.wedge:hover { background: #262626; }
.wedge:active { background: #303030; }
.wedge-up { clip-path: polygon(50% 50%, 0 0, 100% 0); }
.wedge-right { clip-path: polygon(50% 50%, 100% 0, 100% 100%); }
.wedge-down { clip-path: polygon(50% 50%, 100% 100%, 0 100%); }
.wedge-left { clip-path: polygon(50% 50%, 0 100%, 0 0); }
.wedge span { position: absolute; font-size: 13px; line-height: 1; }
.wedge-left span, .wedge-right span { font-size: 22px; font-weight: 300; }
.wedge-up span { top: 14px; left: 50%; transform: translateX(-50%); }
.wedge-down span { bottom: 14px; left: 50%; transform: translateX(-50%); }
.wedge-left span { left: 16px; top: 50%; transform: translateY(-50%); }
.wedge-right span { right: 16px; top: 50%; transform: translateY(-50%); }
.pad-center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 56px;
  height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #262626;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 4px var(--panel);
}
.pad-center:hover { background: #333; }

.row { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; width: 100%; }
.row button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: #1c1c1c; }
.row button:hover { background: #2a2a2a; }
/* speaker icon: waves when live, a cross when muted */
#remote [data-action="mute"] .cross { display: none; }
#remote [data-action="mute"].active .wave { display: none; }
#remote [data-action="mute"].active .cross { display: block; }

/* Volume bar, shown while adjusting. Top centre: the badge is top left, the toast top right. */
#volume {
  position: absolute;
  left: 50%;
  top: 28px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--green);
  letter-spacing: 0.1em;
  opacity: 0;
  transition: opacity 200ms;
}
#volume.show { opacity: 1; }
#volume .bar { width: 160px; height: 6px; border-radius: 3px; background: #333; overflow: hidden; }
#volume .fill { height: 100%; background: var(--green); width: 50%; }

/* Guide */
#guide {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 560px);
  max-height: 80vh;
  overflow: auto;
  z-index: 25;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 0 8px;
  font-family: var(--mono);
  font-size: 14px;
}
#guide[hidden] { display: none; }
.guide-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--green);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.guide-head button { font-size: 22px; line-height: 1; padding: 0 4px; color: var(--muted); }
#guide-list { list-style: none; margin: 0; padding: 0; }
#guide-list li { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
#guide-list li:hover, #guide-list li:focus-visible { background: rgba(255,255,255,0.04); outline: none; }
#guide-list li.current .g-ch { color: var(--green); }
.g-head { display: flex; gap: 12px; align-items: baseline; }
.g-ch { font-weight: 700; }
.g-name { color: var(--text); }
.g-loop { margin-left: auto; color: var(--muted); font-size: 12px; }
.g-row { display: flex; gap: 10px; margin-top: 6px; color: var(--muted); font-size: 13px; }
.g-row .g-when { flex: 0 0 5.5em; color: var(--muted); }
.g-row.now { color: var(--text); }
.g-row.now .g-when { color: var(--green); }
.g-what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }


@media (prefers-reduced-motion: reduce) {
  #channel-badge, #lower-third, #toast, #remote, #static { transition: none; }
}


/* Phones held upright: the video is a band at the top, the now-playing info
   sits right under it at full width, and the remote is a wide bar along the
   bottom with the pad on the left and the buttons on the right. */
@media (orientation: portrait) and (max-width: 700px) {
  #screen { bottom: auto; height: 56.25vw; }
  #channel-badge { top: 12px; left: 12px; }
  #unmute { top: 28.125vw; }
  #toast { top: 12px; right: 12px; }

  #volume {
    top: calc(56.25vw - 14px);
    left: 12px;
    right: 12px;
    transform: none;
    padding: 4px 10px;
    border-radius: 6px;
    gap: 8px;
    font-size: 11px;
  }
  #volume .bar { flex: 1; width: auto; height: 4px; }

  #lower-third {
    top: calc(56.25vw + 12px);
    bottom: auto;
    left: 12px;
    right: 12px;
    max-width: none;
    padding: 10px 12px;
  }
  .lt-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-size: 17px;
  }
  .lt-artist { font-size: 14px; }

  #remote {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: auto;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    opacity: 1;
  }
  .pad { width: 136px; height: 136px; flex: none; }
  .pad-center { width: 50px; height: 50px; }
  .row { width: auto; display: grid; grid-template-columns: repeat(3, 42px); gap: 8px; justify-content: end; }
  #remote.minimized { left: auto; right: 12px; width: auto; }

  #guide {
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: auto;
    max-height: none;
    transform: none;
    border-radius: 0;
    border: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
  .guide-head { padding-top: calc(12px + env(safe-area-inset-top)); }
}

/* Phones on their side: the video wants the whole screen, so the chrome stays small. */
@media (orientation: landscape) and (max-height: 500px) {
  #channel-badge { top: 10px; left: 14px; font-size: 18px; }
  #lower-third { left: 14px; bottom: 14px; padding: 8px 12px; }
  .lt-title { font-size: 15px; }
  .lt-artist { font-size: 12px; }
  .lt-meta { margin-top: 4px; font-size: 11px; }
  #remote { right: calc(10px + env(safe-area-inset-right)); bottom: 10px; padding: 10px; gap: 8px; width: 150px; }
  .pad { width: 110px; height: 110px; }
  .pad-center { width: 40px; height: 40px; }
  .pad button span { font-size: 11px; }
  .wedge-left span, .wedge-right span { font-size: 18px; }
  .row { gap: 6px; }
  .row button { width: 34px; height: 34px; }
  #remote svg { width: 16px; height: 16px; }
}
