:root {
  --bg: #fbfaf7;
  --panel: #f2f0eb;
  --card: #ffffff;
  --ink: #1e2126;
  --muted: #5d636b;
  --rule: #e2ded6;
  --accent: #17706b;
  --accent-soft: #e2efed;
  --warn: #9a5b13;
  --sans: "Segoe UI", "Nirmala UI", Mangal, system-ui, -apple-system, sans-serif;
  --math: "Cambria Math", Cambria, "Times New Roman", serif;
  --mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --panel: #1d2024;
    --card: #22262b;
    --ink: #e6e3dd;
    --muted: #9ba1a9;
    --rule: #30343a;
    --accent: #5ec4bb;
    --accent-soft: #1a2e2c;
    --warn: #e0a458;
  }
}
:root[data-theme="dark"] {
  --bg: #15171a;
  --panel: #1d2024;
  --card: #22262b;
  --ink: #e6e3dd;
  --muted: #9ba1a9;
  --rule: #30343a;
  --accent: #5ec4bb;
  --accent-soft: #1a2e2c;
  --warn: #e0a458;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 18px/1.8 var(--sans); }
main { max-width: 860px; margin: 0 auto; padding: 28px 20px 120px; }
a { color: var(--accent); text-underline-offset: 3px; }
p { margin: 0 0 14px; }
b, strong { font-weight: 650; }
q { quotes: "“" "”"; }
.math, i.v { font-family: var(--math); }
code, .code { font-family: var(--mono); font-size: 0.88em; background: var(--panel); padding: 1px 5px; border-radius: 4px; }

/* top bar */
.topbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; font-size: 14px; color: var(--muted); padding-bottom: 14px; border-bottom: 1px solid var(--rule); margin-bottom: 40px; }
.topbar a { color: var(--muted); }

/* lesson header */
.kicker { font-size: 14px; color: var(--accent); font-weight: 600; margin: 0 0 6px; }
h1 { font-size: 40px; line-height: 1.2; margin: 0 0 16px; font-weight: 700; letter-spacing: -0.01em; }
.lede { font-size: 20px; line-height: 1.75; margin: 0 0 22px; }
.goals { background: var(--panel); border-radius: 8px; padding: 16px 22px; margin: 0 0 14px; }
.goals h2 { font-size: 15px; margin: 0 0 6px; color: var(--muted); font-weight: 650; }
.goals ul, .goals ol { margin: 0; padding-left: 22px; }
.goals li { margin: 4px 0; font-size: 17px; }
.pre { font-size: 15px; color: var(--muted); margin: 0 0 8px; }

h2 { font-size: 26px; line-height: 1.35; margin: 0 0 10px; font-weight: 700; }
h3 { font-size: 21px; line-height: 1.4; margin: 0 0 4px; font-weight: 700; }
.cn { color: var(--accent); margin-right: 8px; font-variant-numeric: tabular-nums; }

.opening { margin: 44px 0 0; }
.concept { margin: 60px 0 0; padding-top: 6px; border-top: 1px solid var(--rule); }
.concept > h3 { margin-top: 26px; }
.story .concept > h3 { margin-bottom: 14px; }
.concept h4.sub { font-size: 18px; line-height: 1.45; margin: 34px 0 8px; font-weight: 700; }
details.more { background: var(--panel); border-radius: 6px; padding: 10px 16px; margin: 0 0 18px; }
details.more summary { cursor: pointer; font-size: 15px; font-weight: 600; color: var(--accent); }
details.more[open] summary { margin-bottom: 8px; }
details.more .tscroll { margin-bottom: 4px; }
.src { font-size: 13.5px; color: var(--muted); margin: 0 0 18px; line-height: 1.6; }

/* क्यों / क्या / कैसे / कहाँ */
.part { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 0 22px; }
.part + .part { margin-top: 22px; }
.part > .lab { font-size: 14px; font-weight: 650; color: var(--accent); border-top: 2px solid var(--accent); padding-top: 4px; margin-top: 7px; height: max-content; }
.part > div { min-width: 0; }
.part > div > :last-child { margin-bottom: 0; }

