/* AICPIC — studio backdrop palette. Light-role colours are semantic and reused everywhere. */
:root {
  --bg: #0f0e0c;        /* AICPIC black */
  --panel: #191714;
  --panel-2: #221f1b;
  --line: #34302a;
  --ink: #ece7df;
  --muted: #a39b8f;
  --brand: #dea450;     /* AICPIC gold (logo) */
  --key: #dea450;       /* key light – same gold, also the action colour */
  --fill: #7eaedf;      /* fill – daylight blue */
  --rim: #eef2f7;       /* back / rim */
  --prac: #ff8a4c;      /* practical */
  --bgl: #b98ae0;       /* background light */
  --ok: #6fcf97;
  --bad: #ef6b6b;
  --on-key: #1d1f23;
  --radius-s: 6px;
  --radius-l: 14px;
  --display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --text: "Source Serif 4", Georgia, "Times New Roman", serif;
  --ui: "Archivo", "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #e4e1dc; --panel: #f1efeb; --panel-2: #e9e6e1; --line: #cbc6be;
  --ink: #1c1e22; --muted: #5d636b; --brand: #a8701f; --key: #a8701f; --fill: #2f6fae; --rim: #59606a;
  --prac: #c4531b; --bgl: #7b4ab0; --on-key: #fff; color-scheme: light;
}
/* Dark (brand) is the default; visitors can switch to light with the theme button. */
:root[lang="ar"] { --display: "IBM Plex Sans Arabic", Tahoma, sans-serif; --text: "IBM Plex Sans Arabic", Tahoma, sans-serif; --ui: "IBM Plex Sans Arabic", Tahoma, sans-serif; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
html, body { overflow-x: clip; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.55 var(--ui); min-height: 100vh; }
img, svg, canvas { max-width: 100%; display: block; }
a { color: var(--key); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--key); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- buttons & form ---------- */
.btn { display: inline-flex; align-items: center; gap: .5em; border: 1px solid var(--line); background: var(--panel-2); padding: .62em 1.05em; border-radius: var(--radius-s); cursor: pointer; font-weight: 600; font-size: .94rem; text-decoration: none; color: var(--ink); transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--key); border-color: var(--key); color: var(--on-key); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: .35em .7em; font-size: .85rem; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: grid; gap: .35rem; margin-bottom: .9rem; }
.field label { font-size: .86rem; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .65em .8em; width: 100%; }
.field textarea { min-height: 90px; resize: vertical; }
.error-text { color: var(--bad); font-size: .9rem; min-height: 1.3em; margin: .2rem 0 .6rem; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.segmented button { background: transparent; border: 0; padding: .4em .7em; cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--panel-2); color: var(--ink); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 1rem; padding: .7rem 1.2rem; padding-top: calc(.7rem + env(safe-area-inset-top, 0px)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .55rem; font: 800 1.05rem/1 var(--display); font-stretch: 118%; letter-spacing: .01em; text-decoration: none; color: var(--ink); }
.brand svg { width: 30px; height: auto; color: var(--brand); }
.brand-name { letter-spacing: .08em; }
.topbar .spacer { flex: 1; }
.topbar .crumb { color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- landing ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 3rem; align-items: center; max-width: 1180px; margin: 0 auto; padding: 3.5rem 1.4rem 2.5rem; }
.hero h1 { font: 800 clamp(2.4rem, 5.4vw, 4.3rem)/.98 var(--display); font-stretch: 125%; margin: 0 0 1.1rem; letter-spacing: -.01em; }
:root[lang="ar"] .hero h1 { line-height: 1.25; }
.hero p.lede { font: 400 1.18rem/1.6 var(--text); color: var(--muted); max-width: 34rem; margin: 0 0 1.6rem; }
.hero .actions { display: flex; gap: .7rem; flex-wrap: wrap; }
.hero-stage { position: relative; }
.hero-note { margin-top: .8rem; color: var(--muted); font-size: .9rem; }
.tracks { max-width: 1180px; margin: 0 auto; padding: 2rem 1.4rem 4rem; }
.tracks h2, .section-title { font: 700 1.6rem/1.2 var(--display); font-stretch: 112%; margin: 0 0 1.2rem; }
.track-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); border-top: 1px solid var(--line); }
.track { padding: 1.3rem 1.3rem 1.5rem 0; border-bottom: 1px solid var(--line); }
.track h3 { margin: 0 0 .4rem; font: 700 1.15rem/1.25 var(--display); }
.track p { margin: 0 0 .6rem; color: var(--muted); font-size: .95rem; }
.track ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; font-size: .93rem; }
.track li { display: flex; justify-content: space-between; gap: .6rem; }
.tag { font-size: .76rem; font-weight: 700; padding: .12em .55em; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.open { color: var(--on-key); background: var(--key); border-color: var(--key); }
.how { max-width: 1180px; margin: 0 auto; padding: 0 1.4rem 4rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 2rem; }
.how ol { margin: 0; padding-inline-start: 1.2rem; color: var(--muted); }
.how li { margin-bottom: .5rem; }
.how li strong { color: var(--ink); }
footer.site { border-top: 1px solid var(--line); padding: 1.4rem; text-align: center; color: var(--muted); font-size: .88rem; padding-bottom: calc(1.4rem + env(safe-area-inset-bottom, 0px)); }

/* dialog */
dialog { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: var(--radius-l); padding: 1.6rem; width: min(420px, calc(100vw - 2rem)); }
dialog::backdrop { background: rgb(0 0 0 / .55); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 1rem; font: 700 1.35rem/1.2 var(--display); }
.dialog-wide { width: min(720px, calc(100vw - 2rem)); }

/* ---------- course app ---------- */
.app { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 57px); }
.rail { border-inline-end: 1px solid var(--line); padding: 1.2rem 0; position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto; }
.rail h2 { font: 700 .95rem/1.3 var(--display); margin: 0 1.2rem .3rem; }
.rail .chapter-progress { margin: 0 1.2rem 1rem; font-size: .85rem; color: var(--muted); }
.bar { height: 4px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: .4rem; }
.bar > i { display: block; height: 100%; background: var(--key); width: 0; transition: width .6s ease; }
.rail ol { list-style: none; margin: 0; padding: 0; counter-reset: m; }
.rail li a { display: grid; grid-template-columns: 2.1rem 1fr auto; align-items: center; gap: .4rem; padding: .62rem 1.2rem; text-decoration: none; color: var(--ink); font-size: .94rem; border-inline-start: 3px solid transparent; }
.rail li a:hover { background: var(--panel); }
.rail li a[aria-current="page"] { background: var(--panel); border-inline-start-color: var(--key); }
.rail .num { font: 800 .9rem/1 var(--display); font-stretch: 125%; color: var(--muted); }
.rail .done .num { color: var(--ok); }
.rail .check { width: 16px; height: 16px; color: var(--ok); }
.rail .rail-foot { margin: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); display: grid; gap: .5rem; }
.main { padding: 2.2rem clamp(1rem, 4vw, 3.2rem) 5rem; min-width: 0; }
.rail-toggle { display: none; }

