:root {
  --tv-bg: #050914;
  --tv-panel: rgba(15, 23, 42, 0.92);
  --tv-panel-soft: rgba(30, 41, 59, 0.78);
  --tv-text: #f8fafc;
  --tv-muted: #a8b4c8;
  --tv-line: rgba(148, 163, 184, 0.24);
  --tv-accent: #3b82f6;
  --tv-accent-strong: #2563eb;
  --tv-success: #22c55e;
  --tv-danger: #ef4444;
  --text: var(--tv-text);
  --panel: #0f172a;
  --line: var(--tv-line);
  --accent: var(--tv-accent);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, "Segoe UI", sans-serif;
  color: var(--tv-text);
  background:
    radial-gradient(circle at 15% 8%, rgba(37, 99, 235, 0.3), transparent 34rem),
    radial-gradient(circle at 92% 88%, rgba(14, 165, 233, 0.18), transparent 28rem),
    var(--tv-bg);
}

button,
input,
select { font: inherit; }

button,
.tv-button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 12px 18px;
  color: #fff;
  background: var(--tv-accent-strong);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.tv-button:hover { background: var(--tv-accent); }

button:focus-visible,
.tv-button:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(96, 165, 250, 0.66);
  outline-offset: 3px;
}

button:disabled { cursor: not-allowed; opacity: 0.55; }

.tv-button.secondary,
button.secondary {
  border-color: var(--tv-line);
  color: var(--tv-text);
  background: var(--tv-panel-soft);
}

.tv-shell {
  width: min(1500px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 50px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.tv-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tv-header .quick-share-language-label > span:first-child {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tv-header .quick-share-language-control { min-width: 190px; }

.tv-brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: var(--tv-text);
  text-decoration: none;
}

.tv-brand img { width: 48px; height: 48px; border-radius: 12px; }
.tv-brand strong { display: block; font-size: 23px; }
.tv-brand span { display: block; color: var(--tv-muted); font-size: 13px; }

.tv-panel {
  width: min(1120px, 100%);
  margin: auto;
  padding: clamp(22px, 4vw, 50px);
  border: 1px solid var(--tv-line);
  border-radius: 18px;
  background: var(--tv-panel);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.38);
}

.tv-panel[hidden] { display: none !important; }

.tv-kicker {
  display: block;
  margin-bottom: 10px;
  color: #60a5fa;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tv-panel h1,
.tv-panel h2 { margin: 0; line-height: 1.1; }
.tv-panel h1 { font-size: clamp(34px, 5vw, 66px); }
.tv-panel h2 { font-size: clamp(27px, 3.3vw, 44px); }
.tv-lead { max-width: 850px; margin: 18px 0 0; color: var(--tv-muted); font-size: clamp(17px, 2vw, 24px); line-height: 1.5; }

.tv-policy {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 28px 0;
  color: var(--tv-muted);
  font-size: 17px;
  line-height: 1.45;
}

.tv-policy input { width: 24px; height: 24px; flex: 0 0 auto; accent-color: var(--tv-accent); }
.tv-policy a { color: #93c5fd; }

.tv-mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 28px 0 0;
  padding: 0;
  border: 0;
}

.tv-mode-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 17px;
  border: 1px solid var(--tv-line);
  border-radius: 13px;
  background: rgba(2, 6, 23, 0.55);
  cursor: pointer;
}

.tv-mode-card:has(input:checked) { border-color: rgba(96, 165, 250, 0.72); background: rgba(37, 99, 235, 0.14); }
.tv-mode-card:has(input:disabled),
.tv-mode-card.disabled { cursor: not-allowed; opacity: 0.58; }
.tv-mode-card input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--tv-accent); }
.tv-mode-card strong,
.tv-mode-card small { display: block; }
.tv-mode-card small { margin-top: 7px; color: var(--tv-muted); line-height: 1.4; }
.tv-mode-card em { padding: 3px 6px; border-radius: 999px; color: #bfdbfe; background: rgba(37, 99, 235, 0.28); font-size: 11px; font-style: normal; }
.tv-processing-consent { margin-top: -10px; padding: 14px; border: 1px solid rgba(245, 158, 11, 0.35); border-radius: 12px; background: rgba(245, 158, 11, 0.08); }
.tv-adaptive-option { margin-top: -10px; padding: 14px; border: 1px solid rgba(34, 197, 94, 0.34); border-radius: 12px; background: rgba(34, 197, 94, 0.08); }
.tv-track-option { margin-top: -10px; padding: 14px; border: 1px solid rgba(168, 85, 247, 0.34); border-radius: 12px; background: rgba(168, 85, 247, 0.08); }
.tv-mode-notice { margin-top: 18px; padding: 13px 15px; border: 1px solid rgba(96, 165, 250, 0.35); border-radius: 11px; color: #bfdbfe; background: rgba(37, 99, 235, 0.1); line-height: 1.45; }

.tv-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }
.tv-actions + .tv-status { margin-top: 18px; }

.tv-pair-grid {
  display: grid;
  grid-template-columns: minmax(280px, 440px) 1fr;
  align-items: center;
  gap: clamp(24px, 5vw, 70px);
}

.tv-qr-frame {
  padding: 15px;
  border-radius: 16px;
  background: #fff;
}

.tv-qr-frame img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; }

