/* ============================================================
   طريق الإنجليزية — editorial system (Linear/Vercel spirit,
   Arabic-first). Dark default, light via [data-theme="light"].
   ============================================================ */

:root {
  --bg: #090b11;
  --bg-soft: #0c0f17;
  --panel: #0e1119;
  --panel-2: #131826;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --ink: #e8ebf2;
  --muted: #9aa3b5;
  --faint: #6b7385;
  --cyan: #5eead4;
  --cyan-ink: #0b3b36;
  --violet: #a78bfa;
  --amber: #fbbf24;
  --danger: #fda4af;
  --glow-cyan: rgba(94, 234, 212, 0.14);
  --glow-violet: rgba(167, 139, 250, 0.16);
  --shadow: 0 18px 50px -18px rgba(0, 0, 0, 0.65);
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --font-ar: "IBM Plex Sans Arabic", "Inter", "Segoe UI", Tahoma, sans-serif;
  --font-latin: "Inter", "IBM Plex Sans Arabic", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --nav-h: 60px;
  --canvas-w: 78ch;
}

[data-theme="light"] {
  --bg: #fbfbf9;
  --bg-soft: #f3f4f2;
  --panel: #ffffff;
  --panel-2: #f4f5f3;
  --line: rgba(23, 24, 28, 0.1);
  --line-strong: rgba(23, 24, 28, 0.18);
  --ink: #17181d;
  --muted: #5b606e;
  --faint: #8a8fa0;
  --cyan: #0e7490;
  --cyan-ink: #ecfeff;
  --violet: #6d28d9;
  --amber: #b45309;
  --glow-cyan: rgba(14, 116, 144, 0.1);
  --glow-violet: rgba(109, 40, 217, 0.1);
  --shadow: 0 18px 45px -22px rgba(23, 24, 28, 0.25);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ar);
  font-size: 17.5px;
  line-height: 1.9;
  overflow-x: clip;
  transition: background 0.35s ease, color 0.35s ease;
}
::selection { background: rgba(94, 234, 212, 0.28); }
[data-theme="light"] ::selection { background: rgba(14, 116, 144, 0.18); }

h1, h2, h3, h4 { scroll-margin-top: calc(var(--nav-h) + 28px); }
a { color: inherit; }
img, svg { max-width: 100%; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ---------- ambient glow (single, quiet) ---------- */
.page-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(640px 300px at 50% -60px, var(--glow-cyan), transparent 70%),
    radial-gradient(760px 340px at 82% 4%, var(--glow-violet), transparent 70%);
}
[data-theme="light"] .page-glow { opacity: 0.8; }

/* ---------- progress ---------- */
.progress-track {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  height: 2px;
  z-index: 80;
  background: transparent;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--violet));
  border-radius: 2px;
}

/* ---------- glass nav ---------- */
.glass-nav {
  position: fixed;
  inset-block-start: 2px;
  inset-inline: 0;
  z-index: 70;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-block-end: 1px solid var(--line);
  transition: transform 0.3s ease, background 0.35s ease;
}
.glass-nav.is-hidden { transform: translateY(-110%); }
.nav-inner {
  max-width: 1180px;
  margin-inline: auto;
  min-height: var(--nav-h);
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}
.brand-word em { font-style: normal; color: var(--cyan); }
.brand-orbit {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel);
  flex: none;
}
.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 0 12px var(--glow-cyan);
}
.nav-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-inline-start: auto;
  color: var(--muted);
  font-size: 13.5px;
}
.nav-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 34ch;
  color: var(--ink);
  font-weight: 600;
}
.nav-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--faint); flex: none; }
.nav-time { white-space: nowrap; font-variant-numeric: tabular-nums; }
.nav-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.icon-btn:hover { border-color: var(--line-strong); transform: translateY(-1px); }
#themeToggle .ic-sun { display: none; }
[data-theme="light"] #themeToggle .ic-sun { display: block; }
[data-theme="light"] #themeToggle .ic-moon { display: none; }

.toc-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.toc-btn:hover { border-color: var(--line-strong); transform: translateY(-1px); }