.lesson { max-width: 46rem; margin: 0 auto; }
.lesson-head { margin-bottom: 2.4rem; }
.lesson-head .mnum { font: 800 clamp(3.5rem, 9vw, 6.5rem)/.85 var(--display); font-stretch: 125%; color: var(--line); margin-bottom: .2rem; }
.lesson-head h1 { font: 800 clamp(1.9rem, 4vw, 2.8rem)/1.08 var(--display); font-stretch: 112%; margin: 0 0 .8rem; }
:root[lang="ar"] .lesson-head h1 { line-height: 1.35; }
.lesson-head .summary { font: 400 1.15rem/1.6 var(--text); color: var(--muted); margin: 0; }
.lesson-head .meta { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }
.lesson section { margin: 0 0 2.6rem; }
.lesson h2 { font: 700 1.45rem/1.25 var(--display); font-stretch: 108%; margin: 0 0 .8rem; }
.lesson .prose p { font: 400 1.08rem/1.72 var(--text); margin: 0 0 1rem; }
:root[lang="ar"] .lesson .prose p { line-height: 1.95; }
.lesson .prose strong { font-weight: 650; }
.tips { margin: 1rem 0 0; padding: 1rem 1.2rem; border-inline-start: 3px solid var(--fill); background: var(--panel); border-radius: 0 var(--radius-s) var(--radius-s) 0; }
:root[dir="rtl"] .tips { border-radius: var(--radius-s) 0 0 var(--radius-s); }
.tips h3 { margin: 0 0 .5rem; font: 700 .9rem/1.2 var(--ui); color: var(--fill); }
.tips ul { margin: 0; padding-inline-start: 1.1rem; }
.tips li { margin-bottom: .35rem; font-size: .98rem; }
.table-wrap { overflow-x: auto; margin: 1rem 0; }
table.ref { border-collapse: collapse; width: 100%; font-size: .94rem; }
table.ref th, table.ref td { text-align: start; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.ref th { font-weight: 700; color: var(--muted); font-size: .85rem; }
.widget { margin: 1.6rem 0; }
.takeaways { border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.3rem 1.5rem; margin: 2.5rem 0; }
.takeaways h2 { font-size: 1.15rem; }
.takeaways ol { margin: 0; padding-inline-start: 1.3rem; }
.takeaways li { margin-bottom: .45rem; }

/* quiz */
.quiz { border-top: 1px solid var(--line); padding-top: 2rem; margin-top: 3rem; }
.q { margin-bottom: 1.6rem; }
.q-text { font-weight: 650; margin: 0 0 .6rem; }
.q-opts { display: grid; gap: .45rem; }
.q-opt { text-align: start; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s); padding: .65em .9em; cursor: pointer; transition: border-color .15s, background .15s; }
.q-opt:hover:not(:disabled) { border-color: var(--muted); }
.q-opt.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, var(--panel)); }
.q-opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--panel)); }
.q-explain { margin-top: .6rem; font-size: .95rem; color: var(--muted); }
.quiz-score { font: 800 1.3rem/1.2 var(--display); margin: 1rem 0; }

