/* ==========================================================================
   رفع الجودة / AI Upscaler — ai-upscaler.php
   كل الأنماط محصورةٌ تحت ‎#upTop‎ و‎#up‎ و‎#upBtm‎ — هذا الملفُّ لا يُحمَّل على
   أيِّ صفحةٍ أخرى (عبر ‎$extraHead‎)، فلا شيءَ هنا يصل إلى بقية الموقع.

   ⚠ قواعدُ مكتسبة من الأداتين الأُخريين (HANDOFF §8):
   • لا ‎transform/filter/perspective/will-change/overflow:hidden‎ على ‎#up‎ أو جدٍّ
     له — ‎.up-bar‎ تلتصق بأقرب حاوية تمرير (‎position:sticky‎).
   • ‎[hidden]{display:none!important}‎ مُعادةٌ داخل النطاق (الفخّ: الصنفُ يضبط display).
   • الأيقوناتُ ‎span.up-ic‎ بالنوع + الصنف لا الصنف وحده (الفخّ 90: ابتلاعُ القاعدة).
   • لا ‎transition‎ على مقبض المقارنة المسحوب (الفخّان 78 و80).
   • ‎@keyframes‎ على سطرٍ واحد ولا أقواس داخل التعليقات (الفخّ 98).
   ========================================================================== */
#up,#upTop,#upBtm{
  --brand:#6C4CE0;--brand2:#8A6CFF;--soft:#C9BCF3;
  --bg:#f4f5fb;--surface:#fff;--surface2:#f1f1f9;
  --text:#16162a;--dim:#63647e;--line:#e7e7f2;
  --radius:16px;--shadow:0 8px 30px rgba(30,20,80,.08);--ok:#1f9d55;
  --up-deep:#5B3ECB;--up-ink:#3f2b8f;--up-tonal:#efeafd;--up-dash:#c3b6ef;
}
#up *,#upTop *,#upBtm *{box-sizing:border-box}
#up [hidden],#upTop [hidden],#upBtm [hidden]{display:none !important}
#up{--up-lift:0px;overflow-x:clip;max-width:100%;color:var(--text);line-height:1.6;
  font-family:'Cairo',system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans Arabic",Tahoma,sans-serif}

/* ===== البطل ===== */
#upTop .page-title{display:flex;align-items:center;gap:10px;font-size:26px;letter-spacing:-.3px}
#upTop span.up-tic{width:34px;height:34px;border-radius:10px;flex:0 0 auto;color:#fff;
  background:linear-gradient(100deg,#5B3ECB,#6C4CE0);display:grid;place-items:center}
#upTop span.up-tic svg{width:19px;height:19px;display:block}
#upTop .page-sub{font-size:15.5px;margin:6px 0 0;max-width:62ch}
#upTop .up-chips{display:flex;flex-wrap:wrap;gap:7px;margin:12px 0 4px}
#upTop .up-chips span{display:inline-flex;align-items:center;gap:6px;background:#fff;
  border:1px solid #e7e7f2;border-radius:999px;padding:5px 12px;font-size:12.5px;font-weight:700;color:#63647e}
#upTop .up-chips svg{width:14px;height:14px;flex:0 0 auto;color:#6C4CE0;display:block}

/* ===== تنبيه عدم الدعم ===== */
#up .up-alert{display:flex;gap:10px;align-items:flex-start;margin:0 0 16px;padding:14px 16px;border-radius:14px;
  background:#fff6e6;border:1px solid #f1d39a;color:#6b4a00;font-size:14px;line-height:1.7}
#up .up-alert svg{width:18px;height:18px;flex:0 0 auto;margin-top:3px;display:block}

/* ===== بطاقةُ خطوة ===== */
#up .up-step{background:var(--surface);border:1px solid var(--line);border-radius:20px;
  box-shadow:var(--shadow);margin-bottom:16px;overflow:hidden}
#up .up-sh{display:flex;align-items:flex-start;gap:12px;padding:18px 18px 0}
#up .up-n{flex:0 0 auto;width:32px;height:32px;border-radius:10px;display:grid;place-items:center;
  font-weight:900;font-size:15px;color:#fff;background:linear-gradient(100deg,#5B3ECB,var(--brand))}
#up .up-n svg{width:18px;height:18px;display:block}
#up .up-n.up-n-ok{background:linear-gradient(100deg,#13804a,#1f9d55)}
#up .up-st{flex:1;min-width:0}
#up .up-st h2{font-size:17px;font-weight:800;margin:0}
#up .up-st p{margin:3px 0 0;color:var(--dim);font-size:13.5px;line-height:1.6}
#up .up-sb{padding:14px 18px 18px}
#up .up-done{flex:0 0 auto;display:inline-flex;align-items:center;gap:5px;font-size:12px;font-weight:800;
  color:#167a41;background:#eefaf2;border:1px solid #9fdcb9;border-radius:999px;padding:3px 10px;white-space:nowrap}
