/* ==========================================================================
   أفتارات PS3 — دبلوماسي بلس
   الصور هي الصفحة: خلفية داكنة (كحلي وأسود)، بحث وشرائح كحلية، الأبيض للنسخ.
   ========================================================================== */

:root {
  /* ألوان Pinterest الداكنة: أسود ورصاصي، والأبيض للأهم (النسخ والتحديد) */
  --bg: #111111;             /* أسود */
  --ink: #ffffff;            /* أبيض */
  --ink-2: #b5b5b5;          /* نص ثانوي */
  --ink-3: #a3a3a3;          /* تلميحات */
  --fill: #2a2a2a;           /* البحث والشرائح: رصاصي */
  --fill-hover: #363636;
  --line: #262626;
  --tile: #1e1e1e;           /* خلفية الصورة قبل تحميلها */
  --accent: #ffffff;         /* النسخ والتحديد */
  --accent-hover: #e9e9e9;
  --on-accent: #111111;
  --brand-light: #d9d9d9;    /* مؤشر التحميل والشارات */
  --surface: #1a1a1a;        /* النوافذ */
  --dark: #333333;           /* «اطلبه الآن» والإشعار */
  --on-dark: #ffffff;
  --navy-deep: #1a1a1a;
  --ok: #3ccf7f;
  --fav: #ff5c86;
  --scrim: rgba(0, 0, 0, .72);
  --float: rgba(17, 17, 17, .78);   /* أزرار فوق الصور */
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 8px 24px -8px rgba(0,0,0,.7);
  --shadow-lg: 0 28px 72px -18px rgba(0,0,0,.85);

  --font: "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --r: 16px;
  --gutter: 16px;
  --bar-h: 64px;
  --chips-h: 52px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: dark;
}

/* الخطوط: مستضافة مع الموقع (WOFF2 مقصوصة للعربي واللاتيني) */
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-SemiBold.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans Arabic"; src: url("../assets/fonts/IBMPlexSansArabic-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + var(--chips-h) + 8px); scrollbar-color: var(--fill-hover) var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
body.is-locked { overflow: hidden; }
img { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
input { caret-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 10px; }

.skip-link { position: fixed; top: 8px; inset-inline-start: 8px; z-index: 100; padding: 8px 14px; border-radius: 999px; background: var(--dark); color: var(--on-dark); transform: translateY(-160%); transition: transform .2s; }
.skip-link:focus { transform: none; }

/* ---------- عناصر مشتركة ---------- */
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 999px; color: var(--ink);
  transition: background .15s;
}
.icon-btn:hover { background: var(--fill); }
.icon-btn:active { background: var(--fill-hover); }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.icon-btn--lg { width: 52px; height: 52px; background: var(--fill); }
.icon-btn--lg:hover { background: var(--fill-hover); }