/* ---------- shell + rail ---------- */
.shell {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin-inline: auto;
  padding: calc(var(--nav-h) + 40px) 20px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-content: center;
  gap: 24px;
}
.shell > * { min-width: 0; }
@media (min-width: 1120px) {
  .shell {
    grid-template-columns: 76px minmax(0, var(--canvas-w));
    column-gap: 48px;
    align-items: start;
  }
}
.level-rail { display: none; }
@media (min-width: 1120px) {
  .level-rail {
    display: block;
    position: sticky;
    top: calc(var(--nav-h) + 32px);
    align-self: start;
    padding-top: 6px;
    pointer-events: none; /* decorative only — never intercepts or touches text */
  }
}
.rail-line {
  position: absolute;
  inset-inline-start: 8px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.rail-fill {
  width: 100%;
  height: 0%;
  background: linear-gradient(180deg, var(--cyan), var(--violet));
}
.rail-levels { list-style: none; margin: 0; padding: 0; display: grid; gap: 22px; position: relative; }
.rail-levels li { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12.5px; font-family: var(--font-latin); }
.rail-levels i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  flex: none;
  position: relative;
}
.rail-levels li.is-on { color: var(--ink); }
.rail-levels li.is-on i { border-color: var(--cyan); box-shadow: 0 0 0 4px var(--glow-cyan); }
.rail-levels li.is-on i::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
}

/* ---------- canvas ---------- */
.canvas { min-width: 0; max-width: var(--canvas-w); width: 100%; margin-inline: auto; }
@media (min-width: 1120px) { .canvas { margin-inline: auto; } }
.article-body > *:first-child { margin-top: 0; }
.article-body {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* hero = first centered section with h1 */
.article-body > section[data-align="center"]:first-of-type {
  text-align: center;
  padding: clamp(28px, 6vw, 64px) clamp(16px, 4vw, 40px);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background:
    radial-gradient(420px 180px at 50% 0%, var(--glow-cyan), transparent 70%),
    linear-gradient(180deg, var(--panel), var(--bg-soft));
  box-shadow: var(--shadow);
  margin-bottom: 36px;
}
.article-body > section[data-align="center"]:first-of-type h1 {
  font-size: clamp(2.3rem, 6vw, 3.6rem);
  line-height: 1.35;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}
.article-body > section[data-align="center"]:first-of-type h3 {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
  font-size: clamp(1.02rem, 2.6vw, 1.3rem);
  line-height: 2;
  border: none;
  padding: 0;
}
.article-body > section[data-align="center"]:first-of-type h3::before { content: none; }

/* generic centered sections */
.article-body section[data-align="center"] > h2 {
  text-align: center;
  text-wrap: balance;
}
div[data-align="center"] { text-align: center; }

/* ---------- typography ---------- */
.article-body p {
  margin: 1.1em 0;
  max-width: 75ch;
  line-height: 1.95;
}
.article-body li { line-height: 1.95; }
.article-body strong { color: var(--ink); font-weight: 700; }
.article-body h2 {
  font-size: clamp(1.5rem, 3.4vw, 2rem);
  line-height: 1.7;
  margin: 2.4em 0 0.7em;
  padding-top: 0.4em;
  text-wrap: balance;
}
.article-body h3 {
  font-size: clamp(1.15rem, 2.6vw, 1.4rem);
  line-height: 1.9;
  margin: 2em 0 0.6em;
  padding-inline-start: 14px;
  border-inline-start: 2px solid var(--line-strong);
  text-wrap: balance;
}
.article-body h3:where(:has(.roman)) { border-color: var(--cyan); }
.article-body h4 {
  font-size: 1.05rem;
  margin: 1.6em 0 0.4em;
  color: var(--muted);
  font-weight: 600;
}
.article-body ul, .article-body ol { padding-inline-start: 1.4em; margin: 1em 0; }
.article-body li { margin: 0.35em 0; }
.article-body li::marker { color: var(--cyan); }

.article-body hr {
  border: none;
  margin: 3em auto;
  height: 1px;
  max-width: 420px;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
  position: relative;
}
.article-body hr::after {
  content: "";
  position: absolute;
  inset-inline-start: 50%;
  top: -3px;
  width: 7px;
  height: 7px;
  transform: translateX(50%) rotate(45deg);
  background: var(--panel);
  border: 1px solid var(--cyan);
}
html[dir="ltr"] .article-body hr::after { transform: translateX(-50%) rotate(45deg); }

/* ---------- source links as quiet buttons ---------- */
.article-body p > a[href^="http"] {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  direction: rtl;
  text-decoration: none;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 14.5px;
  font-weight: 600;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.article-body p > a[href^="http"]:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px var(--glow-cyan);
  transform: translateY(-1px);
}

/* ---------- resource cards (pre.text) ---------- */
.res-card {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  margin: 1.2em 0;
  overflow: hidden;
}
.res-card:hover { border-color: var(--line-strong); }
.res-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-block-end: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.res-dots { display: inline-flex; gap: 5px; }
.res-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.res-dots i:first-child { background: var(--cyan); }
.res-label {
  font-family: var(--font-mono);
  font-size: 12px;
  direction: ltr;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  color: var(--faint);
}
.res-copy {
  margin-inline-start: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  font-size: 12.5px;
  padding: 4px 10px;
  cursor: pointer;
  flex: none;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.res-copy:hover { color: var(--ink); border-color: var(--line-strong); }
.res-copy.is-ok { color: var(--cyan); border-color: var(--cyan); }
.res-card pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  background: transparent;
}
.res-card pre code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.9;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  direction: ltr;
  unicode-bidi: isolate;
  display: block;
  text-align: left;
  color: var(--ink);
}
/* ladder variant: the A1→B2 journey spine */
.res-card.is-ladder {
  border-color: color-mix(in srgb, var(--violet) 35%, var(--line));
  background:
    radial-gradient(360px 140px at 50% 0%, var(--glow-violet), transparent 70%),
    linear-gradient(180deg, var(--panel-2), var(--bg-soft));
}
.res-card.is-ladder pre code {
  text-align: center;
  font-family: var(--font-ar);
  font-size: 15.5px;
  font-weight: 600;
  line-height: 2.2;
}
/* plain-english variant */
.res-card.is-english { border-inline-start: 2px solid var(--cyan); }

