/* ═══════════════════════════════════════════════════════
   Ta3laM Power BI — Editorial Course Shell
   ═══════════════════════════════════════════════════════ */

:root {
  --bg:        #0A1017;
  --bg-1:      #0F1923;
  --bg-2:      #131F2B;
  --bg-3:      #1A2836;
  --line:      #1E2D3D;
  --line-2:    #2A3A4D;

  --ink:       #ECEFF3;
  --ink-2:     #A8B2BF;
  --ink-3:     #6A7685;
  --ink-4:     #3E4A59;

  --gold:      #F5A623;
  --gold-soft: rgba(245,166,35,.12);
  --gold-line: rgba(245,166,35,.35);
  --teal:      #00B4D8;
  --teal-soft: rgba(0,180,216,.12);
  --coral:     #E85D4A;
  --violet:    #A17BFF;
  --grass:     #3FD37A;

  --accent:     var(--gold);
  --accent-soft: var(--gold-soft);
  --accent-ink:  #000;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --r-xl: 22px;

  --display-ar: "Alexandria", "Plus Jakarta Sans", "Cairo", system-ui, sans-serif;
  --display-en: "Inter", "Plus Jakarta Sans", system-ui, sans-serif;
  --serif: var(--display-ar);
  --sans:  var(--display-ar);
  --mono:  "JetBrains Mono", "Fira Code", ui-monospace, monospace;

  --sidebar-w: 352px;
  --reader-max: 850px;
  --reader-pad-near: 22px;
  --reader-pad-far: 40px;

  --density: 1;
}

[data-density="compact"] { --density: .82; }
[data-density="cozy"]    { --density: 1; }
[data-density="spacious"] { --density: 1.18; }

html.lang-en {
  --serif: var(--display-en);
  --sans: var(--display-en);
}

[data-accent="gold"] { --accent: #F5A623; --accent-soft: rgba(245,166,35,.12); --accent-ink: #000; }
[data-accent="teal"] { --accent: #00B4D8; --accent-soft: rgba(0,180,216,.13); --accent-ink: #001b22; }
[data-accent="dual"] { --accent: #F5A623; --accent-soft: rgba(0,180,216,.12); --accent-ink: #000; }

/* Light mode */
html[data-theme="light"] {
  --bg:        #FFFFFF;
  --bg-1:      #F8F9FB;
  --bg-2:      #F0F3F7;
  --bg-3:      #E8EDF3;
  --line:      #E2E8F0;
  --line-2:    #CBD5E0;

  --ink:       #1A202C;
  --ink-2:     #4A5568;
  --ink-3:     #718096;
  --ink-4:     #A0AEC0;

  --gold-soft: rgba(245,166,35,.08);
  --gold-line: rgba(245,166,35,.2);
  --teal-soft: rgba(0,180,216,.08);
}

/* Light mode element-specific overrides */
html[data-theme="light"] .sidebar {
  background: linear-gradient(180deg, rgba(248,249,251,.95), rgba(255,255,255,.98));
}

html[data-theme="light"] .reader-topbar {
  background: rgba(248,249,251,.8);
}

html[data-theme="light"] .tweaks {
  background: rgba(240,243,247,.95);
  box-shadow: 0 20px 60px rgba(0,0,0,.1);
}

html[data-theme="light"] .lesson-item:hover {
  background: rgba(0,0,0,.04);
}

html[data-theme="light"] .lesson-item:hover .lesson-title {
  color: var(--ink);
}

/* Certificate modal light mode */
html[data-theme="light"] #certificateModal {
  background: rgba(255,255,255,0.96) !important;
}

html[data-theme="light"] #certificateCard {
  background: var(--bg-1) !important;
  border-color: var(--accent) !important;
}

html[data-theme="light"] #certHeading {
  color: var(--accent) !important;
}

html[data-theme="light"] #certSubheading {
  color: var(--ink-2) !important;
}

html[data-theme="light"] #certCourseTitle {
  color: var(--ink) !important;
}

html[data-theme="light"] #certNameInput {
  background: var(--bg-2) !important;
  border-color: var(--line) !important;
  color: var(--ink) !important;
}

