/* ========== CSS Variables ========== */
:root {
  --primary: #00b4d8;
  --primary-dark: #0096b7;
  --primary-light: #48cae4;
  --accent: #caf0f8;
  --accent-dark: #90e0ef;
  --accent-light: #e0fbfc;
  --bg-dark: #0a0e1a;
  --bg-card: #121829;
  --bg-surface: #1a2138;
  --text-primary: #ffffff;
  --text-secondary: #94a3b8;
  --text-muted: #4a5568;
  --danger: #ff6b6b;
  --success: #00e676;
  --warning: #ffd93d;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --glow-blue: 0 0 20px rgba(0, 180, 216, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ========== Reset & Base ========== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  overscroll-behavior: none;
}

/* ========== Header ========== */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: calc(8px + var(--safe-top));
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  background: linear-gradient(
    180deg,
    rgba(10, 14, 26, 0.97) 0%,
    rgba(18, 24, 41, 0.92) 100%
  );
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(0, 180, 216, 0.25);
  box-shadow: 0 2px 20px rgba(0, 180, 216, 0.15);
}

.header-search {
  flex: 1;
  min-width: 0;
}

.header-search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid rgba(0, 180, 216, 0.15);
  transition: var(--transition);
}

.header-search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 180, 216, 0.15);
}

.header-search-box i {
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}

.header-search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  min-width: 0;
}

.header-search-box input::placeholder {
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ========== Icon Buttons ========== */
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  touch-action: manipulation;
}

.icon-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.2);
}

.icon-btn-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: var(--transition);
}

/* ========== Video Player Area ========== */
.player-area {
  position: fixed;
  top: calc(50px + var(--safe-top));
  left: 0;
  right: 0;
  height: 0;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  max-height: 50vh;
  background: #000;
  z-index: 10;
  overflow: hidden;
}

.player-area.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  padding-bottom: 0;
  max-height: 100vh;
  z-index: 9999;
}

#video-player {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: none;
}

#video-player.active {
  display: block;
}

.player-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}

.player-placeholder i {
  font-size: 48px;
  opacity: 0.4;
}

.player-placeholder p {
  font-size: 14px;
  opacity: 0.6;
}

/* Player Controls */
.player-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 5;
}

.player-area:hover .player-controls,
.player-area.controls-visible .player-controls {
  opacity: 1;
}

.player-controls-left,
.player-controls-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ctrl-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.ctrl-btn:active {
  transform: scale(0.9);
}

.volume-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  outline: none;
  margin-left: 4px;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
}

/* Player Channel Info Overlay */
.player-channel-info {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-sm);
  z-index: 4;
  animation: fadeIn 0.3s ease;
}

.player-ch-logo {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.1);
}

.player-ch-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
  display: block;
}

.player-ch-cat {
  font-size: 11px;
  color: var(--primary-light);
  display: block;
}

/* Player Loading */
.player-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 6;
  gap: 12px;
}

.player-loading p {
  color: var(--text-secondary);
  font-size: 13px;
}

/* Player Error */
.player-error {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  z-index: 6;
  gap: 10px;
  color: var(--danger);
}

.player-error i {
  font-size: 32px;
}

.player-error p {
  font-size: 13px;
  color: var(--text-secondary);
}

.retry-btn {
  margin-top: 6px;
  padding: 8px 20px;
  border-radius: 20px;
  border: 1.5px solid var(--primary);
  background: rgba(0, 180, 216, 0.15);
  color: var(--primary-light);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.retry-btn:hover {
  background: rgba(0, 180, 216, 0.3);
}

/* ========== Content Area ========== */
.content-area {
  position: fixed;
  /* top is set dynamically by JS based on player height */
  top: calc(50px + var(--safe-top) + 56.25vw);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  z-index: 11;
  background: var(--bg-dark);
  padding-bottom: var(--safe-bottom);
}

/* ========== Country Selector ========== */
.country-section {
  padding: 6px 12px;
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
}

.country-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.country-section-header span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.country-toggle-btn {
  border: none;
  background: rgba(0, 180, 216, 0.12);
  color: var(--primary-light);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: var(--transition);
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 4px;
}

.country-toggle-btn:active {
  transform: scale(0.95);
}

.country-toggle-btn i {
  font-size: 10px;
  transition: transform 0.3s ease;
}

.country-section.expanded .country-toggle-btn i {
  transform: rotate(180deg);
}

.country-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 82px;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.country-section.expanded .country-selector {
  max-height: 500px;
}

.country-pill {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  gap: 5px;
}

.country-pill.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.country-pill:active {
  transform: scale(0.95);
}

.country-pill .flag-emoji {
  font-size: 15px;
}

/* ========== Category Filters ========== */
.category-section {
  padding: 6px 12px;
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
}

.category-section-header {
  display: flex;
  align-items: center;
  margin-bottom: 6px;
}

.category-section-header span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.category-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cat-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  touch-action: manipulation;
}