/* bare pre fallback (before JS runs / no-JS) */
.article-body pre.text {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
  padding: 14px 16px;
  overflow-x: auto;
}
.article-body pre.text code {
  font-family: var(--font-mono);
  font-size: 13.5px;
  direction: ltr;
  unicode-bidi: isolate;
  display: block;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* real code */
.article-body code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: color-mix(in srgb, var(--cyan) 10%, var(--panel));
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 1px 7px;
  direction: ltr;
  unicode-bidi: isolate;
}
.res-card code, .article-body pre code { background: none; border: none; padding: 0; }
.codewrap { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; margin: 1.2em 0; background: #0b0e15; }
[data-theme="light"] .codewrap { background: #101319; }
.codewrap .code-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  color: #9aa3b5;
  font-family: var(--font-mono);
  font-size: 12px;
  border-block-end: 1px solid rgba(255, 255, 255, 0.08);
  direction: ltr;
}
.codewrap pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.codewrap pre code { color: #e8ebf2; font-size: 13.5px; direction: ltr; display: block; text-align: left; }

/* ---------- quotes ---------- */
.article-body blockquote {
  margin: 1.4em 0;
  padding: 12px 18px;
  border-inline-start: 2px solid var(--cyan);
  background: linear-gradient(90deg, var(--glow-cyan), transparent 65%);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
html[dir="rtl"] .article-body blockquote { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.article-body blockquote p { margin: 0.4em 0; color: var(--ink); }
.article-body blockquote p:first-child { margin-top: 0; }
.article-body blockquote p:last-child { margin-bottom: 0; }

/* ---------- mermaid journey ---------- */
.mermaid-card {
  border: 1px solid color-mix(in srgb, var(--cyan) 30%, var(--line));
  border-radius: var(--r-lg);
  background:
    radial-gradient(500px 200px at 50% 0%, var(--glow-cyan), transparent 70%),
    linear-gradient(180deg, var(--panel-2), var(--bg-soft));
  padding: clamp(14px, 3vw, 28px);
  margin: 2em 0;
  box-shadow: var(--shadow);
  overflow-x: auto;
}
.mermaid-card .mermaid-title {
  text-align: center;
  font-weight: 700;
  margin-bottom: 10px;
  font-size: 1.05rem;
}
.mermaid-card .mermaid { display: flex; justify-content: center; min-width: 560px; }
.mermaid-card .mermaid svg { max-width: 100%; height: auto; }
.mermaid-fallback { display: none; }

/* ---------- appendix TOC ---------- */
.appendix {
  margin-top: 4em;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  padding: clamp(20px, 4vw, 36px);
}
.appendix-head h2 { margin: 0.2em 0 0.3em; font-size: clamp(1.4rem, 3vw, 1.8rem); }
.appendix-head p { color: var(--muted); margin: 0 0 1em; font-size: 15px; }
.appendix-kicker {
  display: inline-block;
  font-size: 13px;
  color: var(--cyan);
  border: 1px solid color-mix(in srgb, var(--cyan) 40%, var(--line));
  border-radius: 999px;
  padding: 2px 12px;
  background: var(--glow-cyan);
}
.appendix-toc ul { list-style: none; margin: 0; padding: 0; }
/* Tree roadmap: strict single column — nested levels never fragment. */
.appendix-toc > ul { display: block; }
/* Level 1 — stations of the road: bold, separated, marked. */
.appendix-toc > ul > li {
  margin: 0;
  padding: 6px 0 10px;
  border-bottom: 1px solid var(--line);
}
.appendix-toc > ul > li:last-child { border-bottom: none; padding-bottom: 0; }
.appendix-toc > ul > li > a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--ink);
  font-weight: 700;
  font-size: 15.5px;
}
.appendix-toc > ul > li > a::before {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  align-self: center;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  box-shadow: 0 0 10px var(--glow-cyan);
}
/* Level 2 — branches off the right-hand guide (RTL). */
.appendix-toc > ul > li > ul {
  margin: 8px 6px 2px 0;
  padding-right: 16px;
  border-right: 1px solid var(--line);
}
.appendix-toc > ul > li > ul > li { margin: 1px 0; }
.appendix-toc > ul > li > ul > li > a {
  font-weight: 500;
  font-size: 14px;
  color: var(--muted);
}
/* Level 3 — leaves: muted, compact, further in. */
.appendix-toc > ul > li > ul > li > ul {
  margin: 2px 0 2px 0;
  padding-right: 14px;
  border-right: 1px dashed var(--line);
}
.appendix-toc > ul > li > ul > li > ul a {
  font-size: 13px;
  color: var(--faint);
  padding-top: 4px;
  padding-bottom: 4px;
  line-height: 1.7;
}
.appendix-toc a {
  display: block;
  text-decoration: none;
  color: var(--muted);
  font-size: 14.5px;
  padding: 7px 12px;
  border-radius: 9px;
  line-height: 1.8;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}
.appendix-toc a:hover {
  background: var(--panel-2);
  color: var(--cyan);
  transform: translateX(-4px);
}
html[dir="ltr"] .appendix-toc a:hover { transform: translateX(4px); }

/* pandoc default TOC ids */
#TOC ul { list-style: none; }

/* ---------- drawer (pure overlay — never a layout element) ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 1;
}
.scrim[hidden] { display: none !important; }
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  inset-inline-start: 0;
  height: 100vh;
  width: min(380px, 88vw);
  z-index: 9999;
  background: var(--panel);
  border-inline-end: 1px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  /* CLOSED by default: fully off-screen, unfocusable, inert to pointer */
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-110%); /* LTR: parked off the left edge */
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.32s;
  box-shadow: var(--shadow);
  will-change: transform;
}
html[dir="rtl"] .drawer {
  /* RTL: drawer docks to the right edge, so park it off the RIGHT edge */
  transform: translateX(110%);
}
/* OPEN state — wins over both directional rules by specificity */
.drawer.is-open,
.drawer.open,
html[dir="rtl"] .drawer.is-open,
html[dir="rtl"] .drawer.open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0s;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-block-end: 1px solid var(--line);
}
.drawer-head strong { display: block; font-size: 16px; }
.drawer-kicker { font-size: 12.5px; color: var(--cyan); }
.drawer-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 14px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--muted);
  background: var(--bg-soft);
}
.drawer-search input {
  flex: 1;
  border: none;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  min-width: 0;
}
.drawer-toc { flex: 1; overflow-y: auto; padding: 10px 14px 20px; }
.drawer-toc ul { list-style: none; margin: 0; padding: 0; }
.drawer-toc ul ul { padding-inline-start: 14px; border-inline-start: 1px solid var(--line); margin-inline-start: 5px; }
.drawer-toc a {
  display: block;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  padding: 7px 10px;
  border-radius: 8px;
  line-height: 1.8;
}
.drawer-toc a:hover { background: var(--panel-2); color: var(--ink); }
.drawer-toc a.is-active { color: var(--cyan); background: var(--glow-cyan); }
.drawer-toc li.is-hidden { display: none; }
.drawer-foot { padding: 10px 18px; border-block-start: 1px solid var(--line); color: var(--faint); font-size: 12.5px; }