.tv-code {
  display: inline-flex;
  margin-top: 18px;
  padding: 13px 18px;
  border: 1px solid rgba(96, 165, 250, 0.4);
  border-radius: 12px;
  background: rgba(37, 99, 235, 0.14);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: clamp(25px, 4vw, 48px);
  font-weight: 900;
  letter-spacing: 0.14em;
}

.tv-link-field {
  width: 100%;
  margin-top: 18px;
  padding: 13px 14px;
  border: 1px solid var(--tv-line);
  border-radius: 10px;
  color: var(--tv-muted);
  background: rgba(2, 6, 23, 0.76);
}

.tv-status {
  min-height: 52px;
  padding: 15px 18px;
  border: 1px solid var(--tv-line);
  border-radius: 12px;
  color: var(--tv-muted);
  background: rgba(2, 6, 23, 0.62);
  line-height: 1.4;
}

.tv-status.success { border-color: rgba(34, 197, 94, 0.45); color: #bbf7d0; }
.tv-status.error { border-color: rgba(239, 68, 68, 0.5); color: #fecaca; }

.tv-player-panel {
  width: 100%;
  max-width: none;
  padding: 0;
  overflow: hidden;
  background: #000;
}

.tv-video-wrap {
  position: relative;
  display: grid;
  min-height: min(72vh, 820px);
  place-items: center;
  background: #000;
}

.tv-video-wrap video { width: 100%; max-height: 78vh; background: #000; }

.tv-play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  gap: 14px;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.28), rgba(0, 0, 0, 0.6));
  font-size: clamp(26px, 4vw, 50px);
}

.tv-play-overlay[hidden] { display: none; }

.tv-player-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 18px 18px;
  background: #070b14;
}

