:root {
  --ttv-red-glow: #ff4d62;
  --ttv-cream: #f6e8d4;
  --ttv-phosphor: #9dffb8;
  --ttv-amber: #ffb347;
  --ttv-bezel-dark: #1a1614;
  --ttv-bezel-mid: #3d3530;
  --ttv-bezel-light: #5c5248;
  --ttv-remote-body: #1e1418;
  --ttv-remote-key: #2c1e24;
  --ttv-shadow: 0 24px 80px rgba(0, 0, 0, 0.65);
  --ttv-crt-inset: clamp(10px, 2.2vw, 26px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

.ttv-body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ttv-cream);
  background: #000;
}

.ttv-fullscreen {
  position: fixed;
  inset: 0;
  background: #050505;
  z-index: 1;
}

.ttv-overlay-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), transparent);
  pointer-events: none;
}

.ttv-overlay-link {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  color: #fff;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
}

.ttv-overlay-link:hover {
  color: var(--ttv-phosphor);
}

/* ── CRT cabinet ── */
.ttv-screen-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #050505;
}

.ttv-crt {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}

.ttv-crt-bezel {
  position: relative;
  width: 100%;
  height: 100%;
  padding: var(--ttv-crt-inset);
  border-radius: clamp(18px, 3vw, 36px);
  background:
    linear-gradient(160deg, var(--ttv-bezel-light) 0%, var(--ttv-bezel-mid) 18%, var(--ttv-bezel-dark) 55%, #0a0808 100%);
  box-shadow:
    inset 0 2px 6px rgba(255, 255, 255, 0.22),
    inset 0 -6px 18px rgba(0, 0, 0, 0.85),
    0 12px 48px rgba(0, 0, 0, 0.7);
}

.ttv-crt-glass {
  pointer-events: none;
  position: absolute;
  inset: var(--ttv-crt-inset);
  border-radius: clamp(10px, 1.8vw, 20px);
  z-index: 12;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.12) 0%,
    transparent 28%,
    transparent 72%,
    rgba(255, 255, 255, 0.04) 100%
  );
}

.ttv-crt-screen {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: clamp(10px, 1.8vw, 20px);
  background: #000;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.55);
}

.ttv-crt-frame {
  pointer-events: none;
  position: absolute;
  inset: var(--ttv-crt-inset);
  border-radius: clamp(10px, 1.8vw, 20px);
  z-index: 11;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

/* Player layer — plain ancestors only (no transforms/filters) for Twitch visibility */
.ttv-player-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  background: #000;
}

.ttv-player-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  min-width: 400px;
  min-height: 300px;
}

.ttv-player {
  position: absolute;
  top: -7%;
  left: -4%;
  width: 108%;
  height: 122%;
  border: 0;
  background: #000;
}

video.ttv-player {
  object-fit: cover;
}

/* CRT effects — sibling overlay, not an ancestor of the iframe */
.ttv-crt-fx {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border-radius: inherit;
  overflow: hidden;
}

.ttv-screen-wrap.is-off .ttv-player-stage {
  opacity: 0;
  pointer-events: none;
}

.ttv-screen-wrap.is-off .ttv-crt-fx .ttv-osd,
.ttv-screen-wrap.is-off .ttv-crt-fx .ttv-lower-third,
.ttv-screen-wrap.is-off .ttv-crt-fx .ttv-grain,
.ttv-screen-wrap.is-off .ttv-crt-fx .ttv-scanlines,
.ttv-screen-wrap.is-off .ttv-crt-fx .ttv-glass {
  opacity: 0;
  pointer-events: none;
}

.ttv-screen-wrap.is-off .ttv-power-off {
  opacity: 1;
}

.ttv-power-off {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle, #111 0%, #000 70%);
  opacity: 0;
  transition: opacity 0.35s ease;
  z-index: 6;
}

.ttv-power-off-text {
  font-size: 0.8rem;
  letter-spacing: 0.5em;
  color: rgba(255, 255, 255, 0.15);
}

.ttv-static {
  position: absolute;
  inset: 0;
  z-index: 7;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 300 300' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='s'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23s)' opacity='0.95'/%3E%3C/svg%3E");
  animation: ttv-static-flicker 0.08s steps(3) infinite;
  mix-blend-mode: screen;
  opacity: 0.85;
}

@keyframes ttv-static-flicker {
  0% { transform: translate(0, 0) scale(1.02); }
  50% { transform: translate(-1%, 1%) scale(1.03); }
  100% { transform: translate(1%, -1%) scale(1.02); }
}

.ttv-osd {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(14px, 3vw, 28px) clamp(14px, 3vw, 24px) clamp(18px, 4vw, 32px);
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  font-family: "Courier New", Courier, monospace;
}

.ttv-osd-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: clamp(0.72rem, 2vw, 0.85rem);
  color: var(--ttv-phosphor);
}

