:root {
  --bg: #000; --card: #1c1c1e; --line: #262626;
  --muted: #9a9a9a; --text: #f2f2f2; --accent: #1db954; --danger: #ff6b6b;
  --played: #128a3d;   /* الجزء اللي انسمع من الأغنية */
  --track: #4a4a4a;    /* الباقي */
  --top: env(safe-area-inset-top); --bottom: env(safe-area-inset-bottom);
  --tabs-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, system-ui, "Segoe UI", Tahoma, sans-serif;
  -webkit-user-select: none; user-select: none;
  /* الصفحة نفسها ثابتة — اللي يتمرر هو الوسط بس (يمنع تمدد الأشرطة في آيفون) */
  position: fixed; inset: 0; overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.hidden { display: none !important; }
.ic { width: 22px; height: 22px; display: block; flex: none; }
i[data-icon] { display: contents; }
[dir="rtl"] .flip .ic, [dir="rtl"] .ic.flip { transform: scaleX(-1); }

/* ---------- الدخول ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
#login form { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; }
#login img { width: 88px; height: 88px; border-radius: 20px; margin: 0 auto 8px; }
.input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid #333; font-size: 16px;
  background: var(--card); color: var(--text); -webkit-user-select: text; user-select: text;
}
.btn {
  padding: 12px 14px; border-radius: 10px; background: var(--accent); color: #000; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn .ic { width: 18px; height: 18px; }
.btn.ghost { background: #2a2a2a; color: var(--text); }
.btn.danger { background: #3a1d1d; color: var(--danger); }
.err { color: var(--danger); min-height: 1.2em; margin: 0; }

/* ---------- هيكل التطبيق ---------- */
/* --app-h: الطول الحقيقي للشاشة (آيفون يعطي طول أقصر في تطبيقات الشاشة الرئيسية، فنحسبه بالجافاسكربت) */
#app, #full, #sheet, #login { top: 0; bottom: auto !important; height: var(--app-h, 100%); }
#app { position: fixed; left: 0; right: 0; display: flex; flex-direction: column; }
header {
  flex: none; padding: calc(10px + var(--top)) 16px 10px; display: grid; gap: 10px;
  background: var(--bg); border-bottom: 1px solid transparent;
}
.head-row { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.head-row h1 { margin: 0; font-size: 28px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: #232323; flex: none;
}
.icon-btn:disabled { opacity: .4; }
.back-btn {
  display: flex; align-items: center; gap: 2px; height: 38px; padding: 0 12px 0 8px; border-radius: 19px;
  background: #232323; font-weight: 600; flex: none;
}
[dir="rtl"] .back-btn { padding: 0 8px 0 12px; }
.back-btn .ic { width: 24px; height: 24px; }
#banner { background: #3a2f12; color: #ffd27a; font-size: 13px; padding: 8px 12px; border-radius: 8px; }
#upload-bar { height: 4px; background: #333; border-radius: 2px; overflow: hidden; }
#upload-bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* المحتوى يتمرر من تحت الشريط العائم، ومسافة آخره بقد الشريط */
main {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding-bottom: var(--dock-space, 120px);
}

/* ---------- القوائم ---------- */
.sub { color: var(--muted); font-size: 13px; padding: 0 16px 10px; }
.actions { display: flex; gap: 8px; padding: 0 16px 12px; }
.actions .btn { flex: 1; }
.actions .icon-btn { width: 46px; height: 46px; border-radius: 10px; }

.songs { list-style: none; margin: 0; padding: 0; }
.song { display: flex; gap: 12px; align-items: center; padding: 7px 16px; min-height: 62px; }
.song:active { background: #1b1b1b; }
.song.playing .t { color: var(--accent); }
.song.unavailable { opacity: .35; }
.art {
  width: 48px; height: 48px; border-radius: 6px; flex: none; background: #2a2a2a;
  display: grid; place-items: center; color: #5a5a5a; overflow: hidden;
}
.art img, .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.meta { flex: 1; min-width: 0; }
.t, .a { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.a { color: var(--muted); font-size: 13px; margin-top: 3px; }
.dl, .more {
  width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); flex: none; border-radius: 50%;
}
.dl .ic { width: 20px; height: 20px; }
.dl.done { color: var(--accent); }
.dl.busy { font-size: 11px; color: var(--accent); font-variant-numeric: tabular-nums; }
.empty, .hint { color: var(--muted); text-align: center; padding: 40px 24px; line-height: 1.9; }
.hint { padding: 6px 16px 18px; text-align: start; font-size: 14px; }

.section-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 16px 10px; }
.section-head h3 { margin: 0; font-size: 20px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 12px; border-radius: 16px;
  background: #232323; font-size: 14px; font-weight: 600;
}
.chip .ic { width: 16px; height: 16px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; padding: 0 16px 20px; }
.card { text-align: start; min-width: 0; }
.card .cover {
  aspect-ratio: 1; width: 100%; border-radius: 8px; background: #2a2a2a; overflow: hidden;
  display: grid; place-items: center; color: #5a5a5a;
}
.card .cover .ic { width: 44px; height: 44px; }
.card.folder .cover { background: linear-gradient(135deg, #1f3a2a, #18241d); color: var(--accent); }
.card .t { margin-top: 8px; font-size: 14px; font-weight: 600; }

.detail-head { display: flex; gap: 16px; align-items: flex-end; padding: 4px 16px 16px; }
.detail-head .cover {
  width: 124px; height: 124px; border-radius: 8px; overflow: hidden; background: #2a2a2a; flex: none;
  display: grid; place-items: center; color: #5a5a5a;
}
.detail-head .cover .ic { width: 48px; height: 48px; }
.detail-head.folder .cover { background: linear-gradient(135deg, #1f3a2a, #18241d); color: var(--accent); }
.detail-head h2 { margin: 0 0 4px; font-size: 21px; word-break: break-word; }

/* ---------- الشريط العائم (تصميم زجاجي مثل iOS الجديد) ---------- */
#dock {
  position: absolute; left: 12px; right: 12px; z-index: 10;
  bottom: calc(max(14px, calc(var(--bottom) - 6px)) + var(--kb, 0px));
  border-radius: 44px; overflow: hidden;
  transition: bottom .25s ease;
  background: rgba(38, 38, 38, .62);
  -webkit-backdrop-filter: blur(28px) saturate(180%); backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, .09);
  box-shadow: 0 10px 40px rgba(0, 0, 0, .55), inset 0 1px 0 rgba(255, 255, 255, .06);
}

/* الأغنية الشغالة داخل الشريط — تطلع من تحت لما تشغّل أول أغنية */
#mini-wrap {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .5s cubic-bezier(.2, .9, .25, 1);
}
#dock.has-mini #mini-wrap { grid-template-rows: 1fr; }
#mini {
  min-height: 0; overflow: hidden; opacity: 0; transform: translateY(40px);
  transition: opacity .35s ease, transform .55s cubic-bezier(.2, .9, .25, 1.15);
}
#dock.has-mini #mini { opacity: 1; transform: none; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.mini-row { display: flex; align-items: center; gap: 14px; padding: 16px 16px 10px; cursor: pointer; }
#mini .art { width: 66px; height: 66px; border-radius: 15px; box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
#mini .art.pop { animation: pop .45s cubic-bezier(.2, .9, .25, 1.3); }
@keyframes pop { from { transform: scale(.82); opacity: .4; } to { transform: none; opacity: 1; } }
#mini .t { font-size: 18px; font-weight: 600; }
#mini .a { font-size: 15px; }
#mini .ctrl { width: 56px; height: 56px; display: grid; place-items: center; flex: none; border-radius: 50%; }
#mini .ctrl:active { background: rgba(255, 255, 255, .1); }
#mini .ctrl .ic { width: 34px; height: 34px; }
/* شريط تقدّم الأغنية بمساحته الخاصة */
#mini-progress {
  margin: 4px 20px 16px; height: 5px; border-radius: 3px;
  background: rgba(255, 255, 255, .14); direction: ltr; overflow: hidden;
}
#mini-progress div { height: 100%; width: 0; background: var(--played); border-radius: 3px; }

/* البحث داخل الشريط السفلي */
#search-row {
  display: flex; align-items: center; gap: 10px; margin: 12px 12px 0; height: 52px; padding: 0 16px;
  border-radius: 26px; background: rgba(255, 255, 255, .1); color: var(--muted);
}
#search-row .ic { width: 22px; height: 22px; }
#search-row input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 17px; -webkit-appearance: none; appearance: none; -webkit-user-select: text; user-select: text;
}
#search-row input::placeholder { color: var(--muted); }
#search-row:focus-within { background: rgba(255, 255, 255, .16); }