.tv-player-controls button { min-width: 60px; }
.tv-symbol-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
}
.tv-symbol-button span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.tv-symbol {
  display: block;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  object-fit: contain;
  pointer-events: none;
}
.tv-symbol-large {
  width: clamp(38px, 5vw, 64px);
  height: clamp(38px, 5vw, 64px);
  flex-basis: clamp(38px, 5vw, 64px);
}
.tv-quality { display: flex; align-items: center; gap: 8px; color: var(--tv-muted); font-size: 14px; }
.tv-quality select { min-height: 40px; padding: 7px 10px; border: 1px solid var(--tv-line); border-radius: 9px; color: var(--tv-text); background: #111827; }
.tv-player-time { margin-left: auto; color: var(--tv-muted); font-variant-numeric: tabular-nums; }
.tv-player-time,
#controllerPlaybackTime { direction: ltr; unicode-bidi: isolate; }

.tv-controller-shell { width: min(760px, 100%); padding: 18px; }
.tv-controller-shell .tv-panel { padding: clamp(20px, 5vw, 34px); border-radius: 14px; }
.tv-controller-shell .tv-panel h1 { font-size: clamp(32px, 9vw, 50px); }

.tv-field { display: grid; gap: 8px; margin-top: 18px; }
.tv-field span { color: var(--tv-muted); font-weight: 700; }
.tv-field input[type="text"],
.tv-field input[type="file"] {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid var(--tv-line);
  border-radius: 10px;
  color: var(--tv-text);
  background: rgba(2, 6, 23, 0.8);
}

.tv-progress { margin-top: 18px; }
.tv-progress-track { height: 12px; overflow: hidden; border-radius: 999px; background: rgba(148, 163, 184, 0.2); }
.tv-progress-fill { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #2563eb, #22c55e); transition: width 160ms linear; }
.tv-progress-label { display: flex; justify-content: space-between; gap: 10px; margin-top: 7px; color: var(--tv-muted); }
.tv-progress-label span { min-width: 0; overflow-wrap: anywhere; }
.tv-progress-label strong { flex: 0 0 auto; }

.tv-file-card,
.tv-playback-card {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--tv-line);
  border-radius: 12px;
  background: rgba(2, 6, 23, 0.55);
}

.tv-file-card strong,
.tv-playback-card strong { display: block; overflow-wrap: anywhere; }
.tv-file-card span,
.tv-playback-card span { display: block; margin-top: 5px; color: var(--tv-muted); }

.tv-remote-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.tv-remote-grid button { min-width: 0; min-height: 58px; padding: 12px 10px; font-size: 16px; }
.tv-remote-grid .wide { grid-column: span 3; }

.tv-remote-timeline {
  display: grid;
  gap: 9px;
  margin-top: 18px;
  color: var(--tv-muted);
  font-weight: 700;
}

.tv-remote-timeline input,
.tv-remote-control input[type="range"] {
  width: 100%;
  direction: ltr;
  accent-color: var(--tv-accent);
}

.tv-remote-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.tv-remote-control {
  display: grid;
  align-content: center;
  gap: 9px;
  min-height: 82px;
  padding: 13px 14px;
  border: 1px solid var(--tv-line);
  border-radius: 11px;
  color: var(--tv-muted);
  background: rgba(2, 6, 23, 0.55);
  font-weight: 700;
}

.tv-remote-control[hidden] { display: none; }
.tv-remote-control span { display: flex; justify-content: space-between; gap: 12px; }
.tv-remote-control output { color: var(--tv-text); }
.tv-remote-control select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--tv-line);
  border-radius: 9px;
  color: var(--tv-text);
  background: #111827;
}

.tv-small { color: var(--tv-muted); font-size: 14px; line-height: 1.45; }

@media (max-width: 760px) {
  .tv-shell { padding: 14px; }
  .tv-header { align-items: flex-start; }
  .tv-header-actions { max-width: 56%; flex-direction: column; align-items: stretch; }
  .tv-brand span { display: none; }
  .tv-pair-grid { grid-template-columns: 1fr; }
  .tv-mode-grid { grid-template-columns: 1fr; }
  .tv-qr-frame { width: min(360px, 100%); margin: 0 auto; }
  .tv-actions { display: grid; grid-template-columns: 1fr; }
  .tv-actions > * { width: 100%; text-align: center; }
  .tv-player-controls { flex-wrap: wrap; }
  .tv-player-time { width: 100%; margin-left: 0; text-align: center; }
  .tv-remote-settings { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .tv-remote-grid .tv-symbol-button:not(.wide) span { display: none; }
  .tv-remote-grid .tv-symbol-button[data-display]::after {
    content: attr(data-display);
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
  }
}
