/* ============================================================
   serendipi.tv — style.css
   Design System: Dark TV aesthetic, glass morphism, 10-ft UI
   ============================================================ */

:root {
  --bg-deep:       #080c14;
  --bg-panel:      #0e1420;
  --bg-card:       #141c2e;
  --bg-card-hover: #1c2740;
  --bg-focused:    #1a2d50;
  --accent:        #e63946;
  --accent-glow:   rgba(230, 57, 70, 0.35);
  --gold:          #f4c430;
  --cyan:          #48cae4;
  --text-primary:  #f0f4ff;
  --text-secondary:#8896b0;
  --text-dim:      #4a5568;
  --sidebar-w:     220px;
  --hud-h:         160px;
  --ruler-h:       40px;
  --cell-h:        80px;
  --focus-ring:    0 0 0 3px var(--accent), 0 0 20px var(--accent-glow);
  --glass:         rgba(14, 20, 32, 0.85);
  --font-ui:       'Inter', sans-serif;
  --font-display:  'Outfit', sans-serif;
  --transition:    0.18s ease;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Loading Overlay ─────────────────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg-deep);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.6s ease;
}
#loading-overlay.fade-out { opacity: 0; pointer-events: none; }

#loading-inner { text-align: center; }

#loading-logo {
  font-family: var(--font-display);
  font-size: 52px; font-weight: 900;
  color: var(--text-primary);
  letter-spacing: -2px;
  margin-bottom: 32px;
}
#loading-logo span { color: var(--accent); }

#loading-bars {
  display: flex; gap: 6px; justify-content: center; margin-bottom: 20px;
}
.lbar {
  width: 6px; height: 36px; border-radius: 3px;
  background: var(--accent);
  animation: barPulse 1.1s ease-in-out infinite;
}
.lbar:nth-child(1) { animation-delay: 0s; }
.lbar:nth-child(2) { animation-delay: 0.15s; }
.lbar:nth-child(3) { animation-delay: 0.3s; }
.lbar:nth-child(4) { animation-delay: 0.45s; }
.lbar:nth-child(5) { animation-delay: 0.6s; }

@keyframes barPulse {
  0%, 100% { transform: scaleY(0.3); opacity: 0.4; }
  50%       { transform: scaleY(1);   opacity: 1;   }
}

#loading-text {
  font-size: 14px; color: var(--text-secondary);
  letter-spacing: 0.1em; text-transform: uppercase;
}

/* ── HUD ─────────────────────────────────────────────────── */
#hud {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--hud-h);
  background: linear-gradient(180deg, rgba(8,12,20,0.98) 70%, transparent);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

#hud-meta { display: flex; align-items: center; gap: 20px; flex: 1; min-width: 0; }

#hud-channel-badge {
  width: 56px; height: 56px; border-radius: 12px;
  background: var(--bg-card);
  border: 2px solid rgba(255,255,255,0.1);
  overflow: hidden; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
#hud-channel-badge img { width: 100%; height: auto; }

#hud-text { min-width: 0; }

#hud-channel-name {
  font-size: 11px; font-weight: 700; letter-spacing: 0.15em;
  text-transform: uppercase; color: var(--accent);
  margin-bottom: 4px;
}
#hud-title {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#hud-description {
  font-size: 12px; color: var(--text-secondary);
  margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 600px;
}

#hud-right { display: flex; align-items: center; gap: 24px; }

#mini-player-wrapper {
  width: 240px; height: 135px; flex-shrink: 0;
  position: relative;
}

#mini-player {
  position: absolute; top: 0; right: 0;
  width: 240px; height: 135px; /* 16:9 ratio */
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
}

body.idle-fullscreen #mini-player {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  width: 100vw; height: 100vh;
  border-radius: 0; border: none;
  z-index: 50;
}

body.idle-fullscreen #hud-meta,
body.idle-fullscreen #hud-time-block,
body.idle-fullscreen #channel-sidebar,
body.idle-fullscreen #epg-grid-wrapper,
body.idle-fullscreen #key-hints {
  opacity: 0;
  pointer-events: none;
}

#hud-meta, #hud-time-block, #channel-sidebar, #epg-grid-wrapper, #key-hints {
  transition: opacity 0.5s ease;
}

