:root {
  --gold: #d4af37;
  --gold-light: #f5d76e;
  --gold-dark: #9a7720;
  --bg: #07040f;
  --surface: #120a22;
  --surface2: #1e1235;
  --text: #f5f0e8;
  --muted: #9b8fb8;
  --live: #ff3b3b;
  --radius: 16px;
  --sidebar-w: 340px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 10% -20%, rgba(212,175,55,.12), transparent 50%),
    radial-gradient(ellipse 60% 50% at 100% 100%, rgba(80,40,140,.25), transparent);
  pointer-events: none;
}

.tv-app { display: flex; height: 100vh; height: 100dvh; position: relative; z-index: 1; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: rgba(18,10,34,.97);
  border-right: 1px solid rgba(212,175,55,.12);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(20px);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.brand-icon {
  width: 44px; height: 44px;
  background: linear-gradient(145deg, var(--gold-light), var(--gold-dark));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 20px rgba(212,175,55,.35);
}
.brand strong { font-size: 16px; font-weight: 800; letter-spacing: -.3px; }
.brand small { color: var(--gold); font-size: 10px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; }

.search-wrap { padding: 14px 16px 10px; position: relative; }
.search-icon { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); font-size: 14px; opacity: .5; pointer-events: none; }
.search-wrap input {
  width: 100%;
  padding: 12px 14px 12px 38px;
  border-radius: 12px;
  border: 1px solid rgba(212,175,55,.15);
  background: rgba(0,0,0,.35);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-wrap input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,175,55,.12);
}

.stats-bar {
  padding: 0 16px 12px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}
.live-dot {
  width: 8px; height: 8px;
  background: var(--live);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--live);
  animation: pulse 1.4s ease infinite;
}
@keyframes pulse { 50% { opacity: .4; transform: scale(.85); } }

.groups {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px calc(16px + var(--safe-b));
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dark) transparent;
}

.group-title {
  padding: 10px 12px 8px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--gold);
  position: sticky;
  top: 0;
  background: rgba(18,10,34,.97);
  z-index: 2;
}

.channel-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition: all .18s ease;
}
.channel-btn:hover { background: rgba(212,175,55,.08); border-color: rgba(212,175,55,.15); }
.channel-btn.active {
  background: linear-gradient(90deg, rgba(212,175,55,.18), rgba(212,175,55,.04));
  border-color: rgba(212,175,55,.35);
  box-shadow: inset 3px 0 0 var(--gold);
}
.channel-btn img {
  width: 64px; height: 64px;
  border-radius: 14px;
  object-fit: contain;
  background: rgba(0,0,0,.5);
  padding: 6px;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
}
.channel-btn .no-logo {
  width: 64px; height: 64px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(212,175,55,.2), rgba(212,175,55,.05));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.channel-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #000; }

.player-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,.05);
  z-index: 10;
}

.btn-icon {
  background: rgba(255,255,255,.06);
  border: none;
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 18px;
  display: none;
  align-items: center;
  justify-content: center;
}
.sidebar-close { display: none; }

.now-playing { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.now-playing span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; font-size: 15px; }

.live-badge {
  background: var(--live);
  color: #fff;
  font-size: 9px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: .8px;
  flex-shrink: 0;
  animation: pulse 2s infinite;
}

.btn-outline-sm {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid rgba(212,175,55,.3);
  color: var(--gold-light);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

/* ── Player stage ── */
.player-stage {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

#player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  transition: object-fit .3s ease, transform .3s ease;
}

.player-stage.zoom-fill #player {
  object-fit: cover;
  transform: scale(1.02);
}

.player-stage:fullscreen #player,
.player-stage:-webkit-full-screen #player {
  object-fit: contain;
  max-height: 100vh;
}

.player-stage:fullscreen.zoom-fill #player,
.player-stage:-webkit-full-screen.zoom-fill #player {
  object-fit: cover;
}

.player-watermark {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 4;
  pointer-events: none;
}
.player-watermark img {
  height: 72px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  filter: drop-shadow(0 3px 12px rgba(0,0,0,.9));
  opacity: .95;
}

.unmute-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
  z-index: 8;
  padding: 14px 24px;
  border-radius: 50px;
  border: none;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: #1a0a2e;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(212,175,55,.45);
  animation: bounce 2s ease infinite;
}
@keyframes bounce { 0%,100%{transform:translate(-50%,-50%) scale(1)} 50%{transform:translate(-50%,-50%) scale(1.04)} }