#up .up-done svg{width:13px;height:13px;display:block}
#up .up-done b{font-weight:900}

/* الخطوتان ٢ و٣ باهتتان حتى يُختار ملف — تُقرأ ولا تُستعمل */
#up[data-state="empty"] #upS2,#up[data-state="empty"] #upS3{opacity:.55}
#up[data-state="empty"] #upS2 .up-sb{pointer-events:none}

/* ===== أزرار ===== */
#up .btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;border-radius:12px;padding:12px 16px;
  font-size:15px;font-weight:800;cursor:pointer;border:1px solid var(--line);background:var(--surface);color:var(--text);
  font-family:inherit;text-decoration:none;line-height:1.3}
#up .btn svg{width:17px;height:17px;flex:0 0 auto;display:block}
#up .btn.primary{background:var(--brand);border-color:var(--brand);color:#fff}
#up .btn.ghost{background:transparent}
#up .btn.small{padding:8px 12px;font-size:13px;font-weight:700}
#up .btn.small svg{width:14px;height:14px}
#up .btn:active{transform:scale(.98)}
#up .btn[disabled]{opacity:.45;cursor:not-allowed}
#up .btn:focus-visible,#up .seg button:focus-visible,#up .up-mode:focus-visible,#up .up-drop:focus-visible{
  outline:3px solid #b9a8f5;outline-offset:2px}

/* ===== منطقةُ الاختيار ===== */
#up .up-drop{display:flex;flex-direction:column;align-items:stretch;text-align:center;border-radius:16px;cursor:pointer;
  background:var(--surface2);border:2px dashed var(--up-dash);transition:border-color .15s,background .15s}
#up .up-drop:hover,#up .up-drop.up-over{border-color:var(--brand);background:var(--up-tonal)}
#up .up-ph{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;padding:26px 16px}
#up .up-ph span.up-ic{width:60px;height:60px;border-radius:50%;color:#fff;
  background:linear-gradient(140deg,#7B5BEA,#5B3ECB);
  box-shadow:0 8px 20px rgba(91,62,203,.38),0 0 0 4px rgba(108,76,224,.13);
  display:inline-flex;align-items:center;justify-content:center;margin-bottom:12px;
  font-size:0;line-height:0;transition:transform .15s,box-shadow .15s}
#up .up-ph span.up-ic svg{width:29px;height:29px;display:block}
#up .up-drop:hover span.up-ic,#up .up-drop.up-over span.up-ic{transform:scale(1.05);
  box-shadow:0 10px 26px rgba(91,62,203,.48),0 0 0 6px rgba(108,76,224,.18)}
#up .up-ph b{font-size:16px;font-weight:800;color:var(--text)}
#up .up-ph span{font-size:13.5px;color:var(--dim)}
#up .up-ph small{margin-top:10px;font-size:12px;font-weight:700;color:var(--dim);
  background:var(--surface);border:1px solid var(--line);border-radius:999px;padding:3px 11px}

/* بطاقةُ الملف المختار */
#up .up-file{display:flex;align-items:center;gap:12px;padding:10px;border:1px solid var(--line);border-radius:14px;background:var(--surface2)}
#up .up-thumb{flex:0 0 auto;width:96px;height:54px;border-radius:9px;overflow:hidden;background:#0b0b12}
#up .up-thumb canvas{width:100%;height:100%;display:block;object-fit:cover}
#up .up-finfo{flex:1;min-width:0;display:flex;flex-direction:column}
#up .up-finfo b{font-size:14px;font-weight:800;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;direction:ltr;text-align:start}
#up .up-finfo span{font-size:12.5px;color:var(--dim);font-variant-numeric:tabular-nums}

/* ===== الإعدادات ===== */
#up .fl{display:flex;align-items:center;gap:7px;font-size:13.5px;margin:18px 0 8px;color:var(--up-ink);font-weight:800}
#up .up-sb > .fl:first-child{margin-top:0}
#up .fl svg{width:15px;height:15px;flex:0 0 auto;color:var(--brand);display:block}
#up .seg{display:flex;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--surface2)}
#up .seg button{flex:1;border:0;background:transparent;padding:10px 6px;font-size:14px;cursor:pointer;color:var(--text);
  font-family:inherit;line-height:1.35;min-height:44px}
