/* ============================================================================
   TUKO99 — Arabic Letters V2  ·  style.css
   P.1 Working Visual Version

   ⚠️  كل الأحجام والمسافات والألوان أدناه قابلة للتعديل بحرّية.
       هي متغيّرات CSS في قسم :root — غيّرها هناك فقط، ولا تحرّر القواعد أدناه.
       لا شيء هنا «مقفل» في هذه المرحلة.
   ========================================================================== */

/* ---------------------------------------------------------------- 1. TOKENS */
:root {
  /* --- خطوط (ترشيح مبدئي — CAN DECIDE) --- */
  --font-ui:      'Readex Pro', 'Cairo', 'Noto Sans Arabic', system-ui, sans-serif;
  --font-display: 'Lalezar', 'Readex Pro', 'Noto Sans Arabic', system-ui, sans-serif;
  --font-teach:   'Scheherazade New', 'Amiri', 'Noto Naskh Arabic', serif;

  /* --- ألوان الهوية (ذهبي/كريمي — قسم «العالم العربي») --- */
  --bg: #F7F7F5;
  --surface: #FFFCF2;
  --surface-sunk: #FFF8E3;
  --ink: #10264D;
  --ink-soft: #203858;
  --ink-mute: #566079;
  --line: #FFD56B;
  --line-strong: #F4A600;
  --container-line: #D6B978;

  --gold: #FFD43B;
  --gold-deep: #C78500;
  --action: #FFCC27;
  --action-dark: #BA7900;
  --action-ink: #10264D;

  --correct:      #E4FBF1;
  --correct-ink:  #0A825D;
  --warn: #FFF5D3;
  --warn-line: #F4A600;
  --warn-ink: #203858;

  /* --- 12 لون حرف (مستعارة من اللوحة الحالية — ثروة رمزية) --- */
  --c-mint: #FFD43B;  --ink-mint: #503409;
  --c-coral: #FF6258;  --ink-coral: #10264D;
  --c-butter: #FFD43B;  --ink-butter: #503409;
  --c-peri: #A979FF;  --ink-peri: #10264D;
  --c-peach: #FF6258;  --ink-peach: #10264D;
  --c-lavender: #A979FF;  --ink-lavender: #10264D;
  --c-sky: #08C8EE;  --ink-sky: #10264D;
  --c-rose: #FF69B8;  --ink-rose: #10264D;
  --c-pistachio: #FFD43B;  --ink-pistachio: #503409;
  --c-aqua: #00C9D8;  --ink-aqua: #10264D;
  --c-blush: #FF69B8;  --ink-blush: #10264D;
  --c-canary: #FFD43B;  --ink-canary: #503409;

  /* --- أنصاف أقطار --- */
  --r-tile:  22px;
  --r-card:  28px;
  --r-pill:  999px;

  /* --- ظلال --- */
  --sh-card: 0 18px 34px -28px oklch(58% 0.12 88 / .28),
             inset 0 1px 0 oklch(99% 0.01 90 / .75);
  --sh-tile: 0 4px 0 0 oklch(60% 0.1 82 / .35),
             0 8px 14px -8px oklch(48% 0.08 82 / .26),
             inset 0 1.5px 0 rgba(255,255,255,.65);

  /* --- مسافات قابلة للتعديل --- */
  --pad-page:   clamp(12px, 2.2vw, 40px);
  --gap-page:   clamp(10px, 1.4vw, 26px);
  --gap-panel:  clamp(10px, 1.2vw, 20px);
  --pad-panel:  clamp(12px, 1.4vw, 24px);

  /* --- أحجام الحروف (قابلة للتعديل بحرّية) --- */
  --tile-size:      clamp(52px, 8.4vw, 128px);
  --tile-glyph:     clamp(24px, 3vw, 44px);
  --stage-letter:   clamp(46px, 6.4vw, 112px);
  --stage-name:     clamp(15px, 1.8vw, 24px);
  --stage-word:     clamp(22px, 2.8vw, 44px);
  --placeholder:    clamp(120px, 22vw, 340px);

  /* --- حركة --- */
  --ease: cubic-bezier(.22, 1, .36, 1);
  --dur:  180ms;
  --stem: 5px;
}

