:root {
  --bg:            #0a0d12;
  --bg-2:          #0d1119;
  --glass:         rgba(255,255,255,0.045);
  --glass-strong:  rgba(255,255,255,0.08);
  --border:        rgba(255,255,255,0.09);
  --teal:          #45e6c7;
  --teal-dim:      rgba(69,230,199,0.35);
  --coral:         #ff5c4d;
  --text:          #f2f5f7;
  --text-muted:    #8792a2;
  --ctrl-h:        52px;        /* ارتفاع نوار کنترل‌های پلیر */
  --font-display:  'Space Grotesk', sans-serif;
  --font-body:     'Inter', sans-serif;
  --font-mono:     'JetBrains Mono', monospace;
}

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

html, body {
  height: 100%;
  color-scheme: dark;
  background: radial-gradient(ellipse at 20% -10%, #121826 0%, var(--bg) 45%, #060709 100%);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
}

/* ---------- scanline ---------- */
.scanline-overlay {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.012) 0px, rgba(255,255,255,0.012) 1px,
    transparent 1px, transparent 3px
  );
  mix-blend-mode: overlay;
}

/* ================================================================
   TOPBAR
   ================================================================ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 32px;
  position: sticky; top: 0; z-index: 50;
  background: rgba(10,13,18,0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex; align-items: baseline; gap: 8px;
  font-family: var(--font-display); flex-shrink: 0;
}
.brand-mark {
  background: linear-gradient(135deg, var(--teal), #1fae95);
  color: #06110e; font-weight: 700;
  padding: 4px 10px; border-radius: 6px;
  letter-spacing: 0.5px;
  box-shadow: 0 0 24px var(--teal-dim);
}
.brand-name {
  font-size: 15px; letter-spacing: 3px;
  color: var(--text-muted); font-weight: 600; white-space: nowrap;
}
.brand-dot { color: var(--coral); }

.menu-toggle {
  display: none; width: 40px; height: 40px;
  align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--glass); color: var(--text);
  flex-shrink: 0; cursor: pointer;
}
.menu-toggle svg { width: 20px; height: 20px; }

.controls {
  display: flex; align-items: center; gap: 12px;
  flex-wrap: nowrap; flex: 1;
  justify-content: flex-end; min-width: 0;
}

.search-wrap {
  position: relative; display: flex; align-items: center;
  flex: 1; max-width: 280px; min-width: 0;
}
.search-icon {
  position: absolute; right: 12px;
  width: 16px; height: 16px;
  color: var(--text-muted); pointer-events: none;
}
#search {
  width: 100%;
  padding: 9px 38px 9px 14px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--glass); color: var(--text);
  font-family: var(--font-body); font-size: 14px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
#search:focus {
  border-color: var(--teal-dim);
  box-shadow: 0 0 0 3px rgba(69,230,199,0.12);
}

/* dropdown */
.dropdown { position: relative; flex-shrink: 0; }
.dropdown-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--glass); color: var(--text);
  font-family: var(--font-body); font-size: 13px;
  max-width: 150px; cursor: pointer; white-space: nowrap;
}
.dropdown-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-btn .chev {
  width: 14px; height: 14px; flex-shrink: 0;
  color: var(--text-muted); transition: transform .2s;
}
.dropdown.open .dropdown-btn .chev { transform: rotate(180deg); }
.dropdown-panel {
  position: absolute; top: calc(100% + 8px); left: 0;
  min-width: 220px; max-width: 280px; max-height: 340px;
  overflow-y: auto; background: #12151d;
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 20px 50px -15px rgba(0,0,0,0.6);
  padding: 6px; display: none; z-index: 60;
}
.dropdown.open .dropdown-panel { display: block; }
.dropdown-item {
  padding: 9px 12px; border-radius: 8px;
  font-size: 13px; color: var(--text-muted);
  cursor: pointer; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.dropdown-item:hover { background: var(--glass-strong); color: var(--text); }
.dropdown-item.active { background: rgba(69,230,199,0.12); color: var(--teal); }

.channel-count {
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-muted); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 10px;
  background: var(--glass); white-space: nowrap; flex-shrink: 0;
}

/* mobile backdrop */
.controls-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 40;
}
.controls-backdrop.show { display: block; }

/* ================================================================
   STAGE  –  two-column layout on desktop
   ================================================================ */
.stage {
  display: grid;
  grid-template-columns: 1fr 380px;   /* پلیر | لیست */
  grid-template-rows: 1fr;
  gap: 20px;
  padding: 16px 28px 40px;
  max-width: 1440px;
  margin: 0 auto;
  min-height: calc(100vh - 62px);
  align-items: start;
}

/* ================================================================
   PLAYER COLUMN
   ================================================================ */
.player-col {
  position: sticky;
  top: 78px;          /* زیر هدر می‌مونه */
}

.monitor-bezel {
  background: linear-gradient(160deg, #1a2029, #0c0f14 60%);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 14px;
  box-shadow:
    0 30px 80px -30px rgba(0,0,0,0.7),
    inset 0 1px 0 rgba(255,255,255,0.04);
}

.monitor-top {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 6px 12px;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-muted);
}

