/* ==========================================================================
   1. المتغيرات والسمات (الوضع الفاتح والداكن)
   ========================================================================== */
:root {
  --bg: #f2f4f6;
  --surface: #fff;
  --ink: #14213d;
  --muted: #52607a;
  --line: #d5dbe3;
  --alert: #c4233a;
  --alert-bg: #fde8eb;
  --safe: #0b7a75;
  --safe-bg: #dff3f1;
  --code: #0f1a2e;
  --code-fg: #dbe4f3;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1424;
    --surface: #131e33;
    --ink: #e8eef8;
    --muted: #9aa9c2;
    --line: #26344f;
    --alert: #ff7a8a;
    --alert-bg: #3a1822;
    --safe: #4fd1c5;
    --safe-bg: #10343a;
    --code: #070c17;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0c1424;
  --surface: #131e33;
  --ink: #e8eef8;
  --muted: #9aa9c2;
  --line: #26344f;
  --alert: #ff7a8a;
  --alert-bg: #3a1822;
  --safe: #4fd1c5;
  --safe-bg: #10343a;
  --code: #070c17;
  color-scheme: dark;
}

/* ==========================================================================
   2. الأساسيات والهيكل العام
   ========================================================================== */
html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1.05rem/1.85 "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  background: var(--surface);
  z-index: 10;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--safe);
  outline-offset: 3px;
  border-radius: 4px;
}

.wrap {
  max-width: 62rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}

main section {
  padding: 2.5rem 0 4rem;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  line-height: 1.4;
  margin: 0 0 1rem;
  font-weight: 700;
}

h2 {
  font-size: clamp(1.3rem, 3.2vw, 1.7rem);
  margin: 2.2rem 0 .6rem;
  line-height: 1.5;
}

p {
  margin: 0 0 1rem;
  max-width: 44rem;
}

.lead {
  font-size: 1.15rem;
  color: var(--muted);
}

.section-note {
  margin-top: 1.5rem;
}

.en {
  font-family: "IBM Plex Mono", monospace;
  font-size: .82em;
  color: var(--muted);
  direction: ltr;
  unicode-bidi: isolate;
}

/* ==========================================================================
   3. الرأس والتنقل والتذييل
   ========================================================================== */
header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 9;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 3.6rem;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.brand i {
  display: inline-block;
  width: .7rem;
  height: 1.2rem;
  background: var(--alert);
  border-radius: 2px;
}

nav {
  display: flex;
  gap: .25rem;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}

nav::-webkit-scrollbar {
  display: none;
}

nav a {
  padding: .45rem .85rem;
  text-decoration: none;
  white-space: nowrap;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
}

nav a[aria-current] {
  color: var(--ink);
  background: var(--bg);
  box-shadow: inset 0 -3px 0 var(--alert);
}

.theme {
  flex: none;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 6px;
  padding: .3rem .55rem;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  text-decoration: none;
  line-height: 1.5;
}

footer {
  border-top: 1px solid var(--line);
  padding: 1.5rem 0;
  color: var(--muted);
  font-size: .92rem;
  background: var(--surface);
}

footer p {
  margin: 0;
}

/* ==========================================================================
   4. الأزرار والبطاقات والترحيب والتقدّم
   ========================================================================== */
.btns {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 1.4rem;
}

.btn {
  display: inline-block;
  padding: .65rem 1.3rem;
  border-radius: 6px;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  border: 2px solid var(--ink);
  background: none;
  color: var(--ink);
  cursor: pointer;
}

.btn.p {
  background: var(--ink);
  color: var(--bg);
}

.hero {
  display: grid;
  gap: 2rem;
  align-items: center;
}

@media (min-width: 56rem) {
  .hero {
    grid-template-columns: 1.1fr 1fr;
  }
}

.term {
  background: var(--code);
  color: var(--code-fg);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  font-size: .95rem;
  line-height: 1.9;
}

.term b {
  display: block;
  font: 400 .75rem "IBM Plex Mono", monospace;
  color: #8da2c4;
  margin-top: .6rem;
}

.term b:first-child {
  margin-top: 0;
}