/* وقت الكتابة: يبقى البحث بس فوق الكيبورد */
body.kb-open #mini-wrap, body.kb-open nav#tabs { display: none; }
body.kb-open #search-row { margin: 10px; }
body.kb-open #dock { bottom: calc(8px + var(--kb, 0px)); border-radius: 36px; }

/* التبويبات */
nav#tabs { display: flex; gap: 4px; padding: 10px; }
nav#tabs button {
  flex: 1; height: 78px; border-radius: 34px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 6px; font-size: 14px; font-weight: 500; color: var(--text);
  transition: background .25s, color .25s, transform .15s;
}
nav#tabs button:active { transform: scale(.94); }
nav#tabs button .ic { width: 32px; height: 32px; }
nav#tabs button.active { background: rgba(255, 255, 255, .13); color: var(--accent); }

/* ---------- المشغل الكامل ---------- */
#full {
  /* الأعلى أسود عشان يندمج مع شريط الحالة، ووراء الغلاف توهّج بلون الغلاف نفسه */
  position: fixed; inset: 0; z-index: 20;
  background:
    radial-gradient(140% 58% at 50% 40%, rgba(var(--tint, 70, 70, 70), .6), rgba(var(--tint, 70, 70, 70), .14) 58%, transparent 82%),
    #000;
  padding: calc(12px + var(--top)) 22px calc(20px + var(--bottom)); display: flex; flex-direction: column;
  transform: translateY(100%); visibility: hidden; will-change: transform;
  transition: transform .45s cubic-bezier(.2, .9, .25, 1), visibility 0s linear .45s;
}
#full.open { transform: none; visibility: visible; transition: transform .45s cubic-bezier(.2, .9, .25, 1), visibility 0s; }
#full.dragging { transition: none; }
/* مقبض صغير فوق يوضح إنك تقدر تسحب لتحت */
#full::before {
  content: ''; position: absolute; top: calc(6px + var(--top)); left: 50%; width: 40px; height: 5px;
  margin-left: -20px; border-radius: 3px; background: rgba(255, 255, 255, .25);
}
#full .top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
#full .top .icon-btn .ic { width: 26px; height: 26px; }
#full .big-art {
  width: min(100%, 44vh); aspect-ratio: 1; margin: auto; border-radius: 12px; background: #2a2a2a;
  overflow: hidden; display: grid; place-items: center; color: #555; box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