/* ------------------------------------------------------------- 2. RESET */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}
body { overflow-x: hidden; }
button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
svg { display: block; }

/* احترام تفضيل تقليل الحركة */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* --------------------------------------------------------------- 3. BOARD */
.board {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--gap-page);
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  max-width: 1600px;
  margin-inline: auto;
}

/* -------------------------------------------------------------- 4. TOPBAR
   مُستخرج مباشرة من english-letters/style.css (اللوحة الإنجليزية المرجعية):
   بنية · ارتفاع · مسافات · border/shadow · hover · press depth · easing · أيقونات ·
   responsive · إخفاء النصوص · focus.
   الاختلاف الوحيد: الألوان من هوية العربية (كريمي/ذهبي) + RTL طبيعي.
   ------------------------------------------------------------------------- */

/* ألوان chrome الهيدر — مقابل #FFFFFF / #F3FBF7 / #E5C22B في الإنجليزية */
:root {
  --bar-surface: #FFFCF2;          /* لون موحّد مسطّح — بلا تدرّج */
  --bar-line: var(--container-line);
  --bar-tabs-bg: #FFFCF2;
  --bar-chrome:    #FFFFFF;
  --bar-chrome-hv: #FFF5D3;
  --bar-chrome-bd: var(--line-strong);
  /* ثلاثية الكهرماني لحالات mute / speed ≠ 1 / press */
  --bar-amber-bg: #FFD43B;
  --bar-amber-bd: #F4A600;
  --bar-amber-ink: #10264D;
  --bar-shadow:    0 5px 16px -10px oklch(35% .04 80 / .22), inset 0 -1px 0 #FFFFFF;
  --bar-btn-shadow: 0 5px 0 var(--btn-dark), 0 12px 22px -14px oklch(35% .04 80 / .5), inset 0 2px 0 rgba(255,255,255,.48);
}

/* الهيدر يتمدّد إلى حافة الصفحة (bleed) عبر هوامش سالبة — نفس هندسة الإنجليزية،
   بنفس قيم padding (الهوامش السالبة هي التي تُحدث التوسيع فقط). */
.app-topbar {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  min-height: 78px;
  margin:
    calc(-1 * max(12px, env(safe-area-inset-top)))
    calc(-1 * max(14px, env(safe-area-inset-right)))
    0
    calc(-1 * max(14px, env(safe-area-inset-left)));
  padding:
    12px
    clamp(20px, 2.2vw, 34px)
    clamp(20px, 2.2vw, 34px)
    clamp(20px, 2.2vw, 34px);
  background: var(--bar-surface);
  border-bottom: 2px solid var(--bar-line);
  box-shadow: var(--bar-shadow);
}

/* ---------- الشعار: أقصى اليسار (آخر عنصر في DOM = آخر عمود) ---------- */
.brand-mark {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  width: clamp(122px, 12vw, 174px);
  height: 80px;
  text-decoration: none;
}
.brand-mark img {
  display: block;
  width: auto;
  max-width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 6px 8px oklch(35% .04 80 / .14));
}

/* ---------- المنتصف ---------- */
.header-space {
  min-height: 1px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- الأدوات: أقصى اليمين (أول عنصر في DOM = أول عمود) ---------- */
.header-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: clamp(10px, 1vw, 14px);
}

/* ============================ التبويبات ============================ */
.mode-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-self: center;
  padding: 5px;
  border: 1.5px solid var(--bar-line);
  border-radius: var(--r-pill);
  background: var(--bar-tabs-bg);
}
.mode-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 22px;
  border: 1.5px solid transparent;
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  background: transparent;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: .95rem;
  cursor: pointer;
  transition: background 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--ease);
}
.mode-tab svg { width: 19px; height: 19px; flex: none; }
.mode-tab:hover { color: var(--ink); background: rgba(255,255,255,.75); }
.mode-tab:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

