/* ============================================================
   Fault-Tolerant Systems — interactive study site
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;600&display=swap');


:root {
  --font: 'Vazirmatn', 'Sahel', 'Segoe UI', Tahoma, sans-serif;
  --mono: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;

  --bg: #070b10;
  --bg-2: #0b1117;
  --surface: #0e161e;
  --surface-2: #131c25;
  --surface-3: #19242f;
  --line: rgba(158, 186, 208, .13);
  --line-2: rgba(158, 186, 208, .26);

  --text: #eef4f9;
  --text-2: #c3d1dd;
  --muted: #90a5b6;
  --dim: #64798a;

  --mint: #5eead4;
  --mint-d: #14b8a6;
  --amber: #fbbf24;
  --amber-d: #d97706;
  --red: #fb8f8f;
  --violet: #b4a0ff;
  --blue: #7cb8ff;

  --r: 12px;
  --r-lg: 20px;
  --shadow: 0 1px 2px rgba(0,0,0,.42), 0 14px 34px -14px rgba(0,0,0,.62);
  --shadow-lg: 0 28px 70px -24px rgba(0,0,0,.78);
  --rail-w: 272px;
  --ease: cubic-bezier(.2,.7,.3,1);
}

html[data-theme="light"] {
  --bg: #f7f8f6;
  --bg-2: #eef1ee;
  --surface: #ffffff;
  --surface-2: #f4f7f5;
  --surface-3: #e8eeeb;
  --line: rgba(18, 42, 52, .11);
  --line-2: rgba(18, 42, 52, .22);

  --text: #0f1e27;
  --text-2: #31454e;
  --muted: #5c717b;
  --dim: #8095a0;

  --mint: #0f766e;
  --mint-d: #0d9488;
  --amber: #a16207;
  --amber-d: #d97706;
  --red: #b91c1c;
  --violet: #5b21b6;
  --blue: #1d4ed8;

  --shadow: 0 1px 2px rgba(16,40,50,.05), 0 12px 30px -16px rgba(16,40,50,.22);
  --shadow-lg: 0 30px 70px -30px rgba(16,40,50,.32);
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16.5px;
  line-height: 2;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  min-height: 100vh;
  letter-spacing: -.005em;
}

/* ambient background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(94, 234, 212, .10), transparent 62%),
    radial-gradient(760px 460px at 4% 4%, rgba(167, 139, 250, .09), transparent 60%),
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,.10), transparent 100%);
}
html[data-theme="light"] body::before {
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(13, 148, 136, .10), transparent 62%),
    radial-gradient(760px 460px at 4% 4%, rgba(109, 40, 217, .07), transparent 60%);
}

a { color: var(--mint); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
strong { color: var(--text); font-weight: 700; }
em { font-style: normal; color: var(--amber); font-weight: 600; }
code { font-family: var(--mono); }

/* ============================ RAIL ============================ */
.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
  padding: 20px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(14px);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: thin;
}

.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--mint-d), #0b3b3a);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.14), 0 6px 18px -8px rgba(20,184,166,.9);
}
.brand-mark svg { width: 22px; height: 22px; }
.brand-t { line-height: 1.35; }
.brand-t b { display: block; font-size: 14.5px; font-weight: 800; letter-spacing: -.2px; }
.brand-t span { font-size: 11.5px; color: var(--muted); }