#up .seg button.on{background:var(--brand);color:#fff;font-weight:800}
#up .seg button[disabled]{cursor:not-allowed;color:var(--dim)}
#up .seg button.on[disabled]{background:#d9d2f6;color:#3f2b8f}
#up .seg button small{display:block;font-size:11px;font-weight:700;opacity:1;color:inherit}

/* بطاقتا النمط */
#up .up-modes{display:grid;grid-template-columns:1fr 1fr;gap:10px}
#up .up-mode{display:flex;flex-direction:column;align-items:flex-start;gap:4px;text-align:start;cursor:pointer;
  border:2px solid var(--line);background:var(--surface);border-radius:14px;padding:12px 14px;font-family:inherit;color:var(--text)}
#up .up-mode:hover{border-color:#cdc0f5}
#up .up-mode.on{border-color:var(--brand);background:var(--up-tonal)}
#up .up-mh{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
#up .up-mh b{font-size:15.5px;font-weight:900}
#up .up-mh i{font-style:normal;font-size:11px;font-weight:800;color:#fff;background:linear-gradient(100deg,#5B3ECB,var(--brand));
  border-radius:999px;padding:1px 9px}
#up .up-md{font-size:12.5px;color:var(--dim);line-height:1.55}
#up .up-mode.on .up-md{color:#4a3d86}

#up .up-note{display:flex;gap:8px;margin:14px 0 0;color:var(--dim);font-size:12.5px;line-height:1.65;
  background:var(--surface2);border:1px solid var(--line);border-radius:11px;padding:10px 12px}
#up .up-note svg{width:15px;height:15px;flex:0 0 auto;color:var(--brand);margin-top:2px;display:block}
#up .up-note.warn{background:#fff6e6;border-color:#f1d39a;color:#6b4a00}
#up .up-note.warn svg{color:#b7791f}

/* ===== مسرحُ المقارنة (داكن) ===== */
#up .up-stage{position:relative;width:100%;aspect-ratio:16/10;max-height:70vh;border-radius:14px;overflow:hidden;
  background:#08080e;touch-action:pan-y;user-select:none;-webkit-user-select:none}
#up .up-stage canvas#upBefore,#up .up-stage canvas#upAfter{position:absolute;inset:0;width:100%;height:100%;display:block;
  image-rendering:auto;object-fit:contain}
#up .up-stage canvas#upAfter{clip-path:inset(0 0 0 50%)}
#up .up-stage .up-lab{position:absolute;top:10px;padding:3px 11px;border-radius:999px;font-size:12px;font-weight:800;
  letter-spacing:.2px;pointer-events:none;z-index:3}
#up .up-stage .up-lab-b{left:10px;background:rgba(10,10,20,.72);color:#ececf4}
#up .up-stage .up-lab-a{right:10px;background:var(--brand);color:#fff}
#up .up-split{position:absolute;top:0;bottom:0;left:50%;width:0;z-index:4}
#up .up-split::before{content:"";position:absolute;top:0;bottom:0;left:-1px;width:2px;background:#fff;
  box-shadow:0 0 0 1px rgba(0,0,0,.25)}
#up .up-knob{position:absolute;top:50%;left:-22px;width:44px;height:44px;margin-top:-22px;border-radius:50%;
  border:0;background:#fff;color:var(--brand);box-shadow:0 4px 14px rgba(0,0,0,.35);cursor:ew-resize;
  display:grid;place-items:center;touch-action:none;padding:0}
#up .up-knob svg{width:22px;height:22px;display:block}
/* منطقةُ لمسٍ عريضة حول الخط — يبدأ السحبُ منها دون أن تسرقه تمريرةُ الصفحة */
#up .up-split::after{content:"";position:absolute;top:0;bottom:0;left:-22px;width:44px;touch-action:none;cursor:ew-resize}
#up .up-mini{position:absolute;bottom:10px;left:10px;width:112px;height:63px;padding:0;border:2px solid rgba(255,255,255,.85);
  border-radius:8px;overflow:hidden;background:#000;cursor:crosshair;z-index:5;box-shadow:0 4px 14px rgba(0,0,0,.45)}
#up .up-mini canvas{width:100%;height:100%;display:block}
#up .up-mini:focus-visible{outline:3px solid #ffd166;outline-offset:2px}
#up .up-mini i{position:absolute;border:2px solid #ffd166;box-shadow:0 0 0 1px rgba(0,0,0,.5);pointer-events:none}
#up .up-busy{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;
  background:rgba(8,8,14,.55);color:#ececf4;z-index:6;font-size:14px}