.ttv-osd-station {
  letter-spacing: 0.18em;
  font-weight: 700;
}

.ttv-osd-live {
  color: var(--ttv-red-glow);
  font-weight: 700;
  letter-spacing: 0.12em;
  animation: ttv-blink 1.4s step-end infinite;
}

.ttv-osd-live.is-off {
  color: var(--ttv-amber);
  animation: none;
  opacity: 0.9;
}

.ttv-osd-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: clamp(0.72rem, 2vw, 0.85rem);
  color: var(--ttv-phosphor);
}

.ttv-lower-third {
  position: absolute;
  left: clamp(12px, 2.5vw, 22px);
  bottom: clamp(14px, 3vw, 26px);
  z-index: 9;
  max-width: min(78%, 520px);
  pointer-events: none;
  opacity: 0;
  transform: translateY(28px);
  filter: blur(2px);
}

.ttv-lower-third.is-visible {
  animation: ttv-lower-third-in 0.85s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.ttv-lower-third.is-out {
  animation: ttv-lower-third-out 1.1s ease-in forwards;
}

.ttv-lower-third-bar {
  height: 3px;
  margin-bottom: 6px;
  background: linear-gradient(90deg, var(--ttv-red-glow), var(--ttv-amber), var(--ttv-phosphor));
  box-shadow: 0 0 12px rgba(255, 77, 98, 0.55);
  transform-origin: left center;
  transform: scaleX(0);
}

.ttv-lower-third.is-visible .ttv-lower-third-bar {
  animation: ttv-bar-wipe 0.7s 0.15s ease-out forwards;
}

.ttv-lower-third-body {
  padding: 8px 12px 10px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.45) 85%, transparent 100%);
  border-left: 3px solid var(--ttv-red-glow);
}

.ttv-lower-third-title {
  margin: 0;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.88rem, 2.4vw, 1.15rem);
  font-weight: 700;
  color: #fff;
  text-shadow:
    1px 0 0 rgba(255, 77, 98, 0.45),
    -1px 0 0 rgba(157, 255, 184, 0.35),
    0 1px 6px rgba(0, 0, 0, 0.9);
  letter-spacing: 0.04em;
}

.ttv-lower-third-meta,
.ttv-lower-third-tune {
  margin: 4px 0 0;
  font-family: "Courier New", Courier, monospace;
  font-size: clamp(0.65rem, 1.8vw, 0.78rem);
  color: var(--ttv-amber);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
  letter-spacing: 0.06em;
}

@keyframes ttv-lower-third-in {
  0% {
    opacity: 0;
    transform: translateY(28px);
    filter: blur(3px);
  }
  60% {
    opacity: 1;
    transform: translateY(-2px);
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

@keyframes ttv-lower-third-out {
  0% {
    opacity: 1;
    transform: translateY(0) translateX(0);
    filter: blur(0);
  }
  40% {
    opacity: 0.85;
    transform: translateY(2px) translateX(-1px);
    filter: blur(0.5px);
  }
  70% {
    opacity: 0.45;
    transform: translateY(6px) translateX(2px);
    filter: blur(1.5px);
  }
  100% {
    opacity: 0;
    transform: translateY(14px) translateX(-3px);
    filter: blur(4px);
  }
}

@keyframes ttv-bar-wipe {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.ttv-osd-sat {
  color: var(--ttv-red-glow);
  animation: ttv-blink 1s step-end infinite;
}

@keyframes ttv-blink {
  50% { opacity: 0.35; }
}

.ttv-grain {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 8;
  opacity: 0.1;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
}

.ttv-scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 8;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.18) 3px,
    rgba(0, 0, 0, 0.18) 4px
  );
  opacity: 0.35;
}

.ttv-glass {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 8;
  background: linear-gradient(125deg, rgba(255, 255, 255, 0.08) 0%, transparent 35%, transparent 65%, rgba(255, 255, 255, 0.03) 100%);
}

.ttv-tap-play {
  position: absolute;
  top: calc(max(8px, env(safe-area-inset-top)) + 2 * var(--ttv-crt-inset));
  right: calc(max(8px, env(safe-area-inset-right)) + 2 * var(--ttv-crt-inset));
  bottom: calc(max(8px, env(safe-area-inset-bottom)) + 2 * var(--ttv-crt-inset));
  left: calc(max(8px, env(safe-area-inset-left)) + 2 * var(--ttv-crt-inset));
  z-index: 15;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: none;
  border-radius: clamp(10px, 1.8vw, 20px);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.ttv-tap-play i {
  font-size: 2.4rem;
  color: var(--ttv-red-glow);
}

.ttv-tap-play[hidden] {
  display: none !important;
}

/* ── Remote FAB ── */
.ttv-remote-fab {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 12px 20px;
  background: rgba(20, 10, 14, 0.82);
  color: #fff;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.ttv-remote-fab:hover {
  color: var(--ttv-phosphor);
}

.ttv-remote-fab.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(12px);
}