#youtube-container, #audio-player-container {
  width: 100%; height: 100%; position: absolute; inset: 0;
}
#youtube-player {
  pointer-events: none; /* Disable all controls and interactions */
  width: 100%; height: 100%;
}

#audio-player-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a2d50, #0e1f3c);
  gap: 8px;
}

#audio-visualizer {
  display: flex; gap: 4px; align-items: flex-end; height: 32px;
}
.viz-bar {
  width: 6px; border-radius: 3px;
  background: linear-gradient(180deg, var(--cyan), var(--accent));
  animation: vizAnim calc(0.7s + var(--i) * 0.12s) ease-in-out infinite alternate;
}
@keyframes vizAnim {
  0%   { height: 8px; opacity: 0.5; }
  100% { height: 32px; opacity: 1;   }
}

#audio-channel-name { display: none; }
#audio-status {
  font-size: 10px; font-weight: 800; letter-spacing: 0.15em;
  background: var(--accent); color: white;
  padding: 4px 10px; border-radius: 4px;
}

#fullscreen-back {
  position: fixed;
  top: 40px; left: 40px;
  background: rgba(0,0,0,0.6);
  color: white; border: 1px solid rgba(255,255,255,0.2);
  padding: 12px 24px; border-radius: 8px;
  font-family: var(--font-ui); font-size: 14px; font-weight: 600;
  cursor: pointer; z-index: 1000;
  backdrop-filter: blur(10px);
  transition: opacity 0.3s ease;
  pointer-events: none; opacity: 0;
}
body.idle-fullscreen #fullscreen-back.visible {
  opacity: 1; pointer-events: auto;
}

#hud-time-block { text-align: right; flex-shrink: 0; }

#hud-clock {
  font-family: var(--font-display);
  font-size: 28px; font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -1px;
}

/* ── Layout ──────────────────────────────────────────────── */
#epg-layout {
  position: fixed;
  top: var(--hud-h); bottom: 40px; left: 0; right: 0;
  display: flex; overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */
#channel-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex; flex-direction: column;
  overflow: hidden;
}

#sidebar-logo {
  height: var(--cell-h);
  display: flex; align-items: center; padding: 0 20px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.logo-text {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 900;
  color: var(--text-primary); letter-spacing: -0.5px;
}
.logo-tv { color: var(--accent); }

#channel-list { flex: 1; overflow-y: auto; }
#channel-list::-webkit-scrollbar { width: 3px; }
#channel-list::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 2px; }

.channel-row {
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  height: var(--cell-h);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition), border-color var(--transition);
  outline: none;
  position: relative;
}
.channel-row:hover, .channel-row.hover-focus {
  background: var(--bg-card-hover);
}
.channel-row.active {
  background: var(--bg-focused);
  border-left-color: var(--accent);
}
.channel-row.focused {
  background: var(--bg-focused);
  border-left-color: var(--cyan);
  box-shadow: inset 0 0 0 1px rgba(72, 202, 228, 0.2);
}

.channel-logo-wrap {
  width: 40px; height: 28px; flex-shrink: 0;
  background: var(--bg-card);
  border-radius: 6px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.channel-logo-wrap img { width: 100%; height: auto; }

.channel-info { min-width: 0; }
.channel-name {
  font-size: 12px; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.channel-type-badge {
  font-size: 9px; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim);
  margin-top: 2px;
}
.channel-type-badge.live { color: var(--accent); }

.channel-live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); margin-left: auto; flex-shrink: 0;
  animation: pulse 2s ease infinite;
  display: none;
}
.channel-row.active .channel-live-dot {
  display: block;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

/* ── EPG Grid ────────────────────────────────────────────── */
#epg-grid-wrapper {
  position: relative;
  overflow-x: hidden; /* No more horizontal scrolling */
  overflow-y: auto;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-card);
}
#epg-grid-wrapper::-webkit-scrollbar { height: 4px; width: 4px; }
#epg-grid-wrapper::-webkit-scrollbar-thumb {
  background: var(--text-dim); border-radius: 2px;
}

#time-ruler {
  height: var(--cell-h);
  border-bottom: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  position: sticky; top: 0; z-index: 20;
  background: rgba(14,20,32,0.95); backdrop-filter: blur(8px);
}
.ruler-tick {
  color: var(--text-dim); font-size: 10px; font-weight: 700;
  letter-spacing: 0.15em; text-transform: uppercase;
  padding: 0 24px;
  height: 100%; display: flex; align-items: center;
  border-right: 1px solid var(--border-subtle);
}

