:root {
    --bg: #0a0b10;
    --surface: #13151d;
    --surface-raised: #191c26;
    --border: #242732;
    --border-soft: #1a1c25;
    --text: #f1f2f6;
    --text-dim: #949cb0;
    --text-faint: #565c6d;
    --accent: #c7a466;
    --accent-bright: #e2c48c;
    --accent-soft: rgba(199, 164, 102, 0.1);
    --accent-soft-2: rgba(199, 164, 102, 0.2);
    --accent2: #4fb3c0;
    --live: #cf4a4a;
    --telegram: #229ed9;
    --header-h: 110px; /* يُحدَّث تلقائياً من app.js */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Cairo', sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}
button { font-family: inherit; color: inherit; }

.bg-layer { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.bg-layer::before {
    content: '';
    position: absolute; inset: 0;
    background:
        radial-gradient(ellipse 55vw 38vh at 15% -8%, rgba(199, 164, 102, 0.08) 0%, transparent 62%),
        radial-gradient(ellipse 45vw 32vh at 100% 15%, rgba(79, 179, 192, 0.06) 0%, transparent 60%);
}

/* ===== Header ===== */
header {
    position: sticky; top: 0; z-index: 100;
    background: rgba(10, 11, 16, 0.9);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-soft);
}
.header-main {
    padding: 0 32px; height: 72px; max-width: 1320px; margin: 0 auto;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.logo { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; }
.logo-emblem {
    width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto;
    background: var(--surface-raised); border: 1px solid var(--accent-soft-2);
    display: flex; align-items: center; justify-content: center;
    transition: border-color .3s ease;
}
.logo:hover .logo-emblem { border-color: var(--accent); }
.logo-emblem span { font-size: 18px; }
.logo-main { font-size: 20px; font-weight: 900; letter-spacing: .5px; color: var(--text); white-space: nowrap; }
.logo-sub { font-size: 10px; color: var(--text-faint); letter-spacing: 3px; margin-top: 1px; font-weight: 600; }

.tg-btn {
    display: flex; align-items: center; gap: 8px; white-space: nowrap;
    background: var(--telegram); color: #fff; text-decoration: none;
    font-size: 14px; font-weight: 700; padding: 9px 18px; border-radius: 10px;
    transition: filter .2s ease;
}
.tg-btn:hover { filter: brightness(1.1); }

/* ===== Ticker ===== */
.ticker-wrap {
    background: var(--surface); border-top: 1px solid var(--border-soft);
    padding: 9px 0; overflow: hidden; display: flex; align-items: center;
}
.ticker-badge {
    padding: 0 16px; font-weight: 800; font-size: 11px; white-space: nowrap;
    border-left: 1px solid var(--border); display: flex; align-items: center; gap: 7px;
    color: var(--accent-bright); letter-spacing: .5px; flex-shrink: 0;
}
.ticker-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent2); }
.ticker-track { flex: 1; overflow: hidden; display: flex; }
.ticker-text {
    display: inline-block; padding-right: 100%;
    animation: tick 30s linear infinite;
    font-size: 12.5px; font-weight: 500; white-space: nowrap; color: var(--text-dim);
}
@keyframes tick { from { transform: translateX(100%); } to { transform: translateX(-100%); } }

/* ===== Content ===== */
.content-wrap {
    max-width: 1320px; width: 100%; margin: 0 auto;
    padding: 24px 32px 60px; position: relative; z-index: 1;
}
.section-head {
    margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--border-soft);
    display: flex; align-items: center; gap: 12px;
}
.section-head .rule { width: 3px; height: 20px; background: var(--accent); border-radius: 2px; }
.section-head h2 { font-weight: 800; color: var(--text); font-size: 19px; }

/* ===== شبكة القنوات (مصفوفة) ===== */
.channels-grid { display: block; }
.channel-group + .channel-group { margin-top: 30px; }
.channel-group-head {
    margin-bottom: 14px; padding-bottom: 11px; border-bottom: 1px solid var(--border-soft);
    display: flex; align-items: center; gap: 10px;
}
.channel-group-head .rule {
    width: 3px; height: 19px; background: var(--accent); border-radius: 2px;
}
.channel-group-head h3 { font-weight: 800; color: var(--text); font-size: 16px; }
.channel-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
}
.channels-empty {
    text-align: center; color: var(--text-dim);
    padding: 40px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}

.channel-card {
    position: relative; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    padding: 20px 12px 16px; min-height: 176px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
    cursor: pointer; text-align: center;
    transition: border-color .25s ease, transform .2s ease, box-shadow .2s ease, background .2s ease;
    -webkit-tap-highlight-color: transparent;
}
.channel-card:hover { border-color: var(--accent-soft-2); transform: translateY(-2px); box-shadow: 0 12px 32px rgba(0, 0, 0, .22); }
.channel-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.channel-card.active { border-color: var(--accent); background: var(--accent-soft); }