.ttv-remote-backdrop {
  position: fixed;
  inset: 0;
  z-index: 34;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

/* ── Remote drawer ── */
.ttv-remote {
  position: fixed;
  z-index: 35;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88vh, 820px);
  overflow: auto;
  padding: 8px 12px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #2a1c22 0%, #12080e 100%);
  border-radius: 22px 22px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 -12px 50px rgba(0, 0, 0, 0.55);
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  user-select: none;
}

.ttv-remote.is-open {
  transform: translateY(0);
}

.ttv-remote-handle {
  display: flex;
  justify-content: center;
  padding: 6px 0 10px;
}

.ttv-remote-grip {
  width: 52px;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
}

.ttv-remote-shell {
  max-width: 360px;
  margin: 0 auto;
  padding: 14px 16px 10px;
  border-radius: 28px 28px 22px 22px;
  background:
    linear-gradient(180deg, #3a2830 0%, var(--ttv-remote-body) 12%, #10080c 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    inset 0 -8px 20px rgba(0, 0, 0, 0.5),
    0 8px 24px rgba(0, 0, 0, 0.4);
}

.ttv-remote-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.ttv-remote-brand {
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: 0.92rem;
}

.ttv-remote-brand span {
  color: var(--ttv-red-glow);
}

.ttv-remote-leds {
  display: flex;
  gap: 8px;
  align-items: center;
}

.ttv-led {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #2a1018;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.6);
}

.ttv-led-power.is-on {
  background: #3ad46a;
  box-shadow: 0 0 8px rgba(58, 212, 106, 0.6);
}

.ttv-led-sat.is-on {
  background: #e8243a;
  box-shadow: 0 0 10px var(--ttv-red-glow);
}

.ttv-remote-section {
  margin-bottom: 12px;
}

.ttv-remote-section-pad {
  margin-bottom: 4px;
}

.ttv-remote-label {
  margin: 0 0 6px;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  opacity: 0.45;
  text-align: center;
}

.ttv-remote-grid {
  display: grid;
  gap: 8px;
}

.ttv-remote-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.ttv-remote-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  max-width: 228px;
  margin: 0 auto;
}

.ttv-remote-section-pad .ttv-remote-label {
  margin-bottom: 5px;
}

.ttv-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 44px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--ttv-remote-key) 0%, #1a1016 100%);
  color: var(--ttv-cream);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 8px 6px;
  cursor: pointer;
  box-shadow:
    0 4px 0 #0a0608,
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.ttv-remote-pad .ttv-key {
  min-height: 0;
  padding: 0;
  box-shadow:
    0 3px 0 #0a0608,
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.ttv-remote-pad .ttv-key:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0a0608;
}

.ttv-key:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0a0608;
}

.ttv-key-power {
  color: var(--ttv-red-glow);
  font-size: 1.1rem;
}

.ttv-key-sat {
  letter-spacing: 0.14em;
}

.ttv-key-mute {
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

.ttv-key-ch {
  flex-direction: column;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
}

.ttv-key-ch i {
  font-size: 0.85rem;
}

.ttv-key-share {
  color: #8fd3ff;
  font-size: 1rem;
}

.ttv-key-dingle {
  color: var(--ttv-amber);
}

.ttv-key-digit {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border-radius: 50%;
  font-size: 0.76rem;
}

.ttv-key-fn {
  border-radius: 10px;
  font-size: 0.58rem;
  letter-spacing: 0.06em;
  min-height: 34px;
}

.ttv-key-go {
  border-radius: 10px;
  background: linear-gradient(180deg, #4a2830 0%, #2a1418 100%);
  color: var(--ttv-red-glow);
  letter-spacing: 0.1em;
  font-size: 0.62rem;
  min-height: 34px;
}

.ttv-toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: max(88px, calc(18px + env(safe-area-inset-bottom)));
  transform: translateX(-50%);
  background: rgba(20, 10, 14, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--ttv-cream);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  box-shadow: var(--ttv-shadow);
  pointer-events: none;
}

.ttv-screen-wrap.flash-dingle {
  animation: ttv-dingle-flash 0.55s ease;
}

@keyframes ttv-dingle-flash {
  0% { filter: hue-rotate(0deg) brightness(1); }
  40% { filter: hue-rotate(40deg) brightness(1.35); }
  100% { filter: hue-rotate(0deg) brightness(1); }
}

@media (min-width: 720px) {
  .ttv-remote {
    left: 50%;
    right: auto;
    width: min(400px, 96vw);
    transform: translate(-50%, 100%);
  }

  .ttv-remote.is-open {
    transform: translate(-50%, 0);
  }
}