/* progress */
.progwrap {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--r);
  padding: 9px 12px;
  display: flex; align-items: center; gap: 11px;
}
.ring { width: 46px; height: 46px; flex: 0 0 46px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.ring .bg { stroke: var(--line-2); }
.ring .fg { stroke: var(--mint); transition: stroke-dashoffset .6s var(--ease); }
.progwrap .pt { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.progwrap .pt b { display: block; color: var(--text); font-size: 15px; font-weight: 700; }

/* nav */
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-lbl {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--dim); margin: 8px 8px 4px; font-weight: 700;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 9px; border-radius: 9px;
  color: var(--text-2); font-size: 13.2px; font-weight: 500;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .18s, color .18s, border-color .18s;
}
.nav a .n {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  width: 20px; text-align: center; color: var(--dim);
  flex: 0 0 20px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active {
  background: color-mix(in srgb, var(--mint) 13%, transparent);
  color: var(--text);
  border-color: color-mix(in srgb, var(--mint) 30%, transparent);
}
.nav a.active .n { color: var(--mint); }
.nav a .tick {
  margin-inline-start: auto; width: 14px; height: 14px; opacity: 0; color: var(--mint);
}
.nav a.is-done .tick { opacity: 1; }

.railfoot { margin-top: auto; display: flex; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.ghost {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-2); font-family: var(--font); font-size: 12.5px; font-weight: 600;
  transition: .18s;
}
.ghost:hover { color: var(--text); border-color: var(--line-2); background: var(--surface-3); }
.ghost svg { width: 15px; height: 15px; }

/* ============================ MAIN ============================ */
main { position: relative; z-index: 1; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 40px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .crumb { font-size: 13px; color: var(--muted); flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .crumb b { color: var(--text-2); font-weight: 600; }
.topbar .sp { flex: 1; }

.searchbtn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 8px 12px 8px 10px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--muted); font-family: var(--font); font-size: 13px; cursor: pointer;
  transition: .18s; white-space: nowrap;
}
.searchbtn:hover { border-color: var(--line-2); color: var(--text-2); }
.searchbtn kbd {
  font-family: var(--mono); font-size: 10.5px; padding: 1px 6px;
  border-radius: 5px; background: var(--surface-3); border: 1px solid var(--line);
  color: var(--dim);
}
.searchbtn svg { width: 15px; height: 15px; }

.iconbtn {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2);
  cursor: pointer; transition: .18s;
}
.iconbtn:hover { color: var(--text); border-color: var(--line-2); }
.iconbtn svg { width: 17px; height: 17px; }

.wrap { padding: 34px 40px 90px; max-width: 1000px; margin: 0 auto; }

/* ============================ HERO ============================ */
.hero {
  position: relative;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background:
    radial-gradient(600px 300px at 15% 0%, color-mix(in srgb, var(--mint) 16%, transparent), transparent 70%),
    radial-gradient(500px 260px at 90% 110%, color-mix(in srgb, var(--violet) 14%, transparent), transparent 70%),
    var(--surface);
  padding: 44px 40px 38px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.hero::after {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: .28;
  mask-image: radial-gradient(120% 80% at 70% 0%, #000 10%, transparent 70%);
  pointer-events: none;
}
.hero > * { position: relative; z-index: 1; }
.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
  color: var(--mint);
  border: 1px solid color-mix(in srgb, var(--mint) 35%, transparent);
  background: color-mix(in srgb, var(--mint) 10%, transparent);
  padding: 5px 12px; border-radius: 999px;
}
.hero h1 {
  font-size: clamp(26px, 3.4vw, 40px);
  line-height: 1.35; margin: 18px 0 10px; font-weight: 800; letter-spacing: -.6px;
}
.hero h1 .grad {
  background: linear-gradient(100deg, var(--mint), var(--blue) 60%, var(--violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p.lead { font-size: 16px; color: var(--text-2); max-width: 62ch; margin: 0 0 22px; }

.srcgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 24px; }
.src {
  border: 1px solid var(--line); border-radius: var(--r);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
  padding: 10px 12px;
}
.src b { display: block; font-family: var(--mono); font-size: 12px; color: var(--mint); }
.src span { font-size: 11.5px; color: var(--muted); }

.cta { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 20px; border-radius: 11px; cursor: pointer;
  font-family: var(--font); font-size: 14px; font-weight: 700;
  border: 1px solid transparent; transition: .18s var(--ease);
  white-space: nowrap;
}
.btn.pri {
  background: linear-gradient(180deg, var(--mint), var(--mint-d));
  color: #04211f;
  box-shadow: 0 10px 24px -12px color-mix(in srgb, var(--mint) 80%, transparent);
}
html[data-theme="light"] .btn.pri { color: #fff; }
.btn.pri:hover { transform: translateY(-1px); box-shadow: 0 16px 30px -14px color-mix(in srgb, var(--mint) 85%, transparent); }
.btn.alt { background: var(--surface-2); border-color: var(--line-2); color: var(--text); }
.btn.alt:hover { background: var(--surface-3); }
.btn svg { width: 16px; height: 16px; }

/* ============================ SECTIONS ============================ */
#s1 { --h: 205; }
#s2 { --h: 264; }
#s3 { --h: 38; }
#s4 { --h: 352; }
#s5 { --h: 172; }
#s6 { --h: 145; }
#s7 { --h: 316; }
#s8 { --h: 192; }
#s9 { --h: 225; }

.sec { padding-top: 52px; scroll-margin-top: 74px; --acc: hsl(var(--h, 190) 78% 72%); }
html[data-theme="light"] .sec { --acc: hsl(var(--h, 190) 66% 36%); }

.sec-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 6px; }
.sec-num {
  font-family: var(--mono); font-size: 12px; font-weight: 600;
  color: var(--acc);
  border: 1px solid color-mix(in srgb, var(--acc) 34%, transparent);
  background: color-mix(in srgb, var(--acc) 11%, transparent);
  border-radius: 8px; padding: 3px 10px; margin-top: 11px;
  flex: 0 0 auto;
}
.sec h2 {
  font-size: clamp(23px, 2.6vw, 31px); margin: 0; font-weight: 800;
  letter-spacing: -.8px; line-height: 1.4;
  text-wrap: balance;
}
.sec .sub { color: var(--muted); font-size: 14px; margin: 3px 0 0; }
.sec-rule {
  height: 1px; margin: 20px 0 28px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--acc) 55%, transparent), var(--line), transparent);
}
.done-btn {
  margin-inline-start: auto; flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font); font-size: 12px; font-weight: 600;
  padding: 7px 13px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  transition: .2s;
}
.done-btn:hover { color: var(--text); border-color: var(--line-2); }
.done-btn.on {
  color: var(--acc); border-color: color-mix(in srgb, var(--acc) 46%, transparent);
  background: color-mix(in srgb, var(--acc) 13%, transparent);
}