html[data-theme="light"] #certNameInput::placeholder {
  color: var(--ink-3) !important;
}

html[data-theme="light"] #certDate,
html[data-theme="light"] #certDateLabel {
  color: var(--ink-2) !important;
}

/* Light mode code syntax highlighting */
html[data-theme="light"] .tk-cm {
  color: #5A7085 !important;
}

html[data-theme="light"] .copy-btn {
  color: var(--ink-2) !important;
}

html[data-theme="light"] .search-input::placeholder {
  color: #5A7085 !important;
}

html[data-theme="light"] .eyebrow {
  color: #5A7085 !important;
}

html[data-theme="light"] .lesson-meta {
  color: #6A7685 !important;
}

html[data-theme="light"] .lesson-kind {
  background: #8A98A8 !important;
}

/* Light mode: fix hardcoded dark gradient backgrounds on reader cards */
html[data-theme="light"] .lesson-path {
  background: var(--bg-2) !important;
  border-color: var(--line) !important;
}

html[data-theme="light"] .chapter-gateway,
html[data-theme="light"] .chapter-checkpoint {
  background: var(--bg-2) !important;
  border-color: var(--line) !important;
}

html[data-theme="light"] .lesson-outline,
html[data-theme="light"] .lesson-wrap {
  background: var(--bg-2) !important;
  border-color: var(--line) !important;
}

html[data-theme="light"] .lesson-outline-item,
html[data-theme="light"] .lesson-wrap-card,
html[data-theme="light"] .lesson-wrap-checklist {
  background: var(--bg-1) !important;
  border-color: var(--line) !important;
}

html[data-theme="light"] .chapter-gateway-stat {
  background: var(--bg-1) !important;
  border-color: var(--line) !important;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.75;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: #E85D4A;
  border-radius: 6px;
  border: 2px solid #0A1017;
}

::-webkit-scrollbar-thumb:hover {
  background: #D94830;
}

/* Light mode scrollbar */
html[data-theme="light"] ::-webkit-scrollbar-track {
  background: var(--bg);
}

html[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #CBD5E0;
  border: 2px solid #FFFFFF;
}

html[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: #A0AEC0;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

/* Shell grid */
.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-w);
  grid-template-areas: "reader sidebar";
  direction: ltr; /* explicit LTR so the lesson list stays on the right */
  height: 100vh;
  position: relative;
}

/* ───────────── Backdrop ───────────── */
.backdrop {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .55;
}
.backdrop svg { width: 100%; height: 100%; display: block; }
body.no-backdrop .backdrop { display: none; }

.grain {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: .06;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='200' height='200' filter='url(%23n)' opacity='.8'/></svg>");
  mix-blend-mode: overlay;
}
body.no-grain .grain { display: none; }

/* ───────────── Sidebar ───────────── */
.sidebar {
  grid-area: sidebar;
  direction: rtl;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(15,25,35,.92), rgba(10,16,23,.98));
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  padding: 22px 22px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.brand-mark {
  width: 120px; height: 120px;
  border-radius: 0;
  display: grid; place-items: center;
  position: relative;
  overflow: hidden;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.brand-text .name {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.2px;
}
.brand-text .name em { color: var(--accent); font-style: normal; }
.brand-text .tagline {
  font-size: 10.5px;
  color: var(--ink-3);
  letter-spacing: .16em;
  text-transform: uppercase;
  margin-top: 3px;
}

/* Sidebar progress rail */
.rail {
  padding: 14px 22px 18px;
  border-bottom: 1px solid var(--line);
}
.rail-top {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px;
}
.rail-label { font-size: 10.5px; color: var(--ink-3); letter-spacing: .15em; text-transform: uppercase; }
.rail-val { font-family: var(--serif); font-size: 22px; color: var(--accent); font-weight: 500; }
.rail-val span { color: var(--ink-3); font-size: 14px; }
.rail-bar {
  height: 2px; background: var(--line-2); border-radius: 2px; overflow: hidden;
  position: relative;
}
@keyframes progressPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .7; }
}

