/* التخطيط: عمود واحد (حتى 58rem) تحت شريط علوي زجاجي ثابت.
   الطابع: مختبر أمن سيبراني بأسلوب منتجات الذكاء الاصطناعي على خلفية بيضاء — توهج سماوي وبنفسجي خفيف وشبكة خطوط باهتة،
   بطاقات بيضاء بحدود ناعمة، تدرّجات في العناوين والأزرار، وسطر طرفية صغير داكن في الواجهة. ثيم فاتح واحد مقصود. */
:root {
  color-scheme: light;
  --gutter: clamp(16px, 4vw, 32px);
  --paper: #FFFFFF; --surface: rgba(255, 255, 255, .88); --surface-solid: #FFFFFF; --sunk: #F1F5F9; --field-bg: #F8FAFC;
  --ink: #0F172A; --muted: #5B6B82; --line: #E2E8F0; --line-strong: #CBD5E1;
  --accent: #0E7490; --accent-hover: #155E75; --accent-ink: #FFFFFF; --accent-soft: rgba(8, 145, 178, .08);
  --violet: #6D28D9; --violet-soft: rgba(124, 58, 237, .08);
  --grad: linear-gradient(135deg, #0E7490 0%, #4F46E5 100%);
  --grad-text: linear-gradient(90deg, #0E7490 0%, #4F46E5 55%, #7C3AED 100%);
  --glow: 0 0 0 1px rgba(8, 145, 178, .35), 0 10px 28px -8px rgba(8, 145, 178, .25);
  --ok: #047857; --ok-soft: #ECFDF5; --on-ok: #FFFFFF;
  --bad: #BE123C; --bad-soft: #FFF1F2; --on-bad: #FFFFFF;
  --warn: #B45309; --warn-soft: #FFFBEB;
  --bg-glow-1: rgba(34, 211, 238, .10); --bg-glow-2: rgba(139, 92, 246, .08); --grid-line: rgba(15, 23, 42, .04);
  --term-bg: #0B1220; --term-ink: #E2E8F0; --term-muted: #94A3B8; --term-ok: #34D399; --term-caret: #22D3EE;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 18px -8px rgba(15, 23, 42, .08);
  --shadow-md: 0 16px 36px -12px rgba(15, 23, 42, .16);
  --f-display: "Readex Pro", "IBM Plex Sans Arabic", Tahoma, sans-serif;
  --f-body: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  --f-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --r-sm: 8px; --r: 12px; --r-lg: 18px;
}

/* ---------- الأساس ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink);
  font-family: var(--f-body); font-size: 16px; line-height: 1.7;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(56rem 34rem at 90% -14%, var(--bg-glow-1), transparent 62%),
    radial-gradient(48rem 36rem at -8% 108%, var(--bg-glow-2), transparent 62%);
}
body::after {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px), linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 10%, transparent 80%);
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 10%, transparent 80%);
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { background: rgba(34, 211, 238, .25); color: var(--ink); }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mono { font-family: var(--f-mono); font-weight: 700; }
.muted { color: var(--muted); font-weight: 400; }
h1 { margin: 0; font-family: var(--f-display); font-weight: 700; font-size: clamp(1.6rem, 4.6vw, 2.4rem); line-height: 1.4; text-wrap: balance; }
.hero-home h1, .hero-course h1 {
  background: var(--grad-text); -webkit-background-clip: text; background-clip: text; color: transparent;
}

.app {
  max-width: 58rem; margin-inline: auto; padding-inline: var(--gutter); padding-block: 0 56px;
  display: flex; flex-direction: column; gap: 24px;
}
.app > * { min-width: 0; }

/* ---------- الشريط العلوي ---------- */
.appbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 64px; margin-inline: calc(var(--gutter) * -1); padding: 10px var(--gutter);
  background: rgba(255, 255, 255, .82); -webkit-backdrop-filter: blur(14px) saturate(160%); backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer;
  padding: 4px; margin-inline-start: -4px; border: 0; border-radius: var(--r-sm); background: none; text-align: start;
}
.brand svg { width: 30px; height: 30px; flex: none; filter: drop-shadow(0 2px 6px rgba(8, 145, 178, .35)); }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.brand-text b { font-family: var(--f-display); font-size: .98rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { font-size: .74rem; color: var(--muted); }
.appbar-end { display: flex; align-items: center; gap: 8px; flex: none; }
@media (max-width: 420px) {
  .brand-text b { font-size: .88rem; }
  .brand-text small { display: none; }
}
.c1 { fill: #22D3EE; } .c2 { fill: #2563EB; } .c3 { fill: #7C3AED; }

/* ---------- أزرار ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  min-height: 48px; padding: 10px 18px; border-radius: 11px; text-decoration: none;
  border: 1px solid var(--line-strong); background: var(--surface-solid); color: var(--ink);
  font-weight: 600; font-size: .95rem; line-height: 1.5;
  transition: background .15s, border-color .15s, box-shadow .2s, filter .15s;
}
.btn:hover { border-color: rgba(8, 145, 178, .5); background: var(--accent-soft); }
.btn.primary { background: var(--grad); border-color: transparent; color: var(--accent-ink); box-shadow: 0 8px 22px -10px rgba(79, 70, 229, .55); }
.btn.primary:hover { filter: brightness(1.08); box-shadow: var(--glow); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: var(--on-bad); }
.btn.danger:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; filter: none; }
.count-pill {
  min-width: 1.5rem; padding-inline: 6px; border-radius: 999px; text-align: center;
  background: var(--grad); color: var(--accent-ink); font-family: var(--f-mono); font-size: .74rem; font-weight: 700; line-height: 1.5rem;
}
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: inherit; }

/* ---------- رموز وشارات ---------- */
.code {
  direction: ltr; white-space: nowrap; font-family: var(--f-mono); font-weight: 700; font-size: .74rem; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(8, 145, 178, .22);
}
.code.ink { background: var(--violet-soft); color: var(--violet); border-color: rgba(124, 58, 237, .25); }
.code.lg { font-size: .82rem; padding: 3px 10px; }
.chip { white-space: nowrap; font-size: .8rem; font-weight: 500; padding: 2px 10px; border-radius: 999px; background: var(--sunk); color: var(--muted); border: 1px solid var(--line); }
.chip.new { background: var(--grad); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.kicker { font-size: .84rem; font-weight: 600; color: var(--accent); }
.meter { display: block; height: 6px; border-radius: 999px; background: var(--sunk); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--grad); transition: width .3s; }
.meter.ok > span { background: var(--ok); } .meter.warn > span { background: var(--warn); } .meter.bad > span { background: var(--bad); }

/* ---------- الرئيسية ---------- */
.hero-home {
  position: relative; overflow: hidden; margin-top: 8px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "text art"; align-items: center; gap: 20px 36px;
  padding: clamp(22px, 5vw, 44px); border-radius: var(--r-lg);
  background: linear-gradient(155deg, rgba(34, 211, 238, .10), rgba(129, 140, 248, .06) 45%, rgba(139, 92, 246, .10)), var(--surface-solid);
  border: 1px solid rgba(8, 145, 178, .18);
  box-shadow: 0 24px 60px -30px rgba(8, 145, 178, .35);
}
.hero-home::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(15, 23, 42, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(15, 23, 42, .05) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: linear-gradient(to left, transparent 0%, #000 100%);
  mask-image: linear-gradient(to left, transparent 0%, #000 100%);
}
.hero-home::after {
  content: ""; position: absolute; inset-inline: 0; top: -30%; height: 30%; pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(34, 211, 238, .08), transparent);
  animation: scan 7s linear infinite;
}
@keyframes scan { to { transform: translateY(450%); } }
.hero-text { position: relative; z-index: 1; grid-area: text; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; min-width: 0; }
.hero-home .kicker { display: inline-flex; align-items: center; gap: 8px; }
.hero-home .kicker::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #10B981; box-shadow: 0 0 8px rgba(16, 185, 129, .8);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; } }
.hero-home h1 { max-width: 32rem; }
.hero-home .lead { margin: 0; color: var(--muted); max-width: 36rem; font-size: 1.02rem; }
.term {
  direction: ltr; display: inline-flex; align-items: center; gap: 8px; max-width: 100%; overflow: hidden; white-space: nowrap;
  padding: 6px 12px; border-radius: 8px; background: var(--term-bg); box-shadow: 0 6px 16px -8px rgba(15, 23, 42, .5);
  font-family: var(--f-mono); font-size: .78rem; color: var(--term-muted);
}
.term .prompt { color: var(--term-ok); }
.term .cmd { color: var(--term-ink); overflow: hidden; text-overflow: ellipsis; }
.caret { flex: none; width: .55em; height: 1.1em; background: var(--term-caret); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.cube-art {
  position: relative; z-index: 1; grid-area: art; width: clamp(110px, 17vw, 176px); height: auto;
  filter: drop-shadow(0 12px 22px rgba(8, 145, 178, .28)); animation: float 6s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-7px); } }
.cf1 { fill: rgba(34, 211, 238, .30); } .cf2 { fill: rgba(37, 99, 235, .26); } .cf3 { fill: rgba(124, 58, 237, .26); }
.cf1, .cf2, .cf3 { stroke: #0E7490; stroke-width: 1.2; stroke-linejoin: round; }
.cg { fill: none; stroke: rgba(14, 116, 144, .45); stroke-width: .9; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 0; padding: 0; list-style: none; }
.stats li { padding: 4px 12px; border-radius: 999px; background: var(--surface-solid); border: 1px solid var(--line); font-size: .84rem; color: var(--muted); }
.stats b { font-family: var(--f-mono); font-weight: 700; color: var(--accent); }
@media (max-width: 560px) {
  .hero-home { grid-template-columns: 1fr; grid-template-areas: "art" "text"; }
  .cube-art { width: 76px; }
}

.group { display: flex; flex-direction: column; gap: 14px; }
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.group-head h2 { margin: 0; font-family: var(--f-display); font-size: 1.15rem; font-weight: 600; }
.group-head small { font-size: .84rem; color: var(--muted); font-family: var(--f-body); }

/* البطاقات المشتركة */
.course-card, .tile, .qcard, .score, .ritem, .notebox, .note, .mappanel, .settings {
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-sm);
}
.courses { display: flex; flex-direction: column; gap: 12px; }
.course-card {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(12rem, 15rem); grid-template-areas: "info side";
  align-items: center; gap: 18px 32px; padding: clamp(18px, 3vw, 26px); text-align: start; cursor: pointer; border-radius: var(--r-lg);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.course-card::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px; background: var(--grad); }
.course-card:hover { border-color: rgba(8, 145, 178, .45); box-shadow: var(--glow); transform: translateY(-2px); }
.cc-info { grid-area: info; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cc-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.cc-name { font-family: var(--f-display); font-size: clamp(1.2rem, 3vw, 1.4rem); font-weight: 600; line-height: 1.45; }
.cc-en { direction: ltr; text-align: right; font-size: .86rem; color: var(--muted); font-family: var(--f-mono); }
.cc-meta { font-size: .88rem; color: var(--muted); }
.cc-side { grid-area: side; display: flex; flex-direction: column; gap: 12px; }
.cc-progress { display: flex; flex-direction: column; gap: 6px; }
.cc-progress-label { font-size: .84rem; color: var(--muted); }
.cc-cta {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px 16px;
  border-radius: 11px; background: var(--grad); color: var(--accent-ink); font-weight: 700; font-size: .94rem;
  box-shadow: 0 8px 22px -10px rgba(79, 70, 229, .55); transition: filter .15s;
}
.course-card:hover .cc-cta { filter: brightness(1.08); }
@media (max-width: 640px) {
  .course-card { grid-template-columns: 1fr; grid-template-areas: "info" "side"; }
}

.foot { display: flex; flex-direction: column; gap: 4px; padding-top: 16px; border-top: 1px solid var(--line); font-size: .84rem; color: var(--muted); }
.foot p { margin: 0; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--r); background: var(--surface); }

.problems {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; font-size: .9rem;
  border: 1px solid rgba(180, 83, 9, .35); background: var(--warn-soft); border-radius: var(--r);
}
.problems h2 { margin: 0; font-size: .95rem; color: var(--warn); }
.problems p { margin: 0; }
.problems ul { margin: 0; padding-inline-start: 20px; }

/* ---------- صفحة المادة ---------- */
.hero-course { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding-top: 12px; }
.hero-course .lead { margin: 0; color: var(--muted); max-width: 40rem; }
.hero-en { margin: 0; direction: ltr; text-align: right; color: var(--muted); font-size: .9rem; font-family: var(--f-mono); }
.facts { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 0; padding: 0; list-style: none; }
.facts li { padding: 3px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-solid); font-size: .82rem; color: var(--muted); }
.facts b { font-family: var(--f-mono); font-weight: 700; color: var(--accent); }

.settings { border-radius: var(--r); }
.settings summary {
  display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 12px 16px;
  cursor: pointer; list-style: none; border-radius: var(--r);
}
.settings summary::-webkit-details-marker { display: none; }
.settings summary::after {
  content: ""; margin-inline-start: auto; width: 8px; height: 8px; flex: none;
  border-right: 2px solid var(--accent); border-bottom: 2px solid var(--accent); transform: rotate(45deg) translateY(-2px); transition: transform .15s;
}
.settings[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.settings-title { flex: none; font-weight: 600; }
.settings-sum { flex: 1; min-width: 0; font-size: .86rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-body { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 28px; padding: 14px 16px 16px; border-top: 1px solid var(--line); }
.field { display: flex; align-items: center; gap: 10px; flex: 1 1 16rem; min-width: 0; font-size: .94rem; }
.field input, .notebox textarea {
  font: inherit; color: var(--ink); background: var(--field-bg); border: 1px solid var(--line-strong);
  transition: border-color .15s, box-shadow .15s;
}
.field input { flex: 1; min-width: 0; max-width: 18rem; min-height: 44px; padding: 8px 12px; border-radius: 10px; }
.field input:focus, .notebox textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); background: var(--surface-solid); }
.field input::placeholder, .notebox textarea::placeholder { color: var(--muted); }
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: .94rem; }
.switch input {
  appearance: none; -webkit-appearance: none; margin: 0; flex: none; cursor: pointer;
  width: 2.6rem; height: 1.5rem; border-radius: 999px; position: relative;
  background: var(--sunk); border: 1px solid var(--line-strong); transition: background .15s, border-color .15s;
}
.switch input::after {
  content: ""; position: absolute; top: 50%; inset-inline-start: 3px;
  width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--surface-solid); box-shadow: 0 1px 3px rgba(15, 23, 42, .25);
  transform: translateY(-50%); transition: inset-inline-start .15s;
}
.switch input:checked { background: var(--grad); border-color: transparent; }
.switch input:checked::after { inset-inline-start: calc(100% - 1.1rem - 3px); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 12px; }
.tiles.fit { grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: 6px; padding: 18px; text-align: start; cursor: pointer; border-radius: var(--r-lg);
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.tile:hover { border-color: rgba(8, 145, 178, .45); box-shadow: var(--glow); transform: translateY(-2px); }
.tile.special { background: linear-gradient(150deg, rgba(124, 58, 237, .07), rgba(34, 211, 238, .05)), var(--surface-solid); border-color: rgba(124, 58, 237, .22); }
.tile.special:hover { border-color: rgba(124, 58, 237, .5); box-shadow: 0 0 0 1px rgba(124, 58, 237, .3), 0 10px 28px -8px rgba(124, 58, 237, .25); }
.tile-top { display: flex; align-items: center; gap: 8px; }
.tile-top .count { margin-inline-start: auto; font-size: .8rem; color: var(--muted); }
.tile-name { font-family: var(--f-display); font-size: 1.1rem; font-weight: 600; line-height: 1.5; }
.tile-en { direction: ltr; text-align: right; font-size: .8rem; color: var(--muted); line-height: 1.5; font-family: var(--f-mono); }
.tile-note { font-size: .86rem; color: var(--muted); }
.tile-foot { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.tile-foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .8rem; color: var(--muted); }
.tile-foot-row bdi { color: var(--ink); }
.tile-go { flex: none; color: var(--accent); font-weight: 700; font-size: .88rem; }
.tile.special .tile-go { color: var(--violet); }

/* ---------- الاختبار ---------- */
.quizbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; flex-direction: column; gap: 10px;
  margin-inline: calc(var(--gutter) * -1); padding: 12px var(--gutter);
  background: rgba(255, 255, 255, .86); -webkit-backdrop-filter: blur(14px) saturate(160%); backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid var(--line);
}
.quizbar-row { display: flex; align-items: center; gap: 12px; }
.qb-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qb-title .mono { font-size: .76rem; color: var(--accent); margin-inline-end: 8px; }
.qb-progress { display: flex; align-items: center; gap: 12px; font-size: .84rem; color: var(--muted); white-space: nowrap; }
.qb-progress .bar { flex: 1; }
.qb-pos b { font-family: var(--f-mono); color: var(--accent); }
.bar { height: 8px; border-radius: 999px; background: var(--sunk); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: inherit; background: var(--grad); transition: width .25s; }