.inj {
  background: var(--alert);
  color: #fff;
  padding: .1rem .35rem;
  border-radius: 3px;
}

.meter {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  max-width: 44rem;
}

.track {
  height: .6rem;
  background: var(--bg);
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  margin-top: .5rem;
}

.fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--safe);
  transition: width .4s;
}

/* ==========================================================================
   5. قوائم الدروس والمعامل والاختبارات
   ========================================================================== */
.list {
  border-top: 2px solid var(--ink);
  margin-top: 1rem;
}

.lrow {
  display: grid;
  grid-template-columns: 1fr auto 1.6rem;
  gap: 1rem;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}

.lrow:hover strong {
  text-decoration: underline;
}

.lv {
  font-size: .85rem;
  color: var(--muted);
}

.ck {
  width: 1.4rem;
  height: 1.4rem;
  border: 2px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .85rem;
  line-height: 1;
}

.ck.on {
  background: var(--safe);
  border-color: var(--safe);
  color: var(--surface);
}

.ck.on::after {
  content: "✓";
}

.lvh {
  margin: 1.6rem 0 .2rem;
  font-size: 1.05rem;
  color: var(--muted);
}

.list .lvh:first-child {
  margin-top: .8rem;
}

.tag2 {
  font-size: .75rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 .4rem;
  color: var(--muted);
  font-weight: 400;
}

.crumb {
  font-size: .9rem;
  color: var(--muted);
  margin-bottom: .5rem;
}

.crumb a {
  color: var(--muted);
}

.box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 5px solid var(--safe);
  padding: .9rem 1.1rem;
  border-radius: 4px;
  max-width: 44rem;
  margin: 1rem 0;
}

.box.bad {
  border-inline-start-color: var(--alert);
}

.box h3 {
  margin: 0 0 .3rem;
  font-size: 1.05rem;
}

.box p,
.box ul {
  margin: 0;
}

.box ul {
  padding-inline-start: 1.2rem;
}

.quiz {
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 1.1rem 1.2rem;
  max-width: 44rem;
  margin-top: 2rem;
  background: var(--surface);
}

.quiz button {
  display: block;
  width: 100%;
  text-align: start;
  font: inherit;
  padding: .65rem .9rem;
  margin-top: .5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}

.quiz button:hover:not(:disabled) {
  border-color: var(--ink);
}

.quiz button.right {
  border-color: var(--safe);
  background: var(--safe-bg);
}

.quiz button.wrong {
  border-color: var(--alert);
  background: var(--alert-bg);
}

.quiz .fb {
  margin: .8rem 0 0;
  font-weight: 500;
}

.ok {
  color: var(--safe);
}

.no {
  color: var(--alert);
}

.pn {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 2rem;
  max-width: 44rem;
  flex-wrap: wrap;
}

/* ==========================================================================
   6. واجهة المعامل والنماذج
   ========================================================================== */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin: 1rem 0;
}

.tabs button {
  font: inherit;
  padding: .45rem .9rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
}

.tabs button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

.chat {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  max-width: 44rem;
  overflow: hidden;
}

.msgs {
  height: 17rem;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}

.m {
  padding: .5rem .8rem;
  border-radius: 8px;
  max-width: 88%;
  white-space: pre-wrap;
}

.m.u {
  align-self: flex-start;
  background: var(--ink);
  color: var(--bg);
}

.m.b {
  align-self: flex-end;
  background: var(--bg);
  border: 1px solid var(--line);
}

.send {
  display: flex;
  border-top: 1px solid var(--line);
}

.send input {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: .8rem 1rem;
  font: inherit;
  background: var(--surface);
  color: var(--ink);
}