.player-controls {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: linear-gradient(transparent 40%, rgba(0,0,0,.75) 100%);
  opacity: 1;
  transition: opacity .25s;
  pointer-events: none;
}
.player-controls > * { pointer-events: auto; }
.player-stage.controls-hidden .player-controls { opacity: 0; }
.player-stage.controls-hidden .player-controls * { pointer-events: none; }

.controls-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(rgba(0,0,0,.65), transparent);
}

.ctrl-channel { display: flex; align-items: center; gap: 12px; }
.ctrl-channel img {
  width: 52px; height: 52px;
  border-radius: 12px;
  object-fit: contain;
  background: rgba(0,0,0,.5);
  padding: 4px;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.ctrl-channel strong { display: block; font-size: 14px; font-weight: 700; }
.ctrl-channel span { font-size: 11px; color: var(--gold); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }

.live-pill {
  background: rgba(255,59,59,.2);
  border: 1px solid var(--live);
  color: var(--live);
  font-size: 10px;
  font-weight: 900;
  padding: 5px 12px;
  border-radius: 20px;
  letter-spacing: 1px;
}

.controls-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px calc(14px + var(--safe-b));
}

.ctrl-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, transform .1s;
}
.ctrl-btn:active { transform: scale(.92); background: rgba(212,175,55,.35); }
.ctrl-btn.active { background: rgba(212,175,55,.4); color: #fff; box-shadow: 0 0 12px rgba(212,175,55,.35); }
.ctrl-live { width: auto; padding: 0 16px; border-radius: 22px; font-size: 12px; font-weight: 800; letter-spacing: .5px; }

.volume-slider {
  width: 80px;
  accent-color: var(--gold);
  cursor: pointer;
}
.ctrl-spacer { flex: 1; }

.player-start {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(30,18,53,.9), rgba(0,0,0,.95));
  text-align: center;
  padding: 24px;
  transition: opacity .35s, visibility .35s;
}
.player-start.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.start-logo { font-size: 56px; margin-bottom: 16px; filter: drop-shadow(0 4px 20px rgba(212,175,55,.4)); }
.player-start h2 { font-size: 28px; font-weight: 800; margin-bottom: 8px; background: linear-gradient(90deg, var(--gold-light), var(--gold)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.player-start p { color: var(--muted); font-size: 15px; }

/* ── Footer quick ── */
.player-footer {
  padding: 12px 16px calc(12px + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.05);
}
.quick-label { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 10px; }

.quick-channels {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.quick-channels::-webkit-scrollbar { display: none; }

.quick-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 8px;
  border-radius: 14px;
  border: 1px solid rgba(212,175,55,.2);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.quick-btn img { width: 44px; height: 44px; border-radius: 10px; object-fit: contain; background: rgba(0,0,0,.4); padding: 3px; }
.quick-btn.active, .quick-btn:hover {
  border-color: var(--gold);
  background: rgba(212,175,55,.15);
  color: var(--gold-light);
}

/* ── Mobile — full screen cinema ── */
@media (max-width: 768px) {
  :root { --sidebar-w: 100vw; }

  .tv-app { height: 100dvh; height: 100svh; }

  .main {
    position: relative;
    flex: 1;
    min-height: 0;
    height: 100dvh;
    height: 100svh;
  }

  .player-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 25;
    background: linear-gradient(rgba(0,0,0,.75), transparent);
    border: none;
    padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px;
  }

  .player-footer { display: none; }

  .player-stage {
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    min-height: 100svh;
  }

  #player {
    object-fit: cover;
  }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    width: 100vw;
    min-width: 100vw;
    max-width: 100vw;
    transform: translateX(-105%);
    box-shadow: 8px 0 40px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: translateX(0); }

  .channel-btn {
    padding: 12px 14px;
    font-size: 15px;
  }
  .channel-btn img,
  .channel-btn .no-logo {
    width: 72px;
    height: 72px;
  }

  .btn-icon, .sidebar-close { display: flex; }
  .volume-slider { width: 56px; }
  .player-watermark img { height: 64px; max-width: 140px; }
  .player-header .btn-outline-sm { display: none; }
  .controls-bar { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .ctrl-channel img { width: 56px; height: 56px; }
}

@media (min-width: 769px) {
  .player-stage:hover .player-controls { opacity: 1; }
}