.rail-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), color-mix(in oklab, var(--accent), white 20%));
  width: 0%;
  transition: width .5s cubic-bezier(.34,.1,.68,.55);
  box-shadow: 0 0 12px var(--accent), inset 0 0 6px rgba(255,255,255,.3);
  animation: progressPulse 3s ease-in-out infinite;
}

/* Chapter list */
.toc {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 0 40px;
  direction: ltr;
  scrollbar-gutter: stable;
}

.toc::-webkit-scrollbar {
  width: 8px;
}

.toc::-webkit-scrollbar-track {
  background: transparent;
}

.toc::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 4px;
  border: 2px solid transparent;
}

.chapter {
  padding: 0 16px;
  margin-bottom: 6px;
  direction: rtl;
}
.chapter-head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 12px 8px 8px;
  cursor: pointer;
  user-select: none;
  position: relative;
  direction: rtl;
}
.chapter-num {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: .08em;
  min-width: 22px;
}
.chapter-title {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}
.chapter-sub {
  font-size: 9.5px;
  color: var(--ink-3);
  letter-spacing: .04em;
  text-transform: none;
  margin-top: 2px;
  font-family: var(--sans);
  line-height: 1.45;
}
.chapter-count {
  font-size: 10.5px;
  font-family: var(--mono);
  color: var(--ink-3);
  background: var(--bg-3);
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--line);
}
.chapter.open .chapter-count { color: var(--accent); border-color: var(--gold-line); }

.chapter-chev {
  color: var(--ink-3);
  font-size: 10px;
  transition: transform .3s ease;
}
.chapter.open .chapter-chev { transform: rotate(-90deg); color: var(--accent); }

.chapter-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .4s cubic-bezier(.2,.8,.2,1);
  direction: rtl;
}
.chapter.open .chapter-body { max-height: 1200px; }

.lesson-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 7px 12px 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s ease;
  position: relative;
  direction: rtl;
}
.lesson-item:hover { background: rgba(255,255,255,.03); }
.lesson-item.active {
  background: var(--accent-soft);
}
.lesson-item.active::before {
  content: "";
  position: absolute;
  right: -16px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 22px;
  background: var(--accent);
  border-radius: 3px 0 0 3px;
}
.lesson-idx {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-3);
  text-align: center;
}
.lesson-item.done .lesson-idx { color: var(--grass); }
.lesson-item.active .lesson-idx { color: var(--accent); }
.lesson-title {
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.4;
}
.lesson-item.active .lesson-title { color: var(--ink); font-weight: 600; }
.lesson-item.done .lesson-title { color: var(--ink-3); }
.lesson-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-4);
}

.lesson-kind {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--ink-4);
}
.lesson-kind[data-k="concept"]   { background: var(--teal); }
.lesson-kind[data-k="practice"]  { background: var(--accent); }
.lesson-kind[data-k="theory"]    { background: var(--violet); }
.lesson-kind[data-k="code"]      { background: var(--coral); }
.lesson-kind[data-k="reference"] { background: var(--ink-3); }

/* Sidebar search */
.search {
  padding: 12px 22px 8px;
  border-bottom: 1px solid var(--line);
}
.search-input {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px 9px 34px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft), inset 0 0 0 1px var(--accent-soft);
}
.search-input::placeholder { color: var(--ink-3); }
.search-wrap { position: relative; }
.search-wrap::before {
  content: "⌕";
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: 15px;
  pointer-events: none;
}

/* ───────────── Reader (main) ───────────── */
.reader {
  grid-area: reader;
  min-width: 0;
  min-height: 0;
  direction: ltr;
  overflow-y: scroll;
  overflow-x: hidden;
  position: relative;
  z-index: 5;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  scroll-behavior: auto;
}
.reader::-webkit-scrollbar { width: 8px; }
.reader::-webkit-scrollbar-track { background: transparent; }
.reader::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 4px; }