.send button {
  border: 0;
  border-inline-start: 1px solid var(--line);
  padding: 0 1.2rem;
  font: inherit;
  font-weight: 700;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.links a {
  display: block;
  padding: .5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  text-decoration: none;
  font: .9rem "IBM Plex Mono", monospace;
  direction: ltr;
}

label {
  display: block;
  font-weight: 500;
  margin: 1rem 0 .3rem;
}

textarea {
  width: 100%;
  max-width: 44rem;
  font: inherit;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.opt {
  display: flex;
  gap: .6rem;
  align-items: center;
  font-weight: 400;
  cursor: pointer;
}

.opt input {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--safe);
}

input[type=range] {
  width: 100%;
  max-width: 44rem;
  accent-color: var(--safe);
}

.gauge {
  height: 1.2rem;
  background: var(--alert-bg);
  border-radius: 6px;
  overflow: hidden;
  max-width: 44rem;
  border: 1px solid var(--line);
  margin: .6rem 0;
}

.gauge span {
  display: block;
  height: 100%;
  background: var(--safe);
  transition: width .2s;
}

.ans {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin: .8rem 0;
}

select {
  font: inherit;
  padding: .6rem .8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  max-width: 44rem;
}

.ex {
  background: var(--safe-bg);
}

.ex h3 {
  margin: .9rem 0 .2rem;
}

.ex h3:first-child {
  margin-top: 0;
}

.ex ol {
  margin: 0;
  padding-inline-start: 1.3rem;
}

.ex li {
  margin-bottom: .2rem;
}

.ex details {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: .6rem;
}

.ex summary {
  cursor: pointer;
  font-weight: 700;
}

.cap {
  font-size: .9rem;
  color: var(--muted);
  margin: .8rem 0 0;
}

/* ==========================================================================
   7. الإشعارات والشارات والقاموس
   ========================================================================== */
.toast {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  max-width: 28rem;
  margin: 0 auto;
  background: var(--ink);
  color: var(--bg);
  padding: .8rem 1.1rem;
  border-radius: 8px;
  font-weight: 500;
  z-index: 20;
  display: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}

.toast.show {
  display: block;
}

.badges {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: .8rem;
  margin: 1rem 0;
}

.bd {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: .9rem .7rem;
  text-align: center;
  line-height: 1.5;
}

.bd i {
  display: block;
  font-style: normal;
  font-size: 2rem;
}

.bd b {
  display: block;
}

.bd small {
  color: var(--muted);
}

.bd.off {
  opacity: .45;
  filter: grayscale(1);
}

.gs {
  width: 100%;
  max-width: 44rem;
  font: inherit;
  padding: .7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.term-row {
  border-bottom: 1px solid var(--line);
  padding: 1rem 0;
  max-width: 46rem;
}

.term-row h3 {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem 1rem;
  align-items: baseline;
}

.term-row .en {
  font-size: .95rem;
  color: var(--muted);
}

.term-row p {
  margin: .3rem 0 .2rem;
  color: var(--muted);
}

.term-row a {
  font-size: .9rem;
}

/* ==========================================================================
   8. الشهادة والطباعة
   ========================================================================== */
.certw {
  position: relative;
  margin: 1.2rem auto;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
}

.cert {
  position: absolute;
  top: 0;
  right: 0;
  width: 1123px;
  height: 794px;
  transform-origin: top right;
  direction: rtl;
  overflow: hidden;
  color: #14213d;
  background: radial-gradient(circle at 50% 45%, #fffefa 0, #fbf4e2 100%);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  line-height: 1.5;
}

.cert::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(45deg, rgba(184, 137, 43, .05) 0 1px, transparent 1px 14px),
    repeating-linear-gradient(-45deg, rgba(184, 137, 43, .05) 0 1px, transparent 1px 14px);
}

.cf1 {
  position: absolute;
  inset: 16px;
  border: 5px double #b8892b;
}

.cf2 {
  position: absolute;
  inset: 34px;
  border: 1px solid #cdb26a;
}

.co {
  position: absolute;
  width: 92px;
  height: 92px;
}

.co.tl { top: 36px; left: 36px; }
.co.tr { top: 36px; right: 36px; transform: scaleX(-1); }
.co.bl { bottom: 36px; left: 36px; transform: scaleY(-1); }
.co.br { bottom: 36px; right: 36px; transform: rotate(180deg); }

.wm {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 420px;
  height: auto;
  transform: translate(-50%, -50%);
  opacity: .2;
}

.ci {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 62px 110px 0;
  text-align: center;
}

.cbrand {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 700 26px/1 "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

.cbrand i {
  width: 12px;
  height: 24px;
  background: #c4233a;
  border-radius: 2px;
}

.cbrand small {
  font: 500 14px "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color: #52607a;
  margin-inline-start: 12px;
  padding-inline-start: 14px;
  border-inline-start: 1px solid #cdb26a;
}

.cert h2 {
  margin: 16px 0 0;
  font: 700 76px/1.15 Amiri, "Traditional Arabic", "Times New Roman", serif;
  color: #9c7424;
}

.cen {
  margin-top: 4px;
  font: 400 17px Georgia, "Times New Roman", serif;
  letter-spacing: 7px;
  direction: ltr;
  color: #14213d;
}

.cdiv {
  position: relative;
  width: 380px;
  height: 14px;
  margin: 12px 0 4px;
}

.cdiv::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #b8892b, transparent);
}

.cdiv span {
  position: absolute;
  left: 50%;
  top: 1px;
  width: 11px;
  height: 11px;
  margin-left: -5px;
  background: #b8892b;
  transform: rotate(45deg);
}

.cpre {
  font: 400 24px "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color: #3a4763;
}

.cname {
  margin-top: 4px;
  min-height: 84px;
  font: 700 64px/1.3 Amiri, "Traditional Arabic", "Times New Roman", serif;
  color: #14213d;
}

.cline {
  width: 580px;
  height: 2px;
  background: linear-gradient(90deg, transparent, #b8892b, transparent);
}

.cert .cbody {
  margin: 22px 0 0;
  max-width: 780px;
  font: 400 21px/1.95 "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color: #2c3a58;
}

.cfoot {
  position: absolute;
  left: 112px;
  right: 112px;
  bottom: 96px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.cdate,
.csig {
  width: 290px;
  text-align: center;
}

.cdate b {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 64px;
  font: 700 22px "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  padding-bottom: 8px;
}

.cdate span,
.csig span {
  display: block;
  height: 2px;
  background: #14213d;
  opacity: .75;
}

.cdate small,
.csig small {
  display: block;
  margin-top: 6px;
  font: 500 15px "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color: #52607a;
}

.csig {
  direction: ltr;
}

.sg {
  display: block;
  height: 64px;
  line-height: 64px;
  text-align: center;
  white-space: nowrap;
  font-family: "Great Vibes", "Brush Script MT", "Segoe Script", "Lucida Handwriting", cursive;
  font-size: 54px;
  color: #1b2d66;
}

.csig b {
  display: block;
  margin-top: 8px;
  font: 700 19px Georgia, "Times New Roman", serif;
  color: #14213d;
}

.csig small {
  font: 500 15px Georgia, serif;
  letter-spacing: 3px;
}

.cseal {
  width: 140px;
  height: 175px;
  margin-bottom: -24px;
}

.cid {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 52px;
  padding: 0 120px;
  text-align: center;
  font: 400 12.5px "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
  color: #6b7692;
}

@page {
  size: A4 landscape;
  margin: 0;
}

@media print {
  html,
  body {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body::before,
  body > header,
  body > footer,
  .toast,
  .noprint {
    display: none !important;
  }

  main section > *:not(#cert-area),
  #cert-area > *:not(.certw) {
    display: none !important;
  }

  main.wrap,
  main section,
  #cert-area {
    display: block;
    margin: 0;
    padding: 0;
    max-width: none;
  }

  .certw {
    width: 1122px !important;
    height: 793px !important;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .cert {
    transform: none !important;
    width: 1122px;
    height: 793px;
  }
}

/* ==========================================================================
   9. الاستجابة للشاشات الصغيرة
   ========================================================================== */
@media (max-width: 40rem) {
  .bar {
    gap: .6rem;
  }

  .brand {
    font-size: 1.05rem;
  }

  main section {
    padding: 1.8rem 0 3rem;
  }

  .lrow {
    grid-template-columns: 1fr 1.6rem;
  }

  .lv {
    display: none;
  }
}