.qcard { display: flex; flex-direction: column; gap: 16px; padding: clamp(18px, 4vw, 30px); border-radius: var(--r-lg); }
.qmeta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.qtext { margin: 0; font-size: clamp(1.12rem, 2.8vw, 1.34rem); font-weight: 600; line-height: 1.6; outline: none; overflow-wrap: anywhere; }
.hint { margin: 0; text-align: left; font-size: .88rem; color: var(--muted); }
.hint.full { color: var(--accent); font-weight: 600; }
.opts { border: 0; margin: 0; padding: 0; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-solid);
  transition: border-color .15s, background .15s, box-shadow .2s;
}
.opt:hover { border-color: var(--line-strong); background: var(--field-bg); }
.opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.opt.is-sel { border-color: var(--accent); background: var(--accent-soft); box-shadow: var(--glow); }
.opt.is-locked { opacity: .45; cursor: not-allowed; }
.opt.is-locked:hover { border-color: var(--line); background: var(--surface-solid); }
.badge {
  flex: none; width: 2rem; height: 2rem; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--f-mono); font-weight: 700; font-size: .82rem;
  border: 1px solid var(--line-strong); color: var(--muted); background: var(--field-bg);
}
.badge.sq { border-radius: 7px; }
.opt.is-sel .badge { background: var(--grad); border-color: transparent; color: var(--accent-ink); }
.opt-text { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; overflow-wrap: anywhere; }
.opt-ar { font-size: .86rem; color: var(--muted); }