h3 {
  font-size: 18px; font-weight: 800; margin: 36px 0 12px;
  letter-spacing: -.35px; color: var(--text);
  display: flex; align-items: center; gap: 10px;
}
h3::before {
  content: ''; width: 6px; height: 18px; border-radius: 3px; flex: 0 0 6px;
  background: var(--acc, var(--mint));
  box-shadow: 0 0 14px -2px color-mix(in srgb, var(--acc, var(--mint)) 70%, transparent);
}
h4 { font-size: 15px; font-weight: 700; margin: 22px 0 8px; color: var(--text-2); letter-spacing: -.15px; }
p { margin: 0 0 13px; color: var(--text-2); }
ul, ol { margin: 0 0 15px; padding-inline-start: 24px; color: var(--text-2); }
ol { list-style-type: persian; }
li { margin-bottom: 7px; }
li::marker { color: var(--acc, var(--mint)); }
li::marker { font-weight: 700; }

/* cards */
.card {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  padding: 22px 24px;
  margin: 16px 0;
  box-shadow: var(--shadow);
  transition: border-color .2s, transform .2s var(--ease);
}
.card:hover { border-color: var(--line-2); }
.card > h3:first-child, .card > h4:first-child { margin-top: 0; }
.card.flat { box-shadow: none; background: var(--surface-2); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid2 > .card, .grid3 > .card { margin: 0; }

/* inline math + formula blocks */
.mi {
  font-family: var(--mono); font-size: .88em;
  direction: ltr; unicode-bidi: isolate;
  background: color-mix(in srgb, var(--mint) 9%, transparent);
  border-radius: 5px; padding: 1px 5px;
  color: var(--text);
  white-space: nowrap;
}
.fx {
  direction: ltr; text-align: center; white-space: pre-wrap;
  font-family: var(--mono); font-size: 14.5px; line-height: 2.15;
  color: var(--text);
  background: linear-gradient(180deg, var(--surface-2), color-mix(in srgb, var(--surface-2) 60%, var(--surface)));
  border: 1px solid var(--line);
  border-inline-start: 3px solid color-mix(in srgb, var(--acc, var(--mint)) 65%, transparent);
  border-radius: var(--r);
  padding: 14px 18px; margin: 16px 0;
  overflow-x: auto;
}
.fx b { color: var(--mint); font-weight: 600; }
.fx .c { color: var(--muted); font-size: 12.5px; }

/* callouts */
.note, .warn, .tip, .def {
  border-radius: var(--r);
  padding: 14px 18px;
  margin: 16px 0;
  font-size: 14.5px;
  border: 1px solid;
  border-inline-start-width: 3px;
}
.note { background: color-mix(in srgb, var(--blue) 8%, transparent); border-color: color-mix(in srgb, var(--blue) 30%, transparent); }
.warn { background: color-mix(in srgb, var(--red) 8%, transparent); border-color: color-mix(in srgb, var(--red) 32%, transparent); }
.tip  { background: color-mix(in srgb, var(--amber) 8%, transparent); border-color: color-mix(in srgb, var(--amber) 32%, transparent); }
.def  { background: color-mix(in srgb, var(--violet) 8%, transparent); border-color: color-mix(in srgb, var(--violet) 30%, transparent); }
.note .t, .warn .t, .tip .t, .def .t {
  display: block; font-size: 11.5px; font-weight: 800; letter-spacing: .06em;
  margin-bottom: 4px;
}
.note .t { color: var(--blue); }
.warn .t { color: var(--red); }
.tip .t { color: var(--amber); }
.def .t { color: var(--violet); }
.note p:last-child, .warn p:last-child, .tip p:last-child, .def p:last-child { margin-bottom: 0; }
.note, .warn, .tip, .def { color: var(--text-2); }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin: 16px 0; }
.tbl th {
  text-align: start; font-weight: 700; font-size: 12px;
  color: var(--muted); letter-spacing: .02em;
  padding: 9px 13px; border-bottom: 1px solid var(--line-2);
  background: transparent;
}
.tbl td { padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--text-2); line-height: 1.85; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .15s; }
.tbl tbody tr:hover td { background: color-mix(in srgb, var(--acc, var(--mint)) 5%, transparent); }
.tbl .c { text-align: center; }
.tbl .mono { font-family: var(--mono); direction: ltr; text-align: left; font-size: 12.8px; color: var(--text); }
.tbl.tight td, .tbl.tight th { padding: 8px 11px; font-size: 13px; }

