:root {
  --bg: #f4f1ea;
  --bg-elev: #fffdf8;
  --bg-soft: #ece7dc;
  --ink: #1b2230;
  --ink-soft: #4a5568;
  --muted: #6b7385;
  --line: #ddd6c8;
  --accent: #0b7a62;
  --accent-2: #0e9678;
  --accent-soft: #d8f3ec;
  --amber: #b86a00;
  --amber-soft: #fde9c8;
  --rose: #9b2c3a;
  --rose-soft: #f8dfe3;
  --blue: #1f4e8c;
  --blue-soft: #dce7f6;
  --shadow: 0 10px 30px rgba(27, 34, 48, 0.08);
  --radius: 16px;
  --sidebar: 290px;
  --header: 64px;
  --font: "IBM Plex Sans Arabic", "IBM Plex Sans", "Segoe UI", Tahoma, sans-serif;
  --mono: "IBM Plex Sans", ui-monospace, monospace;
}
html[data-theme="dark"] {
  --bg: #0e1219;
  --bg-elev: #171d28;
  --bg-soft: #1e2633;
  --ink: #e9eef6;
  --ink-soft: #c3cad6;
  --muted: #97a0b0;
  --line: #2b3444;
  --accent: #3ee0b0;
  --accent-2: #7cf0cb;
  --accent-soft: #16362e;
  --amber: #ffc56a;
  --amber-soft: #3a2d16;
  --rose: #ff8a9a;
  --rose-soft: #3a1c23;
  --blue: #8cb6f0;
  --blue-soft: #1b2a40;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.75;
  min-height: 100vh;
}
.ltr, .katex, .katex-display, code, pre, .math, input, select, .result-grid {
  direction: ltr;
  unicode-bidi: isolate;
}
.katex-display { overflow-x: auto; overflow-y: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button, input, select { font-family: inherit; }

.skip-link {
  position: absolute; right: 12px; top: -40px; background: var(--accent); color: #06281f;
  padding: 6px 10px; border-radius: 8px; z-index: 100;
}
.skip-link:focus { top: 12px; }

.header {
  position: sticky; top: 0; z-index: 40;
  height: var(--header);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font-weight: 700; }
.brand:hover { text-decoration: none; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #1a9cff);
  display: grid; place-items: center; color: #04251c; font-weight: 800; font-size: 14px;
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn, .menu-btn {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink);
  width: 40px; height: 40px; border-radius: 12px; cursor: pointer;
}
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: calc(100vh - var(--header)); }
.sidebar {
  border-left: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 16px 12px 48px;
  position: sticky; top: var(--header);
  height: calc(100vh - var(--header));
  overflow: auto;
}
.nav-section { margin-bottom: 18px; }
.nav-section h3 {
  margin: 0 8px 6px; font-size: 11px; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 600;
}
.nav-section a, .nav-section .nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 10px; color: var(--ink-soft); text-decoration: none;
  font-size: 14px;
}
.nav-section a:hover { background: var(--bg-soft); text-decoration: none; }
.nav-section a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.progress-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: 0 0 auto; }
.progress-dot.done { background: var(--accent); }

.content { padding: 28px 28px 80px; max-width: 920px; }
.hero {
  background: linear-gradient(160deg, var(--bg-elev), var(--accent-soft));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.hero h1 { margin: 0 0 8px; font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.4; }
.hero p { margin: 0; color: var(--ink-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.chip {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--ink-soft);
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-top: 0; }
.muted { color: var(--muted); }
.kicker { color: var(--accent); font-weight: 700; font-size: 13px; margin: 0 0 6px; }

.subpoint {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 20px 16px;
  margin: 28px 0;
  box-shadow: var(--shadow);
}
.subpoint > h2 { margin-top: 0; font-size: 1.35rem; }
.subpoint .idea, .subpoint .circuit, .subpoint .waveforms, .subpoint .formulas, .subpoint .examples {
  margin: 14px 0;
}
.placeholder {
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--ink-soft);
  font-size: 14.5px;
}

.practice {
  margin-top: 22px;
  padding-top: 8px;
  border-top: 2px solid var(--accent-soft);
}
.practice-title {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 0 6px; font-size: 1.05rem;
}
.practice-title .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.q-card {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 10px 0 14px;
}
.q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag {
  font-size: 11px; border-radius: 999px; padding: 2px 8px; font-weight: 600;
  background: var(--blue-soft); color: var(--blue);
}
.tag.marks { background: var(--amber-soft); color: var(--amber); }
.tag.sheet { background: var(--accent-soft); color: var(--accent); }
.freq { background: var(--rose-soft); color: var(--rose); }
.q-body { margin: 0 0 10px; }
.sol-btn {
  background: var(--accent); color: #06281f; border: 0; border-radius: 10px;
  padding: 7px 12px; font-weight: 700; cursor: pointer;
}
html[data-theme="dark"] .sol-btn { color: #04251c; }
.sol-btn[aria-expanded="true"] { background: var(--bg-soft); color: var(--ink); border: 1px solid var(--line); }
.solution {
  display: none;
  margin-top: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.solution.open { display: block; }
.solution h4 { margin: 0 0 6px; }

.mark-done {
  margin-top: 8px;
  background: transparent; color: var(--accent); border: 1px dashed var(--accent);
  border-radius: 10px; padding: 6px 10px; cursor: pointer; font-weight: 600;
}
.mark-done.done { background: var(--accent-soft); border-style: solid; }

.calc-wrap { display: grid; gap: 16px; }
.calc-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.field label { font-weight: 600; }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  background: var(--bg); color: var(--ink);
}
.calc-form .wide { grid-column: 1 / -1; }
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.result {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.result .label { font-size: 12px; color: var(--muted); }
.result .value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.note { background: var(--amber-soft); color: var(--ink); border-radius: 12px; padding: 10px 12px; font-size: 14px; }

.formulas-block { margin: 22px 0; }
.formulas-block h2 { border-bottom: 1px solid var(--line); padding-bottom: 6px; }

.toc a { display: block; padding: 4px 0; }

.footer {
  margin-top: 40px; color: var(--muted); font-size: 13px;
  border-top: 1px solid var(--line); padding-top: 16px;
}

@media (max-width: 900px) {
  .menu-btn { display: inline-grid; place-items: center; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: var(--header) 0 0 auto;
    width: min(86vw, var(--sidebar));
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    z-index: 30;
    box-shadow: var(--shadow);
  }
  html[dir="rtl"] .sidebar { transform: translateX(110%); }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 18px 14px 80px; }
  .backdrop { display: none; position: fixed; inset: var(--header) 0 0 0; background: rgba(0,0,0,.35); z-index: 25; }
  .backdrop.show { display: block; }
}