.rec-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #3a4048; flex-shrink: 0;
  transition: background .3s, box-shadow .3s;
}
.rec-dot.live {
  background: var(--coral);
  box-shadow: 0 0 10px 2px rgba(255,92,77,0.6);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}
.now-label { flex: 1; color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-tag {
  color: var(--teal); border: 1px solid var(--teal-dim);
  padding: 3px 10px; border-radius: 6px; flex-shrink: 0;
}

/* ================================================================
   SCREEN  +  CUSTOM PLAYER CONTROLS
   ================================================================ */
.screen {
  position: relative;
  width: 100%; aspect-ratio: 16/9;
  background: #000; border-radius: 12px;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.6);
}

#video {
  width: 100%; height: 100%;
  display: block; background: #000;
}

.screen-noise {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0,0,0,0.55) 100%);
}

/* placeholder */
.screen-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #06070a;
  transition: opacity .3s;
}
.screen-placeholder.hidden { opacity: 0; pointer-events: none; }
.placeholder-inner {
  display: flex; flex-direction: column;
  align-items: center; gap: 14px;
  color: var(--text-muted);
  font-family: var(--font-mono); font-size: 13px;
  text-align: center; padding: 20px;
}
.placeholder-icon {
  width: 56px; height: 56px;
  color: rgba(255,255,255,0.15);
}

/* ---- custom controls overlay ---- */
.player-controls {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 0 12px 10px;
  background: linear-gradient(to top, rgba(0,0,0,0.82) 0%, transparent 100%);
  opacity: 0;
  transition: opacity .22s ease;
  pointer-events: none;
}
.screen:hover .player-controls,
.screen.controls-pinned .player-controls {
  opacity: 1;
  pointer-events: auto;
}

/* progress */
.progress-bar-wrap {
  padding: 8px 0 6px;
  cursor: pointer;
}
.progress-bar {
  position: relative;
  height: 4px; border-radius: 4px;
  background: rgba(255,255,255,0.18);
  transition: height .15s;
}
.progress-bar-wrap:hover .progress-bar { height: 6px; }
.progress-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--teal); border-radius: 4px;
  width: 0%;
  transition: width .25s linear;
  pointer-events: none;
}
/* live stream → barre complète animée */
.live-mode .progress-fill {
  width: 100%;
  background: linear-gradient(90deg, var(--teal) 0%, #1fae95 60%, var(--teal-dim) 100%);
  animation: live-bar 2s linear infinite;
  background-size: 200% 100%;
}
@keyframes live-bar {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.progress-thumb {
  position: absolute; top: 50%;
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; transform: translate(-50%, -50%);
  left: 0%;
  opacity: 0; transition: opacity .15s;
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
  pointer-events: none;
}
.progress-bar-wrap:hover .progress-thumb { opacity: 1; }

/* controls row */
.controls-row {
  display: flex; align-items: center;
  justify-content: space-between; gap: 8px;
}
.ctrl-left, .ctrl-right {
  display: flex; align-items: center; gap: 6px;
}

.ctrl-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.1);
  border: none; border-radius: 8px;
  color: #fff; cursor: pointer;
  transition: background .15s, transform .1s;
  flex-shrink: 0;
}
.ctrl-btn svg { width: 18px; height: 18px; }
.ctrl-btn--sm svg { width: 16px; height: 16px; }
.ctrl-btn:hover  { background: rgba(255,255,255,0.2); }
.ctrl-btn:active { transform: scale(0.92); }

.hidden { display: none !important; }

/* volume slider */
.volume-wrap {
  display: flex; align-items: center; gap: 6px;
}
.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 72px; height: 4px;
  border-radius: 4px; outline: none;
  background: rgba(255,255,255,0.25);
  cursor: pointer;
  accent-color: var(--teal);
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

.time-display {
  font-family: var(--font-mono); font-size: 11px;
  color: rgba(255,255,255,0.7); white-space: nowrap;
}

/* ================================================================
   QUALITY SELECTOR
   ================================================================ */
.quality-wrap {
  position: relative;
}

.quality-btn {
  width: auto !important;
  padding: 0 10px;
  gap: 4px;
  font-family: var(--font-mono);
}

.quality-label {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: 0.3px;
}

/* badge روی دکمه وقتی ABR فعاله */
.quality-btn.abr-active .quality-label::after {
  content: " ●";
  color: var(--teal);
  font-size: 9px;
}

.quality-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 130px;
  background: #12151d;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 -16px 40px -12px rgba(0,0,0,0.7);
  padding: 6px;
  display: none;
  z-index: 80;
  overflow: hidden;
}
.quality-panel.open { display: block; }

.quality-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.quality-item:hover { background: var(--glass-strong); color: var(--text); }
.quality-item.active { color: var(--teal); background: rgba(69,230,199,0.1); }

.quality-item .q-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  padding: 2px 5px;
  border-radius: 4px;
}
.quality-item.active .q-badge { color: var(--teal); background: rgba(69,230,199,0.15); }