/* tables that need horizontal scroll on narrow screens */
.tblwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 16px 0; }
.tblwrap > .tbl { margin: 0; }
@media (max-width: 640px) {
  .tblwrap > .tbl.wide { min-width: 540px; }
  .tblwrap:has(> .tbl.wide)::before {
    content: '← برای دیدن ستون‌های بیشتر بکشید';
    display: block; font-size: 11px; color: var(--dim); margin-bottom: 6px;
  }
}

/* ============================ CHAIN WIDGET ============================ */
.chain { display: grid; grid-template-columns: 1fr 44px 1fr 44px 1fr; align-items: center; gap: 0; margin: 22px 0 8px; }
.chain-node {
  position: relative; cursor: pointer; text-align: center;
  border: 1px solid var(--line-2); border-radius: var(--r);
  background: var(--surface-2);
  padding: 16px 10px 14px;
  transition: .25s var(--ease);
}
.chain-node:hover { transform: translateY(-2px); }
.chain-node.on[data-k="fault"] { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 16%, transparent); }
.chain-node.on[data-k="error"] { border-color: var(--amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 16%, transparent); }
.chain-node.on[data-k="failure"] { border-color: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 16%, transparent); }
.chain-node .en { font-family: var(--mono); font-size: 15px; font-weight: 600; }
.chain-node .fa { font-size: 12.5px; color: var(--muted); }
.chain-node .lv {
  font-size: 10.5px; color: var(--dim); margin-top: 6px;
  border-top: 1px dashed var(--line); padding-top: 6px;
}
.chain-arrow { display: grid; place-items: center; color: var(--dim); }
.chain-arrow svg { width: 26px; height: 14px; }
.chain-arrow.live { color: var(--mint); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { opacity: .45 } 50% { opacity: 1 } }

.chain-detail {
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface-2); padding: 16px 18px; min-height: 92px;
  font-size: 14.5px; color: var(--text-2);
  transition: .25s;
}
.chain-detail b { color: var(--text); }

/* ============================ METRIC TILES ============================ */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 16px 0; }
.tile {
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface-2); padding: 14px 16px;
}
.tile .k { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }
.tile .v { font-family: var(--mono); font-size: 20px; font-weight: 600; color: var(--text); line-height: 1.5; }
.tile .v small { font-size: 11px; color: var(--muted); font-family: var(--font); }