.nav {
  position: sticky; bottom: 0; z-index: 6;
  display: flex; justify-content: space-between; gap: 12px;
  margin-inline: calc(var(--gutter) * -1); padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, .88); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
@media (max-width: 640px) { .nav .btn { flex: 1; } }

.confirm {
  display: flex; flex-direction: column; gap: 12px; padding: 16px;
  border: 1px solid rgba(180, 83, 9, .35); background: var(--warn-soft); border-radius: var(--r);
}
.confirm p { margin: 0; font-weight: 500; }
.confirm .row { display: flex; flex-wrap: wrap; gap: 10px; }

.mappanel { display: flex; flex-direction: column; gap: 14px; padding: 16px; border-radius: var(--r-lg); }
.mp-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 16px; }
.mp-head h2 { margin: 0; font-size: .96rem; font-weight: 600; }
.qmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr)); gap: 6px; }
.cell {
  height: 2.75rem; border-radius: var(--r-sm); cursor: pointer;
  border: 1px solid var(--line); background: var(--field-bg); color: var(--muted);
  font-family: var(--f-mono); font-size: .84rem;
}
.cell:hover { border-color: var(--line-strong); }
.cell.is-done { background: var(--accent-soft); border-color: rgba(8, 145, 178, .3); color: var(--accent); font-weight: 700; }
.cell.is-cur { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: .85rem; height: .85rem; border-radius: 3px; border: 1px solid var(--line); background: var(--field-bg); }
.legend i.lg-done { background: var(--accent-soft); border-color: rgba(8, 145, 178, .3); }
.legend i.lg-cur { outline: 2px solid var(--accent); outline-offset: 1px; }
.kbd-hint { display: none; margin: 0; font-size: .8rem; color: var(--muted); }
@media (hover: hover) and (min-width: 700px) { .kbd-hint { display: block; } }
kbd {
  font-family: var(--f-mono); font-size: .72rem; padding: 0 6px; border-radius: 4px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; background: var(--field-bg); color: var(--ink);
}

