* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0b0f;
  color: #f5f5f7;
  font-family: "LG Smart", "Segoe UI", system-ui, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  display: flex;
  width: 100%;
  height: 100%;
}

/* ---------------- Sidebar ---------------- */
#sidebar {
  width: 620px;
  height: 100%;
  background: #14141b;
  border-right: 2px solid #23232e;
  display: flex;
  flex-direction: column;
  padding: 28px 24px;
}

.sidebar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}

.logo {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -1px;
}
.logo span {
  color: #e50914;
}

.channel-count {
  font-size: 20px;
  color: #9a9aa8;
}

.search-box input {
  width: 100%;
  height: 60px;
  padding: 0 20px;
  font-size: 24px;
  border-radius: 12px;
  border: 2px solid #2c2c3a;
  background: #1d1d27;
  color: #fff;
  outline: none;
}
.search-box input:focus {
  border-color: #e50914;
  box-shadow: 0 0 0 3px rgba(229, 9, 20, 0.35);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 20px 0;
}

.tool-btn {
  flex: 1 1 auto;
  min-width: 110px;
  height: 64px;
  font-size: 21px;
  font-weight: 600;
  color: #fff;
  background: #24242f;
  border: 2px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.tool-btn:focus,
.ctrl-btn:focus {
  outline: none;
  background: #e50914;
  border-color: #ff5a63;
  transform: scale(1.06);
}

.channel-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}
.channel-list::-webkit-scrollbar { width: 8px; }
.channel-list::-webkit-scrollbar-thumb { background: #33333f; border-radius: 4px; }

.channel-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-radius: 12px;
  margin-bottom: 8px;
  background: #1a1a23;
  border: 2px solid transparent;
  cursor: pointer;
}
.channel-item:focus {
  outline: none;
  border-color: #e50914;
  background: #26262f;
  transform: scale(1.02);
}
.channel-item.active {
  background: #3a1114;
  border-color: #e50914;
}

.ch-logo {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: cover;
  background: #000;
  flex-shrink: 0;
}
.ch-logo-fallback {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #e50914;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  flex-shrink: 0;
}

.ch-info { overflow: hidden; }
.ch-name {
  font-size: 24px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ch-group {
  font-size: 18px;
  color: #8a8a98;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-hint {
  text-align: center;
  color: #6d6d7a;
  font-size: 22px;
  padding: 40px 20px;
  line-height: 1.6;
}
.empty-hint.hidden { display: none; }

/* ---------------- Player ---------------- */
#player-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000;
  position: relative;
}

.video-wrap {
  flex: 1;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#video {
  width: 100%;
  height: 100%;
  background: #000;
}

.player-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  color: #5c5c6a;
  pointer-events: none;
}
.player-overlay.hidden { display: none; }
.overlay-logo { font-size: 120px; color: #e50914; opacity: 0.7; }
.overlay-text { font-size: 28px; }

.loading-spinner {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.4);
}
.loading-spinner.show { display: flex; }
.spinner {
  width: 80px;
  height: 80px;
  border: 8px solid rgba(255,255,255,0.2);
  border-top-color: #e50914;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.now-playing {
  padding: 18px 34px;
  background: #0f0f16;
  border-top: 2px solid #1e1e28;
}
.np-title { font-size: 30px; font-weight: 700; }
.np-group { font-size: 20px; color: #9a9aa8; margin-top: 4px; }

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 34px 28px;
  background: #0f0f16;
}
.ctrl-btn {
  width: 76px;
  height: 76px;
  font-size: 32px;
  border-radius: 50%;
  background: #24242f;
  border: 2px solid transparent;
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}

.status-badge {
  margin-left: auto;
  padding: 10px 22px;
  border-radius: 30px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  background: #2a2a35;
  color: #9a9aa8;
}
.status-badge.live {
  background: #e50914;
  color: #fff;
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ---------------- Immersive (fullscreen video) ---------------- */
body.immersive #sidebar { display: none; }
body.immersive #player-area {
  position: fixed;
  inset: 0;
  z-index: 90;
}
body.immersive .video-wrap { cursor: none; }
body.immersive .now-playing {
  position: fixed;
  left: 0; right: 0; bottom: 120px;
  background: rgba(0,0,0,0.55);
  border: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
body.immersive .controls {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.85));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
/* Reveal overlays only while active (timer-driven). Hover/focus are
   intentionally NOT used so controls reliably hide after the timeout. */
body.immersive.show-controls .now-playing,
body.immersive.show-controls .controls {
  opacity: 1;
}
body.immersive.show-controls .controls {
  pointer-events: auto;
}

