:root {
  --bg: #0b1220;
  --bg2: #111a2e;
  --card: #152036;
  --line: #22304d;
  --text: #e6edf7;
  --muted: #8ea0bd;
  --accent: #a78bfa;
  --accent2: #ec4899;
  --danger: #f87171;
  --ok: #34d399;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Cairo", "Segoe UI", Tahoma, system-ui, sans-serif;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: rgba(11, 18, 32, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.logo { width: 34px; height: 34px; }
.brand-name {
  font-size: 1.35rem; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.search {
  flex: 1; display: flex; max-width: 640px; margin-inline: auto;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 999px;
  overflow: hidden;
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 16px; outline: none;
}
.search button {
  border: 0; background: transparent; padding: 0 14px; cursor: pointer; display: grid; place-items: center;
}
.search svg, .icon-btn svg {
  width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round;
}
.icon-btn {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg2); cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--accent); }

/* ---------- Settings ---------- */
.settings {
  background: var(--bg2); border-bottom: 1px solid var(--line);
  padding: 12px 16px; display: grid; gap: 10px;
}
.settings-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.settings select, .settings input[type=url] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
}
.settings input[type=url] { flex: 1; min-width: 200px; }
.btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 14px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #1e0b3a; border-color: var(--accent); font-weight: 700; }
.status-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: .88rem; }
.status-list li { display: flex; gap: 8px; align-items: center; direction: ltr; justify-content: flex-end; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--danger); }

/* ---------- Main ---------- */
main { padding: 16px; max-width: 1500px; margin: 0 auto; }
.section-title { font-size: 1.1rem; margin: 4px 0 14px; color: var(--muted); font-weight: 600; }