/* ---------- النتيجة ---------- */
.score {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 16px 24px; margin-top: 8px;
  padding: clamp(18px, 4vw, 28px); border-radius: var(--r-lg);
  background: linear-gradient(155deg, rgba(34, 211, 238, .08), rgba(139, 92, 246, .07)), var(--surface-solid);
  border-color: rgba(8, 145, 178, .2);
}
.ring { width: clamp(96px, 18vw, 128px); height: auto; aspect-ratio: 1; direction: ltr; }
.ring .track { fill: none; stroke: var(--sunk); stroke-width: 10; }
.ring .val { fill: none; stroke-width: 10; stroke-linecap: round; transform: rotate(-90deg); transform-origin: 60px 60px; }
.ring .val.ok { stroke: var(--ok); } .ring .val.warn { stroke: var(--warn); } .ring .val.bad { stroke: var(--bad); }
.ring text { font-family: var(--f-mono); font-weight: 700; font-size: 23px; fill: var(--ink); }
.score-main { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.score-main .kicker { font-size: .82rem; }
.big { font-family: var(--f-mono); font-weight: 700; font-size: clamp(1.8rem, 5vw, 2.4rem); line-height: 1.2; }
.grade { font-family: var(--f-display); font-size: 1.12rem; font-weight: 600; }
.tally { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.tally li { display: flex; flex-direction: column; padding: 10px 12px; border-radius: var(--r-sm); font-size: .82rem; color: var(--muted); border: 1px solid var(--line); }
.tally b { font-family: var(--f-mono); font-size: 1.25rem; line-height: 1.3; }
.tally .t-ok { background: var(--ok-soft); border-color: rgba(4, 120, 87, .2); } .tally .t-ok b { color: var(--ok); }
.tally .t-bad { background: var(--bad-soft); border-color: rgba(190, 18, 60, .18); } .tally .t-bad b { color: var(--bad); }
.tally .t-blank { background: var(--warn-soft); border-color: rgba(180, 83, 9, .2); } .tally .t-blank b { color: var(--warn); }
.rule { grid-column: 1 / -1; margin: 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: .86rem; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: 10px; }
@media (max-width: 640px) {
  .actions .btn { flex: 1 1 auto; }
  .actions .btn.primary { flex-basis: 100%; }
}

.review-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.review-head h2 { margin: 0; font-family: var(--f-display); font-size: 1.15rem; font-weight: 600; }
.seg { display: inline-flex; max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-solid); }
.seg button { flex: none; min-height: 42px; padding: 8px 14px; border: 0; background: none; color: var(--muted); font-size: .9rem; cursor: pointer; white-space: nowrap; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; box-shadow: inset 0 -2px 0 var(--accent); }

.review { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.ritem { display: flex; flex-direction: column; gap: 12px; padding: clamp(16px, 3vw, 22px); border-radius: var(--r-lg); }
.ritem-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.num { min-width: 1.6rem; font-family: var(--f-mono); font-weight: 700; color: var(--muted); }
/* بطاقة المراجعة اتجاهها LTR والشارات داخلها RTL، لذلك الهوامش هنا فيزيائية */
.status { margin-left: auto; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; border: 1px solid transparent; }
.status.ok { background: var(--ok-soft); color: var(--ok); border-color: rgba(4, 120, 87, .22); }
.status.bad { background: var(--bad-soft); color: var(--bad); border-color: rgba(190, 18, 60, .2); }
.status.blank { background: var(--warn-soft); color: var(--warn); border-color: rgba(180, 83, 9, .22); }
.rq { margin: 0; font-size: 1.04rem; font-weight: 600; line-height: 1.6; overflow-wrap: anywhere; }
.ropts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ropt { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 9px 12px; border-radius: 10px; font-size: .95rem; border: 1px solid transparent; }
.ropt .badge { width: 1.7rem; height: 1.7rem; font-size: .74rem; }
.ropt .opt-text { gap: 2px 8px; }
.ropt.r-ok { background: var(--ok-soft); border-color: rgba(4, 120, 87, .2); }
.ropt.r-ok .badge { background: var(--ok); border-color: var(--ok); color: var(--on-ok); }
.ropt.r-bad { background: var(--bad-soft); border-color: rgba(190, 18, 60, .18); }
.ropt.r-bad .badge { background: var(--bad); border-color: var(--bad); color: var(--on-bad); }
.ropt.r-dim { color: var(--muted); }
.tag { margin-left: auto; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.r-ok .tag { color: var(--ok); } .r-bad .tag { color: var(--bad); }
@media (max-width: 520px) {
  .ropt .tag { flex-basis: 100%; margin-left: calc(1.7rem + 10px); text-align: left; }
}
.rnote { margin: 0; text-align: right; font-size: .86rem; color: var(--muted); }
.why {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; border-radius: var(--r);
  background: linear-gradient(135deg, rgba(34, 211, 238, .07), rgba(139, 92, 246, .07)); border: 1px solid rgba(124, 58, 237, .18);
}
.why-label { font-size: .8rem; font-weight: 700; color: var(--violet); }
.why-label::before { content: "✦ "; color: var(--accent); }
.why p { margin: 0; font-size: .96rem; line-height: 1.85; }
.why.none p { color: var(--muted); }

/* ---------- الملاحظات ---------- */
.notebox { display: flex; flex-direction: column; gap: 10px; padding: clamp(16px, 4vw, 24px); border-radius: var(--r-lg); }
.notebox h2 { margin: 0; font-family: var(--f-display); font-size: 1.1rem; font-weight: 600; }
.notebox p { margin: 0; }
.notebox textarea { width: 100%; min-height: 9rem; resize: vertical; padding: 12px 14px; line-height: 1.75; border-radius: var(--r); }
.notebox.sent { border-color: rgba(4, 120, 87, .35); background: var(--ok-soft); }
.notebox.sent h2 { color: var(--ok); }
.note-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 16px; font-size: .86rem; }
.note-err { color: var(--bad); font-size: .9rem; font-weight: 500; }
.note-alt { padding-top: 10px; border-top: 1px solid var(--line); font-size: .86rem; color: var(--muted); }

.notes-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.note { display: flex; flex-direction: column; gap: 8px; padding: 16px 18px; border-radius: var(--r-lg); }
.note-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.note-name { font-weight: 700; font-size: 1.02rem; }
.note-name.muted { color: var(--muted); font-weight: 500; }
.note-date { font-size: .78rem; color: var(--muted); font-family: var(--f-mono); }
.note-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .86rem; color: var(--muted); }
.note-text { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.85; }
.note-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* ---------- بريد التواصل ---------- */
.contact { overflow-wrap: anywhere; }
.email { color: var(--accent); font-weight: 600; text-decoration: none; unicode-bidi: isolate; white-space: nowrap; font-family: var(--f-mono); font-size: .92em; }
.email:hover { text-decoration: underline; text-underline-offset: 3px; }
.email-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.email-row .email { font-size: 1rem; }

/* ---------- طريقة الحل (اختبار/تدريب) ---------- */
.modebar {
  display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-radius: var(--r);
  border: 1px solid rgba(8, 145, 178, .2); background: linear-gradient(135deg, rgba(34, 211, 238, .06), rgba(139, 92, 246, .05)), var(--surface-solid);
}
.modebar-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; }
.modebar-title { font-weight: 600; }
.modebar-note { margin: 0; font-size: .86rem; color: var(--muted); }
.code.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(180, 83, 9, .25); }