/* ============================ CHART ============================ */
.chartbox { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); padding: 18px 20px; box-shadow: var(--shadow); }
.chart-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.chart-head h4 { margin: 0; }
.chiprow { display: flex; gap: 6px; flex-wrap: wrap; margin-inline-start: auto; }
.chip {
  font-family: var(--font); font-size: 12px; font-weight: 600;
  padding: 5px 12px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  transition: .18s;
}
.chip:hover { color: var(--text-2); border-color: var(--line-2); }
.chip.on {
  color: #04211f; background: var(--mint); border-color: var(--mint);
}
html[data-theme="light"] .chip.on { color: #fff; }

.plot { width: 100%; height: auto; display: block; direction: ltr; }
.plot .axis { stroke: var(--line-2); stroke-width: 1; }
.plot .gridline { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 4; }
.plot .lbl { fill: var(--dim); font-family: var(--mono); font-size: 12px; }
.plot .curve { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.plot .area { opacity: .12; }

.sliders { display: grid; gap: 10px; margin-top: 14px; }
.slider { display: grid; grid-template-columns: 128px 1fr 62px; align-items: center; gap: 12px; }
.slider label { font-size: 12.5px; color: var(--text-2); font-family: var(--mono); direction: ltr; text-align: right; }
.slider output { font-family: var(--mono); font-size: 12.5px; color: var(--mint); text-align: left; }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--line-2); border-radius: 99px; outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--mint); cursor: pointer;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mint) 22%, transparent);
  transition: transform .15s;
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.18); }
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border: 0; border-radius: 50%; background: var(--mint); cursor: pointer;
}

.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 15px; color: var(--text); }

/* ============================ CALC ============================ */
.calc { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12.5px; color: var(--muted); }
.field input {
  font-family: var(--mono); font-size: 14px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 12px; outline: none; transition: .18s;
  direction: ltr; text-align: left;
}
.field input:focus { border-color: var(--mint); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mint) 14%, transparent); }
.out { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.out .row { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.out .row:last-child { border-bottom: 0; }
.out .row span { font-size: 12.5px; color: var(--muted); }
.out .row b { font-family: var(--mono); font-size: 15px; color: var(--mint); font-weight: 600; direction: ltr; unicode-bidi: isolate; }

/* ============================ STEPPER ============================ */
.stepper { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); padding: 20px 22px; box-shadow: var(--shadow); }
.step-q { font-size: 14.5px; color: var(--text-2); border-inline-start: 2px solid var(--line-2); padding-inline-start: 12px; margin-bottom: 14px; }
.steps { display: grid; gap: 0; }
.step { display: none; }
.step.on {
  display: block; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); padding: 12px 14px;
  animation: fade .28s var(--ease);
}
.btn.sm { padding: 8px 14px; font-size: 13px; border-radius: 9px; }
.step .n { font-family: var(--mono); font-size: 10.5px; color: var(--mint); display: block; margin-bottom: 3px; }
.step .fx { margin: 6px 0 0; background: transparent; border: 0; padding: 4px 0; text-align: left; font-size: 13.5px; }

/* mini examples (details/summary) */
.minigrid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.mini {
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); padding: 14px 16px;
  transition: border-color .18s;
}
.mini:hover { border-color: var(--line-2); }
.mini[open] { border-color: color-mix(in srgb, var(--acc, var(--mint)) 34%, transparent); }
.mini summary {
  cursor: pointer; font-weight: 700; font-size: 14px; color: var(--text);
  list-style: none; display: flex; align-items: center; gap: 10px;
}
.mini summary::-webkit-details-marker { display: none; }
.mini summary::after {
  content: '+'; margin-inline-start: auto; color: var(--acc, var(--mint));
  font-family: var(--mono); font-size: 16px; line-height: 1;
}
.mini[open] summary::after { content: '−'; }
.mini p { margin: 10px 0 0; font-size: 13.5px; color: var(--text-2); }
.mini p.small { font-size: 12.5px; color: var(--muted); }
.mini .fx { margin: 10px 0 0; padding: 10px 12px; font-size: 13px; line-height: 2; }
.step-ctl { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.step-ctl .hint { font-size: 12px; color: var(--dim); margin-inline-start: auto; }

/* ============================ QUIZ ============================ */
.quiz { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); padding: 24px; box-shadow: var(--shadow); }
.qbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.qbar .qn { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.qbar .track { flex: 1; height: 5px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.qbar .fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--mint), var(--blue)); transition: width .4s var(--ease); }
.qbar .score { font-family: var(--mono); font-size: 12px; color: var(--mint); }