.channel-logo-wrap { width: 88px; height: 88px; display: flex; align-items: center; justify-content: center; }
.channel-logo { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.channel-logo-placeholder {
    width: 100%; height: 100%; border-radius: 18px;
    background: var(--surface-raised); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent-bright); font-size: 30px;
}
.channel-name { width: 100%; font-size: 13px; line-height: 1.45; font-weight: 800; color: var(--text); overflow-wrap: anywhere; }

.channel-play {
    position: absolute; top: 10px; left: 10px; width: 28px; height: 28px; border-radius: 50%;
    background: var(--accent); color: #16130a; font-size: 10px;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transform: scale(.85); transition: opacity .2s ease, transform .2s ease;
}
.channel-card:hover .channel-play, .channel-card:focus-visible .channel-play { opacity: 1; transform: none; }

.channel-now {
    position: absolute; top: 11px; right: 11px; display: none; width: 9px; height: 9px; border-radius: 50%;
    background: var(--live); box-shadow: 0 0 0 3px rgba(207, 74, 74, .25); animation: pulse 1.4s infinite;
}
.channel-card.active .channel-now { display: block; }
.channel-card.active .channel-play { display: none; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .5; transform: scale(1.3); } }

/* ===== قسم المشغل ===== */
.player-section {
    max-width: 980px; margin: 0 auto 28px;
    scroll-margin-top: calc(var(--header-h) + 12px);
    animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.player-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.player-title { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 16px; font-weight: 800; }
.player-title img { width: 34px; height: 34px; object-fit: contain; flex: 0 0 auto; }
.player-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-close {
    width: 38px; height: 38px; flex: 0 0 auto; border-radius: 10px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); font-size: 16px;
    display: flex; align-items: center; justify-content: center; transition: all .2s ease;
}
.player-close:hover { border-color: var(--live); color: var(--live); }

.player-wrap {
    position: relative; width: 100%; aspect-ratio: 16 / 9;
    background: #000; border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
}

/* ===== المشغل ===== */
.pro-player {
    position: absolute; inset: 0; background: #000; overflow: hidden;
    -webkit-user-select: none; user-select: none;
}
.pro-player video { position: absolute; inset: 0; width: 100%; height: 100%; background: #000; object-fit: contain; display: block; }
.pro-player #externalPlayerFrame { position:absolute; inset:0; width:100%; height:100%; border:0; background:#000; display:none; }
.pro-player.external-mode video { display:none; }
.pro-player.external-mode #externalPlayerFrame { display:block; }
.pro-player.external-mode .pp-center,
.pro-player.external-mode .pp-topbar,
.pro-player.external-mode .pp-bottom { display:none; }
.pro-player:fullscreen { border-radius: 0; }
.pro-player:-webkit-full-screen { border-radius: 0; }

.pp-center { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.pp-bigplay {
    pointer-events: auto; width: 60px; height: 60px; border-radius: 50%; border: none; cursor: pointer;
    background: rgba(199, 164, 102, 0.94); color: #16130a; font-size: 20px;
    display: flex; align-items: center; justify-content: center; transition: transform .15s ease;
}
.pp-bigplay:hover { transform: scale(1.07); }
.pp-spinner {
    display: none; position: absolute; width: 38px; height: 38px; border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.18); border-top-color: var(--accent);
    animation: pp-spin .8s linear infinite;
}
.pp-spinner.show { display: block; }
@keyframes pp-spin { to { transform: rotate(360deg); } }

.pp-error {
    display: none; position: absolute; inset: 0; z-index: 4; padding: 20px;
    flex-direction: column; align-items: center; justify-content: center; gap: 12px;
    background: rgba(0, 0, 0, .7); color: #fff; text-align: center;
}
.pp-error.show { display: flex; }
.pp-error-icon { font-size: 32px; color: var(--live); }
.pp-error span { font-size: 13px; color: var(--text-dim); font-weight: 600; line-height: 1.7; }
.pp-retry-btn {
    background: var(--accent); color: #16130a; border: none; padding: 9px 22px; border-radius: 9px;
    font-weight: 800; cursor: pointer; font-size: 13px;
}

.pp-topbar { position: absolute; z-index: 3; top: 10px; right: 10px; left: 10px; display: flex; pointer-events: none; }
.pp-status {
    display: flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px;
    font-size: 10.5px; font-weight: 800; letter-spacing: .3px; color: #fff; background: rgba(0, 0, 0, .6);
}
.pp-status.is-live { background: var(--live); }
.pp-status.is-live::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: pulse 1.4s infinite; }
.pp-status.is-error { background: rgba(207, 74, 74, .85); }