#up .up-empty{position:absolute;inset:0;display:none;align-items:center;justify-content:center;text-align:center;padding:20px;
  color:#9a9ab8;font-size:14px;z-index:2;background:#08080e}
#up[data-state="empty"] .up-empty{display:flex}
#up[data-state="empty"] .up-split,#up[data-state="empty"] .up-mini,#up[data-state="empty"] .up-lab{display:none}
#up .up-spin{display:inline-block;width:26px;height:26px;border-radius:50%;border:3px solid rgba(255,255,255,.25);
  border-top-color:#fff;animation:upSpin .8s linear infinite}
@keyframes upSpin{to{transform:rotate(360deg)}}
#up .up-n .up-spin{width:18px;height:18px;border-width:2.5px}

/* اختيارُ اللقطة */
#up .up-frames{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-top:10px}
#up .up-frames button{position:relative;padding:0;border:2px solid transparent;border-radius:9px;overflow:hidden;
  background:#0b0b12;cursor:pointer;aspect-ratio:16/9}
#up .up-frames button.on{border-color:var(--brand)}
#up .up-frames canvas{width:100%;height:100%;display:block;object-fit:cover}
#up .up-frames span{position:absolute;bottom:4px;inset-inline-start:4px;background:rgba(10,10,20,.78);color:#fff;
  font-size:10.5px;font-weight:800;border-radius:5px;padding:0 5px;font-variant-numeric:tabular-nums;direction:ltr}
#up .up-speed{margin:10px 0 0;font-size:13px;color:var(--up-ink);font-weight:700;font-variant-numeric:tabular-nums}

/* ===== شريطُ الإجراء ===== */
#up .up-bar{position:sticky;z-index:19;margin:18px 0 0;
  bottom:calc(var(--up-lift) + env(safe-area-inset-bottom,0px));
  background:var(--surface);border:1px solid var(--line);border-radius:18px;
  box-shadow:0 -6px 24px rgba(30,20,80,.12);transition:border-color .15s,box-shadow .15s}
#up[data-state="ready"] .up-bar{border-color:#cdc0f5;box-shadow:0 -6px 24px rgba(108,76,224,.16)}
#up[data-state="run"] .up-bar,#up[data-state="done"] .up-bar{display:none}
#up .up-bar-in{display:flex;align-items:center;gap:14px;padding:12px 16px 14px;flex-wrap:wrap}
#up .up-sum{display:flex;gap:18px;flex:0 1 auto;min-width:0}
#up .up-sum div{min-width:0}
#up .up-sum b{display:block;font-size:16px;font-weight:900;color:var(--text);
  font-variant-numeric:tabular-nums;line-height:1.3;white-space:nowrap}
#up .up-sum b.dim{color:var(--dim);font-weight:700;font-size:13px}
#up .up-sum span{display:block;font-size:11px;color:var(--dim)}
#up .up-bar .btn.primary{flex:1 1 300px;min-height:58px;font-size:17px;font-weight:900;
  padding:16px 26px;border-radius:15px;background:linear-gradient(100deg,#5B3ECB,var(--brand));
  border-color:transparent;color:#fff;box-shadow:0 10px 26px rgba(108,76,224,.4)}
#up .up-bar .btn.primary svg{width:22px;height:22px}
#up .up-bar .btn.primary[disabled]{box-shadow:none}

/* الخطواتُ الثلاث تختفي أثناء المعالجة وبعدها */
#up[data-state="run"] #upS1,#up[data-state="run"] #upS2,#up[data-state="run"] #upS3,
#up[data-state="done"] #upS1,#up[data-state="done"] #upS2,#up[data-state="done"] #upS3{display:none}

/* ===== أثناء المعالجة ===== */
#up .up-runprev{position:relative;width:100%;aspect-ratio:16/9;max-height:52vh;border-radius:14px;overflow:hidden;background:#08080e}
#up .up-runprev canvas{width:100%;height:100%;display:block;object-fit:contain}
#up .up-prog{height:12px;border-radius:999px;background:#ece8fb;overflow:hidden;margin-top:14px}
#up .up-progbar{height:100%;width:0;border-radius:999px;background:linear-gradient(90deg,#5B3ECB,var(--brand2))}
#up .up-runrow{display:flex;flex-wrap:wrap;align-items:baseline;gap:6px 14px;margin-top:9px;font-size:13px;color:var(--dim);
  font-variant-numeric:tabular-nums}
#up .up-runrow b{font-size:20px;font-weight:900;color:var(--text)}
#up .up-runrow span:last-child{margin-inline-start:auto;font-weight:800;color:var(--up-ink)}
#up .up-cancel{margin-top:14px;width:100%}

