:root {
  --bg: #0d0d12;
  --surface: #16161f;
  --surface2: #1e1e2a;
  --surface3: #252533;
  --primary: #7c3aed;
  --primary2: #9333ea;
  --accent: #a855f7;
  --accent-glow: rgba(124,58,237,.35);
  --text: #f0f0f5;
  --muted: #6b6b80;
  --live-red: #ef4444;
  --radius: 10px;
  --nav-h: 60px;
  --topbar-h: 54px;
}
* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
#app { display: flex; flex-direction: column; height: 100%; }

#splash {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity .5s ease;
}
#splash img {
  width: 160px; object-fit: contain;
  animation: splash-pulse 1.2s ease-in-out infinite;
}
@keyframes splash-pulse {
  0%,100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.95); }
}

/* ── LOGIN TOKEN SCREEN ── */
#token-screen {
  position: fixed; inset: 0; z-index: 9998;
  background: var(--bg);
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
#token-screen.show { display: flex; }
#token-screen img { width: 100px; object-fit: contain; margin-bottom: 24px; }
#token-screen h2 { font-size: 17px; margin-bottom: 6px; }
#token-screen p { font-size: 12.5px; color: var(--muted); margin-bottom: 22px; max-width: 280px; }
#token-input {
  width: 100%; max-width: 260px;
  background: var(--surface2); border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 13px 16px;
  color: var(--text); font-size: 15px; text-align: center;
  letter-spacing: 1px; outline: none;
  text-transform: uppercase;
}
#token-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--accent-glow); }
#token-submit {
  width: 100%; max-width: 260px; margin-top: 12px;
  background: var(--primary); border: none; color: white;
  border-radius: 10px; padding: 13px 16px;
  font-size: 14px; font-weight: 700; cursor: pointer;
}
#token-submit:disabled { opacity: .6; cursor: default; }
#token-error {
  color: var(--live-red); font-size: 12px; margin-top: 14px;
  min-height: 16px;
}

/* ── TOPBAR ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); height: var(--topbar-h);
  padding: 0 16px; flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
  box-shadow: 0 2px 20px rgba(0,0,0,.6);
  position: relative; z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }
.topbar-brand img { height: 32px; object-fit: contain; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.search-wrap {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1px solid rgba(255,255,255,.07);
  border-radius: 20px; padding: 6px 12px;
}
.search-wrap svg { color: var(--muted); flex-shrink: 0; }
#search-input {
  background: none; border: none; outline: none; color: var(--text);
  font-size: 13px; width: 130px;
}
#search-input::placeholder { color: var(--muted); }

/* ── VIEWS ── */
#view-list { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
#view-channel { display: none; flex-direction: column; height: 100%; overflow: hidden; }
#view-channel.active { display: flex; }
#view-list.hidden { display: none; }

/* ── CHANNEL PAGE ── */
#ch-page-back {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 6px;
  flex-shrink: 0;
}
.back-btn {
  background: var(--surface2); border: none; color: var(--text);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}
.back-btn:active { opacity: .7; }
#ch-page-title { font-size: 14px; font-weight: 700; color: var(--text); }

/* ── PLAYER SECTION ── */
#player-section { flex-shrink: 0; background: #000; position: relative; }
#player-wrap {
  width: 100%; aspect-ratio: 16/9; max-height: 220px;
  background: #000; position: relative; overflow: hidden;
}
@media (min-height: 700px) { #player-wrap { max-height: 260px; } }
#video-el { width: 100%; height: 100%; object-fit: contain; display: block; }

#player-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; background: #000;
}
#player-placeholder .placeholder-icon { font-size: 40px; opacity: .3; }
#player-placeholder .placeholder-txt { font-size: 13px; color: var(--muted); }