/* جميع الأقسام تستخدم درجة تعلّم الذهبية اللامعة عند الاختيار. */
.mode-tab.is-active {
  color: var(--action-ink);
  background: linear-gradient(180deg, #FFDF57, #FFCA22);
  border-color: var(--gold-deep);
  box-shadow: 0 3px 10px -6px oklch(50% .13 75 / .55), inset 0 1px 0 rgba(255,255,255,.5);
}

/* ====================== الأزرار العامة للهيدر ====================== */
.toy-button {
  --btn-bg: var(--gold);
  --btn-dark: var(--gold-deep);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 12px 22px;
  border: 0;
  border-radius: var(--r-pill);
  color: var(--ink);
  background: var(--btn-bg);
  box-shadow: var(--bar-btn-shadow);
  font-family: var(--font-ui);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: transform 170ms var(--ease), box-shadow 170ms var(--ease),
              filter 170ms var(--ease), opacity 170ms var(--ease);
}
.toy-button svg { width: 21px; height: 21px; flex: none; }
.toy-button:hover:not(:disabled) { transform: translateY(-2px); filter: saturate(1.06); }
.toy-button:active:not(:disabled) {
  transform: translateY(4px) scale(.97);
  box-shadow: 0 0 0 var(--btn-dark), 0 3px 8px -6px oklch(35% .04 80 / .4), inset 0 2px 0 rgba(255,255,255,.3);
  transition-duration: 160ms;
}
.toy-button:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }
.toy-button:disabled { opacity: .38; cursor: not-allowed; filter: saturate(.35); }

/* أزرار chrome بيضاء: السرعة · الصوت · الخروج */
.speed-button,
.exit-button {
  --btn-bg: var(--bar-chrome);
  --btn-dark: transparent;
  min-height: 46px;
  padding: 9px 18px;
  border: 1.5px solid var(--bar-chrome-bd);
  border-radius: var(--r-pill);
  color: var(--ink);
  font-weight: 700;
  font-size: .95rem;
  box-shadow: none;
}
.speed-button svg,
.exit-button svg { width: 21px; height: 21px; }
.speed-button:hover:not(:disabled),
.exit-button:hover:not(:disabled) { transform: none; filter: none; background: var(--bar-chrome-hv); }

.mute-button {
  --btn-bg: var(--bar-chrome);
  --btn-dark: transparent;
  width: 46px; height: 46px;
  min-width: 46px; min-height: 46px;
  padding: 0;
  justify-content: center;
  border: 1.5px solid var(--bar-chrome-bd);
  border-radius: 50%;
  color: var(--ink);
  box-shadow: none;
}
.mute-button svg { width: 21px; height: 21px; }
.mute-button:hover:not(:disabled) { transform: none; filter: none; background: var(--bar-chrome-hv); }

/* الحالة الصفراء الموحّدة: كتم / سرعة ≠ 1 */
.mute-button.is-muted,
.speed-button.is-fast {
  color: var(--bar-amber-ink);
  border-color: var(--bar-amber-bd);
  background: var(--bar-amber-bg);
}

/* ضغط أزرار الهيدر: تكبير خفيف + تجويف داخلي (نفس الإنجليزية) */
.mute-button:active:not(:disabled),
.speed-button:active:not(:disabled),
.exit-button:active:not(:disabled) {
  transform: scale(.96);
  --btn-bg: var(--bar-amber-bg);
  --btn-dark: transparent;
  background: var(--bar-amber-bg);
  border-color: var(--bar-amber-bd);
  color: var(--bar-amber-ink);
  box-shadow: inset 0 2px 5px oklch(55% .1 70 / .22);
}

/* ------------------------------------------------------------ 5. WORKSPACE */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, .92fr) minmax(0, 1.28fr);
  gap: var(--gap-page);
  min-height: 0;
}
.panel {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--sh-card);
  padding: var(--pad-panel);
  display: flex;
  flex-direction: column;
  gap: var(--gap-panel);
  min-height: 0;
}

/* عمود الحروف: شبكة الحروف داخل حاوية واحدة
   minmax(0,1fr) على العمود ضروري — بدونه يتمدّد الشريط الأفقي إلى عرض محتواه. */
.tray-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--gap-panel);
  min-height: 0;
  min-width: 0;
}

/* عمود المسرح (يسار): المسرح والمحتوى فقط */
.stage-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--gap-panel);
  min-height: 0;
  min-width: 0;
}