/* ── Grid Rows & Cells ───────────────────────────────────── */
#epg-grid {
  position: relative;
}

.grid-row {
  height: var(--cell-h);
  border-bottom: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}
.grid-row-audio { background: rgba(0,0,0,0.2); }

.grid-cell {
  height: 100%; border-right: 1px solid var(--border-subtle);
  padding: 16px 24px;
  display: flex; flex-direction: column; justify-content: center;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  transition: background var(--transition);
  position: relative; overflow: hidden;
  outline: none;
}
.grid-cell:hover, .grid-cell.focused {
  background: rgba(255,255,255,0.06);
}
.grid-cell.past { opacity: 0.5; }
.grid-cell.now-playing {
  background: linear-gradient(135deg, #1a2d50 0%, #0e1f3c 100%);
}
.grid-cell.past { opacity: 0.45; }

.cell-title {
  font-size: 12px; font-weight: 600;
  color: var(--text-primary);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.cell-time {
  font-size: 10px; color: var(--text-dim);
  margin-top: 4px;
}
.cell-progress {
  position: absolute; bottom: 0; left: 0;
  height: 3px; background: var(--accent);
  border-radius: 0 2px 0 0;
  transition: width 1s linear;
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Audio channel row in grid */
.grid-row-audio .grid-cell-audio {
  flex: 1;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: var(--bg-card);
  border-right: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  transition: background var(--transition);
  min-height: var(--cell-h);
  outline: none;
}
.grid-row-audio .grid-cell-audio:hover,
.grid-row-audio .grid-cell-audio.hover-focus { background: var(--bg-card-hover); }
.grid-row-audio .grid-cell-audio.focused {
  background: var(--bg-focused);
  box-shadow: var(--focus-ring);
  z-index: 2;
}
.audio-live-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent); color: white;
  font-size: 9px; font-weight: 800; letter-spacing: 0.12em;
  padding: 3px 8px; border-radius: 3px; text-transform: uppercase;
}
.audio-stream-info { min-width: 0; }
.audio-stream-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.audio-stream-sub  { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }



/* ── Discovery Overlay ───────────────────────────────────── */
#discovery-overlay {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 300;
  padding: 0 0 40px;
  animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
#discovery-overlay.hidden { display: none; }

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

#discovery-tray {
  background: linear-gradient(135deg, rgba(8,12,28,0.97) 0%, rgba(14,20,40,0.97) 100%);
  backdrop-filter: blur(24px);
  border-top: 1px solid rgba(255,255,255,0.12);
  border-left: 4px solid var(--accent);
  display: flex; gap: 32px; align-items: center;
  padding: 24px 32px;
}

#discovery-left { flex: 1; min-width: 0; }

#discovery-label {
  font-size: 10px; font-weight: 800; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--accent);
  display: flex; align-items: center; gap: 6px; margin-bottom: 10px;
}
.discovery-spark { font-size: 14px; }

#discovery-headline {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700;
  color: var(--text-primary); line-height: 1.3;
  margin-bottom: 8px;
}
#discovery-reason {
  font-size: 13px; color: var(--text-secondary);
  margin-bottom: 12px;
}
#discovery-link {
  font-size: 13px; font-weight: 600;
  color: var(--cyan); text-decoration: none;
  transition: color var(--transition);
}
#discovery-link:hover { color: var(--text-primary); }

#discovery-right { flex-shrink: 0; text-align: center; }

#discovery-qr-label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px;
}
#discovery-qr {
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.1);
  display: block;
}
#discovery-hint {
  text-align: center;
  font-size: 11px; color: var(--text-dim);
  padding: 6px;
}

/* ── Key Hints ───────────────────────────────────────────── */
#key-hints {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 40px;
  background: var(--bg-panel);
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 28px;
  padding: 0 24px;
  font-size: 11px; color: var(--text-dim);
  z-index: 50;
}
kbd {
  display: inline-block;
  background: var(--bg-card);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-ui);
  font-size: 10px;
  color: var(--text-secondary);
  margin-right: 3px;
}

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }

/* Current-time indicator line */
#now-indicator {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  z-index: 5;
  pointer-events: none;
}
#now-indicator::before {
  content: '';
  position: absolute; top: 0;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  left: -3px;
}