#full .big-art .ic { width: 96px; height: 96px; }
#full .big-art img { width: 100%; height: 100%; object-fit: cover; }
#full .info { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
#full .info .meta .t { font-size: 24px; font-weight: 700; }
#full .info .meta .a { font-size: 17px; }
#full .info .icon-btn { width: 44px; height: 44px; }
#full .info .icon-btn.done { color: var(--accent); }
#full .info .icon-btn.busy { color: var(--accent); font-size: 12px; }

#seek {
  -webkit-appearance: none; appearance: none; width: 100%; height: 32px; margin: 18px 0 2px;
  background: transparent; direction: ltr; --pct: 0%; touch-action: none;
}
#seek::-webkit-slider-runnable-track {
  height: 8px; border-radius: 4px;
  background: linear-gradient(to right, var(--played) var(--pct), var(--track) var(--pct));
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -6px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 6px rgba(0, 0, 0, .5);
}
#seek::-moz-range-track { height: 8px; border-radius: 4px; background: var(--track); }
#seek::-moz-range-progress { height: 8px; border-radius: 4px; background: var(--played); }
#seek::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: #fff; }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; direction: ltr; font-variant-numeric: tabular-nums; }

.controls { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; direction: ltr; }
.controls button { width: 66px; height: 66px; display: grid; place-items: center; color: var(--text); border-radius: 50%; }
.controls button .ic { width: 40px; height: 40px; }
.controls .main { width: 88px; height: 88px; background: var(--text); color: #000; }
.controls .main .ic { width: 44px; height: 44px; }
.controls .toggle { color: var(--muted); position: relative; }
.controls .toggle .ic { width: 28px; height: 28px; }
.controls .toggle.on { color: var(--accent); }
.controls .toggle .one { position: absolute; font-size: 10px; font-weight: 800; bottom: 14px; right: 14px; }

/* ---------- القوائم المنبثقة ---------- */
#sheet { position: fixed; inset: 0; z-index: 40; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); opacity: 0; transition: opacity .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; background: #222; border-radius: 16px 16px 0 0;
  padding: 10px 12px calc(12px + var(--bottom)); transform: translateY(100%); transition: transform .22s ease;
  max-height: 80vh; overflow-y: auto;
}
#sheet.open .sheet-backdrop { opacity: 1; }
#sheet.open .sheet-panel { transform: none; }
.sheet-title { padding: 8px 8px 12px; font-weight: 700; border-bottom: 1px solid #333; margin-bottom: 6px; }
.sheet-title .a { font-weight: 400; }
.sheet-items { display: grid; }
.sheet-item { display: flex; align-items: center; gap: 14px; padding: 14px 8px; border-radius: 10px; text-align: start; font-size: 16px; }
.sheet-item:active { background: #2c2c2c; }
.sheet-item.danger { color: var(--danger); }
.sheet-item.selected { color: var(--accent); }
.sheet-cancel { width: 100%; padding: 14px; margin-top: 6px; border-radius: 10px; background: #2c2c2c; font-weight: 600; }
.sheet-form { display: grid; gap: 10px; padding: 6px 4px; }
.sheet-form .row { display: flex; gap: 8px; }
.sheet-form .row .btn { flex: 1; }
.sheet-section { color: var(--muted); font-size: 13px; padding: 10px 8px 4px; }
.seg { display: flex; gap: 6px; padding: 4px 4px 10px; }
.seg button { flex: 1; padding: 11px; border-radius: 10px; background: #2c2c2c; font-weight: 600; }
.seg button.on { background: var(--accent); color: #000; }

/* ---------- صف الأزرار الدائرية ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; padding: 2px 16px 16px; }
.toolbar .spacer { flex: 1; }
.round {
  width: 52px; height: 52px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: #2a2a2a; color: var(--text);
}
.round .ic { width: 24px; height: 24px; }
.round.play { width: 60px; height: 60px; background: var(--accent); color: #000; box-shadow: 0 6px 20px rgba(29, 185, 84, .3); }
.round.play .ic { width: 28px; height: 28px; transform: translateX(2px); }
.round.tool { width: 44px; height: 44px; background: #1c1c1c; }
.round.tool .ic { width: 21px; height: 21px; }

/* زر القلب جنب التنزيل في كل أغنية */
.like-btn {
  width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted); flex: none; border-radius: 50%;
}
.like-btn .ic { width: 20px; height: 20px; }
.like-btn.on { color: var(--heart); }
#mini .ctrl.like .ic { width: 26px; height: 26px; }
/* الجوالات العادية: نصغّر الأزرار شوي عشان يبقى مكان لاسم الأغنية */
@media (max-width: 440px) {
  .mini-row { gap: 10px; padding: 14px 12px 10px; }
  #mini .art { width: 56px; height: 56px; border-radius: 13px; }
  #mini .t { font-size: 16px; }
  #mini .a { font-size: 13px; }
  #mini .ctrl { width: 42px; height: 42px; }
  #mini .ctrl .ic { width: 28px; height: 28px; }
  #mini .ctrl.like .ic { width: 23px; height: 23px; }
}
#mini .ctrl.like.liked { color: var(--heart); }

/* ---------- المفضلة ---------- */
:root { --heart: #ff375f; }
.ic.filled { fill: currentColor; }
.liked-mark { display: inline-flex; vertical-align: -2px; color: var(--heart); margin-inline-end: 6px; }
.liked-mark .ic { width: 14px; height: 14px; }
#full .info .icon-btn.liked { color: var(--heart); }
nav#tabs button[data-tab="likes"].active { color: var(--heart); }
nav#tabs button[data-tab="likes"].active .ic { fill: currentColor; }
#full .big-art { position: relative; }
.big-heart {
  position: absolute; inset: 0; display: grid; place-items: center; color: #fff; pointer-events: none;
  animation: bigheart .9s cubic-bezier(.2, .9, .3, 1.3) forwards; filter: drop-shadow(0 6px 24px rgba(0, 0, 0, .45));
}
.big-heart .ic { width: 38%; height: 38%; }
@keyframes bigheart {
  0% { transform: scale(.3); opacity: 0; }
  25% { transform: scale(1.1); opacity: 1; }
  45% { transform: scale(.95); }
  75% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.15); opacity: 0; }
}

/* ---------- لوحة المتابعة ---------- */
.green { color: var(--accent); }
.red { color: var(--danger); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 4px 16px 18px; }
.stat { background: var(--card); border-radius: 16px; padding: 14px 16px; display: grid; gap: 4px; }
.stat b { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.people, .events { list-style: none; margin: 0; padding: 0 0 12px; }
.person { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.avatar {
  position: relative; width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #2f5a3f, #1d3326); color: #d8f5e1; font-weight: 700; font-size: 19px;
}
.avatar .dot {
  position: absolute; bottom: 1px; inset-inline-end: 1px; width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}
.person .meta .a { white-space: normal; }
.chip.danger { color: var(--danger); background: #2a1616; }
.event { display: flex; align-items: center; gap: 12px; padding: 9px 16px; font-size: 14px; }
.ev-ic { width: 32px; height: 32px; border-radius: 50%; background: var(--card); display: grid; place-items: center; flex: none; color: var(--muted); }
.ev-ic .ic { width: 16px; height: 16px; }
.event.play .ev-ic, .event.download .ev-ic { color: var(--accent); }
.event.login_failed .ev-ic, .event.kicked .ev-ic { color: var(--danger); }
.ev-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-time { color: var(--muted); font-size: 12px; flex: none; }

/* ---------- أنيميشن الضغط على الأزرار ---------- */
button, label.icon-btn, .song {
  transition: transform .18s cubic-bezier(.3, .7, .4, 1.6), background-color .2s, color .2s, opacity .2s;
}
button:active, label.icon-btn:active { transform: scale(.9); }
.btn:active { transform: scale(.95); }
.card:active { transform: scale(.95); }
.song:active { transform: scale(.98); background: #151515; }
.controls .main:active { transform: scale(.86); }
.controls button:active { background: rgba(255, 255, 255, .08); }
.controls .main:active { background: #d8d8d8; }
.sheet-item:active { transform: scale(.98); }
/* الأيقونة تنبض لما تتغير (تشغيل/إيقاف، عشوائي، تكرار) */
.ic.bump { animation: bump .35s cubic-bezier(.3, .7, .4, 1.6); }
@keyframes bump { 0% { transform: scale(.6); opacity: .5; } 100% { transform: none; opacity: 1; } }
.controls .toggle.on .ic { filter: drop-shadow(0 0 6px rgba(29, 185, 84, .55)); }

#toast {
  position: fixed; left: 50%; top: calc(16px + var(--top)); z-index: 60; transform: translate(-50%, -160%);
  background: #333; color: var(--text); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px); transition: transform .25s ease; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
#toast.show { transform: translate(-50%, 0); }