/* ---------------------------------------------------------- 6. LETTER TRAY
   الحاوية: حشو عمودي أقل + توزيع space-evenly — نفس منطق .letter-tray
   الإنجليزية (بلا حشو داخلي + align-content: space-evenly) = انغلاق أنظف. */
.panel.tray {
  padding-block: clamp(8px, .8vw, 14px);
  gap: clamp(6px, .7vw, 11px);
}

.tray-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}
.tray-title { font-size: clamp(.85rem, 1.1vw, 1rem); font-weight: 700; color: var(--ink-soft); }
.tray-count { font-size: clamp(.75rem, .95vw, .9rem); font-weight: 600; color: var(--ink-mute); }

.letter-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: clamp(6px, .8vw, 12px);
  direction: rtl;
  align-content: space-evenly;
  align-self: stretch;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
}

/* ------------------------------------------- 6b. أزرار الحروف
   نظام الأزرار مُستخرج من .letter-tile الإنجليزية:
   stem · gradient wash · sheen (::before) · inset highlights · press · selected.
   الألوان عربية بالكامل عبر --tile / --tile-ink
   (و--tile-dark مشتق من حبر الحرف نفسه). */
.letter-tile {
  --stem: 5px;
  /* --tile-dark comes from the shared English palette. */
  --tile-drop: rgba(23,62,56,.5);
  --tile-press: rgba(10,40,32,.4);
  /* وجه الزرار: مُشتق مُشبَع من نفس لون اللوحة العربية.
     اللوحة (--c-*) نفسها لم تُمَسّ — هذا اشتقاق منها فقط. */
  --tile-face: var(--tile-finish, var(--tile));
  container-type: inline-size;
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  max-width: var(--tile-size);
  min-width: 0;
  justify-self: center;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  padding: 4px;
  border: 0;
  border-radius: var(--r-tile);
  color: var(--tile-ink);
  background:
    linear-gradient(135deg, rgba(255,255,255,.12), transparent 35%, rgba(0,0,0,.13)),
    var(--tile-face, var(--tile));
  box-shadow:
    0 var(--stem) 0 var(--tile-dark),
    0 10px 16px -9px var(--tile-drop),
    inset 0 2px 1px rgba(255,255,255,.65),
    inset 1px 0 2px rgba(255,255,255,.32),
    inset 0 -3px 5px rgba(0,0,0,.16);
  cursor: pointer;
  user-select: none;
  transition: transform 170ms var(--ease), box-shadow 170ms var(--ease), filter 170ms var(--ease);
}
/* The approved reference uses explicit vivid colors; no extra saturation transform. */

/* لمعة خفيفة (gloss) — نفس موضع الإنجليزية: أسفل-يمين */
.letter-tile::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(ellipse at 86% 88%, rgba(255,255,255,.12), transparent 38%);
  transition: opacity 170ms var(--ease);
}

/* ------------------------------------------- 6c. الحرف داخل الزر
   1) مقاس مرتبط بالمربّع نفسه (container query) — نفس آلية الإنجليزية،
      فيبقى الحرف متناسبًا مع الزر في كل مقاس بدون media queries.
   2) optical transform: --ox / --oy / --os تأتي من خريطة OPTICAL
      في letters-data.js (قِيست بالبكسل لكل حرف على حدة).
   3) تعبئة متدرّجة داخل الحرف (background-clip: text) = شخصية البلاستيك المصقول. */
.letter-tile:not(.phonics-choice) > span {
  font-size: clamp(26px, 64cqw, 44px);
}
.letter-tile > span {
  position: relative;
  z-index: 1;
  font-family: var(--font-teach);
  font-weight: 700;
  line-height: 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
  font-variant-ligatures: none;
  text-shadow:
    0 1px 0 rgba(255,255,255,.48),
    0 -1px 0 rgba(0,0,0,.12);
  transform: translate(var(--ox, 0em), var(--oy, 0em)) scale(var(--os, 1));
  transform-origin: 50% 50%;
  transition: transform 170ms var(--ease);
}
/* الحرف نفسه: تعبئة متدرّجة (من الحبر المُفتَّح إلى الحبر) = وجه لامع.
   الإضاءة الخافتة أسفل الحرف مقصودة أخف من الإنجليزية (.22 بدل .5) لأن
   خطوط النستليق رفيعة —-offset قوي يظهر كنزيف حبر مزدوج لا كلمعة. */