/* ---------------- Modal ---------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-box {
  width: 900px;
  max-height: 80%;
  background: #17171f;
  border-radius: 20px;
  padding: 40px;
  border: 2px solid #2c2c3a;
  overflow-y: auto;
}
.modal-box h2 { font-size: 34px; margin-bottom: 24px; }

.modal-input, .modal-textarea {
  width: 100%;
  font-size: 24px;
  padding: 18px;
  border-radius: 12px;
  border: 2px solid #2c2c3a;
  background: #1d1d27;
  color: #fff;
  outline: none;
}
.modal-textarea { height: 320px; resize: none; font-family: monospace; font-size: 18px; }
.modal-input:focus, .modal-textarea:focus {
  border-color: #e50914;
  box-shadow: 0 0 0 3px rgba(229,9,20,0.35);
}

.modal-actions {
  display: flex;
  gap: 16px;
  justify-content: flex-end;
  margin-top: 28px;
}
.modal-btn {
  min-width: 160px;
  height: 64px;
  font-size: 24px;
  font-weight: 600;
  border-radius: 12px;
  border: 2px solid transparent;
  background: #24242f;
  color: #fff;
  cursor: pointer;
}
.modal-btn.primary { background: #e50914; }
.modal-btn:focus {
  outline: none;
  border-color: #ff5a63;
  transform: scale(1.05);
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  background: #1d1d27;
  border-radius: 12px;
  margin-bottom: 12px;
  border: 2px solid transparent;
  cursor: pointer;
}
.saved-item:focus { outline: none; border-color: #e50914; background: #26262f; }
.saved-name { font-size: 24px; font-weight: 600; }
.saved-meta { font-size: 18px; color: #8a8a98; }
.saved-del {
  padding: 8px 16px;
  font-size: 18px;
  border-radius: 8px;
  border: none;
  background: #3a1114;
  color: #ff8a8a;
  cursor: pointer;
}
.saved-del:focus { outline: 2px solid #e50914; }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: #e50914;
  color: #fff;
  font-size: 24px;
  font-weight: 600;
  padding: 18px 36px;
  border-radius: 40px;
  z-index: 200;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.toast.hidden { display: none; }

/* ---------------- Responsive (desktop / tablet / mobile) ---------------- */

/* Laptops / small desktops: scale down TV proportions */
@media (max-width: 1400px) {
  #sidebar { width: 34%; min-width: 300px; padding: 20px 16px; }
  .logo { font-size: 30px; }
  .search-box input { height: 52px; font-size: 20px; }
  .tool-btn { height: 54px; font-size: 18px; }
  .ch-name { font-size: 20px; }
  .ch-group { font-size: 16px; }
  .ctrl-btn { width: 64px; height: 64px; font-size: 26px; }
  .np-title { font-size: 24px; }
  .np-group { font-size: 18px; }
  .overlay-logo { font-size: 90px; }
  .overlay-text { font-size: 22px; }
}

@media (max-width: 1000px) {
  #sidebar { width: 320px; min-width: 260px; }
  .channel-count { font-size: 15px; }
  .ch-logo, .ch-logo-fallback { width: 46px; height: 46px; }
  .modal-box { width: 90%; padding: 28px; }
}

/* Phones / small tablets: stack player above the channel list */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  #player-area { flex: 0 0 auto; height: 40vh; min-height: 220px; }
  #sidebar {
    width: 100%;
    min-width: 0;
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    border-right: none;
    border-top: 2px solid #23232e;
    padding: 14px 14px 18px;
  }
  .sidebar-head { margin-bottom: 12px; }
  .logo { font-size: 24px; }
  .search-box input { height: 46px; font-size: 16px; }
  .toolbar { margin: 12px 0; gap: 8px; }
  .tool-btn { height: 46px; font-size: 15px; min-width: 84px; }
  .channel-item { padding: 10px 12px; gap: 12px; margin-bottom: 6px; }
  .ch-name { font-size: 17px; }
  .ch-group { font-size: 14px; }
  .ch-logo, .ch-logo-fallback { width: 40px; height: 40px; }
  .now-playing { padding: 10px 16px; }
  .np-title { font-size: 18px; }
  .np-group { font-size: 14px; }
  .controls { padding: 10px 12px 14px; gap: 10px; flex-wrap: wrap; }
  .ctrl-btn { width: 52px; height: 52px; font-size: 22px; }
  .status-badge { font-size: 15px; padding: 6px 14px; }
  .overlay-logo { font-size: 60px; }
  .overlay-text { font-size: 17px; text-align: center; padding: 0 16px; }
  .modal-box { width: 94%; padding: 20px; max-height: 88%; }
  .modal-box h2 { font-size: 24px; }
  .modal-textarea { height: 220px; }
  .modal-btn { min-width: 110px; height: 52px; font-size: 18px; }
  .toast { font-size: 16px; padding: 12px 22px; bottom: 30px; }
}

/* Landscape phones: keep side-by-side but compact */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  #app { flex-direction: row; }
  #sidebar { width: 42%; min-width: 0; height: 100%; border-top: none; }
  #player-area { height: 100%; }
}