/* practice */
.practice { margin-top: 3rem; padding: 1.5rem; border-radius: var(--radius-l); background: var(--panel); border: 1px solid var(--line); }
.practice h2 { margin-top: 0; }
.practice ol { padding-inline-start: 1.3rem; }
.practice li { margin-bottom: .45rem; }
.checklist { list-style: none; padding: 0 !important; }
.checklist label { display: flex; gap: .6rem; align-items: flex-start; cursor: pointer; }
.checklist input { margin-top: .3em; accent-color: var(--key); }
.status-pill { display: inline-block; font-size: .8rem; font-weight: 700; padding: .15em .6em; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); }
.status-pill.approved { color: var(--ok); border-color: var(--ok); }
.status-pill.revise { color: var(--bad); border-color: var(--bad); }
.lesson-nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; flex-wrap: wrap; }

/* dashboard */
.dash { max-width: 60rem; margin: 0 auto; }
.dash h1 { font: 800 clamp(1.8rem, 4vw, 2.6rem)/1.1 var(--display); font-stretch: 112%; margin: 0 0 .4rem; }
.dash .sub { color: var(--muted); margin: 0 0 2rem; }
.cat { margin-bottom: 2.2rem; }
.cat h2 { font: 700 1.2rem/1.2 var(--display); margin: 0 0 .7rem; }
.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.chapter-card { display: block; padding: 1.2rem; border: 1px solid var(--line); border-radius: var(--radius-l); text-decoration: none; color: var(--ink); background: var(--panel); position: relative; }
.chapter-card:hover:not(.locked) { border-color: var(--key); }
.chapter-card h3 { margin: 0 0 .3rem; font: 700 1.05rem/1.3 var(--display); }
.chapter-card p { margin: 0 0 .8rem; color: var(--muted); font-size: .92rem; }
.chapter-card.locked { opacity: .55; cursor: default; }