@supports (background-clip: text) and (color: color-mix(in srgb, black, white)) {
  .letter-tile > span {
    background: linear-gradient(145deg,
      color-mix(in srgb, var(--tile-ink), white 10%),
      var(--tile-ink) 55%);
    background-clip: text;
    color: transparent;
    text-shadow: none;
    filter: drop-shadow(0 1px 0 rgba(255,255,255,.5));
  }
}

.letter-tile:hover {
  transform: translateY(-2px);
  filter: saturate(1.05);
}
.letter-tile:active {
  transform: translateY(var(--stem)) scale(.94);
  box-shadow:
    0 0 0 var(--tile-dark),
    0 4px 9px -7px var(--tile-drop),
    inset 0 2px 0 rgba(255,255,255,.4);
}
.letter-tile[aria-pressed="true"] {
  transform: translateY(var(--stem)) scale(.98);
  z-index: 1;
  box-shadow:
    0 0 0 var(--tile-dark),
    inset 0 4px 10px var(--tile-press),
    inset 0 -2px 5px rgba(255,255,255,.35);
}
.letter-tile[aria-pressed="true"]::before { opacity: .72; }
.letter-tile:focus-visible { outline: 3px solid var(--ink); outline-offset: 4px; }

/* ---------------------------------------------------------------- 7. STAGE */
.stage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-pill);
  background: oklch(97% 0.04 92 / .75);
  font-size: clamp(.68rem, .85vw, .8rem);
  font-weight: 600;
  color: var(--ink-soft);
}
.chip .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--tile, var(--gold-deep));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tile, var(--gold)) 30%, transparent);
}
.chip-pos { font-weight: 700; color: var(--ink); letter-spacing: .04em; }

/* الصف العلوي: بطاقة الحرف (يمين) + مكان الصورة (يسار)
   الصورة تأخذ المساحة المرنة لتبقى هي العنصر البصري الأكبر. */
.stage-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: clamp(12px, 2vw, 28px);
  flex: 1 1 auto;
  min-height: 0;
}

/* --- مكان الصورة (يُستبدل لاحقًا بصورة حقيقية 1024² شفافة) --- */
.image-slot {
  --slot: var(--placeholder);
  width: 100%;
  max-width: var(--slot);
  margin-inline: auto;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  position: relative;
}
.image-slot svg { width: 100%; height: 100%; border-radius: clamp(12px, 1.6vw, 22px); }
/* الصورة النهائية: 1024² شفافة، بلا خلفية ولا إطار ولا نص (D-09) */
.object-img { width: 100%; height: 100%; object-fit: contain; display: block; }

/* ألوان الـplaceholder تأتي من متغيّرات لوحة الآباء (--tile) لا من attributes */
.ph-bg    { fill: var(--tile); opacity: .3; }
.ph-frame { fill: none; stroke: var(--tile); stroke-width: 12; stroke-dasharray: 34 26; opacity: .85; }
.ph-name  { font-family: var(--font-display); font-size: 104px; fill: var(--tile-ink); }
.ph-sub   { font-family: var(--font-ui); font-size: 30px; font-weight: 600; fill: var(--tile-ink); opacity: .6; }

/* --- بطاقة الحرف: عنصران فقط (الحرف + كلمة المثال) --- */
.letter-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(2px, .6vw, 8px);
  padding: clamp(10px, 1.4vw, 20px) clamp(14px, 2vw, 30px);
  border: 2px solid color-mix(in srgb, var(--tile) 55%, transparent);
  border-radius: clamp(18px, 2.4vw, var(--r-card));
  background: color-mix(in srgb, var(--tile) 24%, var(--surface));
  min-width: clamp(140px, 15vw, 230px);
}
.letter-glyph {
  font-family: var(--font-teach);
  font-weight: 700;
  font-size: var(--stage-letter);
  line-height: 1.1;
  color: var(--tile-ink);
}
.letter-word {
  font-family: var(--font-teach);
  font-weight: 700;
  font-size: var(--stage-word);
  line-height: 1.15;
  color: var(--ink);
  white-space: nowrap;
}