.grid {
  display: grid; gap: 18px 14px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.card { display: block; border-radius: var(--radius); transition: transform .15s; }
.card:hover { transform: translateY(-2px); }
.thumb {
  position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius);
  overflow: hidden; background: var(--card);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dur {
  position: absolute; bottom: 6px; left: 6px; direction: ltr;
  background: rgba(0,0,0,.8); font-size: .78rem; padding: 1px 6px; border-radius: 6px;
}
.dur:empty { display: none; }
.meta { padding: 8px 2px 0; }
.title {
  margin: 0; font-size: .97rem; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sub { color: var(--muted); font-size: .84rem; margin-top: 2px; }

/* ---------- Watch page ---------- */
.watch { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px; }
.player-box {
  position: relative; aspect-ratio: 16 / 9; background: #000;
  border-radius: var(--radius); overflow: hidden;
}
.player-box video, .player-box iframe { width: 100%; height: 100%; display: block; border: 0; background: #000; }
.player-msg {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: var(--muted); padding: 20px; pointer-events: none;
}
.v-title { font-size: 1.25rem; margin: 14px 0 6px; }
.v-row { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; color: var(--muted); font-size: .9rem; }
.v-row .author { color: var(--text); font-weight: 600; }
.v-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  font-size: .78rem; padding: 2px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted);
}
.chip.ok { border-color: var(--ok); color: var(--ok); }
.chip.warn { border-color: #fbbf24; color: #fbbf24; }
.desc {
  margin-top: 14px; background: var(--bg2); border-radius: var(--radius); padding: 12px 14px;
  white-space: pre-wrap; word-break: break-word; font-size: .9rem; max-height: 140px; overflow: hidden;
  cursor: pointer; position: relative; direction: auto; unicode-bidi: plaintext;
}
.desc.open { max-height: none; }
.related { display: grid; gap: 12px; align-content: start; }
.related .card { display: grid; grid-template-columns: 168px 1fr; gap: 10px; }
.related .thumb { border-radius: 10px; }
.related .meta { padding: 0; }
.related .title { font-size: .88rem; }
.related .sub { font-size: .78rem; }

/* ---------- States ---------- */
.empty, .loading { text-align: center; color: var(--muted); padding: 60px 10px; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 12px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.more { display: flex; justify-content: center; margin: 22px 0; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; z-index: 50; transition: transform .25s; max-width: calc(100% - 32px);
  font-size: .9rem;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 1050px) {
  .watch { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand-name { display: none; }
  main { padding: 12px; }
  .grid { grid-template-columns: 1fr; }
  .watch-main { margin-inline: -12px; }
  .watch-main .player-box { border-radius: 0; }
  .watch-main .info { padding-inline: 12px; }
  .related .card { grid-template-columns: 140px 1fr; }
}

/* ---------- Channels ---------- */
.ch-link { cursor: pointer; }
.ch-link:hover { color: var(--text); text-decoration: underline; }
.ch-strip { display: grid; gap: 10px; margin-bottom: 18px; }
.ch-strip:empty { display: none; }
.ch-card {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius);
}
.ch-card:hover { border-color: var(--accent); }
.ch-card img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--card); flex-shrink: 0; }
.ch-name { font-weight: 700; }
.ch-head { margin-bottom: 18px; }
.ch-banner { width: 100%; aspect-ratio: 6 / 1; object-fit: cover; border-radius: var(--radius); display: block; background: var(--card); }
.ch-row { display: flex; align-items: center; gap: 16px; margin-top: 14px; }
.ch-avatar { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; background: var(--card); flex-shrink: 0; }
.ch-title { margin: 0; font-size: 1.5rem; }
.v-row a.author, .v-row span.author { display: inline-flex; align-items: center; gap: 8px; }
.author-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.author-subs { color: var(--muted); font-weight: 400; font-size: .85rem; }
@media (max-width: 600px) {
  .ch-avatar { width: 64px; height: 64px; }
  .ch-title { font-size: 1.2rem; }
  .ch-banner { aspect-ratio: 4 / 1; }
}

/* ---------- Nuvio Player ---------- */
.np { position: relative; overflow: hidden; outline: none; user-select: none; -webkit-user-select: none; touch-action: manipulation; font-family: "Cairo", "Segoe UI", system-ui, sans-serif; }
.np video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }
.np.fs { border-radius: 0 !important; }
.np-ui { position: absolute; inset: 0; cursor: default; }
.np:not(.ui) .np-ui { cursor: none; }
.np-bottom {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 12px 6px;
  background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,.35) 60%, transparent);
  transition: opacity .25s, transform .25s; opacity: 0; transform: translateY(6px); pointer-events: none;
}
.np.ui .np-bottom, .np.paused .np-bottom { opacity: 1; transform: none; pointer-events: auto; }