.reader-topbar {
  position: sticky; top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 40px 14px;
  backdrop-filter: blur(18px);
  background: rgba(10,16,23,.72);
  border-bottom: 1px solid var(--line);
  direction: rtl;
}
.crumb {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: .08em;
  min-width: 0;
}
.crumb b { color: var(--ink-2); font-weight: 500; }
.topbar-spacer { flex: 1; }
.topbar-btn {
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--ink-2);
  border: 1px solid var(--line);
  transition: all .15s;
  display: flex; align-items: center; gap: 6px;
}
.topbar-btn:hover { border-color: var(--accent); color: var(--ink); }
.topbar-btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}
.topbar-btn.primary:hover { opacity: .92; }

.reading-progress {
  position: sticky; top: 54px;
  z-index: 19;
  height: 1px;
  background: var(--line);
}
.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent), 0 0 24px color-mix(in oklab, var(--accent), white 30%);
  transition: width .15s cubic-bezier(.25,.46,.45,.94);
}

/* Lesson container */
.lesson {
  max-width: var(--reader-max);
  margin-block: 0;
  margin-inline-start: 0;
  margin-inline-end: auto;
  padding-block: calc(56px * var(--density)) calc(120px * var(--density));
  padding-inline: var(--reader-pad-near) var(--reader-pad-far);
  animation: fadeIn .18s ease-out;
  direction: rtl;
  text-align: right;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: .2em;
  text-transform: uppercase;
  margin-bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.eyebrow::before {
  content: "";
  display: block; width: 22px; height: 1px;
  background: var(--accent);
}

h1.lesson-h1 {
  font-family: var(--serif);
  font-size: clamp(30px, 4.2vw, 50px);
  line-height: 1.02;
  font-weight: 500;
  letter-spacing: -.028em;
  margin-bottom: 22px;
  white-space: nowrap;
  text-wrap: nowrap;
}
h1.lesson-h1 :is(em, .title-accent) {
  color: var(--accent);
  font-style: normal;
  font-size: 1em;
}

.lede {
  font-family: var(--serif);
  font-size: clamp(18px, 1.8vw, 22px);
  line-height: 1.55;
  color: var(--ink-2);
  max-width: 620px;
  margin-bottom: 48px;
  font-weight: 400;
  font-style: normal;
  text-wrap: pretty;
}

.lesson-path {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background:
    linear-gradient(180deg, rgba(19,31,43,.88), rgba(15,25,35,.66));
  padding: 18px 18px 16px;
  margin-bottom: 34px;
}

.lesson-path-top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.lesson-path-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--gold-line);
  background: var(--accent-soft);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .08em;
}

.lesson-path-pill.subtle {
  background: transparent;
  border-color: var(--line-2);
  color: var(--ink-2);
}

.lesson-path-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.lesson-path-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}

.lesson-path-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.lesson-path-card p {
  margin: 0;
  font-size: 14.2px;
  line-height: 1.75;
  color: var(--ink-2);
}

.lesson-path-note {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--ink-2);
}

.lesson-path-note strong {
  color: var(--ink);
}

.chapter-gateway,
.chapter-checkpoint {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background:
    linear-gradient(180deg, rgba(17,29,39,.82), rgba(13,22,31,.62));
  padding: 22px 22px 18px;
  margin-bottom: 26px;
}

.chapter-gateway-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.chapter-gateway-kicker {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.chapter-gateway-title {
  margin: 0;
  padding: 0;
  position: static;
  font-family: var(--serif);
  font-size: clamp(18px, 2.5vw, 22px);
  font-weight: 500;
  line-height: 1.15;
  color: var(--ink);
  white-space: nowrap;
}

.chapter-gateway-title::before {
  content: none;
}

.chapter-gateway-stat {
  min-width: 142px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.03);
}

.chapter-gateway-stat span {
  display: block;
  margin-bottom: 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.chapter-gateway-stat strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
  color: var(--ink);
}

.chapter-gateway-lede {
  margin: 0 0 16px;
  font-size: 15.5px;
  line-height: 1.85;
  color: var(--ink-2);
}

.chapter-gateway-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

.chapter-gateway-list {
  margin: 0;
  padding: 0 18px 0 0;
  display: grid;
  gap: 10px;
  color: var(--ink-2);
}

html.lang-en .chapter-gateway-list {
  padding: 0 0 0 18px;
}

.chapter-gateway-list li {
  line-height: 1.8;
}