/* --------------------------------------------------------- 9. SHARED ACTION BUTTONS
   يستخدمها الاختبار والكتابة؛ حاوية التحكم القديمة في تعلم أُزيلت. */

.bar-button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 60px;
  padding: 10px clamp(8px, 1.2vw, 18px);
  --btn-bg: linear-gradient(180deg, #FFDF57, #FFCA22);
  --btn-dark: var(--gold-deep);
  --bar-ink: var(--ink);
  color: var(--bar-ink);
  font-size: clamp(1rem, 1.35vw, 1.3rem);
  border: 1.5px solid var(--gold-deep);
  background: var(--btn-bg);
  box-shadow:
    0 3px 0 var(--btn-dark),
    0 12px 22px -14px oklch(45% .06 80 / .42),
    inset 0 2px 0 rgba(255,255,255,.6),
    inset 0 -3px 6px -3px oklch(45% .1 70 / .32);
  transition:
    transform 220ms var(--ease), clip-path 220ms var(--ease), box-shadow 220ms var(--ease),
    background 180ms var(--ease), border-color 180ms var(--ease),
    color 180ms var(--ease), filter 180ms var(--ease);
}
.bar-button svg { width: clamp(23px, 1.8vw, 27px); height: clamp(23px, 1.8vw, 27px); flex: none; }
.bar-button span { text-shadow: 0 1px 0 rgba(255,255,255,.45); transition: transform 180ms var(--ease); }

/* hover: بداية الضغط — الوجه يبدأ بالغوص */
.bar-button:hover:not(.is-on):not(:active) {
  transform: translateY(1px);
  filter: saturate(1.06);
  box-shadow:
    0 1px 0 var(--btn-dark),
    0 10px 18px -14px oklch(45% .06 80 / .42),
    inset 0 2px 0 rgba(255,255,255,.5),
    inset 0 -2px 6px -2px oklch(45% .1 70 / .38),
    inset 3px 0 8px -4px oklch(45% .1 70 / .24),
    inset -3px 0 8px -4px oklch(45% .1 70 / .24);
}
.bar-button:hover:not(.is-on):not(:active) span { transform: scale(.97); }