/* ---------- toast + to-top ---------- */
.toast {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-start: 50%;
  transform: translateX(50%) translateY(10px);
  z-index: 10000;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--cyan);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}
.toast[hidden] { display: none !important; }
.toast.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(50%) translateY(0);
}
html[dir="ltr"] .toast { transform: translateX(-50%) translateY(10px); }
html[dir="ltr"] .toast.is-visible { transform: translateX(-50%) translateY(0); }
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); }

.to-top {
  position: fixed;
  inset-block-end: 22px;
  inset-inline-end: 22px;
  z-index: 60;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.to-top:hover { border-color: var(--cyan); transform: translateY(-2px); }

/* ---------- contact (navbar button + high-end modal) ---------- */
.nav-inner { flex-wrap: nowrap; }
.nav-actions { flex: none; }
#contactBtn { flex: none; }

#contactModalScrim {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(4, 6, 12, 0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, visibility 0s linear 0.28s;
}
#contactModalScrim.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.28s ease, visibility 0s linear 0s;
}

#contactModal {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 10000;
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.02) inset, 0 0 60px -18px var(--glow-cyan);
  padding: 28px 26px 26px;
  text-align: left;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -48%) scale(0.96);
  transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.28s;
  overflow: hidden;
}
#contactModal.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
  transition: opacity 0.28s ease, transform 0.32s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0s;
}
.contact-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(320px 140px at 50% 0%, var(--glow-cyan), transparent 70%),
    radial-gradient(280px 160px at 90% 20%, var(--glow-violet), transparent 70%);
}
.contact-kicker {
  position: relative;
  display: inline-block;
  font-family: var(--font-latin);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
  border: 1px solid color-mix(in srgb, var(--cyan) 40%, var(--line));
  background: var(--glow-cyan);
  border-radius: 999px;
  padding: 2px 12px;
  margin-bottom: 12px;
}
.contact-title {
  position: relative;
  margin: 0 0 8px;
  padding-right: 36px;
  font-family: var(--font-latin);
  font-size: 1.5rem;
  line-height: 1.3;
  letter-spacing: -0.01em;
}
.contact-sub {
  position: relative;
  margin: 0 0 18px;
  color: var(--muted);
  font-family: var(--font-latin);
  font-size: 14.5px;
  line-height: 1.7;
}
.contact-email-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 12px;
  padding: 11px 14px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--ink);
  direction: ltr;
  overflow-wrap: anywhere;
  margin-bottom: 16px;
}
.contact-email-card svg { color: var(--cyan); flex: none; }
.contact-cta {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--cyan) 45%, transparent);
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  color: #06090f;
  font-family: var(--font-latin);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 8px 32px -8px var(--glow-cyan), 0 0 24px -6px var(--glow-violet);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.contact-cta:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
  box-shadow: 0 12px 40px -8px var(--glow-cyan), 0 0 32px -6px var(--glow-violet);
}
.contact-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 9px;
}

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  body { font-size: 16.5px; }
  .shell { padding: calc(var(--nav-h) + 20px) 14px 30px; }
  .nav-inner { padding: 8px 14px; gap: 10px; }
  .brand-word { display: none; }
  .nav-title { max-width: 22ch; font-size: 13px; }
  .nav-time { display: none; }
  .toc-btn span { display: none; }
  .toc-btn { padding: 0 10px; }
  .article-body p { line-height: 2; }
  .article-body > section[data-align="center"]:first-of-type { padding: 26px 16px; }
  .res-card pre { padding: 12px; }
  .mermaid-card .mermaid { min-width: 520px; }
  #contactBtn { width: 34px; height: 34px; }
  #contactModal { padding: 24px 20px 22px; }
  .contact-title { font-size: 1.3rem; }
}
@media (min-width: 761px) and (max-width: 1119px) {
  .nav-time { display: inline; }
}

/* ---------- motion, a11y, print ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media print {
  .glass-nav, .progress-track, .level-rail, .drawer, .scrim, .to-top, .toast, .res-copy, #contactModalScrim, #contactModal { display: none !important; }
  body { background: #fff; color: #000; font-size: 12pt; }
  .shell { display: block; padding: 0; }
  .res-card, .appendix { break-inside: avoid; border-color: #ccc; }
}