.chapter-checkpoint {
  margin-top: 34px;
  margin-bottom: 0;
  border-style: dashed;
}

.chapter-checkpoint-note {
  margin: 14px 0 0;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink-2);
}

.chapter-checkpoint-note strong {
  color: var(--ink);
}

.lesson-outline,
.lesson-wrap {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(16,27,37,.72), rgba(11,19,27,.54));
  padding: 18px 18px 16px;
  margin-bottom: 26px;
}

.lesson-outline-list {
  display: grid;
  gap: 10px;
}

.lesson-outline-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}

.lesson-outline-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
  color: var(--ink-2);
  line-height: 1.75;
}

.lesson-outline-num {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .12em;
  color: var(--accent);
  margin-top: 2px;
}

.lesson-wrap-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.lesson-wrap-card,
.lesson-wrap-checklist {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.02);
  padding: 14px 16px;
}

.lesson-wrap-card-wide {
  grid-column: 1 / -1;
}

.lesson-wrap-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.lesson-wrap-card p,
.lesson-wrap-checklist li {
  margin: 0;
  font-size: 14.2px;
  line-height: 1.8;
  color: var(--ink-2);
}

.lesson-wrap-checklist {
  margin-top: 12px;
}

.lesson-wrap-checklist ul {
  margin: 0;
  padding: 0 18px 0 0;
  display: grid;
  gap: 10px;
}

html.lang-en .lesson-wrap-checklist ul {
  padding: 0 0 0 18px;
}

/* Lesson meta strip */
.meta-strip {
  display: flex; align-items: center; gap: 32px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 56px;
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--mono);
  letter-spacing: .08em;
}
.meta-item { display: flex; align-items: center; gap: 8px; }
.meta-item b { color: var(--ink); font-weight: 500; font-family: var(--sans); letter-spacing: 0; }
.meta-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-4); }

/* Body — h2 */
.lesson h2 {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -.015em;
  margin: 56px 0 18px;
  line-height: 1.2;
  position: relative;
  padding-right: 20px;
}
.lesson h2::before {
  content: "§";
  position: absolute;
  right: -4px;
  top: 4px;
  color: var(--accent);
  font-size: 18px;
  opacity: .6;
}

.lesson p {
  font-size: 16.5px;
  color: var(--ink-2);
  line-height: 1.9;
  margin-bottom: 20px;
  text-wrap: pretty;
}

.lesson ul.bullets {
  list-style: none;
  padding: 0;
  margin: 0 0 28px;
}
.lesson ul.bullets li {
  position: relative;
  padding: 9px 22px 9px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 15.5px;
  color: var(--ink-2);
}
.lesson ul.bullets li:last-child { border-bottom: 0; }
.lesson ul.bullets li::before {
  content: "";
  position: absolute;
  right: 0; top: 20px;
  width: 10px; height: 1px;
  background: var(--accent);
}

/* Callouts */
.callout {
  border-right: 2px solid var(--accent);
  padding: 18px 22px 18px 22px;
  margin: 28px 0;
  background: linear-gradient(90deg, var(--accent-soft) 0%, transparent 85%);
  border-radius: 0 2px 2px 0;
  position: relative;
}
.callout.tone-warn  { border-right-color: var(--coral); background: linear-gradient(90deg, rgba(232,93,74,.1), transparent 85%); }
.callout.tone-note  { border-right-color: var(--teal);  background: linear-gradient(90deg, var(--teal-soft), transparent 85%); }
.callout-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 600;
}
.callout.tone-warn .callout-label { color: var(--coral); }
.callout.tone-note .callout-label { color: var(--teal); }
.callout-title {
  font-family: var(--serif);
  font-size: 19px;
  margin-bottom: 6px;
  color: var(--ink);
}
.callout-body { font-size: 14.5px; color: var(--ink-2); line-height: 1.75; margin: 0; }