/* ضغط كامل (أو تثبيت «تلقائي»): الوجه ينغرس من كل الجهات — الحواف تُقصّ بـclip-path */
.bar-button:active,
.bar-button.is-on {
  transform: translateY(3px) scale(.97);
  clip-path: inset(3px round 999px);
  --btn-bg: linear-gradient(180deg, #FFA247, #FF7A00);
  --btn-dark: #D69245;
  --bar-ink: oklch(38% 0.09 70);
  color: var(--bar-ink);
  background: var(--btn-bg);
  border-color: #D69245;
  box-shadow:
    inset 0 6px 12px oklch(55% .1 70 / .48),
    inset 0 -3px 6px rgba(255,255,255,.55),
    inset 5px 0 10px -4px oklch(55% .1 70 / .34),
    inset -5px 0 10px -4px oklch(55% .1 70 / .34);
}
/* «تلقائي» مُثبَّت: التمرير فوقه لا يحرّكه — يحافظ على وضعية الضغط */
.bar-button.is-on:hover { transform: translateY(3px) scale(.97); filter: none; }

/* ⭐ أزرار التنقل (السابق/التالي) لا تُعطَّل بصريًا أبدًا.
   تبقى بشكلها الطبيعي الكامل — نفس اللون والـopacity والـshadow والـhover والضغط.
   منطق منع الانتقال عند الطرفين موجود في step() → select() وليس هنا. */
.bar-button[aria-disabled="true"] { opacity: 1; cursor: pointer; }

/* ------------------------------------------------ 10. PENDING-TAB PLACEHOLDER */
.pending {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: clamp(28px, 6vw, 64px) var(--pad-panel);
  min-height: 40vh;
}
.pending-icon {
  width: 68px; height: 68px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: oklch(94% 0.06 90);
  color: var(--gold-deep);
}
.pending-icon svg { width: 32px; height: 32px; }
.pending h2 { font-family: var(--font-display); font-size: clamp(1.4rem, 3vw, 2.2rem); color: var(--ink); }
.pending p { max-width: 46ch; color: var(--ink-soft); line-height: 1.7; font-size: clamp(.9rem, 1.1vw, 1rem); }
.pending .phase {
  font-size: clamp(.72rem, .9vw, .85rem);
  font-weight: 700;
  color: var(--warn-ink);
  background: var(--warn);
  border: 1.5px solid var(--warn-line);
  border-radius: var(--r-pill);
  padding: 5px 14px;
}

/* ------------------------------------------------------------ 11. UTILITIES */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.noscript {
  margin: 40px auto; max-width: 40ch; text-align: center;
  color: var(--ink-soft); font-family: var(--font-ui); line-height: 1.7;
}

:focus-visible { outline: 3px solid var(--ink-soft); outline-offset: 3px; border-radius: 6px; }

/* ---------------------------------------------------------- 12. RESPONSIVE */

/* Laptop / شاشة قصيرة: تصغير عام */
@media (max-width: 1199px) {
  :root {
    --tile-size:   clamp(48px, 6.6vw, 84px);
    --placeholder: clamp(100px, 16vw, 200px);
  }
}

/* Tablet / عمود واحد — المسرح فوق عمود الحروف (أول القراءة) */
@media (max-width: 900px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .stage-column { order: -1; }
  .tray-column { grid-template-rows: auto auto; }
  .bar-button { min-height: 52px; padding: 10px; font-size: 1.02rem; }
}

/* Tablet ضيّق */
@media (max-width: 620px) {
  :root {
    --tile-size:   clamp(48px, 13vw, 62px);
    --tile-glyph:  clamp(24px, 6.4vw, 30px);
    --placeholder: clamp(110px, 30vw, 150px);
    --stage-letter: clamp(42px, 13vw, 62px);
    --stage-word:  clamp(22px, 6.6vw, 30px);
    --gap-panel:   8px;
    --pad-panel:   12px;
  }

  /* ⭐ عمود الحروف كاملًا (الشريط + أزرار التحكّم) يسبق المسرح على الهاتف */
  .tray-column { order: -1; }
  .stage-column { order: 0; }

  /* شريط الحروف: صفّ أفقي واحد قابل للتمرير */
  .letter-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: var(--tile-size);
    gap: 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding-block-end: 4px;
  }
  .letter-tile { scroll-snap-align: center; }

  /* الأزرار المشتركة على الشاشات الصغيرة */
  .bar-button { min-height: 54px; padding: 10px 8px; font-size: 1rem; }
  .bar-button svg { width: 21px; height: 21px; }
  .bar-button span { font-size: .9rem; }


  /* بطاقة الحرف: صفّ أفقي موفّر للارتفاع */
  .stage-top { grid-template-columns: minmax(0, 1fr); justify-items: center; gap: 10px; }
  .letter-card {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 4px 12px;
    min-width: 0; width: 100%;
    padding: 10px 12px;
  }
  .letter-glyph { line-height: 1; }
}

/* ---------- سلّم الـResponsive للهيدر (منقول من الإنجليزية) ---------- */

/* إخفاء ملصقات داخل الأزرار — نفس نمط sr-only الإنجليزي */
.speed-label, .exit-label { transition: opacity 160ms var(--ease); }

/* ≤1023 — ارتفاع أقل */
@media (max-width: 1023px) {
  .app-topbar { min-height: 70px; }
}

/* 640–1100 — تلاصق + إخفاء نصّي السرعة والخروج */
@media (min-width: 640px) and (max-width: 1100px) {
  .app-topbar { gap: 10px; }
  .mode-tab { padding: 8px 10px; gap: 5px; }
  .header-actions { gap: 7px; }
  .speed-button { padding: 8px 12px; }
  .speed-label, .exit-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}

/* 640–900 — الشبكة تحتاج minmax */
@media (min-width: 640px) and (max-width: 900px) {
  .app-topbar { grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; }
  .header-space { min-width: 0; }
  .mode-tab { padding: 8px 10px; gap: 5px; }
  .header-actions { gap: 7px; }
  .exit-button { padding: 8px 13px; }
}