.qtext { font-size: 16.5px; font-weight: 600; color: var(--text); line-height: 1.85; margin-bottom: 16px; }
.opts { display: grid; gap: 9px; }
.opt {
  text-align: start; width: 100%;
  font-family: var(--font); font-size: 14.5px; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 13px 16px; cursor: pointer;
  display: flex; gap: 11px; align-items: flex-start;
  transition: .16s;
}
.opt .key {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  width: 20px; height: 20px; flex: 0 0 20px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--muted); margin-top: 2px;
}
.opt:hover:not(:disabled) { border-color: var(--line-2); background: var(--surface-3); color: var(--text); }
.opt:disabled { cursor: default; }
.opt.correct {
  border-color: var(--mint); background: color-mix(in srgb, var(--mint) 12%, transparent); color: var(--text);
}
.opt.correct .key { background: var(--mint); color: #04211f; }
.opt.wrong {
  border-color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent);
}
.opt.wrong .key { background: var(--red); color: #fff; }
.explain {
  margin-top: 14px; padding: 13px 16px; border-radius: var(--r);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 14px; color: var(--text-2);
  display: none;
}
.explain.show { display: block; animation: fade .3s; }
.explain b { color: var(--mint); }
@keyframes fade { from { opacity: 0; transform: translateY(4px) } to { opacity: 1; transform: none } }
.qfoot { display: flex; gap: 10px; margin-top: 18px; align-items: center; }
.qresult { text-align: center; padding: 20px 0; }
.qresult .big { font-family: var(--mono); font-size: 46px; font-weight: 600; color: var(--mint); line-height: 1.2; }
.qresult .msg { color: var(--text-2); margin: 6px 0 18px; }

/* ============================ FLASHCARDS ============================ */
.deck { display: grid; grid-template-columns: 60px 1fr 60px; gap: 14px; align-items: center; }
.flash {
  perspective: 1400px; height: 300px; cursor: pointer;
}
.flash-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .6s var(--ease);
  transform-style: preserve-3d;
}
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface);
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 30px; text-align: center; box-shadow: var(--shadow);
}
.flash-back { transform: rotateY(180deg); background: var(--surface-2); }
.flash-tag {
  position: absolute; top: 14px; right: 16px;
  font-size: 10.5px; letter-spacing: .08em;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-3) 70%, transparent);
  border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px;
}
.flash-face .big { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.6; }
.flash-back .big { font-size: 16.5px; font-weight: 500; color: var(--text-2); line-height: 2; }
.flash-hint { position: absolute; bottom: 14px; font-size: 11px; color: var(--dim); }
.navbtn {
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-2);
  cursor: pointer; transition: .18s;
}
.navbtn:hover { color: var(--text); border-color: var(--line-2); transform: scale(1.05); }
.navbtn svg { width: 22px; height: 22px; }
.deckfoot { display: flex; gap: 10px; justify-content: center; margin-top: 16px; align-items: center; flex-wrap: wrap; }
.deckfoot .cnt { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }

/* ============================ PALETTE ============================ */
.palette {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 10, 14, .62);
  backdrop-filter: blur(6px);
  display: none; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
.palette.open { display: flex; animation: fade .18s; }
.pal-box {
  width: min(620px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.pal-in {
  width: 100%; border: 0; outline: none; background: transparent;
  font-family: var(--font); font-size: 16px; color: var(--text);
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.pal-in::placeholder { color: var(--dim); }
.pal-list { max-height: 52vh; overflow-y: auto; padding: 8px; }
.pal-item {
  display: flex; gap: 12px; align-items: center; width: 100%;
  padding: 10px 14px; border-radius: 9px; cursor: pointer;
  background: transparent; border: 0; text-align: start;
  font-family: var(--font); font-size: 14px; color: var(--text-2);
}
.pal-item:hover, .pal-item.sel { background: var(--surface-2); color: var(--text); }
.pal-item .s { font-family: var(--mono); font-size: 10.5px; color: var(--dim); }
.pal-item .k { margin-inline-start: auto; font-size: 10.5px; color: var(--dim); }

/* flash highlight when jumping */
.flash-hit { animation: hit 1.6s var(--ease); }
@keyframes hit {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--mint) 70%, transparent); }
  100% { box-shadow: 0 0 0 14px transparent; }
}