.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 999px; font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s, color .15s, transform .1s;
}
.pill:active { transform: scale(.97); }
.pill svg { width: 18px; height: 18px; }
.pill--lg { height: 52px; padding: 0 24px; font-size: 16px; }
.pill--accent { background: var(--accent); color: var(--on-accent); }
.pill--accent:hover { background: var(--accent-hover); }
.pill--accent.is-done { background: var(--ok); color: #04140b; }
.pill--dark { background: var(--dark); color: var(--on-dark); }
.pill--dark:hover { opacity: .88; }
.pill--quiet { background: var(--fill); color: var(--ink); }
.pill--quiet:hover { background: var(--fill-hover); }
.link { color: var(--ink); font-weight: 600; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.link:hover { text-decoration-color: currentColor; }

/* ---------- الهيدر: شريط البحث فقط ---------- */
.hdr {
  position: sticky; top: 0; z-index: 40; padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(16px); -webkit-backdrop-filter: saturate(140%) blur(16px);
  transition: box-shadow .2s;
}
.hdr.is-scrolled { box-shadow: 0 1px 0 var(--line), 0 12px 32px -20px rgba(0,0,0,.9); }
.hdr__row {
  padding: 14px max(var(--gutter), env(safe-area-inset-left, 0px)) 12px max(var(--gutter), env(safe-area-inset-right, 0px));
  max-width: 1600px; margin-inline: auto;
}
.hdr .search { max-width: 720px; margin-inline: auto; }
.hdr .search input {
  height: 54px; background: #1f1f1f; font-size: 16px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 10px 30px -18px rgba(0,0,0,.9);
}
.hdr .search input:hover { background: #262626; }
.hdr .search input:focus { background: #1f1f1f; box-shadow: inset 0 0 0 1px rgba(255,255,255,.55), 0 10px 30px -18px rgba(0,0,0,.9); }
.hdr .search input::placeholder { color: rgba(255,255,255,.42); }
.hdr .search__icon { inset-inline-start: 20px; width: 20px; height: 20px; color: rgba(255,255,255,.55); }
.hdr .search input { padding-inline-start: 52px; }
.hdr .search__lens { inset-inline-end: 8px; width: 40px; height: 40px; background: rgba(255,255,255,.06); }
.hdr .search__lens:hover { background: rgba(255,255,255,.12); }
.hdr .search__clear { inset-inline-end: 52px; }

.search { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; }
.search__icon { position: absolute; inset-inline-start: 16px; width: 18px; height: 18px; color: var(--ink-2); pointer-events: none; }
.search input {
  width: 100%; height: 48px; padding: 0 46px 0 44px; border: 0; outline: 0; border-radius: 999px;
  background: var(--fill); font-size: 16px; transition: background .15s, box-shadow .15s;
}
.search input:hover { background: var(--fill-hover); }
.search input:focus { background: var(--bg); box-shadow: 0 0 0 2px var(--accent); }
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search__clear { position: absolute; inset-inline-end: 6px; width: 36px; height: 36px; border-radius: 999px; display: grid; place-items: center; color: var(--ink-2); }
.search__clear:hover { background: var(--fill-hover); color: var(--ink); }
.search__clear svg { width: 18px; height: 18px; }

/* ---------- الصفحة والشبكة ---------- */
.page {
  max-width: 1600px; margin-inline: auto; outline: 0;
  padding: 4px max(var(--gutter), env(safe-area-inset-right, 0px)) 48px max(var(--gutter), env(safe-area-inset-left, 0px));
}
.status { min-height: 40px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.status__text { margin: 0; color: var(--ink-2); font-size: 14px; }
.status__text b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.status__actions { display: flex; gap: 8px; }
#active-game span { direction: ltr; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
#active-game svg { width: 16px; height: 16px; }

/* شبكة متدرّجة (Masonry): أعمدة، والعمود الثاني من كل زوج ينزل نص بطاقة */
.grid { --cols: 2; --gap-x: 10px; --gap-y: 16px; display: flex; gap: var(--gap-x); align-items: flex-start; }
.grid__col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: var(--gap-y); }
.grid__col:nth-child(even) { padding-top: calc((100vw - 2 * var(--gutter)) / var(--cols) * .42); }
@media (min-width: 600px) { .grid { --cols: 3; --gap-x: 16px; --gap-y: 24px; } }
@media (min-width: 900px) { .grid { --cols: 4; } }
@media (min-width: 1200px) { .grid { --cols: 5; } }
@media (min-width: 1440px) { .grid { --cols: 6; } }
@media (min-width: 1600px) { .grid__col:nth-child(even) { padding-top: calc((1600px - 2 * var(--gutter)) / var(--cols) * .42); } }

/* ---------- البطاقة: صورة + اسم اللعبة ---------- */
.card { min-width: 0; content-visibility: auto; contain-intrinsic-size: 180px 220px; }
.card__frame { position: relative; }
.card__media {
  position: relative; display: block; width: 100%; aspect-ratio: 1; border-radius: var(--r); overflow: hidden;
  background: var(--tile);
}
.card__media::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: rgba(0,0,0,0); transition: background .2s; pointer-events: none; }
@media (hover: hover) { .card:hover .card__media::after { background: rgba(0,0,0,.12); } }
.card__img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s ease-out; }
.card__img.is-loaded { opacity: 1; }
.card__hot { position: absolute; top: 10px; inset-inline-start: 10px; padding: 3px 10px; border-radius: 999px; background: var(--float); color: var(--ink); font-size: 12px; font-weight: 600; box-shadow: var(--shadow); }

.card__copy {
  position: absolute; z-index: 2; inset-inline-start: 8px; bottom: 8px;
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 11px 0 12px; border-radius: 999px;
  background: rgba(17,17,17,.86); color: #fff; font-size: 12px; font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16), 0 6px 16px -8px rgba(0,0,0,.8);
  transition: background .15s, color .15s, transform .1s, opacity .15s;
}
.card__copy svg { width: 14px; height: 14px; }
.card__copy b { font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .05em; }
.card__copy:hover { background: var(--accent); color: var(--on-accent); }
/* بدون تمويش خلفية على أزرار البطاقات: عشرات الطبقات المموّهة تثقل التمرير على الجوال */
.to-top { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.card__copy:active { transform: scale(.95); }
.card.is-copied .card__copy { background: var(--ok); color: #04140b; }
/* على الكمبيوتر: زر النسخ يظهر عند المرور فقط (أهدأ)، وعلى الجوال يبقى ظاهراً */
@media (hover: hover) and (pointer: fine) {
  .card__copy { opacity: 0; transition: opacity .15s, background .15s, color .15s, transform .1s; }
  .card:hover .card__copy, .card__copy:focus-visible, .card.is-copied .card__copy, .card:focus-within .card__copy { opacity: 1; }
}

.card__fav {
  position: absolute; z-index: 2; top: 8px; inset-inline-end: 8px; width: 36px; height: 36px; border-radius: 999px;
  display: grid; place-items: center; background: var(--float); color: var(--ink); box-shadow: var(--shadow);
  opacity: 0; transition: opacity .15s, transform .1s;
}
.card__fav svg { width: 18px; height: 18px; }
.card:hover .card__fav, .card__fav:focus-visible, .card__fav[aria-pressed="true"] { opacity: 1; }
.card__fav[aria-pressed="true"] { color: var(--fav); }
.card__fav[aria-pressed="true"] svg { fill: currentColor; }
.card__fav:active { transform: scale(.9); }

.card__game {
  margin: 8px 4px 0; font-size: 13px; font-weight: 500; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right;
}

.ph {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  font-weight: 700; font-size: 26px; color: var(--ink-3); background: var(--tile);
}
.ph small { display: block; font-size: 11px; font-weight: 500; margin-top: 2px; }
.sentinel { height: 1px; }

/* ---------- لا نتائج ---------- */
.empty { text-align: center; padding: 72px 16px; max-width: 420px; margin: 0 auto; }
.empty h2 { margin: 0 0 8px; font-size: 20px; font-weight: 700; }
.empty p { margin: 0 0 24px; color: var(--ink-2); }

/* ---------- التذييل ---------- */
.foot { border-top: 1px solid var(--line); background: #0b0b0b; padding-bottom: env(safe-area-inset-bottom, 0px); text-align: center; }
.foot__inner {
  max-width: 720px; margin-inline: auto; display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 44px max(var(--gutter), env(safe-area-inset-right, 0px)) 28px max(var(--gutter), env(safe-area-inset-left, 0px));
}
.foot__logo { height: 34px; width: auto; }
.foot__desc { margin: 0; max-width: 40ch; color: var(--ink-2); font-size: 14px; line-height: 1.8; }
.foot__links { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }
.foot__links a { height: 38px; padding: 0 14px; display: inline-flex; align-items: center; border-radius: 999px; color: var(--ink); font-size: 14px; font-weight: 600; }
.foot__links a:hover { background: var(--fill); }
.foot__wa {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding-inline: 6px 14px; border-radius: 999px;
  background: rgba(37,211,102,.1); box-shadow: inset 0 0 0 1px rgba(37,211,102,.28); color: #e9fbef; font-size: 13px; font-weight: 600;
  transition: background .15s, box-shadow .15s;
}
.foot__wa:hover { background: rgba(37,211,102,.18); box-shadow: inset 0 0 0 1px rgba(37,211,102,.5); }
.foot__wa-icon { flex: none; width: 24px; height: 24px; border-radius: 999px; display: grid; place-items: center; background: #25d366; color: #fff; }
.foot__wa-icon svg { width: 15px; height: 15px; }
.foot__wa-num { color: rgba(233,251,239,.7); font-weight: 500; font-variant-numeric: tabular-nums; padding-inline-start: 8px; border-inline-start: 1px solid rgba(37,211,102,.3); }
.foot__legal { max-width: 720px; margin-inline: auto; padding: 0 var(--gutter) 22px; display: grid; gap: 6px; }
.foot__legal p { margin: 0; color: var(--ink-3); font-size: 12px; line-height: 1.8; }
.foot__bottom {
  max-width: 1600px; margin-inline: auto; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 16px var(--gutter) 24px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 12.5px;
}
.foot__bottom p { margin: 0; }
.foot__bottom b { color: var(--ink-2); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- حسابي ---------- */
.account { position: fixed; inset: 0; z-index: 85; }
.account__backdrop { position: absolute; inset: 0; background: var(--scrim); animation: fade .2s ease both; }
.account__panel {
  position: absolute; top: 0; bottom: 0; left: 0; width: min(440px, 100%); display: flex; flex-direction: column;
  background: var(--surface); box-shadow: 0 0 0 1px var(--line), var(--shadow-lg); animation: acc-in .3s var(--ease) both;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@keyframes acc-in { from { transform: translateX(-24px); opacity: 0; } }
.account__head { display: flex; align-items: center; gap: 12px; padding: calc(16px + env(safe-area-inset-top, 0px)) 12px 12px 20px; }
.account__head > div:nth-child(2) { flex: 1; min-width: 0; }
.account__head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.account__avatar { flex: none; width: 48px; height: 48px; border-radius: 999px; display: grid; place-items: center; background: var(--fill); }
.account__avatar svg { width: 24px; height: 24px; }
.account__note { margin: 2px 0 0; color: var(--ink-3); font-size: 12.5px; }
.account__tabs { display: flex; gap: 6px; padding: 4px 20px 12px; border-bottom: 1px solid var(--line); }
.account__tab { height: 38px; padding: 0 14px; border-radius: 999px; background: var(--fill); font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.account__tab span { opacity: .65; font-weight: 500; font-variant-numeric: tabular-nums; }
.account__tab:hover { background: var(--fill-hover); }
.account__tab.is-active { background: var(--accent); color: var(--on-accent); }
.account__body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; overscroll-behavior: contain; }
.account__bar { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.account__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 10px; }
.acc-item { display: grid; gap: 6px; text-align: start; min-width: 0; }
.acc-item__pic { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: var(--tile); transition: opacity .15s; }
.acc-item:hover .acc-item__pic { opacity: .85; }
.acc-item__pic img { width: 100%; height: 100%; object-fit: cover; }
.acc-item__pic .ph { font-size: 16px; }
.acc-item__name { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; }
.account__empty { text-align: center; padding: 56px 16px; }
.account__empty strong { display: block; font-size: 16px; margin-bottom: 6px; }
.account__empty p { margin: 0; color: var(--ink-2); font-size: 14px; }
@media (max-width: 599px) { .account__panel { width: 100%; } .account__grid { gap: 12px 8px; } }

.to-top {
  position: fixed; z-index: 35; inset-inline-start: calc(16px + env(safe-area-inset-left, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: 48px; height: 48px; border-radius: 999px; display: grid; place-items: center;
  background: var(--float); color: var(--ink); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s var(--ease);
}
.to-top.is-visible { opacity: 1; transform: none; pointer-events: auto; }

/* ---------- الإشعار ---------- */
.toasts {
  position: fixed; z-index: 90; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 8px 8px 20px; border-radius: 999px;
  background: var(--dark); color: var(--on-dark); font-size: 15px; font-weight: 600; box-shadow: var(--shadow-lg);
  animation: toast-in .3s var(--ease) both;
}
.toast:not(:has(.toast__action)) { padding-inline-end: 20px; }
.toast__icon { display: none; }
.toast code { display: none; }
.toast__action {
  pointer-events: auto; height: 36px; padding: 0 16px; border-radius: 999px; display: inline-flex; align-items: center;
  background: var(--accent); color: var(--on-accent); font-size: 14px; font-weight: 600;
}
.toast__action:hover { background: var(--accent-hover); }
.toast.is-leaving { animation: toast-out .2s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---------- قائمة الألعاب (نافذة) ---------- */
.scrim { position: fixed; inset: 0; z-index: 60; background: var(--scrim); animation: fade .2s ease both; }
.sheet {
  position: fixed; z-index: 70; left: 50%; top: 50%; width: min(520px, calc(100vw - 32px)); height: min(680px, calc(100vh - 64px));
  display: flex; flex-direction: column; background: var(--bg); border-radius: 24px; box-shadow: var(--shadow-lg);
  transform: translate(-50%, -46%); opacity: 0; visibility: hidden; transition: transform .25s var(--ease), opacity .2s, visibility .2s;
}
.sheet.is-open { transform: translate(-50%, -50%); opacity: 1; visibility: visible; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px 20px; }
.sheet__head h2 { margin: 0; font-size: 18px; font-weight: 700; }
.search--sheet { flex: none; margin: 4px 16px 8px; }
.sheet__list { flex: 1; overflow-y: auto; padding: 0 8px 12px; overscroll-behavior: contain; }
.game-opt {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 12px; text-align: start;
  font-size: 15px; transition: background .12s;
}
.game-opt:hover { background: var(--fill); }
.game-opt.is-active { background: var(--fill); font-weight: 600; }
.game-opt__thumb { flex: none; width: 40px; height: 40px; border-radius: 10px; overflow: hidden; background: var(--tile); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--ink-3); }
.game-opt__thumb img { width: 100%; height: 100%; object-fit: cover; }
.game-opt__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; }
.game-opt__count { flex: none; color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.games__empty { padding: 32px 16px; text-align: center; color: var(--ink-2); }

@media (max-width: 599px) {
  .sheet { left: 0; right: 0; top: auto; bottom: 0; width: 100%; height: 86vh; border-radius: 24px 24px 0 0; transform: translateY(100%); opacity: 1; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .sheet.is-open { transform: none; }
  .sheet__head { padding-top: 20px; position: relative; }
  .sheet__head::before { content: ""; position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 36px; height: 4px; border-radius: 4px; background: var(--line); }
}

/* ---------- عرض الأفتار ---------- */
.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; }
.modal__backdrop { position: absolute; inset: 0; background: var(--scrim); animation: fade .2s ease both; }
.modal__panel {
  position: relative; width: min(960px, 100%); max-height: calc(100vh - 48px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 32px; box-shadow: var(--shadow-lg); animation: pop .25s var(--ease) both;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.985); } }
.modal__top { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; padding: 12px 12px 0; pointer-events: none; }
.modal__top > * { pointer-events: auto; }
.modal__top .icon-btn { background: var(--bg); }
.modal__top .icon-btn:hover { background: var(--fill); }
.modal__nav { display: flex; gap: 4px; }
.modal__main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; padding: 8px 32px 32px; }
.modal__img { position: relative; aspect-ratio: 1; border-radius: 24px; overflow: hidden; background: var(--tile); }
.modal__img img { width: 100%; height: 100%; object-fit: cover; }
.modal__img .ph { font-size: 48px; }
.modal__info { display: flex; flex-direction: column; gap: 16px; min-width: 0; padding-top: 24px; }
.badge { align-self: flex-start; padding: 4px 12px; border-radius: 999px; background: var(--fill); font-size: 13px; font-weight: 600; }
.modal__game { text-align: right; direction: ltr; font-size: 28px; line-height: 1.25; font-weight: 700; text-wrap: balance; }
.modal__game:hover { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 2px; }
.code { display: grid; gap: 6px; }
.code__label { font-size: 13px; color: var(--ink-2); }
.code__value {
  width: 100%; height: 48px; padding: 0 16px; border: 0; outline: 0; border-radius: 14px; background: var(--fill);
  font-family: var(--mono); font-size: 13px; color: var(--ink); text-overflow: ellipsis;
}
.code__value:focus { box-shadow: 0 0 0 2px var(--accent); }
.modal__row { display: flex; gap: 8px; }
.modal__row .pill { flex: 1; height: 52px; font-size: 16px; }
#m-fav[aria-pressed="true"] { color: var(--fav); }
#m-fav[aria-pressed="true"] svg { fill: currentColor; }
.modal__hint { margin: 0; color: var(--ink-2); font-size: 13px; }

.related { padding: 24px 32px 32px; border-top: 1px solid var(--line); }
.related__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.related h3 { margin: 0; font-size: 18px; font-weight: 700; }
.related__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.rel { position: relative; aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: var(--tile); transition: opacity .15s; }
.rel:hover { opacity: .85; }
.rel.is-current { outline: 3px solid var(--accent); outline-offset: 2px; }
.rel img { width: 100%; height: 100%; object-fit: cover; }
.rel .ph { font-size: 14px; }

@media (max-width: 760px) {
  .modal { padding: 0; place-items: end stretch; }
  .modal__panel { width: 100%; max-height: 100%; height: 100%; border-radius: 0; animation: sheet-up .3s var(--ease) both; padding-bottom: env(safe-area-inset-bottom, 0px); }
  @keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
  .modal__top { padding: calc(8px + env(safe-area-inset-top, 0px)) 8px 0; }
  .modal__main { grid-template-columns: 1fr; gap: 16px; padding: 0 16px 24px; margin-top: 8px; }
  .modal__info { padding-top: 0; }
  .modal__game { font-size: 22px; }
  .related { padding: 20px 16px 32px; }
  .related__grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 599px) {
  :root { --bar-h: 60px; }
  .search input { height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- البحث بالصورة ---------- */
.search input { padding-inline-end: 46px; }
.search:has(input:not(:placeholder-shown)) input { padding-inline-end: 84px; }
.search__lens {
  position: absolute; inset-inline-end: 6px; width: 36px; height: 36px; border-radius: 999px;
  display: grid; place-items: center; color: var(--ink);
}
.search__lens:hover { background: var(--fill-hover); }
.search__lens svg { width: 20px; height: 20px; }
.search__clear { inset-inline-end: 44px; }
body.is-dragging::after {
  content: "أفلت الصورة للبحث عنها"; position: fixed; inset: 12px; z-index: 95; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  font-size: 18px; font-weight: 700; color: var(--ink); pointer-events: none;
}

.lens__panel { width: min(640px, 100%); }
.lens__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 24px; }
.lens__head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.lens__pick { padding: 8px 24px 28px; }
.lens__drop {
  width: 100%; min-height: 220px; display: grid; place-items: center; align-content: center; gap: 8px;
  border-radius: 24px; background: var(--fill); color: var(--ink); text-align: center; transition: background .15s;
}
.lens__drop:hover, .lens__drop.is-over { background: var(--fill-hover); }
.lens__drop svg { width: 40px; height: 40px; stroke-width: 1.5; color: var(--ink-2); }
.lens__drop strong { font-size: 18px; }
.lens__drop span { color: var(--ink-2); font-size: 14px; }
.lens__note { margin: 12px 0 0; text-align: center; color: var(--ink-2); font-size: 13px; }

.lens__work { padding: 0 24px 24px; display: grid; gap: 16px; }
.lens__hint { margin: 0; color: var(--ink-2); font-size: 14px; }
.lens__stage {
  position: relative; justify-self: center; max-width: 100%; border-radius: 16px; overflow: hidden; background: var(--tile);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.lens__stage img { display: block; max-width: 100%; max-height: 46vh; width: auto; height: auto; pointer-events: none; }
.lens__stage.is-whole .lens__box { display: none; }
.lens__box {
  position: absolute; border: 2px solid #fff; border-radius: 14px; cursor: move; touch-action: none;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45), 0 0 0 1px rgba(0,0,0,.35);
}
.lens__box:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lens__handle {
  position: absolute; left: -14px; bottom: -14px; width: 28px; height: 28px; border-radius: 999px;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: nesw-resize; touch-action: none;
}
.lens__actions { display: flex; gap: 8px; }
.lens__actions .pill { flex: 1; }
.lens__progress { height: 4px; border-radius: 4px; background: var(--fill); overflow: hidden; }
.lens__progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

.lens__results:empty { display: none; }
.lens__status { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 16px; font-weight: 700; }
.lens__status svg { width: 22px; height: 22px; }
.lens__status.is-found svg { color: var(--ok); }
.lens__status.is-missing svg { color: var(--ink-2); }
.lens__sub { margin: -6px 0 12px; color: var(--ink-2); font-size: 14px; }
.lens__list { display: grid; gap: 8px; }
.lens__item { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 16px; background: var(--fill); }
.lens__thumb { flex: none; width: 64px; height: 64px; border-radius: 14px; overflow: hidden; background: var(--tile); position: relative; }
.lens__thumb img { width: 100%; height: 100%; object-fit: cover; }
.lens__meta { flex: 1; min-width: 0; display: grid; gap: 2px; text-align: start; }
.lens__game { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; }
.lens__tag { font-size: 12px; color: var(--ink-2); }
.lens__item .pill { height: 36px; padding: 0 14px; font-size: 13px; }
.lens__item .pill--accent.is-done { background: var(--ok); color: #04140b; }
.lens__more { margin-top: 16px; }
.lens__more h3 { margin: 0 0 8px; font-size: 14px; color: var(--ink-2); font-weight: 600; }

@media (max-width: 760px) {
  .lens__panel { height: auto; max-height: 100%; }
  .lens__head { padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 8px 16px; }
  .lens__pick, .lens__work { padding-inline: 16px; }
}
.lens__item .pill--quiet { background: var(--bg); }
.lens__item .pill--quiet:hover { background: var(--fill-hover); }

/* ---------- معلومات الأفتار: الأسماء ---------- */
.modal__titles { display: grid; gap: 4px; }
.modal__char { margin: 0; font-size: 28px; line-height: 1.25; font-weight: 700; text-wrap: balance; }
.modal__char + .modal__game { font-size: 16px; font-weight: 600; color: var(--ink-2); }


/* ---------- حالة التحميل ---------- */
.card__loading {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px;
  color: var(--ink-3); font-size: 12px; font-weight: 500; letter-spacing: .01em; pointer-events: none;
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.05) 50%, transparent 70%) var(--tile);
  background-size: 220% 100%; animation: tile-shimmer 1.6s linear infinite;
  transition: opacity .3s ease-out;
}
.card__media.is-ready .card__loading { opacity: 0; animation: none; }
.card__spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.14); border-top-color: var(--brand-light);
  animation: spin .9s linear infinite;
}
@keyframes tile-shimmer { to { background-position: -220% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
.card__media .ph { z-index: 1; }

/* ---------- عرض المزيد ---------- */
.more { display: grid; justify-items: center; gap: 12px; padding: 40px 0 8px; }
.more__btn { min-width: 220px; box-shadow: inset 0 0 0 1px var(--fill-hover); }

/* ---------- نافذة الألعاب ---------- */
.games.sheet { width: min(980px, calc(100vw - 32px)); height: min(820px, calc(100vh - 48px)); background: var(--surface); box-shadow: 0 0 0 1px var(--line), var(--shadow-lg); }
.games .sheet__head { padding: 18px 16px 6px 24px; align-items: flex-start; }
.games__sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.games .search--sheet { margin: 6px 24px 12px; }
.games .sheet__list { padding: 0 24px 24px; }
.games__section + .games__section { margin-top: 24px; }
.games__h { display: flex; align-items: baseline; gap: 8px; margin: 0 0 12px; font-size: 15px; font-weight: 700; }
.games__h small { color: var(--ink-3); font-weight: 500; font-size: 13px; font-variant-numeric: tabular-nums; }
.games__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.gcard {
  position: relative; display: flex; flex-direction: column; gap: 8px; padding: 0; text-align: start; min-width: 0;
  border-radius: 16px; transition: transform .2s var(--ease);
  content-visibility: auto; contain-intrinsic-size: auto 190px;
}
.gcard:hover { transform: translateY(-2px); }
.gcard__cover {
  position: relative; display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; gap: 3px;
  aspect-ratio: 3 / 2; border-radius: 14px; overflow: hidden; background: var(--tile);
  box-shadow: 0 0 0 1px var(--line);
}
.gcard__cover > * { position: relative; overflow: hidden; background: var(--tile); }
.gcard__cover > :first-child { grid-row: 1 / 3; }
.gcard__cover img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .3s ease-out; }
.gcard__cover img.is-loaded { opacity: 1; }
.gcard__cover.is-single { grid-template-columns: 1fr; }
.gcard__cover.is-single > :first-child { grid-row: auto; }
.gcard.is-active .gcard__cover { box-shadow: 0 0 0 2px var(--accent); }
.gcard__name { font-size: 13.5px; font-weight: 600; line-height: 1.35; direction: ltr; text-align: right; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.gall {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border-radius: 14px; margin-bottom: 20px;
  background: var(--fill); font-weight: 600; text-align: start;
}
.gall:hover { background: var(--fill-hover); }
.gall.is-active { box-shadow: inset 0 0 0 2px var(--accent); }
.gall small { margin-inline-start: auto; color: var(--ink-3); font-weight: 500; font-variant-numeric: tabular-nums; }
@media (max-width: 599px) {
  .games.sheet { width: 100%; height: 90vh; }
  .games .sheet__head { padding: 22px 12px 4px 16px; }
  .games .search--sheet { margin: 6px 16px 12px; }
  .games .sheet__list { padding: 0 16px 20px; }
  .games__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}


/* ==========================================================================
   صفحة الأكثر طلباً (popular.html)
   ========================================================================== */
.phero { position: relative; overflow: hidden; isolation: isolate; border-bottom: 1px solid var(--line); }
.phero::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 90% at 15% 40%, rgba(255,255,255,.06), transparent 70%),
    linear-gradient(180deg, #1a1a1a 0%, var(--bg) 100%);
}
.phero__inner {
  max-width: 1100px; margin-inline: auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 32px;
  padding: 40px max(var(--gutter), env(safe-area-inset-right, 0px)) 56px max(var(--gutter), env(safe-area-inset-left, 0px));
}
.phero__back {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 10px; border-radius: 999px; margin-bottom: 24px;
  color: var(--ink-2); font-size: 14px; font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); transition: color .15s, background .15s;
}
.phero__back:hover { color: var(--ink); background: var(--fill); }
.phero__back svg { width: 16px; height: 16px; }
.phero__title { margin: 0; font-size: 64px; line-height: 1.1; font-weight: 700; letter-spacing: -.01em; color: #fff; text-wrap: balance; }
.phero__lead { margin: 16px 0 0; max-width: 34ch; color: var(--ink-2); font-size: 17px; line-height: 1.75; }
.phero__count { margin: 20px 0 0; display: inline-flex; align-items: baseline; gap: 6px; color: var(--ink-2); font-size: 14px; }
.phero__count b { color: var(--brand-light); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* المروحة: أوائل أفتارات المجموعة مرصوصة كأوراق لعب */
.fan { position: relative; height: 300px; }
.fan__card {
  --i: 0; position: absolute; top: 50%; left: 50%; width: 170px; aspect-ratio: 1; border-radius: 22px; overflow: hidden;
  background: var(--tile); box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 24px 50px -18px rgba(0,0,0,.9);
  transform: translate(calc(-50% + (var(--i) - 2) * 72px), calc(-50% + (var(--i) - 2) * (var(--i) - 2) * 7px)) rotate(calc((var(--i) - 2) * 7deg));
  z-index: calc(10 - (var(--i) - 2) * (var(--i) - 2));
  animation: fan-in .9s var(--ease) both; animation-delay: calc(var(--i) * 80ms);
}
.fan__card img { width: 100%; height: 100%; object-fit: cover; }
.fan__card .ph { font-size: 22px; }
@keyframes fan-in { from { opacity: 0; transform: translate(-50%, -40%) rotate(0deg) scale(.9); } }

/* الشبكة: أفتارين في كل صف دائماً */
.page--popular { max-width: 660px; padding-top: 32px; }
.grid--two { --gap-x: 16px; --gap-y: 28px; }
.grid--two .grid__col:nth-child(even) { padding-top: 21%; }
.page--popular .card__media { border-radius: 22px; }
.page--popular .card__game { font-size: 14px; color: var(--ink); font-weight: 600; margin-top: 12px; }
.page--popular .card__hot {
  display: inline-flex; align-items: center; gap: 5px; top: 12px; inset-inline-start: 12px; padding: 5px 11px 5px 10px;
  background: rgba(17,17,17,.86); color: #fff; font-size: 12px; font-weight: 600; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.page--popular .card__hot::before {
  content: ""; width: 12px; height: 12px; background: var(--brand-light);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.8c.6 3.4 3.4 5 3.4 8.6a3.4 3.4 0 0 1-6.8 0c0-1.2.4-2.1 1-2.9-2.3 1.3-4 3.7-4 6.6a6.4 6.4 0 0 0 12.8 0c0-5.6-4.2-8.6-6.4-12.3Z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.8c.6 3.4 3.4 5 3.4 8.6a3.4 3.4 0 0 1-6.8 0c0-1.2.4-2.1 1-2.9-2.3 1.3-4 3.7-4 6.6a6.4 6.4 0 0 0 12.8 0c0-5.6-4.2-8.6-6.4-12.3Z'/%3E%3C/svg%3E") center / contain no-repeat;
}
@media (hover: hover) {
  .page--popular .card__media { transition: transform .35s var(--ease), box-shadow .35s; }
  .page--popular .card:hover .card__media { transform: translateY(-4px); box-shadow: 0 22px 44px -22px rgba(0,0,0,.9), 0 0 0 1px rgba(255,255,255,.16); }
}
/* ظهور هادئ للبطاقات */
.reveal { opacity: 0; transform: translateY(18px); }
.reveal.is-in { opacity: 1; transform: none; transition: opacity .6s var(--ease) var(--d, 0ms), transform .6s var(--ease) var(--d, 0ms); }

@media (max-width: 760px) {
  .phero__inner { grid-template-columns: 1fr; gap: 8px; padding-top: 20px; padding-bottom: 36px; }
  .phero__text { order: 2; }
  .fan { order: 1; height: 180px; }
  .fan__card { width: 110px; border-radius: 16px; transform: translate(calc(-50% + (var(--i) - 2) * 46px), calc(-50% + (var(--i) - 2) * (var(--i) - 2) * 5px)) rotate(calc((var(--i) - 2) * 7deg)); }
  .phero__back { margin-bottom: 16px; }
  .phero__title { font-size: 44px; }
  .phero__lead { font-size: 15.5px; }
  .page--popular { padding-top: 20px; }
  .grid--two { --gap-x: 12px; --gap-y: 20px; }
  .page--popular .card__media { border-radius: 18px; }
  .page--popular .card__hot { top: 8px; inset-inline-start: 8px; padding: 4px 9px 4px 8px; font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { .fan__card { animation: none; } .reveal { opacity: 1; transform: none; } }

/* ---------- القائمة العائمة أسفل الشاشة ---------- */
body { padding-bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }
.dock {
  position: fixed; z-index: 50; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  width: min(460px, calc(100% - 24px)); height: 68px; padding: 0 8px;
  display: flex; align-items: stretch; justify-content: space-between;
  border-radius: 24px; background: rgba(28,28,28,.84);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08), 0 18px 40px -16px rgba(0,0,0,.9);
  backdrop-filter: saturate(150%) blur(18px); -webkit-backdrop-filter: saturate(150%) blur(18px);
}
.dock__item, .dock__store {
  position: relative; flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: rgba(255,255,255,.55); font-size: 11px; font-weight: 600; line-height: 1; border-radius: 18px;
  transition: color .15s, background .15s;
}
.dock__item svg { width: 23px; height: 23px; stroke-width: 1.8; transition: transform .2s var(--ease); }
.dock__item:hover { color: #fff; }
.dock__item:active svg { transform: scale(.9); }
.dock__item.is-active { color: #fff; }
.dock__item.is-active svg { stroke-width: 2.2; }
.dock__item.is-active::after { content: ""; position: absolute; bottom: 6px; width: 4px; height: 4px; border-radius: 50%; background: #fff; }
.dock__item.is-active span { font-weight: 700; }
#tab-popular.is-active svg { fill: currentColor; }
.dock__item.has-filter::before { content: ""; position: absolute; top: 12px; left: calc(50% - 14px); width: 7px; height: 7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(28,28,28,1); }
.dock__store { color: #fff; }
.dock__logo {
  width: 52px; height: 52px; margin-top: -26px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(180deg, #2c2c2c, #151515);
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 5px rgba(255,255,255,.1), 0 10px 22px -8px rgba(0,0,0,.9);
  transition: transform .2s var(--ease);
}
.dock__logo img { width: 30px; height: 30px; object-fit: contain; }
.dock__store:hover .dock__logo { transform: translateY(-2px); }
.dock__store:active .dock__logo { transform: scale(.95); }
.dock__badge {
  position: absolute; top: 9px; left: calc(50% + 4px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  display: grid; place-items: center; background: #fff; color: #111; font-size: 10.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.dock :focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.to-top { bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important; }
.toasts { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