/* بطاقات المراجعة والأسئلة الصعبة */
.tile.review-tile { background: var(--surface-solid); }
.tile.is-empty { cursor: default; box-shadow: none; background: var(--field-bg); border-style: dashed; }
.tile.is-empty:hover { transform: none; border-color: var(--line); box-shadow: none; }
.tile.exam { border-color: rgba(8, 145, 178, .3); }

/* ---------- الاختبار: المؤقت والتدريب ---------- */
.timer {
  flex: none; direction: ltr; font-family: var(--f-mono); font-weight: 700; font-size: .92rem;
  padding: 4px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(8, 145, 178, .3);
}
.timer.low { background: var(--bad-soft); color: var(--bad); border-color: rgba(190, 18, 60, .3); animation: pulse 1.2s ease-in-out infinite; }
.chip.mode { background: var(--violet-soft); color: var(--violet); border-color: rgba(124, 58, 237, .25); }
.chip.mode.exam { background: var(--accent-soft); color: var(--accent); border-color: rgba(8, 145, 178, .25); }
.feedback { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding: 10px 14px; border-radius: var(--r); font-weight: 700; text-align: right; }
.feedback span { font-weight: 500; font-size: .88rem; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid rgba(4, 120, 87, .25); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); border: 1px solid rgba(190, 18, 60, .22); }
.opt.is-revealed { cursor: default; flex-wrap: wrap; }
.opt.is-revealed:hover { background: inherit; }
.opt.r-ok { background: var(--ok-soft); border-color: rgba(4, 120, 87, .3); }
.opt.r-ok .badge { background: var(--ok); border-color: var(--ok); color: var(--on-ok); }
.opt.r-bad { background: var(--bad-soft); border-color: rgba(190, 18, 60, .28); }
.opt.r-bad .badge { background: var(--bad); border-color: var(--bad); color: var(--on-bad); }
.opt.r-dim { color: var(--muted); }
@media (max-width: 520px) {
  .opt.is-revealed .tag { flex-basis: 100%; margin-left: calc(2rem + 12px); text-align: left; }
}
.check-row { display: flex; justify-content: flex-start; }
.cell.is-ok { background: var(--ok-soft); border-color: rgba(4, 120, 87, .3); color: var(--ok); }
.cell.is-bad { background: var(--bad-soft); border-color: rgba(190, 18, 60, .28); color: var(--bad); }
.legend i.lg-ok { background: var(--ok-soft); border-color: rgba(4, 120, 87, .3); }
.legend i.lg-bad { background: var(--bad-soft); border-color: rgba(190, 18, 60, .28); }
.rule.time b { color: var(--bad); }