.cat-btn.active {
  background: rgba(0, 180, 216, 0.2);
  color: var(--primary-light);
  border-color: var(--primary);
}

.cat-btn:active {
  transform: scale(0.95);
}

/* ========== Channel Count ========== */
.channel-count {
  padding: 6px 16px;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== Channel Grid ========== */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  padding: 6px 12px 20px;
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  padding-bottom: calc(20px + var(--safe-bottom));
}

.channel-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  touch-action: manipulation;
}

.channel-card:active {
  transform: scale(0.97);
}

.channel-card:hover {
  border-color: rgba(0, 180, 216, 0.3);
  box-shadow: var(--glow-blue);
}

.channel-card.playing {
  border-color: var(--primary);
  box-shadow: 0 0 16px rgba(0, 180, 216, 0.3);
}

.channel-card-top {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: linear-gradient(
    135deg,
    var(--bg-surface) 0%,
    rgba(0, 180, 216, 0.06) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.channel-card-top img {
  width: 75%;
  height: 75%;
  object-fit: contain;
  transition: var(--transition);
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

.channel-card:hover .channel-card-top img {
  transform: scale(1.08);
}

.channel-card-top .fallback-icon {
  font-size: 36px;
  color: var(--primary);
  opacity: 0.35;
}

.channel-avatar {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  gap: 4px;
  padding: 8px;
}

.channel-avatar .avatar-icon {
  font-size: 22px;
  color: rgba(255, 255, 255, 0.7);
}

.channel-avatar .avatar-name {
  font-size: 11px;
  font-weight: 700;
  color: white;
  text-align: center;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.channel-card-top .live-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--danger);
  color: white;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.channel-card-top .playing-indicator {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.playing-indicator .bar {
  width: 3px;
  background: var(--primary);
  border-radius: 1px;
  animation: equalize 0.8s ease infinite alternate;
}

.playing-indicator .bar:nth-child(1) {
  height: 60%;
  animation-delay: 0s;
}
.playing-indicator .bar:nth-child(2) {
  height: 100%;
  animation-delay: 0.2s;
}
.playing-indicator .bar:nth-child(3) {
  height: 40%;
  animation-delay: 0.4s;
}

.channel-card-bottom {
  padding: 8px 10px;
}

.channel-card-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.channel-card-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 4px;
}

.channel-card-meta .cat-tag {
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(0, 180, 216, 0.12);
  color: var(--primary-light);
  font-size: 9px;
  font-weight: 600;
}

.channel-card .fav-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  opacity: 0;
  z-index: 2;
}

.channel-card:hover .fav-btn,
.channel-card .fav-btn.favorited {
  opacity: 1;
}

.channel-card .fav-btn.favorited {
  color: var(--danger);
  background: rgba(255, 107, 107, 0.2);
}

/* ========== Favorites Panel ========== */
.favorites-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 90vw;
  z-index: 2000;
  background: var(--bg-dark);
  border-left: 1px solid rgba(0, 180, 216, 0.2);
  box-shadow: -8px 0 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  animation: slideInRight 0.3s ease;
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
  }
  to {
    transform: translateX(0);
  }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  padding-top: calc(16px + var(--safe-top));
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header h2 i {
  color: var(--danger);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.fav-channel-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.fav-channel-card:active {
  background: rgba(0, 180, 216, 0.1);
}

.fav-channel-card img {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: contain;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.fav-channel-card .fav-info {
  flex: 1;
  min-width: 0;
}

.fav-channel-card .fav-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-channel-card .fav-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.fav-channel-card .fav-remove {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 107, 107, 0.12);
  color: var(--danger);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

/* Backdrop for favorites */
.favorites-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999;
  animation: fadeIn 0.2s ease;
}

/* ========== Empty State ========== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--text-muted);
  text-align: center;
  grid-column: 1 / -1;
}

.empty-state i {
  font-size: 40px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
  line-height: 1.5;
  max-width: 260px;
}

/* ========== Loading Overlay ========== */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.loading-spinner {
  text-align: center;
  color: var(--text-primary);
}

.loading-countdown {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary);
}

/* ========== Spinner ========== */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(0, 180, 216, 0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ========== Utilities ========== */
.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes equalize {
  0% {
    height: 20%;
  }
  100% {
    height: 100%;
  }
}

/* ========== Scrollbar ========== */
.content-area::-webkit-scrollbar,
.panel-content::-webkit-scrollbar {
  width: 4px;
}

.content-area::-webkit-scrollbar-track,
.panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.content-area::-webkit-scrollbar-thumb,
.panel-content::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

/* ========== Responsive - Small Screens ========== */
@media (max-width: 374px) {
  .header-left h1 {
    font-size: 17px;
  }

  .header-logo {
    width: 30px;
    height: 30px;
  }

  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 8px;
  }
}

/* ========== Responsive - Tablet & Desktop ========== */
@media (min-width: 768px) {
  .player-area {
    padding-bottom: 0;
    height: 45vh;
    max-height: 500px;
  }

  .content-area {
    top: calc(50px + var(--safe-top) + 45vh);
  }

  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    padding: 8px 16px 24px;
  }

  .country-section,
  .category-section {
    padding: 6px 16px;
  }

  .country-selector {
    max-height: 90px;
  }

  .favorites-panel {
    width: 400px;
  }

  .volume-slider {
    width: 100px;
  }
}