/* شريط التقدّم */
.np-bar { position: relative; height: 18px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.np-bar::before { content: ""; position: absolute; left: 0; right: 0; height: 4px; background: rgba(255,255,255,.22); border-radius: 4px; transition: height .15s; }
.np-buf, .np-fill { position: absolute; left: 0; height: 4px; border-radius: 4px; transition: height .15s; pointer-events: none; }
.np-buf { background: rgba(255,255,255,.4); }
.np-fill { background: linear-gradient(90deg, #8b5cf6, #ec4899); }
.np-bar:hover::before, .np-bar:hover .np-buf, .np-bar:hover .np-fill, .np.drag .np-bar::before, .np.drag .np-buf, .np.drag .np-fill { height: 6px; }
.np-knob {
  position: absolute; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #fff;
  box-shadow: 0 0 0 3px rgba(236,72,153,.45); transform: scale(0); transition: transform .15s; pointer-events: none;
}
.np-bar:hover .np-knob, .np.drag .np-knob { transform: scale(1); }
.np-tip {
  position: absolute; bottom: 22px; transform: translateX(-50%); background: rgba(15,15,25,.92); color: #fff;
  font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; opacity: 0; pointer-events: none; white-space: nowrap;
}
.np-bar:hover .np-tip, .np.drag .np-tip { opacity: 1; }

/* الأزرار */
.np-row { display: flex; align-items: center; gap: 2px; height: 44px; color: #fff; }
.np-btn { width: 42px; height: 42px; border: 0; background: none; color: #fff; cursor: pointer; display: grid; place-items: center; border-radius: 50%; padding: 0; flex-shrink: 0; }
.np-btn:hover { background: rgba(255,255,255,.12); }
.np-btn svg, .np-big svg, .np-ripple svg { width: 24px; height: 24px; fill: currentColor; }
.np svg .s { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.np-volwrap { display: flex; align-items: center; }
.np-vol { width: 0; opacity: 0; transition: width .2s, opacity .2s; accent-color: #ec4899; cursor: pointer; }
.np-volwrap:hover .np-vol, .np-vol:focus { width: 80px; opacity: 1; margin-right: 6px; }
.np-time { font-size: 13px; font-weight: 600; padding: 0 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.np-space { flex: 1; }
.np-q { font-size: 10px; font-weight: 800; background: #ec4899; border-radius: 3px; padding: 0 3px; margin-right: -14px; margin-top: -16px; position: relative; z-index: 1; pointer-events: none; }
.np-q:empty { display: none; }

/* الزر الكبير بالنص + التحميل */
.np-big {
  position: absolute; left: 50%; top: 50%; width: 72px; height: 72px; margin: -36px 0 0 -36px;
  border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; color: #fff;
  background: rgba(20,14,40,.62); backdrop-filter: blur(6px); opacity: 0; transform: scale(.85); transition: opacity .2s, transform .2s; pointer-events: none;
}
.np-big svg { width: 34px; height: 34px; }
.np.paused:not(.loading) .np-big { opacity: 1; transform: none; pointer-events: auto; }
.np-spin {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.18); border-top-color: #ec4899; animation: spin .8s linear infinite; opacity: 0; pointer-events: none;
}
.np.loading .np-spin { opacity: 1; }
.np-msg { position: absolute; left: 0; right: 0; top: 50%; margin-top: 40px; text-align: center; color: #fff; font-size: 14px; opacity: 0; pointer-events: none; }
.np-msg.on { opacity: .85; }

/* ضغطتين: تقديم/ترجيع */
.np-ripple {
  position: absolute; top: 0; bottom: 0; width: 38%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: #fff; font-weight: 700; font-size: 13px; background: rgba(255,255,255,.08); opacity: 0; pointer-events: none;
}
.np-ripple.l { left: 0; border-radius: 0 50% 50% 0 / 0 50% 50% 0; }
.np-ripple.r { right: 0; border-radius: 50% 0 0 50% / 50% 0 0 50%; }
.np-ripple span::after { content: " ثانية"; }
.np-ripple.on { animation: np-rip .6s ease-out; }
@keyframes np-rip { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }

/* قائمة الإعدادات */
.np-menu {
  position: absolute; right: 12px; bottom: 64px; min-width: 220px; max-width: calc(100% - 24px); max-height: calc(100% - 80px); overflow: auto;
  background: rgba(18,14,32,.94); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.08); border-radius: 14px; padding: 10px 12px; color: #fff;
}
.np-mt { font-size: 12px; color: #c4b5fd; font-weight: 700; margin: 4px 2px 6px; }
.np-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.np-chip { border: 1px solid rgba(255,255,255,.15); background: none; color: #fff; border-radius: 999px; padding: 4px 11px; font: inherit; font-size: 13px; cursor: pointer; }
.np-chip.on { background: linear-gradient(90deg, #8b5cf6, #ec4899); border-color: transparent; font-weight: 700; }

@media (max-width: 600px) {
  .np-row { height: 40px; }
  .np-btn { width: 38px; height: 38px; }
  .np-vol { display: none; }
  .np-time { font-size: 12px; }
  .np-big { width: 64px; height: 64px; margin: -32px 0 0 -32px; }
}