/* ---------- بطاقات المراجعة ---------- */
.cards-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  min-height: 36px; padding: 4px 14px; border-radius: 999px; cursor: pointer; font-size: .86rem; font-family: var(--f-mono); font-weight: 700;
  border: 1px solid var(--line-strong); background: var(--surface-solid); color: var(--muted);
}
.filter-chip[aria-pressed="true"] { background: var(--grad); border-color: transparent; color: var(--accent-ink); }
.cards-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.cards-pos { margin: 0; font-size: .88rem; color: var(--muted); }
.cards-pos b { color: var(--accent); }
.flash {
  position: relative; display: block; width: 100%; min-height: 260px; padding: 0; border: 0; background: none; cursor: pointer;
  perspective: 1200px; text-align: center;
}
.flash-inner {
  display: grid; min-height: 260px; transition: transform .45s ease; transform-style: preserve-3d;
}
.flash.is-flipped .flash-inner { transform: rotateY(180deg); }
.flash-face {
  grid-area: 1 / 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: clamp(20px, 5vw, 36px); border-radius: var(--r-lg); backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 1px solid var(--line); background: var(--surface-solid); box-shadow: var(--shadow-sm);
}
.flash-face.front { background: linear-gradient(150deg, rgba(34, 211, 238, .09), rgba(139, 92, 246, .08)), var(--surface-solid); border-color: rgba(8, 145, 178, .25); }
.flash-face.back { transform: rotateY(180deg); }
.flash-term { font-family: var(--f-display); font-size: clamp(1.5rem, 5vw, 2.1rem); font-weight: 700; line-height: 1.3; }
.flash-term.small { font-size: 1rem; color: var(--accent); }
.flash-ar { font-size: 1.1rem; color: var(--muted); font-weight: 500; }
.flash-hint { font-size: .8rem; color: var(--muted); }
.flash-en { max-width: 36rem; font-size: 1rem; line-height: 1.7; color: var(--ink); }
.flash-def { max-width: 36rem; font-size: 1rem; line-height: 1.9; color: var(--muted); padding-top: 10px; border-top: 1px solid var(--line); }
.flash-nav { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.flash-nav .btn { flex: 1 1 auto; }
.btn.known { background: var(--ok-soft); border-color: rgba(4, 120, 87, .35); color: var(--ok); }

/* ---------- صفحة المشرف ---------- */
.admin-login {
  display: flex; flex-direction: column; gap: 10px; max-width: 24rem; padding: 20px; border-radius: var(--r-lg);
  border: 1px solid var(--line); background: var(--surface-solid); box-shadow: var(--shadow-sm);
}
.admin-login label { font-weight: 600; }
.admin-login input {
  min-height: 46px; padding: 8px 12px; font: inherit; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--field-bg); color: var(--ink);
}
.admin-login input:focus { outline: none; border-color: var(--accent); box-shadow: var(--glow); }
.admin-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.admin-actions { display: flex; gap: 8px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface-solid); }
.stats-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.stats-table th, .stats-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
.stats-table th { background: var(--field-bg); font-weight: 600; color: var(--muted); white-space: nowrap; }
.stats-table tr:last-child td { border-bottom: 0; }
.q-cell { text-align: left !important; min-width: 16rem; }
.q-text { display: block; margin-top: 4px; line-height: 1.5; }
.num-cell { font-family: var(--f-mono); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rate { font-weight: 700; padding: 1px 8px; border-radius: 999px; }
.rate.ok { background: var(--ok-soft); color: var(--ok); }
.rate.warn { background: var(--warn-soft); color: var(--warn); }
.rate.bad { background: var(--bad-soft); color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