@media (min-width: 1024px) {
  .player-area {
    height: 50vh;
    max-height: 560px;
  }

  .content-area {
    top: calc(50px + var(--safe-top) + 50vh);
  }

  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    max-width: 1400px;
    margin: 0 auto;
  }
}

@media (min-width: 1440px) {
  .channel-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  }
}

/* ========== Landscape Mobile ========== */
@media (max-height: 500px) and (orientation: landscape) {
  .player-area {
    height: 100%;
    max-height: 100%;
    padding-bottom: 0;
    position: fixed;
    top: 0;
    left: 0;
    width: 50%;
    right: auto;
    z-index: 10;
    padding-left: var(--safe-left);
  }

  .content-area {
    top: calc(50px + var(--safe-top));
    left: 50%;
    right: 0;
    padding-right: var(--safe-right);
  }

  .app-header {
    padding-top: calc(4px + var(--safe-top));
    padding-bottom: 4px;
  }

  .player-controls {
    padding-bottom: calc(8px + var(--safe-bottom));
    padding-left: calc(12px + var(--safe-left));
  }
}

/* ========== Mobile Touch & UX Enhancements ========== */
@media (max-width: 767px) {
  /* Larger touch targets on mobile */
  .country-pill {
    padding: 6px 14px;
    font-size: 12px;
    min-height: 32px;
  }

  .cat-btn {
    padding: 6px 14px;
    font-size: 12px;
    min-height: 32px;
  }

  /* Country section collapsed shows ~2 rows */
  .country-selector {
    max-height: 76px;
  }

  .ctrl-btn {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }

  /* Hide volume slider on mobile - use device volume instead */
  .volume-slider {
    display: none;
  }

  /* Slightly larger channel card text for readability */
  .channel-card-name {
    font-size: 13px;
  }

  .channel-card-meta {
    font-size: 11px;
  }

  /* Ensure fav button always visible on touch devices */
  .channel-card .fav-btn {
    opacity: 1;
  }

  /* Larger search input on mobile */
  .header-search-box {
    padding: 10px 16px;
  }

  .header-search-box input {
    font-size: 16px; /* Prevents iOS auto-zoom on focus */
  }

  /* Extra bottom padding for thumb reachability */
  .channel-grid {
    padding-bottom: calc(40px + var(--safe-bottom));
  }

  /* Favorites panel full width on small screens */
  .favorites-panel {
    width: 100vw;
    max-width: 100vw;
    padding-left: var(--safe-left);
  }

  .panel-header {
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
  }
}

/* ========== Android Status Bar Handling ========== */
@media (display-mode: standalone) {
  .app-header {
    padding-top: calc(12px + var(--safe-top));
  }
}

/* ========== Fullscreen Safe Areas ========== */
.player-area.fullscreen .player-controls {
  padding-bottom: calc(12px + var(--safe-bottom));
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
}

.player-area.fullscreen .player-channel-info {
  top: calc(12px + var(--safe-top));
  left: calc(12px + var(--safe-left));
}

/* ========== Safe Area Fallback ========== */
@supports not (padding: env(safe-area-inset-bottom)) {
  :root {
    --safe-bottom: 0px;
    --safe-top: 0px;
    --safe-left: 0px;
    --safe-right: 0px;
  }
}