/* نشانگر ABR – انیمیشن سیگنال */
.quality-item.abr-item .q-signal {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}
.quality-item.abr-item .q-signal span {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: var(--text-muted);
  transition: background .2s;
}
.quality-item.abr-item .q-signal span:nth-child(1) { height: 4px; }
.quality-item.abr-item .q-signal span:nth-child(2) { height: 8px; }
.quality-item.abr-item .q-signal span:nth-child(3) { height: 12px; }
.quality-item.abr-item.active .q-signal span { background: var(--teal); }

/* نوار جداکننده */
.quality-sep {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* اطلاعات کیفیت فعلی روی صفحه (toast) */
.quality-toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.72);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--teal);
  white-space: nowrap;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
  z-index: 70;
}
.quality-toast.show { opacity: 1; }

/* ================================================================
   CHANNELS COLUMN
   ================================================================ */
.channels-col {
  /* scrollt onafhankelijk van de player */
  max-height: calc(100vh - 94px);
  overflow-y: auto;
  border-radius: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.channels-col::-webkit-scrollbar { width: 6px; }
.channels-col::-webkit-scrollbar-track { background: transparent; }
.channels-col::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }

.grid-wrap {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* ---- channel card ---- */
.channel-card {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 8px 10px;
  display: flex; flex-direction: column;
  align-items: center; gap: 8px;
  cursor: pointer;
  transition: border-color .18s, background .18s, box-shadow .18s, transform .12s;
  will-change: transform;
  text-align: center;
}
.channel-card:hover {
  border-color: var(--teal-dim);
  background: var(--glass-strong);
  box-shadow: 0 8px 28px -12px rgba(69,230,199,0.22);
  transform: translateY(-2px);
}
.channel-card.active {
  border-color: var(--teal);
  background: linear-gradient(160deg, rgba(69,230,199,0.12), var(--glass-strong));
  box-shadow: 0 0 0 1px var(--teal-dim), 0 10px 30px -12px rgba(69,230,199,0.35);
}

.card-logo-wrap {
  width: 52px; height: 52px;
  border-radius: 10px;
  background: #eef0f3;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.card-logo-wrap img {
  width: 100%; height: 100%; object-fit: contain;
}
.card-logo-fallback {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700;
  color: #fff; font-size: 14px;
  background: linear-gradient(135deg, #2a3140, #171b23);
}

.card-name {
  font-size: 11.5px; font-weight: 500;
  line-height: 1.3; color: var(--text);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  width: 100%;
}

.card-group {
  font-family: var(--font-mono); font-size: 9.5px;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.4px;
  overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; width: 100%;
}

/* badge فرمت غیر-HLS روی کارت */
.card-fmt-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(69,230,199,0.15);
  color: var(--teal);
  border: 1px solid var(--teal-dim);
  margin-right: 4px;
  vertical-align: middle;
}

.empty-state {
  text-align: center; padding: 60px 0;
  color: var(--text-muted); font-family: var(--font-mono);
}

/* touch: اثر سه‌بعدی غیرفعال */
@media (hover: none), (pointer: coarse) {
  .channel-card { transform: none !important; }
  .channel-card:active { background: var(--glass-strong); }
}

/* ================================================================
   SCROLLBAR (global)
   ================================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* ================================================================
   RESPONSIVE  –  tablet  (≤ 1100px): stack vertically
   ================================================================ */
@media (max-width: 1100px) {
  .stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }
  .player-col { position: static; }
  .channels-col {
    max-height: none;
    overflow-y: visible;
  }
  .channel-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .card-group { display: none; }
}

/* ================================================================
   RESPONSIVE  –  mobile  (≤ 860px)
   ================================================================ */
@media (max-width: 860px) {
  .topbar { padding: 12px 18px; }
  .brand-name { display: none; }
  .menu-toggle { display: flex; }

  .controls {
    position: fixed; top: 0; left: 0; right: 0;
    background: #10131a;
    border-bottom: 1px solid var(--border);
    padding: 14px 18px;
    flex-direction: column; align-items: stretch;
    gap: 10px;
    transform: translateY(-120%);
    transition: transform .25s ease;
    z-index: 55;
  }
  .controls.open { transform: translateY(0); }

  .search-wrap { max-width: none; }
  .dropdown { width: 100%; }
  .dropdown-btn { width: 100%; max-width: none; justify-content: space-between; }
  .dropdown-panel { left: 0; right: 0; width: 100%; max-width: none; }
  .channel-count { text-align: center; }

  .stage { padding: 10px 14px 32px; gap: 14px; }
  .monitor-bezel { border-radius: 14px; padding: 10px; }
  .grid-wrap { padding: 10px; border-radius: 14px; }
  .channel-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .card-logo-wrap { width: 40px; height: 40px; }
  .card-name { font-size: 11px; }

  /* کنترل‌های پلیر در موبایل همیشه نمایان */
  .player-controls { opacity: 1; pointer-events: auto; }
  .volume-slider { width: 56px; }
}

@media (max-width: 480px) {
  .channel-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .card-logo-wrap { width: 36px; height: 36px; border-radius: 8px; }
  .card-name { font-size: 10.5px; }
  .card-group { display: none; }
  .channel-card { padding: 10px 4px 8px; gap: 6px; }
}
