:root{
  --bg:#14161a;
  --surface:#1d2024;
  --surface-2:#262a2f;
  --border:#33373d;
  --ink:#ece9e1;
  --muted:#8c8f94;
  --muted-2:#5f6267;
  --live:#e2412b;
  --live-ink:#ffd9d1;
  --accent:#3e8e7e;
  --accent-ink:#bfe6dd;

  --tile-1:#3e5b8e;
  --tile-2:#3e8e7e;
  --tile-3:#8e6a3e;
  --tile-4:#6a3e8e;
  --tile-5:#8e3e5b;

  --font-display:'Space Grotesk', system-ui, sans-serif;
  --font-body:'Inter', system-ui, sans-serif;
  --font-mono:'IBM Plex Mono', 'SFMono-Regular', Menlo, monospace;

  --radius:10px;
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0;height:100%;overflow:hidden;}
body{
  background:var(--bg);
  color:var(--ink);
  font-family:var(--font-body);
  font-size:15px;
  line-height:1.5;
}
button{font-family:inherit;}
.icon{width:18px;height:18px;flex-shrink:0;}

/* utility: real hidden state (wins over any component display rule) */
.is-hidden{display:none !important;}

#app{
  display:flex;
  flex-direction:column;
  height:100vh;
  overflow:hidden;
}

/* topbar */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:14px 24px;
  border-bottom:1px solid var(--border);
  flex-shrink:0;
}
.brand{
  display:flex;
  align-items:center;
  gap:10px;
}
.brand-logo{
  height:28px;
  border-radius:6px;
  width:auto;
  display:block;
  object-fit:contain;
  flex-shrink:0;
}
.wordmark{
  font-family:var(--font-display);
  font-weight:600;
  font-size:19px;
  letter-spacing:0.02em;
  display:flex;
  align-items:baseline;
  gap:2px;
}
.wordmark-sub{
  color:var(--muted);
  font-weight:500;
}
.topbar-meta{
  font-family:var(--font-mono);
  font-size:12px;
  color:var(--muted);
}

/* layout */
.layout{
  display:flex;
  flex:1;
  min-height:0;
  overflow:hidden;
}

/* sidebar */
.sidebar{
  width:300px;
  flex-shrink:0;
  border-right:1px solid var(--border);
  display:flex;
  flex-direction:column;
  height:100%;
  overflow:hidden;
  padding:16px;
  gap:14px;
}
.search-wrap{
  display:flex;
  align-items:center;
  gap:8px;
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:9px 12px;
  color:var(--muted);
  flex-shrink:0;
}
.search-wrap input{
  flex:1;
  background:none;
  border:none;
  color:var(--ink);
  font-size:14px;
  outline:none;
  min-width:0;
}
.search-wrap input::placeholder{color:var(--muted-2);}
.clear-btn{
  background:none;
  border:none;
  color:var(--muted);
  cursor:pointer;
  padding:2px;
  display:flex;
}
.clear-btn svg{width:14px;height:14px;}
.clear-btn:hover{color:var(--ink);}

.sidebar-panel{
  flex:1;
  min-height:0;
  display:flex;
  flex-direction:column;
}