/* ≤639 — ترتيب خاص: الأدوات يمين · الشعار يسار · التبويبات صفّ كامل
   (العمود الأول auto يستوعب مجموعة الأدوات، والثاني المرن يستوعب الشعار) */
@media (max-width: 639px) {
  .app-topbar {
    grid-template-columns: auto minmax(0, 1fr);
    row-gap: 4px;
    padding:
      8px
      14px
      10px
      14px;
  }
  .header-actions { grid-column: 1; grid-row: 1; justify-self: start; gap: 6px; }
  .brand-mark     { grid-column: 2; grid-row: 1; justify-self: end; width: 74px; height: 56px; }
  .header-space   { grid-column: 1 / -1; grid-row: 2; justify-content: center; min-width: 0; }

  .mode-tabs { width: 100%; max-width: 460px; padding: 3px; gap: 2px; }
  .mode-tab { flex: 1 1 0; min-width: 0; min-height: 44px; padding: 6px 4px; font-size: .76rem; gap: 4px; }
  .mode-tab svg { width: 14px; height: 14px; }

  .speed-label, .exit-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .exit-button { min-height: 44px; padding: 8px 13px; font-size: .88rem; }
  .mute-button { width: 42px; height: 42px; min-width: 42px; min-height: 42px; }
  .speed-button { min-height: 42px; padding: 8px 12px; font-size: .8rem; }
  .speed-button svg { width: 18px; height: 18px; }
  .speed-value { font-size: .76rem; }
}

/* هدف اللمس لا يقلّ عن 44px على الشاشات الصغيرة */
@media (max-width: 1023px) {
  .mute-button { min-width: 44px; min-height: 44px; }
  .speed-button { min-height: 44px; }
}

/* ≤480 — إخفاء رقم السرعة أيضًا (أيقونة فقط) */
@media (max-width: 480px) {
  .speed-value { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .speed-button { padding: 8px 10px; }
  .mode-tab { padding: 6px 11px; }
}

/* ≤360 — العودة لثلاثة أعمدة وشعار أصغر */
@media (max-width: 360px) {
  .app-topbar { grid-template-columns: auto 1fr auto; }
  .brand-mark { width: 62px; height: 50px; }
  .speed-button { padding: 8px 9px; }
  .mode-tab span { font-size: .7rem; }
}

/* شاشات قصيرة (لابتوب) */
@media (max-height: 760px) and (min-width: 1024px) {
  .app-topbar { min-height: 64px; padding-top: 8px; padding-bottom: 8px; }
  .brand-mark { width: 108px; height: 60px; }
  .exit-button { min-height: 46px; padding: 8px 16px; font-size: .95rem; }
}

/* وضع التخطيط الأفقي القصير (هاتف أفقي) */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --placeholder: clamp(84px, 15vh, 130px);
    --stage-letter: clamp(36px, 8vh, 60px);
    --gap-panel: 6px;
    --pad-panel: 10px;
  }
  .board { gap: 8px; }
  .stage-top { grid-template-columns: auto minmax(0, 1fr); }
  .letter-card { min-width: 130px; }
  .bar-button { min-height: 46px; font-size: .95rem; }
  .bar-button svg { width: 20px; height: 20px; }
}

/* شاشات عريضة جدًا */
@media (min-width: 1601px) { .board { max-width: none; } }
/* Approved cream/gold reference, 2026-10-04. Geometry and interactions retained. */
.panel, .mode-tabs { border-color: var(--container-line); }
.chip { background: #FFF7DF; color: var(--ink); }
.chip .dot { background: #FF6338; box-shadow: 0 0 0 3px #FF633833; }


/* English mobile tile shape/depth; Arabic selector geometry and glyph optics remain local. */
@media (max-width: 767px) { .letter-tile { --stem: 4px; border-radius: 16px; } }

/* Arabic font ink extends below its line box. Give the text finish paint room without changing glyph placement. */
.letter-tile > span { padding-block-end: .75em; margin-block-end: -.75em; padding-inline: .15em; margin-inline: -.15em; }