#player-loading {
  position: absolute; inset: 0;
  display: none; align-items: center; justify-content: center;
  background: rgba(0,0,0,.7); z-index: 5;
}
#player-loading.show { display: flex; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#player-error {
  position: absolute; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; background: rgba(0,0,0,.85); z-index: 5;
}
#player-error.show { display: flex; }
#player-error .err-icon { font-size: 32px; }
#player-error .err-msg { font-size: 12px; color: var(--muted); text-align: center; padding: 0 20px; }
#player-error .retry-btn {
  margin-top: 4px; background: var(--primary); border: none; color: white;
  border-radius: 8px; padding: 8px 18px; cursor: pointer; font-size: 13px; font-weight: 700;
}

#live-badge {
  position: absolute; top: 10px; left: 10px;
  background: var(--live-red); color: white;
  font-size: 10px; font-weight: 800; letter-spacing: 1px;
  padding: 3px 7px; border-radius: 4px;
  z-index: 10; display: none; transition: opacity .25s;
}
#live-badge.show { display: block; opacity: 1; }
#live-badge.show.ctrl-hidden { opacity: 0 !important; animation: none !important; }
@keyframes pulse-red { 0%,100%{opacity:1} 50%{opacity:.4} }
#live-badge.pulse { animation: pulse-red 1.2s infinite; }

#ctrl-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.7) 0%, transparent 50%);
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 10px 12px; transition: opacity .2s;
}
#ctrl-overlay.hidden { opacity: 0; pointer-events: none; }
.ctrl-row { display: flex; align-items: center; gap: 8px; }
.ctrl-btn {
  background: rgba(255,255,255,.15); border: none; color: white;
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; gap: 4px; backdrop-filter: blur(4px);
}
.ctrl-btn:active { background: rgba(255,255,255,.25); }
.ctrl-spacer { flex: 1; }
#progress-bar { width: 100%; height: 3px; background: rgba(255,255,255,.2); border-radius: 2px; margin-top: 8px; }
#progress-fill { height: 100%; background: var(--accent); border-radius: 2px; width: 0; transition: width .3s; }

#now-playing-bar {
  background: var(--surface); padding: 8px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  min-height: 42px;
}
#now-playing-logo { width: 28px; height: 28px; object-fit: contain; border-radius: 4px; flex-shrink: 0; display: none; }
#now-playing-logo.show { display: block; }
#now-playing-name { font-size: 13px; font-weight: 700; color: var(--text); }
#now-playing-group { font-size: 11px; color: var(--muted); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--live-red); flex-shrink: 0; animation: pulse-red 1.2s infinite; display: none; }
.live-dot.show { display: block; }

/* ── CHANNEL GRID ── */
#channels-section {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 12px 12px calc(var(--nav-h) + 8px);
  scrollbar-width: thin; scrollbar-color: var(--surface3) transparent;
}
#channels-section::-webkit-scrollbar { width: 4px; }
#channels-section::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

#ch-page-list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 8px 12px calc(var(--nav-h) + 8px);
  scrollbar-width: thin; scrollbar-color: var(--surface3) transparent;
}
#ch-page-list::-webkit-scrollbar { width: 4px; }
#ch-page-list::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

.section-label {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin: 0 2px 10px; display: flex; align-items: center; gap: 8px;
}
.section-label::after { content:''; flex:1; height:1px; background: rgba(255,255,255,.06); }

.ch-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 20px;
}
@media (min-width: 400px) { .ch-grid { grid-template-columns: repeat(4, 1fr); } }

.ch-card {
  background: var(--surface2);
  border: 1.5px solid rgba(255,255,255,.06);
  border-radius: 10px; padding: 10px 6px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  cursor: pointer; transition: border-color .18s, background .18s, transform .12s;
  position: relative; overflow: hidden; min-height: 88px;
}
.ch-card:active { transform: scale(.96); }
.ch-card.playing {
  border-color: var(--primary);
  background: rgba(124,58,237,.12);
  box-shadow: 0 0 12px rgba(124,58,237,.25);
}
.ch-card::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(124,58,237,.05) 0%, transparent 60%);
  opacity: 0; transition: opacity .2s;
}
.ch-card:hover::before { opacity: 1; }

.ch-logo-wrap {
  width: 50px; height: 36px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.ch-logo-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }
.ch-logo-fb { font-size: 20px; opacity: .4; }
.ch-name {
  font-size: 10px; font-weight: 700; color: var(--text);
  text-align: center; line-height: 1.2; word-break: break-word; max-width: 100%;
}
.playing-indicator {
  position: absolute; top: 5px; right: 5px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--live-red); display: none;
  animation: pulse-red 1s infinite;
}
.ch-card.playing .playing-indicator { display: block; }

.empty-state { text-align: center; color: var(--muted); font-size: 14px; padding: 48px 24px; }

/* ── LOADING STATE ── */
#playlist-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 60px 24px; gap: 14px;
}
#playlist-loading .spinner { width: 40px; height: 40px; }
#playlist-loading p { color: var(--muted); font-size: 13px; }

/* ── BOTTOM NAV ── */
#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: stretch;
  z-index: 30;
  box-shadow: 0 -4px 20px rgba(0,0,0,.5);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px;
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 10px; font-weight: 600;
  transition: color .15s; padding: 6px 2px; letter-spacing: .3px;
}
.nav-btn svg { transition: transform .15s; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { transform: scale(1.15); }
.nav-btn:active { opacity: .7; }
.nav-active-bar {
  position: absolute; bottom: 0; left: 0; width: 50%;
  height: 2px; background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: left .2s cubic-bezier(.4,0,.2,1);
}

/* ── SEEK FLASH ── */
#seek-flash {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-size: 18px; font-weight: 800; color: white;
  background: rgba(0,0,0,.5); border-radius: 8px; padding: 8px 14px;
  opacity: 0; pointer-events: none; transition: opacity .3s;
}
#seek-flash.show { opacity: 1; }

/* ── KATEGORI POPUP ── */
#cat-overlay {
  display: none;
  pointer-events: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 100;
  background: rgba(0,0,0,.55);
}
#cat-overlay.show {
  display: flex;
  pointer-events: auto;
  align-items: flex-end;
  justify-content: center;
}
#cat-popup {
  width: 100%; max-width: 480px;
  background: rgba(10,10,16,.92);
  border: 1.5px solid var(--primary);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(var(--nav-h) + 16px);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  max-height: 70vh;
  overflow-y: auto;
  animation: slideUp .22s cubic-bezier(.4,0,.2,1);
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
#cat-popup h3 {
  font-size: 13px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 14px; text-align: center;
}
.cat-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px; font-weight: 600;
  border: 1.5px solid transparent;
  margin-bottom: 6px;
  transition: background .15s, border-color .15s;
}
.cat-item:active { background: rgba(124,58,237,.2); }
.cat-item.active {
  background: rgba(124,58,237,.15);
  border-color: var(--primary);
  color: var(--accent);
}
.cat-item .cat-count {
  font-size: 11px; font-weight: 700; color: var(--muted);
  background: var(--surface3); border-radius: 20px;
  padding: 2px 9px;
}
.cat-item.active .cat-count { color: var(--accent); }

/* ── LOGOUT POPUP ── */
#logout-overlay {
  display: none;
  pointer-events: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 200;
  background: rgba(0,0,0,.6);
  padding: 24px;
}
#logout-overlay.show {
  display: flex;
  pointer-events: auto;
  align-items: center;
  justify-content: center;
}
#logout-popup {
  width: 100%; max-width: 320px;
  background: var(--surface2);
  border: 1.5px solid rgba(255,255,255,.1);
  border-radius: 16px;
  padding: 28px 24px 24px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.logout-icon { color: var(--muted); margin-bottom: 4px; }
#logout-popup h3 { font-size: 16px; font-weight: 700; }
#logout-popup p { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.logout-actions {
  display: flex; gap: 10px; width: 100%; margin-top: 8px;
}
.logout-btn-cancel {
  flex: 1; background: var(--surface3); border: none; color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.logout-btn-confirm {
  flex: 1; background: var(--live-red); border: none; color: white;
  border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 700; cursor: pointer;
}