.nav-item{
  display:flex;
  align-items:center;
  gap:10px;
  width:100%;
  background:none;
  border:none;
  color:var(--ink);
  text-align:left;
  padding:9px 10px;
  border-radius:8px;
  cursor:pointer;
  font-size:14px;
  flex-shrink:0;
}
.nav-item:hover{background:var(--surface);}
.nav-item .count{
  margin-left:auto;
  font-family:var(--font-mono);
  font-size:12px;
  color:var(--muted);
}
.nav-divider{
  height:1px;
  background:var(--border);
  margin:10px 2px;
  flex-shrink:0;
}
.nav-loading{
  color:var(--muted);
  font-size:13px;
  padding:8px 10px;
}
.country-flag{font-size:15px;width:20px;text-align:center;flex-shrink:0;}
.country-name{
  flex:1;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.panel-list{
  overflow-y:auto;
  flex:1;
  min-height:0;
  display:flex;
  flex-direction:column;
  gap:1px;
}
.panel-empty{
  color:var(--muted);
  font-size:13px;
  padding:20px 6px;
  text-align:center;
}

/* panel header (country / favorites detail view) */
.panel-header{
  display:flex;
  align-items:center;
  gap:8px;
  padding:2px 2px 10px;
  flex-shrink:0;
}
.back-btn{
  background:none;
  border:none;
  color:var(--ink);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:5px;
  border-radius:6px;
  flex-shrink:0;
}
.back-btn:hover{background:var(--surface);}
.back-btn svg{width:16px;height:16px;}
.panel-header-flag{font-size:16px;flex-shrink:0;}
.panel-header-title{
  font-family:var(--font-display);
  font-weight:600;
  font-size:15px;
  flex:1;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.panel-header-count{
  font-family:var(--font-mono);
  font-size:11px;
  color:var(--muted);
  flex-shrink:0;
}

/* category chips (used inside sidebar panels) */
.chip-row{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
  flex-shrink:0;
}
.panel-chips{margin-bottom:10px;}
.chip{
  background:var(--surface);
  border:1px solid var(--border);
  color:var(--muted);
  font-size:12px;
  padding:5px 11px;
  border-radius:999px;
  cursor:pointer;
}
.chip:hover{color:var(--ink);}
.chip.active{
  background:var(--accent);
  border-color:var(--accent);
  color:#06140f;
}

/* channel row (sidebar list item) */
.channel-row{
  display:flex;
  align-items:center;
  gap:10px;
  padding:8px;
  border-radius:8px;
  cursor:pointer;
  border:1px solid transparent;
}
.channel-row:hover{background:var(--surface);}
.channel-row.is-playing{border-color:var(--live);background:var(--surface-2);}
.channel-row:focus-visible,.nav-item:focus-visible,.chip:focus-visible,.back-btn:focus-visible,input:focus-visible,button:focus-visible{
  outline:2px solid var(--accent-ink);
  outline-offset:2px;
}
.row-tile{
  width:36px;
  height:36px;
  border-radius:6px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-family:var(--font-mono);
  font-weight:500;
  font-size:11px;
  color:rgba(255,255,255,0.92);
  flex-shrink:0;
}
.row-body{
  flex:1;
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:2px;
}
.row-name{
  font-size:13px;
  font-weight:500;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.row-tag{
  font-family:var(--font-mono);
  text-transform:uppercase;
  letter-spacing:0.04em;
  font-size:10px;
  color:var(--muted);
}
.row-star{
  background:none;
  border:none;
  color:var(--muted);
  cursor:pointer;
  padding:4px;
  flex-shrink:0;
  display:flex;
  border-radius:6px;
}
.row-star:hover{color:var(--ink);}
.row-star.is-fav{color:#f3c14a;}
.row-star svg{width:15px;height:15px;}

/* main */
.main{
  flex:1;
  min-width:0;
  min-height:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  padding:24px;
  overflow-y:auto;
}

.player-shell{width:100%;max-width:980px;}
.player-frame{
  position:relative;
  width:100%;
  aspect-ratio:16/9;
  background:#000;
  border-radius:var(--radius);
  overflow:hidden;
  border:1px solid var(--border);
}
.player-frame video{
  width:100%;
  height:100%;
  display:block;
  background:#000;
}
.player-empty,.player-error{
  position:absolute;
  inset:0;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:10px;
  color:var(--muted);
  text-align:center;
  padding:0 24px;
  pointer-events:none;
}
.player-error{pointer-events:auto;}
.player-empty svg{width:40px;height:40px;opacity:0.6;}
.player-error p{margin:0;max-width:320px;color:var(--ink);}
.player-error button,#retryBtn{
  background:var(--surface-2);
  border:1px solid var(--border);
  color:var(--ink);
  padding:7px 14px;
  border-radius:7px;
  cursor:pointer;
  font-size:13px;
}
.player-error button:hover{border-color:var(--muted);}

.player-bar{
  position:absolute;
  top:0;left:0;right:0;
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  background:linear-gradient(180deg, rgba(0,0,0,0.65), rgba(0,0,0,0));
  z-index:2;
}
.onair{
  display:flex;
  align-items:center;
  gap:6px;
  font-family:var(--font-mono);
  font-size:11px;
  letter-spacing:0.06em;
  color:var(--live-ink);
  background:rgba(226,65,43,0.18);
  border:1px solid rgba(226,65,43,0.4);
  padding:3px 8px;
  border-radius:5px;
  flex-shrink:0;
}
.onair-dot{
  width:7px;height:7px;
  border-radius:50%;
  background:var(--live);
  animation:pulse 1.6s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce){
  .onair-dot{animation:none;}
}
@keyframes pulse{
  0%,100%{opacity:1;}
  50%{opacity:0.35;}
}
.player-flag{font-size:16px;flex-shrink:0;}
.player-title{
  font-weight:500;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  flex:1;
}
.player-star,.player-close{
  background:rgba(0,0,0,0.35);
  border:1px solid rgba(255,255,255,0.15);
  color:#fff;
  width:30px;height:30px;
  border-radius:7px;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  flex-shrink:0;
}
.player-star svg,.player-close svg{width:15px;height:15px;}
.player-star.is-fav{color:#f3c14a;border-color:#f3c14a;}
.player-star:hover,.player-close:hover{border-color:#fff;}

.quality-control{
  position:absolute;
  bottom:44px;
  right:10px;
  z-index:3;
}
.quality-btn{
  display:flex;
  align-items:center;
  gap:5px;
  background:rgba(0,0,0,0.55);
  border:1px solid rgba(255,255,255,0.25);
  color:#fff;
  padding:5px 9px;
  border-radius:6px;
  cursor:pointer;
  font-size:11px;
  font-family:var(--font-mono);
  letter-spacing:0.02em;
}
.quality-btn svg{width:13px;height:13px;flex-shrink:0;}
.quality-btn:hover{border-color:#fff;}
.quality-menu{
  position:absolute;
  bottom:calc(100% + 6px);
  right:0;
  background:var(--surface-2);
  border:1px solid var(--border);
  border-radius:8px;
  padding:4px;
  display:flex;
  flex-direction:column;
  gap:2px;
  min-width:100px;
  box-shadow:0 8px 24px rgba(0,0,0,0.45);
}
.quality-item{
  background:none;
  border:none;
  color:var(--ink);
  text-align:left;
  padding:6px 9px;
  border-radius:5px;
  cursor:pointer;
  font-size:12px;
}
.quality-item:hover{background:var(--surface);}
.quality-item.active{color:var(--accent-ink);}

@media (max-width: 760px){
  html,body{height:auto;overflow:auto;}
  #app{height:auto;min-height:100vh;overflow:visible;}
  .layout{flex-direction:column;overflow:visible;}
  .sidebar{
    width:100%;
    height:auto;
    border-right:none;
    border-bottom:1px solid var(--border);
    overflow:visible;
  }
  .sidebar-panel{overflow:visible;}
  .panel-list{max-height:240px;}
  .main{padding:16px;overflow:visible;}
}