/* ===== النتيجة ===== */
#up .up-media{border-radius:14px;overflow:hidden;background:#08080e;display:flex;justify-content:center}
#up .up-media video,#up .up-media img{display:block;max-width:100%;max-height:70vh;width:auto;height:auto}
#up .up-actions{display:flex;gap:10px;margin-top:14px;flex-wrap:wrap}
#up .up-actions .btn{flex:1 1 200px;min-height:54px}
#up .up-actions .btn.primary{background:linear-gradient(100deg,#5B3ECB,var(--brand));border-color:transparent;font-size:16.5px;font-weight:900;
  box-shadow:0 10px 26px rgba(108,76,224,.32)}
#up .up-warn{margin:12px 0 0;padding:10px 12px;border-radius:11px;background:#fff6e6;border:1px solid #f1d39a;color:#6b4a00;font-size:13px}
#up .up-local{margin:12px 0 0;font-size:12.5px;color:#167a41;font-weight:700}

/* ===== أقسامُ المحتوى أسفل الأداة ===== */
#upBtm{margin-top:34px}
#upBtm .content{margin-top:34px}
#upBtm .content:first-child{margin-top:0}
#upBtm .content h2{font-size:21px;font-weight:800;margin:0 0 14px}
#upBtm .steps{display:grid;grid-template-columns:1fr 1fr;gap:12px}
#upBtm .steps li{background:#fff;border:1px solid #e7e7f2;border-radius:14px;padding:16px;
  padding-inline-start:56px;font-size:14px;color:#63647e;box-shadow:0 8px 30px rgba(30,20,80,.08)}
#upBtm .steps li::before{inset-inline-start:15px;top:14px;transform:none;width:30px;height:30px;
  border-radius:9px;font-size:14px;background:linear-gradient(100deg,#5B3ECB,#6C4CE0)}
#upBtm .up-art p{margin:0 0 12px;color:#4b4c63;font-size:15px;line-height:1.85}
#upBtm .up-list{margin:0 0 12px;padding-inline-start:22px;color:#4b4c63;font-size:15px;line-height:1.85}
#upBtm .up-list li{margin:4px 0}
#upBtm .promo{display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap;margin-top:34px;
  background:linear-gradient(100deg,#5B3ECB,#6C4CE0);border:0;border-radius:20px;
  padding:24px 26px;color:#fff;box-shadow:0 14px 32px rgba(108,76,224,.26)}
#upBtm .promo h2{color:#fff;font-size:20px;margin:0 0 6px}
#upBtm .promo p{color:#eee9ff;font-size:14.5px;margin:0}
#upBtm .up-promo-btns{display:flex;gap:10px;flex-wrap:wrap}
#upBtm .promo .btn{display:inline-flex;align-items:center;justify-content:center;border-radius:12px;padding:12px 18px;
  font-weight:800;font-size:15px;text-decoration:none}
#upBtm .promo .btn.primary{background:#fff;color:#3f2b8f;border:1px solid transparent}
#upBtm .promo .btn.ghost{background:transparent;color:#fff;border:1px solid rgba(255,255,255,.7)}
#upBtm .faq details{border-radius:14px;padding:0}
#upBtm .faq summary{padding:14px 17px;font-size:15px}
#upBtm .faq details[open] summary{border-block-end:1px solid #e7e7f2}
#upBtm .faq p{padding:13px 17px 16px;margin:0;font-size:14px}
#upBtm .up-credits{margin:28px 0 0;font-size:12px;color:#63647e;text-align:center}
#upBtm .up-credits a{color:#4b3aa8;text-decoration:underline}

@media (max-width:640px){
  #upTop .page-title{font-size:21px}
  #up .up-sh{padding:15px 14px 0}
  #up .up-sb{padding:12px 14px 15px}
  #up .up-modes{grid-template-columns:1fr}
  #up .up-stage{aspect-ratio:4/3}
  #up .up-mini{width:88px;height:50px}
  #up .up-bar-in{gap:11px;padding:11px 14px 13px}
  #up .up-sum{flex:1 1 100%;justify-content:space-between;gap:10px}
  #up .up-sum b{font-size:15px}
  #up .up-bar .btn.primary{flex:1 1 100%;min-height:56px;font-size:16.5px;padding:15px 20px}
  #upBtm .steps{grid-template-columns:1fr}
  #upBtm .promo .btn{flex:1 1 100%}
  #upBtm .up-promo-btns{width:100%}
}
@media (prefers-reduced-motion:reduce){
  #up .up-spin{animation-duration:2.4s}
}