/* Triple grid */
.triple {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  margin: 28px 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.triple-cell {
  background: var(--bg-1);
  padding: 22px 20px;
  position: relative;
  transition: background .2s;
}
.triple-cell:hover { background: var(--bg-2); }
.triple-tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  font-weight: 600;
}
.triple-title {
  font-family: var(--serif);
  font-size: 20px;
  margin-bottom: 8px;
  font-weight: 500;
}
.triple-body { font-size: 13.5px; color: var(--ink-2); line-height: 1.7; margin: 0; }

/* Compare */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  margin: 32px 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
.compare-side {
  background: var(--bg-1);
  padding: 26px 22px;
}
.compare-side.left  { border-right: 2px solid var(--accent); }
.compare-side.right { border-right: 2px solid var(--teal); }
.compare-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 16px;
  font-weight: 600;
}
.compare-side.right .compare-title { color: var(--teal); }
.compare-side ul { list-style: none; padding: 0; }
.compare-side li {
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14.5px;
  color: var(--ink-2);
}
.compare-side li:last-child { border-bottom: 0; }

/* Pull quote */
.pullquote {
  margin: 48px 0;
  padding: 32px 28px 28px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
  position: relative;
}
.pullquote::before {
  content: "\201D";
  font-family: var(--serif);
  font-size: 120px;
  color: var(--accent);
  opacity: .2;
  position: absolute;
  right: 16px;
  top: -8px;
  line-height: 1;
}
.pullquote-text {
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1.4;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 14px;
  font-style: normal;
  text-wrap: balance;
}
.pullquote-by {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* Code block */
.code {
  direction: ltr;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin: 24px 0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.85;
  position: relative;
  overflow: hidden;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.code-dots {
  display: inline-flex; gap: 5px;
}
.code-dots span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-4);
}
.code-dots span:nth-child(1) { background: #E85D4A; }
.code-dots span:nth-child(2) { background: #F5A623; }
.code-dots span:nth-child(3) { background: #3FD37A; }
.code-body {
  padding: 18px 20px;
  overflow-x: auto;
  white-space: pre;
}
.tk-kw  { color: var(--accent); font-weight: 600; }
.tk-fn  { color: var(--teal); }
.tk-str { color: var(--grass); }
.tk-cm  { color: var(--ink-3); font-style: normal; }
.tk-num { color: var(--coral); }

.copy-btn {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-3);
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  transition: all .15s;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--grass); border-color: var(--grass); }

/* Shortcuts in stub */
.shortcuts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 20px 0 0;
}
.shortcut {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all .2s;
  background: var(--bg-1);
}
.shortcut:hover { border-color: var(--accent); background: var(--bg-2); }
.shortcut-num {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
}
.shortcut-title {
  font-size: 14px;
  color: var(--ink);
}

/* Lesson footer nav */
.lesson-footer {
  max-width: var(--reader-max);
  margin-top: 60px;
  margin-bottom: 0;
  margin-inline-start: 0;
  margin-inline-end: auto;
  padding-block: 32px 48px;
  padding-inline: var(--reader-pad-near) var(--reader-pad-far);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: stretch;
  direction: rtl;
}
.foot-nav {
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  text-align: right;
  transition: all .2s;
  cursor: pointer;
  display: block;
}
.foot-nav.empty { visibility: hidden; }
.foot-nav:hover { border-color: var(--accent); background: var(--bg-1); }
.foot-nav.prev { text-align: left; }
.foot-arrow {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.foot-title {
  font-family: var(--serif);
  font-size: 18px;
  color: var(--ink);
}
.foot-cta {
  background: var(--accent);
  color: var(--accent-ink);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  padding: 18px 26px;
  font-weight: 600;
  font-size: 14px;
  display: flex; align-items: center; gap: 10px;
  justify-content: center;
  transition: all .2s;
}
.foot-cta:hover { opacity: .92; transform: translateY(-1px); }
.foot-cta[disabled] {
  opacity: .58;
  cursor: not-allowed;
}
.foot-cta[disabled]:hover { opacity: .58; transform: none; }

/* ───────────── Tweaks panel ───────────── */
.tweaks {
  position: fixed;
  bottom: 20px; left: 20px;
  width: 280px;
  background: rgba(15,25,35,.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 18px 18px 16px;
  z-index: 100;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  display: none;
  animation: fadeIn .3s ease-out;
  direction: rtl;
}
.tweaks.open { display: block; }
.tweaks-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.tweaks-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
.tweaks-close { color: var(--ink-3); font-size: 18px; }
.tweaks-row {
  margin-bottom: 14px;
}
.tweaks-row:last-child { margin-bottom: 0; }
.tweaks-label {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: .05em;
  margin-bottom: 8px;
  display: block;
}
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  padding: 6px 4px;
  font-size: 11px;
  color: var(--ink-2);
  border-radius: 5px;
  transition: all .15s;
}
.seg button.on {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.sw {
  position: relative;
  width: 34px; height: 18px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  cursor: pointer;
  transition: all .2s;
}
.sw::after {
  content: ""; position: absolute;
  top: 2px; right: 2px;
  width: 12px; height: 12px;
  background: var(--ink-3);
  border-radius: 50%;
  transition: all .2s;
}
.sw.on { background: var(--accent); border-color: var(--accent); }
.sw.on::after { background: var(--accent-ink); right: 18px; }

.tweaks-switch-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0;
  border-top: 1px dashed var(--line);
}
.tweaks-switch-row:first-of-type { border-top: 0; }

/* Tweaks toggle in topbar */
#tweaksToggle {
  display: none;
}
body.tweaks-available #tweaksToggle { display: flex; }