/* ---------- light lab ---------- */
.lab { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1rem; }
.lab.wide { margin-inline: calc(-1 * min(8vw, 7rem)); }
.lab-view { position: relative; border-radius: var(--radius-s); overflow: hidden; background: #000; aspect-ratio: 4 / 5; }
.lab-view canvas { width: 100%; height: 100%; object-fit: cover; image-rendering: auto; }
.lab-view .readout { position: absolute; inset-inline-start: .6rem; bottom: .6rem; background: rgb(0 0 0 / .6); color: #fff; font-size: .78rem; padding: .3em .6em; border-radius: 4px; }
.lab-side { display: grid; gap: .8rem; align-content: start; min-width: 0; }
.plan { position: relative; aspect-ratio: 1; background: var(--bg); border-radius: var(--radius-s); border: 1px solid var(--line); touch-action: none; user-select: none; }
.plan svg { width: 100%; height: 100%; }
.plan .light-node { cursor: grab; }
.plan .light-node:active { cursor: grabbing; }
.plan .light-node.off { opacity: .35; }
.plan .light-node .halo { opacity: 0; transition: opacity .2s; }
.plan .light-node.selected .halo { opacity: 1; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-flex; align-items: center; gap: .4rem; padding: .35em .75em; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; font-size: .85rem; font-weight: 600; }
.chip .dot { width: .7em; height: .7em; border-radius: 50%; background: currentColor; }
.chip[aria-pressed="false"] .dot { background: transparent; border: 2px solid currentColor; }
.chip.selected { border-color: currentColor; }
.chip span.lbl { color: var(--ink); }
.light-info { background: var(--bg); border-radius: var(--radius-s); padding: .8rem .9rem; border: 1px solid var(--line); }
.light-info h4 { margin: 0 0 .3rem; font: 700 .98rem/1.2 var(--display); }
.light-info p { margin: 0 0 .6rem; font-size: .9rem; color: var(--muted); }
.ctrl { display: grid; grid-template-columns: 7.5rem 1fr 3rem; align-items: center; gap: .5rem; font-size: .85rem; margin-bottom: .35rem; }
.ctrl output { text-align: end; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctrl input[type="range"] { width: 100%; accent-color: var(--key); }
.ctrl select { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: .2em .3em; grid-column: span 2; }
.presets { display: flex; flex-wrap: wrap; gap: .35rem; }
.presets .btn { font-size: .8rem; padding: .3em .65em; }
.lab-caption { grid-column: 1 / -1; font-size: .92rem; color: var(--muted); margin: 0; min-height: 1.4em; }

/* small widgets */
.mini { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1rem 1.1rem; }
.mini h4 { margin: 0 0 .6rem; font: 700 .98rem/1.2 var(--display); }
.mini .row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.mini svg { width: 100%; height: auto; }
.mini p.out { margin: .5rem 0 0; font-size: .92rem; color: var(--muted); }

/* ---------- presentation mode ---------- */
.present { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; grid-template-rows: auto 1fr auto; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
.present-top { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.2rem; color: var(--muted); font-size: .9rem; }
.present-top .spacer { flex: 1; }
.slide { overflow-y: auto; padding: 2rem clamp(1rem, 7vw, 7rem); display: grid; align-content: center; }
.slide-inner { max-width: 72rem; margin: 0 auto; width: 100%; animation: slideIn .45s cubic-bezier(.2, .7, .2, 1); }
.slide h2 { font: 800 clamp(2rem, 4.6vw, 3.6rem)/1.05 var(--display); font-stretch: 115%; margin: 0 0 1.4rem; }
.slide .prose p { font: 400 clamp(1.1rem, 1.8vw, 1.45rem)/1.6 var(--text); max-width: 52rem; }
.slide .tips li { font-size: clamp(1rem, 1.5vw, 1.25rem); }
.slide.title-slide h1 { font: 800 clamp(2.6rem, 7vw, 6rem)/.95 var(--display); font-stretch: 125%; margin: 0 0 1rem; }
.present-foot { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.2rem; }
.present-foot .bar { flex: 1; margin: 0; }
@keyframes slideIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* page-load reveal for lessons (single orchestrated moment) */
.lesson.entering .lesson-head > * { animation: rise .6s cubic-bezier(.2, .7, .2, 1) both; }
.lesson.entering .lesson-head > *:nth-child(2) { animation-delay: .06s; }
.lesson.entering .lesson-head > *:nth-child(3) { animation-delay: .12s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

/* ---------- admin ---------- */
.admin { max-width: 1200px; margin: 0 auto; padding: 2rem 1.2rem 4rem; }
.admin-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 2rem; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 1.3rem; }
.card h2 { margin: 0 0 1rem; font: 700 1.15rem/1.2 var(--display); }
.users-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.users-table th, .users-table td { padding: .6rem .5rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: middle; }
.users-table th { color: var(--muted); font-size: .8rem; font-weight: 700; }
.users-table .actions { display: flex; gap: .3rem; flex-wrap: wrap; }
.checks { display: grid; gap: .3rem; font-size: .9rem; }
.checks label { display: flex; gap: .5rem; align-items: center; }
.credential { background: var(--bg); border: 1px dashed var(--key); border-radius: var(--radius-s); padding: .9rem; margin-top: 1rem; font-size: .92rem; white-space: pre-wrap; word-break: break-all; }
.stats { display: flex; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; color: var(--muted); }
.stats strong { display: block; font: 800 1.6rem/1 var(--display); color: var(--ink); }
.toast { position: fixed; bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); inset-inline-start: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: var(--radius-s); font-weight: 600; z-index: 200; animation: rise .25s ease both; }
:root[dir="rtl"] .toast { transform: translateX(50%); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .lab.wide { margin-inline: 0; } }
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: 2rem; gap: 2rem; }
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; inset-block: 57px 0; inset-inline-start: 0; width: min(310px, 86vw); z-index: 40; background: var(--bg); transform: translateX(-102%); transition: transform .25s ease; height: auto; }
  :root[dir="rtl"] .rail { transform: translateX(102%); }
  .rail.open { transform: none !important; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .45); }
  .rail-toggle { display: inline-flex; }
  .admin-grid { grid-template-columns: 1fr; }
  .topbar .crumb { display: none; }
}
@media (max-width: 720px) {
  .topbar { gap: .45rem; padding-inline: .7rem; }
  .brand-name, #user-name, #admin-link, .topbar .theme-toggle { display: none; }
  .topbar .btn.small { padding: .35em .55em; }
  .segmented button { padding: .35em .5em; }
  .lab { grid-template-columns: 1fr; }
  .ctrl { grid-template-columns: 6.5rem 1fr 2.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