/* الشريط السفلي: السيرفرات + أزرار التحكم — يظهر عند اللمس/التحريك */
.pp-bottom {
    position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; padding-top: 34px;
    background: linear-gradient(to top, rgba(0, 0, 0, .86), transparent);
    opacity: 0; transform: translateY(6px); pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}
.pro-player.controls-visible .pp-bottom { opacity: 1; transform: none; pointer-events: auto; }

.pp-servers { display: flex; align-items: center; gap: 8px; padding: 0 12px 8px; overflow-x: auto; scrollbar-width: none; }
.pp-servers::-webkit-scrollbar { display: none; }
.pp-server {
    flex: 0 0 auto; padding: 7px 13px; border-radius: 10px; cursor: pointer; white-space: nowrap;
    background: rgba(16, 21, 34, .92); border: 1px solid #252b3b; color: #d9deea;
    font-size: 11px; font-weight: 800; transition: .2s ease;
}
.pp-server:hover:not(:disabled) { border-color: var(--accent-soft-2); background: #171d2b; }
.pp-server.active { border-color: #22d3ee; background: rgba(34, 211, 238, .16); color: #fff; }
.pp-server:disabled { opacity: .45; cursor: not-allowed; }

.pp-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px 10px; }
.pp-group { display: flex; align-items: center; gap: 6px; min-width: 0; }
.pp-btn {
    flex: 0 0 auto; width: 34px; height: 34px; border: none; border-radius: 8px; cursor: pointer;
    background: transparent; color: #fff; font-size: 14px;
    display: flex; align-items: center; justify-content: center; transition: background .15s;
}
.pp-btn:hover { background: rgba(255, 255, 255, .14); }
.pp-volume-group { display: flex; align-items: center; gap: 4px; }
.pp-volume { width: 70px; accent-color: var(--accent); cursor: pointer; }

.pp-menu-wrap { position: relative; }
.pp-menu {
    position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 6;
    min-width: 120px; padding: 6px; display: none; flex-direction: column; gap: 2px;
    background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.pp-menu.show { display: flex; }
.pp-menu-item {
    padding: 8px 10px; border: none; border-radius: 7px; background: transparent; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    font-size: 12.5px; font-weight: 600; color: var(--text-dim); text-align: right;
}
.pp-menu-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.pp-menu-item.active { color: var(--accent-bright); }
.pp-menu-item.active::after { content: '✓'; font-size: 11px; }

/* ===== Footer ===== */
footer {
    border-top: 1px solid var(--border-soft); padding: 22px 16px; text-align: center;
    margin-top: auto; position: relative; z-index: 1;
}
.footer-logo { font-size: 14px; font-weight: 800; color: var(--text-dim); letter-spacing: 1px; margin-bottom: 6px; }
.footer-text { font-size: 11px; color: var(--text-faint); font-weight: 500; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .header-main { padding: 0 14px; height: 62px; }
    .logo { gap: 9px; }
    .logo-emblem { width: 36px; height: 36px; }
    .logo-main { font-size: 16px; }
    .logo-sub { display: none; }
    .tg-btn { font-size: 12px; padding: 8px 12px; }

    .content-wrap { padding: 16px 14px 40px; }
    .section-head { margin-bottom: 14px; padding-bottom: 12px; }
    .section-head h2 { font-size: 16px; }

    .channels-grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
    .channel-card { min-height: 142px; padding: 14px 8px 12px; gap: 9px; border-radius: 14px; }
    .channel-logo-wrap { width: 62px; height: 62px; }
    .channel-logo-placeholder { font-size: 23px; border-radius: 14px; }
    .channel-name { font-size: 11px; }
    .channel-play { display: none; }

    .player-section { margin-bottom: 20px; }
    .player-title { font-size: 14px; }
    .player-wrap { border-radius: 10px; }
    .pp-volume { display: none; }
    .pp-bottom { padding-top: 26px; }
    .pp-servers { padding: 0 8px 6px; gap: 6px; }
    .pp-server { padding: 6px 10px; font-size: 10px; }
    .pp-controls { padding: 0 6px 6px; }
    .pp-btn { width: 32px; height: 32px; font-size: 13px; }
    .pp-bigplay { width: 52px; height: 52px; font-size: 17px; }
}
@media (max-width: 380px) {
    .channels-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    .ticker-text { animation: none; padding-right: 12px; white-space: normal; }
}