/* Language toggle button */
.lang-toggle {
  min-width: 40px;
  font-weight: 600;
  font-size: 10px;
  letter-spacing: .08em;
}

/* RTL/LTR mode switching */
html.lang-en .lesson { direction: ltr; text-align: left; }
html.lang-en .reader-topbar,
html.lang-en .lesson-footer { direction: ltr; }
html.lang-en .chapter,
html.lang-en .chapter-head,
html.lang-en .chapter-body,
html.lang-en .lesson-item { direction: ltr; }
html.lang-en .chapter-title { font-size: 15.5px; }
html.lang-en .chapter-sub { font-size: 11px; }
html.lang-en .lesson-title { font-size: 15.5px; }
html.lang-en .lesson-meta { font-size: 11.5px; }
html.lang-en .search-input { font-size: 15.5px; }
html.lang-en .crumb { font-size: 12.5px; }
html.lang-en .topbar-btn { font-size: 13.5px; }
html.lang-en .eyebrow { font-size: 13px; }
html.lang-en h1.lesson-h1 { font-size: clamp(34px, 4.8vw, 58px); }
html.lang-en .lede { font-size: clamp(22px, 2.1vw, 26px); }
html.lang-en .meta-strip { font-size: 14px; }
html.lang-en .lesson h2 { font-size: 34px; }
html.lang-en .lesson p { font-size: 19.5px; }
html.lang-en .lesson ul.bullets li { font-size: 18.5px; }
html.lang-en .lesson-path-card p { font-size: 16.2px; }
html.lang-en .lesson-path-note { font-size: 15px; }
html.lang-en .chapter-gateway-lede { font-size: 16.2px; }
html.lang-en .chapter-gateway-list li { font-size: 15.6px; }
html.lang-en .chapter-checkpoint-note { font-size: 15px; }
html.lang-en .lesson-outline-item { font-size: 15.4px; }
html.lang-en .lesson-wrap-card p,
html.lang-en .lesson-wrap-checklist li { font-size: 15.3px; }
html.lang-en .callout-title { font-size: 23px; }
html.lang-en .callout-body { font-size: 17.5px; }
html.lang-en .triple-title { font-size: 24px; }
html.lang-en .triple-body { font-size: 16.5px; }
html.lang-en .compare-side li { font-size: 17px; }
html.lang-en .pullquote-text { font-size: 30px; }
html.lang-en .code { font-size: 15px; }
html.lang-en .code-head { font-size: 12px; }
html.lang-en .shortcut-title { font-size: 16.5px; }
html.lang-en .shortcut-num { font-size: 12.5px; }
html.lang-en .foot-arrow { font-size: 12.5px; }
html.lang-en .foot-title { font-size: 22px; }
html.lang-en .callout { border-right: none; border-left: 2px solid var(--accent); background: linear-gradient(90deg, transparent 0%, var(--accent-soft) 85%); border-radius: 2px 0 0 2px; padding: 18px 22px 18px 22px; }
html.lang-en .callout.tone-warn { border-left-color: var(--coral); }
html.lang-en .callout.tone-note { border-left-color: var(--teal); }
html.lang-en .lesson h2 { padding-right: 0; padding-left: 20px; }
html.lang-en .lesson h2::before { right: auto; left: -4px; }
html.lang-en .lesson ul.bullets li { padding: 9px 0 9px 22px; }
html.lang-en .lesson ul.bullets li::before { right: auto; left: 0; }
html.lang-en .foot-nav { text-align: left; }
html.lang-en .foot-nav.prev { text-align: right; }