.term { color: var(--accent); font-weight: 650; }
ul.plain, ol.plain { margin: 0 0 14px; padding-left: 24px; }
ul.plain li, ol.plain li { margin-bottom: 8px; }
.note { font-size: 15px; color: var(--muted); }
.mine { font-size: 13px; color: var(--muted); border: 1px solid var(--rule); border-radius: 4px; padding: 0 6px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.callout { border-left: 3px solid var(--warn); padding: 4px 0 4px 16px; margin: 0 0 16px; }

/* tables */
.tscroll { overflow-x: auto; margin: 6px 0 18px; }
table.t { width: 100%; border-collapse: collapse; font-size: 16px; line-height: 1.55; }
table.t th { text-align: left; font-weight: 600; color: var(--muted); font-size: 14px; padding: 8px 10px; border-bottom: 1px solid var(--ink); vertical-align: bottom; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.total td { border-bottom: none; font-weight: 650; }
table.t tr.hi td { background: var(--accent-soft); }
table.t .sub { display: block; color: var(--muted); font-size: 14px; }
table.t .mono { font-family: var(--mono); font-size: 14.5px; }

/* formula */
.formula { font-family: var(--math); font-size: 23px; line-height: 1.6; background: var(--panel); border-radius: 6px; padding: 16px 20px; margin: 14px 0 16px; text-align: center; overflow-x: auto; white-space: nowrap; }
.formula .fl { font-family: var(--sans); font-size: 15px; color: var(--muted); display: inline-block; min-width: 88px; text-align: right; margin-right: 10px; }
.sum { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 4px; line-height: 1; }
.sum .op { font-size: 38px; }
.sum .lim { font-size: 13px; margin-top: 4px; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 4px; line-height: 1.3; }
.frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 4px 2px; }
.frac > span:last-child { padding: 2px 4px 0; }
dl.sym { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 18px; font-size: 16px; line-height: 1.6; margin: 0 0 18px; }
dl.sym dt { font-family: var(--math); font-size: 18px; }
dl.sym dd { margin: 0; }

/* token chips */
.tokens { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.tok { font-family: var(--mono); font-size: 15px; background: var(--card); border: 1px solid var(--rule); border-radius: 4px; padding: 2px 8px; white-space: pre; }
.tok .id { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* flow diagram */
figure { margin: 18px 0 22px; }
.flow { display: flex; align-items: stretch; }
.node { flex: 1 1 0; min-width: 0; background: var(--card); border: 1px solid var(--rule); border-radius: 6px; padding: 10px 12px; font-size: 15px; line-height: 1.5; }
.node b { display: block; font-size: 15px; }
.node .ex { display: block; color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.node.key { border-color: var(--accent); }
.arrow { flex: 0 0 26px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.arrow svg { width: 18px; height: 12px; }
figcaption { font-size: 14px; color: var(--muted); margin-top: 10px; line-height: 1.6; }

/* widget */
.widget { background: var(--panel); border-radius: 8px; padding: 20px 22px 18px; margin: 18px 0 22px; }
.widget h4 { font-size: 16px; margin: 0 0 4px; }
.widget .hint { font-size: 14.5px; color: var(--muted); margin-bottom: 14px; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.btns button, button.b { font: 600 14px/1.2 var(--sans); color: var(--ink); background: var(--card); border: 1px solid var(--rule); border-radius: 6px; padding: 9px 12px; cursor: pointer; text-align: left; }
.btns button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.btns button:disabled { opacity: .45; cursor: default; }
.ctl { display: grid; grid-template-columns: max-content minmax(0, 1fr) 44px; gap: 6px 14px; align-items: center; font-size: 15px; margin-bottom: 14px; }
.ctl input[type="range"] { width: 100%; accent-color: var(--accent); }
.ctl output { font-variant-numeric: tabular-nums; text-align: right; color: var(--muted); }
.widget table.t { background: var(--card); }
.out { margin: 12px 0 0; font-size: 16px; }
.bars { display: grid; grid-template-columns: max-content minmax(0, 1fr) 48px; gap: 6px 12px; align-items: center; font-size: 15px; margin: 6px 0 4px; }
.bars .lbl { font-family: var(--mono); font-size: 14.5px; }
.bars button.lbl { background: none; border: 1px solid var(--rule); border-radius: 4px; padding: 2px 8px; cursor: pointer; color: var(--ink); text-align: left; }
.bars button.lbl:hover { border-color: var(--accent); }
.bar { height: 10px; background: var(--rule); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--muted); border-radius: 5px; transition: width .25s ease; }
.bar.win > span { background: var(--accent); }
.bars .val { font-variant-numeric: tabular-nums; text-align: right; }
.sentence { font-family: var(--mono); font-size: 15.5px; background: var(--card); border: 1px solid var(--rule); border-radius: 6px; padding: 10px 12px; margin: 0 0 12px; line-height: 1.6; }
.sentence .new { color: var(--accent); font-weight: 700; }
.switch { display: flex; align-items: center; gap: 10px; font-size: 15px; margin: 0 0 12px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
mark { background: var(--accent-soft); color: inherit; padding: 0 2px; border-radius: 3px; font-weight: 650; }

/* check question */
.recall { border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 6px 6px 0; padding: 14px 20px; margin: 26px 0 0; }
.recall .rl { font-size: 13px; font-weight: 650; color: var(--accent); margin: 0 0 4px; }
.recall p { font-size: 17px; }
.recall summary { cursor: pointer; font-size: 15px; font-weight: 600; color: var(--accent); }
.recall details[open] summary { margin-bottom: 8px; }
.recall details > :last-child { margin-bottom: 0; }

/* end of lesson */
.wrap { margin: 72px 0 0; padding-top: 22px; border-top: 2px solid var(--ink); }
.wrap h2 { font-size: 22px; }
dl.words { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 18px; font-size: 16px; line-height: 1.6; margin: 0 0 18px; }
dl.words dt { font-weight: 650; }
dl.words dd { margin: 0; }
.pager { display: flex; justify-content: space-between; gap: 12px; margin: 36px 0 0; font-size: 16px; }
.pager .muted { color: var(--muted); }
footer { margin-top: 56px; padding-top: 18px; border-top: 1px solid var(--rule); font-size: 14px; color: var(--muted); line-height: 1.7; }

/* index */
ol.lessons { list-style: none; margin: 18px 0 0; padding: 0; border-top: 1px solid var(--rule); }
ol.lessons li { border-bottom: 1px solid var(--rule); display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 2px 14px; padding: 14px 4px; align-items: baseline; }
ol.lessons .n { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
ol.lessons .ttl { font-weight: 650; }
ol.lessons .why { display: block; font-size: 15.5px; color: var(--muted); line-height: 1.6; }
ol.lessons .new { display: block; font-size: 14px; color: var(--muted); line-height: 1.6; margin-top: 2px; }
ol.lessons .st { font-size: 13px; color: var(--muted); white-space: nowrap; text-align: right; }
ol.lessons li.ready .n, ol.lessons li.ready .st { color: var(--accent); }
ol.lessons li.later { opacity: 0.62; }

@media (max-width: 680px) {
  body { font-size: 17px; }
  main { padding: 20px 16px 96px; }
  h1 { font-size: 31px; }
  .lede { font-size: 18.5px; }
  h2 { font-size: 23px; }
  h3 { font-size: 19.5px; }
  .part { grid-template-columns: minmax(0, 1fr); }
  .part > .lab { border-top: none; padding-top: 0; margin: 0 0 2px; }
  .flow { flex-direction: column; }
  .arrow { flex-basis: 24px; }
  .arrow svg { transform: rotate(90deg); }
  .formula { font-size: 19px; padding: 14px 12px; }
  .formula .fl { display: block; text-align: left; min-width: 0; margin: 6px 0 0; }
  .widget { padding: 16px 14px; }
  .ctl { grid-template-columns: minmax(0, 1fr) 40px; }
  .ctl label { grid-column: 1 / -1; margin-bottom: -6px; }
  ol.lessons li { grid-template-columns: 26px minmax(0, 1fr); }
  ol.lessons .st { grid-column: 2; text-align: left; }
  dl.words { grid-template-columns: minmax(0, 1fr); gap: 0 0; }
  dl.words dd { margin-bottom: 10px; }
  .hide-sm { display: none; }
  .widget table.t { font-size: 14.5px; }
  .widget table.t td, .widget table.t th { padding: 7px 6px; }
}

/* lesson map (index) */
.mapsec { margin: 0 0 56px; }
.mlegend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; color: var(--muted); margin: 4px 0 14px; }
.mlegend span { display: inline-flex; align-items: center; gap: 7px; }
.sw { display: inline-block; width: 18px; height: 12px; border-radius: 3px; }
.sw.base { background: var(--accent-soft); border: 1.5px solid var(--accent); }
.sw.core { background: var(--card); border: 1.5px solid var(--accent); }
.sw.deep { background: var(--card); border: 1.5px dashed var(--muted); }
.lmap { position: relative; background: var(--panel); border-radius: 8px; padding: 18px 14px; }
.lmap-edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.lmap-edges path { fill: none; stroke: var(--muted); stroke-width: 1.5; opacity: .5; transition: opacity .2s; }
.lmap-edges path.in { stroke: var(--accent); stroke-width: 2.5; opacity: 1; }
.lmap-edges path.out { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; opacity: .9; }
.lmap-edges path.off { opacity: .1; }
.lmap-grid { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: auto; gap: 26px 10px; }
.mnode { position: relative; justify-self: center; width: 100%; max-width: 150px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 6px 6px; font: 13.5px/1.3 var(--sans); color: var(--ink); background: var(--card); border: 1.5px solid var(--accent); border-radius: 8px; cursor: pointer; text-align: center; transition: opacity .2s, background .2s; }
.mnode.span { width: calc(50% - 5px); }
.mnode b { font-size: 15px; font-variant-numeric: tabular-nums; color: var(--accent); }
.mnode.base { background: var(--accent-soft); }
.mnode.deep { border-style: dashed; border-color: var(--muted); color: var(--muted); }
.mnode.deep b { color: var(--muted); }
.mnode:hover { box-shadow: 0 0 0 2px var(--accent-soft); }
.mnode:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mnode.is-sel { background: var(--accent); border-color: var(--accent); border-style: solid; color: var(--bg); }
.mnode.is-sel b { color: var(--bg); }
.mnode.is-anc { box-shadow: 0 0 0 3px var(--accent); }
.mnode.is-desc { outline: 2px dashed var(--accent); outline-offset: 3px; }
.mnode.is-free { opacity: .32; }
.mapinfo { margin: 14px 0 10px; padding: 14px 18px; border-left: 3px solid var(--accent); background: var(--panel); border-radius: 0 6px 6px 0; font-size: 16px; }
.mapinfo p { margin: 0 0 8px; }
.mapinfo .mi-h { font-weight: 650; }
.mapinfo .tag { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 0 7px; border-radius: 4px; border: 1px solid var(--accent); color: var(--accent); vertical-align: 2px; margin-left: 4px; }
.mapinfo .tag.deep { border-style: dashed; border-color: var(--muted); color: var(--muted); }
dl.mi { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 6px 0 10px; }
dl.mi dt { font-size: 14px; font-weight: 650; color: var(--muted); padding-top: 3px; }
dl.mi dd { margin: 0; line-height: 2; }
.chip { font: 600 14px/1.2 var(--sans); color: var(--ink); background: var(--card); border: 1px solid var(--rule); border-radius: 5px; padding: 3px 8px; cursor: pointer; font-variant-numeric: tabular-nums; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.clear { margin-left: 12px; font-weight: 500; color: var(--muted); }
.mapinfo .grp { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; border: 1px dashed var(--muted); border-radius: 6px; padding: 1px 6px; }
.mapinfo .any, .mapinfo .cnt { font-size: 13px; color: var(--muted); margin-left: 4px; }
.mapinfo .cnt { display: block; margin-left: 0; line-height: 1.6; }
.mapinfo .arr { color: var(--muted); margin: 0 2px; }
.mi-go { margin: 4px 0 0 !important; }
@media (max-width: 680px) {
  .lmap { padding: 14px 8px; }
  .lmap-grid { gap: 22px 6px; }
  .mnode { font-size: 12px; min-height: 48px; padding: 5px 3px; }
  .mnode b { font-size: 14px; }
  dl.mi { grid-template-columns: minmax(0, 1fr); gap: 0; }
  dl.mi dd { margin-bottom: 8px; }
  .mapinfo { padding: 12px 12px; }
}

/* tap-to-open definitions (def.js) */
button.def { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; text-align: inherit; text-decoration: underline dotted var(--accent); text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
button.def::after { content: "▾"; font-size: .85em; color: var(--accent); margin-left: 2px; }
button.def[aria-expanded="true"] { color: var(--accent); }
button.def[aria-expanded="true"]::after { content: "▴"; }
button.def:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.defbox { border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 6px 6px 0; padding: 8px 14px; margin: -4px 0 16px; font-size: 16px; line-height: 1.65; }
.defbox b { margin-right: 4px; }
.defbox a { margin-left: 6px; font-size: 14px; white-space: nowrap; }
.lede + .defbox { font-size: 17px; }

/* phones: long one-line arithmetic in a formula box wraps at spaces instead of scrolling far */
@media (max-width: 480px) {
  .formula { white-space: normal; text-align: left; }
  .formula .frac { white-space: nowrap; }
}

/* phones: tighter tables so 3-4 columns fit a 360px screen */
@media (max-width: 480px) {
  table.t { font-size: 14.5px; line-height: 1.5; }
  table.t th, table.t td { padding: 7px 6px; }
  table.t th { font-size: 13px; }
  table.t .sub { font-size: 12.5px; }
}
