/* ==========================================================================
   ALWAN TV — الأنماط
   يدعم السمة الداكنة والفاتحة عبر المتغير <html data-theme="...">
   يُضبط تلقائياً حسب Telegram.WebApp.colorScheme (انظر app.js)
   ========================================================================== */

/* --- متغيرات السمة (افتراضي: داكن) --- */
:root[data-theme="dark"] {
  --bg: #0b0f1a;
  --bg-soft: #111827;
  --surface: #1a2235;
  --surface-hover: #232f4b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f3f4f6;
  --text-dim: #9ca3af;
  --accent: #ff5a1f;
  --accent-2: #8b5cf6;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --glass: rgba(10, 14, 26, 0.72);
}

:root[data-theme="light"] {
  --bg: #eef1f7;
  --bg-soft: #ffffff;
  --surface: #ffffff;
  --surface-hover: #e5e9f3;
  --border: rgba(15, 23, 42, 0.1);
  --text: #0f172a;
  --text-dim: #5b6478;
  --accent: #e84d0f;
  --accent-2: #7c3aed;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.16);
  --glass: rgba(255, 255, 255, 0.8);
}

/* --- أساسيات --- */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Cairo", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(139, 92, 246, 0.18), transparent 60%),
    radial-gradient(900px 400px at 0% 110%, rgba(255, 90, 31, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100%;
  overflow-x: hidden;
  transition: background 0.4s ease, color 0.4s ease;
  /* احترام مناطق الأمان في الأجهزة ذات الشاشة المقصوصة (iOS) */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* كل عنصر يحمل hidden يجب إخفاؤه مهما كانت قواعد display الأخرى */
[hidden] { display: none !important; }

/* =============================== الرأس =============================== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }

/* شعار متحرك: ثلاث كرات ملونة */
.brand-mark {
  display: flex;
  gap: 4px;
  width: 46px;
  height: 46px;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px rgba(139, 92, 246, 0.4);
}
.brand-mark .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #fff;
  animation: bounce 1.2s ease-in-out infinite;
}
.brand-mark .dot-2 { animation-delay: 0.15s; }
.brand-mark .dot-3 { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.brand-text h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1.1;
}
.brand-tv {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand-text p { font-size: 12px; color: var(--text-dim); }

/* شارة حالة الاتصال */
.badge {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
  transition: all 0.3s ease;
}
.badge-idle { background: var(--surface); }
.badge-live { color: #16c784; border-color: rgba(22, 199, 132, 0.4); background: rgba(22, 199, 132, 0.1); }
.badge-err  { color: #f87171; border-color: rgba(248, 113, 113, 0.4); background: rgba(248, 113, 113, 0.1); }

/* ============================= شبكة القنوات ============================= */
.channels-view {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.channels-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

/* بطاقة القناة */
.channel-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-radius: 20px;
  padding: 0 0 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.channel-card:hover { transform: translateY(-4px); }
.channel-card:active { transform: scale(0.97); }

/* غلاف ملوّن أعلى البطاقة: كل قناة لها تدرّج لوني خاص */
.channel-cover {
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.channel-number {
  font-size: 42px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.channel-title {
  font-size: 16px;
  font-weight: 700;
  padding: 0 12px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* زر التشغيل في البطاقة */
.channel-play {
  margin: 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 18px rgba(255, 90, 31, 0.4);
  transition: transform 0.15s ease;
}
.channel-play:hover { transform: scale(1.1); }

.hint { text-align: center; color: var(--text-dim); font-size: 13px; margin-top: 26px; }

/* =============================== المشغل =============================== */
.player-view {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.player-shell {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* حالة التحميل / الخطأ فوق المشغل */
.player-status {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 14px;
  padding: 16px;
  text-align: center;
  z-index: 3;
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* شريط تبديل القنوات داخل المشغل */
.channel-switcher {
  position: absolute;
  top: 10px;
  right: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 4;
}
.switcher-label { font-size: 12px; color: #fff; text-shadow: 0 1px 3px #000; }
.switcher-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(6px);
  transition: background 0.2s ease;
}
.chip.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; }

/* اللاعب المضمّن من OK.ru: يملأ غلاف المشغل */
.okframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

/* أزرار عائمة على المشغل */
.player-actions {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fab {
  width: 46px; height: 46px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 20px;
  backdrop-filter: blur(6px);
  transition: background 0.2s ease, transform 0.15s ease;
}
.fab:hover { background: rgba(0, 0, 0, 0.8); }
.fab:active { transform: scale(0.92); }
.fab-wide {
  width: auto;
  border-radius: 999px;
  padding: 0 14px;
  height: 40px;
  font-size: 13px;
}

/* معلومات القناة الحالية */
.now-playing {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 0 4px;
}
.live-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #ff2d55;
  box-shadow: 0 0 0 0 rgba(255, 45, 85, 0.6);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 45, 85, 0.6); }
  70% { box-shadow: 0 0 0 9px rgba(255, 45, 85, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 45, 85, 0); }
}
.now-playing h2 { font-size: 17px; flex: 1; }
.now-state { font-size: 12px; color: var(--text-dim); }

/* ============================= إشعار سريع ============================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 50;
  max-width: 90vw;
}

/* ============================= التذييل ============================= */
.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 12px;
  border-top: 1px solid var(--border);
}

/* --- حركات بسيطة للظهور --- */
.channels-view, .player-view { animation: fadeUp 0.35s ease; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- الشاشات الصغيرة --- */
@media (max-width: 480px) {
  .channels-grid { grid-template-columns: 1fr; }
  .channel-cover { height: 110px; }
  .player-shell { aspect-ratio: auto; height: min(56vh, 340px); }
}