/* Micro-headings should read like labels, not code. */
html :is(
  .crumb,
  .eyebrow,
  .lesson-path-pill,
  .lesson-path-label,
  .chapter-gateway-kicker,
  .chapter-gateway-stat span,
  .chapter-gateway-label,
  .lesson-outline-label,
  .lesson-wrap-title,
  .callout-label,
  .triple-tag,
  .compare-title,
  .pullquote-by
) {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.55;
}

html .chapter-gateway-kicker {
  font-size: 13.5px;
}

/* Active lesson indicator flip for LTR */
html.lang-en .lesson-item.active::before {
  right: auto;
  left: -16px;
  border-radius: 0 3px 3px 0;
}
html.lang-en .tweaks {
  direction: ltr;
  left: auto;
  right: 20px;
}
html.lang-en .sw::after {
  right: auto;
  left: 2px;
}
html.lang-en .sw.on::after {
  right: auto;
  left: 18px;
}
.lesson-item.stub {
  opacity: .72;
}
.lesson-item.stub .lesson-title,
.lesson-item.stub .lesson-meta {
  color: var(--ink-3);
}
.lesson-item.stub.active {
  opacity: 1;
}

/* Responsive */
@media (max-width: 880px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas: "reader";
  }
  .sidebar {
    grid-area: unset;
    position: fixed;
    right: 0; top: 0; bottom: 0;
    width: 85%; max-width: 352px;
    transform: translateX(100%);
    transition: transform .3s;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }
  .reader { grid-area: reader; }
  .lesson { padding: 40px 20px 80px; }
  .lesson-footer { padding: 24px 20px 40px; grid-template-columns: 1fr; }
  .chapter-gateway,
  .chapter-checkpoint,
  .lesson-outline,
  .lesson-wrap,
  .lesson-path { padding: 16px 16px 14px; }
  .chapter-gateway-top { flex-direction: column; }
  .chapter-gateway-stat { min-width: 0; width: 100%; }
  .lesson-wrap-grid { grid-template-columns: 1fr; }
  .lesson-path-grid { grid-template-columns: 1fr; }
  .triple, .compare { grid-template-columns: 1fr; }
  .shortcuts { grid-template-columns: 1fr; }
  .tweaks { bottom: 10px; left: 10px; right: 10px; width: auto; }
  html.lang-en .tweaks { left: 10px; right: 10px; }
  h1.lesson-h1 {
    white-space: normal;
    text-wrap: balance;
    font-size: clamp(28px, 9vw, 42px);
    line-height: 1.08;
  }
  .reader-topbar {
    padding: 14px 16px;
    gap: 10px 8px;
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .reader-topbar .crumb {
    order: 1;
    width: 100%;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
    line-height: 1.5;
    white-space: normal;
  }
  #sidebarToggle { order: 2; }
  #topbarLangBtn { order: 3; }
  #tweaksToggle { order: 4; }
  #resetProgressBtn { order: 5; }
  #topbarQuizBtn {
    order: 6;
    flex: 1 1 100%;
    justify-content: center;
    margin-top: 2px;
  }
  .reader-topbar .topbar-spacer { display: none; }
  .reader-topbar .topbar-btn {
    padding: 7px 10px;
    font-size: 11px;
  }
  #resetProgressBtn {
    max-width: none;
    min-width: 88px;
    line-height: 1.15;
    white-space: nowrap;
    text-align: center;
  }
}