/* footer */
.foot { margin-top: 60px; padding-top: 22px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--dim); text-align: center; }

/* reveal on scroll */
.rev { opacity: 0; transform: translateY(14px); transition: opacity .6s var(--ease), transform .6s var(--ease); }
.rev.in { opacity: 1; transform: none; }

/* mobile drawer scrim */
body.drawer::after {
  content: '';
  position: fixed; inset: 0; z-index: 55;
  background: rgba(4, 10, 14, .52);
  backdrop-filter: blur(2px);
  animation: fade .2s;
}

/* ============================ RESPONSIVE ============================ */
@media (max-width: 940px) {
  html { overflow-x: clip; }
  body { grid-template-columns: 1fr; }
  .rail {
    position: fixed; inset-inline-start: 0; top: 0; width: min(320px, 86vw);
    transform: translateX(102%); transition: transform .3s var(--ease);
    box-shadow: var(--shadow-lg); z-index: 60;
  }
  .rail.open { transform: none; }
  .wrap, .topbar { padding-inline: 18px; }
  .grid2, .grid3, .calc { grid-template-columns: 1fr; }
  .srcgrid { grid-template-columns: 1fr 1fr; }
  .chain { grid-template-columns: 1fr; gap: 8px; }
  .chain-arrow { transform: rotate(90deg); }
  .deck { grid-template-columns: 44px 1fr 44px; gap: 8px; }
  .navbtn { width: 44px; height: 44px; }
  .navbtn svg { width: 18px; height: 18px; }
  .slider { grid-template-columns: 92px 1fr 52px; gap: 9px; }
  .minigrid { grid-template-columns: 1fr; }
  .sec-head > div { min-width: 0; }
  .sec h2 { font-size: clamp(21px, 5.2vw, 28px); }
}

@media (max-width: 640px) {
  body { font-size: 16px; line-height: 1.95; }
  .topbar { padding: 9px 12px; gap: 8px; }
  .wrap { padding: 22px 14px 70px; }
  .hero { padding: 26px 18px 22px; border-radius: 16px; }
  .hero h1 { font-size: clamp(23px, 6.4vw, 30px); }
  .hero p.lead { font-size: 14.5px; }
  .kicker { font-size: 10.5px; padding: 4px 10px; }
  .srcgrid { grid-template-columns: 1fr; }
  .card { padding: 17px 15px; border-radius: 15px; }
  .chartbox { padding: 14px 12px; border-radius: 15px; }
  .flash { height: min(320px, 58vh); }
  .flash-face { padding: 22px 18px; }
  .flash-face .big { font-size: 18px; }
  .flash-back .big { font-size: 15px; }
  .sec { padding-top: 40px; }
  .sec-head { gap: 10px; }
  .done-btn { padding: 6px 10px; font-size: 11px; }
  h3 { font-size: 16.5px; margin: 30px 0 10px; }
  .btn { padding: 10px 16px; font-size: 13.5px; }
  .quiz { padding: 16px 14px; border-radius: 15px; }
  .qtext { font-size: 15.5px; }
  .opt { padding: 11px 12px; font-size: 14px; }
  .field input { font-size: 16px; }
  .pal-in { font-size: 16px; }
  .fx { font-size: 13.5px; padding: 12px 12px; }
  .step .fx { font-size: 12.5px; }
  .statgrid { grid-template-columns: 1fr 1fr; }
  .statgrid .stat:nth-child(3) { grid-column: span 2; }
  .out .row b { font-size: 14px; }
  .slider { grid-template-columns: 76px 1fr 44px; gap: 8px; }
  .slider label { font-size: 11.5px; }
  .tbl { font-size: 13px; }
  .mi { white-space: normal; }
  #bath .lbl { font-size: 21px; }
}

@media (max-width: 520px) {
  .searchbtn { padding: 8px; }
  .searchbtn .sb-lbl, .searchbtn kbd { display: none; }
  .topbar .crumb { font-size: 12px; }
  .sec-num { margin-top: 9px; padding: 2px 8px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

::selection { background: color-mix(in srgb, var(--mint) 35%, transparent); }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; border-radius: 6px; }

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 3px solid var(--bg); }
