/* =====================================================================
   Study layer — Janaka Academy content pages
   Loaded AFTER theme.css and subsite.css, together with assets/js/study.js,
   on every Academy module page (not on the Academy hub pages).

   What it does, and the learning-science reason for each piece:
   - reading typography: a 65–75 character measure and 1.6+ line height
     (comfortable reading speed, fewer regressions)
   - numbered sections + an outline card: an "advance organiser" that
     lets the reader see the structure before the detail
   - progress bar, per-section "done" toggles and a resume prompt:
     self-monitoring and closure, which keep long pages finishable
   - a collapsed "how to study this page" note: retrieval practice and
     spacing, stated once, out of the way
   - callouts (.callout.key / .note / .try) for signalling importance
   Everything is built on the theme tokens; no hard-coded colours.
   ===================================================================== */

/* ---- reading typography ---- */
body.study main p,
body.study main li { line-height: 1.65; }
body.study main p { font-size: 1.02rem; }
body.study main .subhero .lede { max-width: 66ch; }
body.study main > section > .wrap > p,
body.study main .card > p,
body.study main .prose > p { max-width: 72ch; }
body.study main h2 { scroll-margin-top: 84px; }
body.study main h3 { scroll-margin-top: 84px; font-family: var(--font-head); font-weight: 700; font-size: 1.04rem; margin: 20px 0 6px; }
body.study main h4 { font-family: var(--font-head); font-weight: 600; font-size: .98rem; margin: 16px 0 4px; }
body.study main ul:not(.study-toc ul):not(.chips):not(.badges),
body.study main ol:not(.study-toc ol) { margin-top: 10px; display: grid; gap: 6px; }
body.study main .card ul { margin-left: 0; }
body.study main section:not(.sec) + section:not(.sec) { margin-top: 16px; }
body.study main .card + .card,
body.study main .card + section.card { margin-top: 16px; }
body.study main .card > h2:first-child,
body.study main .card > .has-done:first-child { margin-top: 0; }
body.study main .card h2 { font-size: 1.28rem; margin-bottom: 12px; }
body.study main .card > h2:not(:first-child),
body.study main .card > .has-done:not(:first-child) { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--ln); }
body.study main .sub { font-family: var(--font-mono); font-size: .76rem; color: var(--tx2); }
body.study main hr { border: none; border-top: 1px solid var(--ln); margin: 22px 0; }
body.study main blockquote { margin-top: 14px; padding-left: 16px; border-left: 3px solid var(--ac); color: var(--tx2); }
body.study main strong, body.study main b { font-weight: 600; }
body.study main mark { background: color-mix(in srgb, var(--ac) 18%, transparent); color: inherit; border-radius: 4px; padding: 0 3px; }
body.study main kbd {
  font-family: var(--font-mono); font-size: .8em; padding: 1px 6px;
  border: 1px solid var(--ln); border-bottom-width: 2px; border-radius: 5px; background: var(--bg2);
}

/* ---- code ---- */
body.study main code {
  font-family: var(--font-mono); font-size: .86em;
  background: var(--chip); border-radius: 5px; padding: 2px 6px;
}
body.study main pre {
  position: relative; margin-top: 14px; padding: 14px 16px; overflow-x: auto;
  background: var(--chip); border: 1px solid var(--ln); border-radius: var(--r);
  font-size: .86rem; line-height: 1.55;
}
body.study main pre code { background: none; padding: 0; font-size: inherit; }
body.study main pre + p { margin-top: 12px; }
.copybtn {
  position: absolute; top: 8px; right: 8px; cursor: pointer;
  font-family: var(--font-mono); font-size: .64rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--tx2); background: var(--bg2); border: 1px solid var(--ln); border-radius: 999px; padding: 3px 9px;
  opacity: 0; transition: opacity .15s ease, color .15s ease, border-color .15s ease;
}
body.study main pre:hover .copybtn, .copybtn:focus-visible, .copybtn.copied { opacity: 1; }
.copybtn:hover { color: var(--ac); border-color: var(--ac); }
.copybtn.copied { color: var(--ok); border-color: var(--ok); }
@media (hover: none) { .copybtn { opacity: 1; } }

/* ---- tables ---- */
body.study main .tablewrap { overflow-x: auto; margin-top: 14px; border: 1px solid var(--ln); border-radius: var(--r); }
body.study main .tablewrap table { margin-top: 0; border: none; }
body.study main table { width: 100%; border-collapse: collapse; font-size: .92rem; margin-top: 14px; }
body.study main th, body.study main td { text-align: left; vertical-align: top; padding: 9px 12px; border-bottom: 1px solid var(--ln); }
body.study main th {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .12em; text-transform: uppercase;
  font-weight: 500; color: var(--tx2); background: var(--chip);
}
body.study main tbody tr:last-child td { border-bottom: none; }
body.study main tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--chip) 45%, transparent); }
body.study main td code { white-space: pre-wrap; word-break: normal; overflow-wrap: normal; }
body.study main th:first-child, body.study main td:first-child { min-width: 12ch; }

/* ---- section numbers and "done" toggles (added by study.js) ---- */
body.study main h2.has-done { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.secnum {
  flex-basis: 100%; font-family: var(--font-mono); font-size: .7rem; letter-spacing: .16em;
  color: var(--ac); font-weight: 500;
}
.donebtn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; margin-left: auto;
  font-family: var(--font-mono); font-size: .64rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--tx2); background: var(--bg2); border: 1px solid var(--ln); border-radius: 999px; padding: 4px 10px;
  transition: color .15s ease, border-color .15s ease;
}
.donebtn:hover { color: var(--ac); border-color: var(--ac); }
.donebtn[aria-pressed="true"] { color: var(--ok); border-color: var(--ok); }

/* ---- reading progress (fixed, top edge) ---- */
.study-progress {
  position: fixed; left: 0; top: 0; height: 3px; width: 0; z-index: 60;
  background: var(--ac); transition: width .12s linear; pointer-events: none;
}

/* ---- page meta and study note (under the H1) ---- */
.study-meta {
  display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 16px;
  font-family: var(--font-mono); font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--tx2);
}
.study-meta b { color: var(--tx); font-weight: 500; }
.study-how { margin-top: 14px; max-width: 72ch; border: 1px solid var(--ln); border-radius: var(--r); background: var(--bg2); padding: 10px 14px; }
.study-how summary {
  cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 10px;
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ac);
}
.study-how summary::-webkit-details-marker { display: none; }
.study-how summary::after { content: "+"; }
.study-how[open] summary::after { content: "–"; }
.study-how ol { margin: 10px 0 4px 18px; display: grid; gap: 6px; font-size: .92rem; color: var(--tx2); }
.study-how ol b { color: var(--tx); font-weight: 600; }

/* ---- outline card (added by study.js when a page has 3+ sections) ---- */
.study-toc-sec { padding-top: 28px; }
.study-toc { border: 1px solid var(--ln); border-radius: var(--r); background: var(--bg2); box-shadow: var(--shadow); padding: 14px 16px 16px; }
.study-toc .toc-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ac);
}
.study-toc .toc-head .toc-count { color: var(--tx2); }
.study-toc .toc-head .toc-count.all { color: var(--ok); }
.study-toc .toc-bar { height: 4px; border-radius: 999px; background: var(--chip); margin-top: 10px; overflow: hidden; }
.study-toc .toc-bar i { display: block; height: 100%; width: 0; background: var(--ok); transition: width .25s ease; }
.study-toc ol { list-style: none; margin: 10px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 18px; }
.study-toc li a {
  display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--tx);
  font-size: .9rem; padding: 4px 8px; border-radius: 7px; line-height: 1.35;
}
.study-toc li a:hover { background: var(--chip); }
.study-toc li a.active { color: var(--ac); background: color-mix(in srgb, var(--ac) 8%, var(--bg2)); }
.study-toc li a .n { font-family: var(--font-mono); font-size: .68rem; color: var(--tx2); min-width: 2.2ch; padding-top: 2px; }
.study-toc li.done a { color: var(--tx2); }
.study-toc li.done a::after { content: "✓"; color: var(--ok); margin-left: auto; font-family: var(--font-mono); font-size: .8rem; }

/* ---- floating "outline · progress" pill and resume prompt ---- */
.study-pill {
  position: fixed; right: 16px; bottom: 16px; z-index: 65; display: none; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; text-decoration: none;
  color: var(--tx2); background: var(--bg2); border: 1px solid var(--ln); border-radius: 999px; padding: 7px 12px; box-shadow: var(--shadow);
}
.study-pill.show { display: inline-flex; }
.study-pill:hover { color: var(--ac); border-color: var(--ac); }
.study-pill b { color: var(--ok); font-weight: 500; }
.study-resume {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px);
  font-size: .86rem; color: var(--tx); background: var(--bg2); border: 1px solid var(--ln); border-radius: 999px;
  padding: 7px 8px 7px 14px; box-shadow: var(--shadow);
}
.study-resume button {
  cursor: pointer; font: 500 .78rem var(--font-sans); border-radius: 999px; padding: 6px 11px;
  border: 1px solid var(--ln); background: var(--bg); color: var(--tx);
}
.study-resume button.go { background: var(--ac); border-color: var(--ac); color: #fff; }
.study-resume button:hover { border-color: var(--ac); }

/* ---- callouts ---- */
.callout {
  margin-top: 14px; padding: 12px 16px; max-width: 72ch;
  border: 1px solid var(--ln); border-left: 3px solid var(--ac); border-radius: 0 var(--r) var(--r) 0;
  background: var(--chip); color: color-mix(in srgb, var(--tx) 88%, var(--tx2));
}
.callout > :first-child { margin-top: 0; }
.callout .lbl { display: block; margin-bottom: 4px; font-family: var(--font-mono); font-size: .66rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ac); }
.callout.key { border-left-color: var(--ok); }
.callout.key .lbl { color: var(--ok); }
.callout.try { border-style: dashed; border-left-style: solid; background: var(--bg2); }
body.study main .callout p { font-size: .95rem; }

/* ---- handbook navigation between sibling pages ---- */
.modnav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.modnav a {
  font-family: var(--font-mono); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; text-decoration: none;
  color: var(--tx2); border: 1px solid var(--ln); border-radius: 999px; padding: 5px 11px; background: var(--bg2);
}
.modnav a:hover { color: var(--ac); border-color: var(--ac); }
.modnav a[aria-current="page"] { color: var(--ac); border-color: color-mix(in srgb, var(--ac) 40%, var(--ln)); background: color-mix(in srgb, var(--ac) 8%, var(--bg2)); }

/* ---- markup carried over from the older handbooks ---- */
body.study main .tile { border: 1px solid var(--ln); border-radius: var(--r); background: var(--bg2); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
body.study main .tile:hover { border-color: color-mix(in srgb, var(--ac) 35%, var(--ln)); }
body.study main .tile h3 { margin: 0; font-size: 1rem; }
body.study main .tile p { margin: 0; font-size: .92rem; color: var(--tx2); }
body.study main .tile a { margin-top: auto; padding-top: 4px; font-family: var(--font-mono); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ac); text-decoration: none; }
body.study main .tile a:hover { text-decoration: underline; }
body.study main a.tile, body.study main a.card { text-decoration: none; color: inherit; }
body.study main .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 14px; }
body.study main .cards2 > .card > h2:first-child { margin-top: 0; }
body.study main .badge { display: inline-block; margin-top: 4px; }

/* the theme's dash bullets must not leak into the outline or into checkbox lists */
.study-toc li, .study-toc li::before { padding-left: 0; content: none; }
body.study main li:has(> input[type="checkbox"]) { padding-left: 0; }
body.study main li:has(> input[type="checkbox"])::before { content: none; }
body.study main li > input[type="checkbox"] { accent-color: var(--ac); margin-right: 8px; }

/* ---- checklists carried in some modules ---- */
body.study main .checklist { list-style: none; margin-left: 0; }
body.study main .checklist li { display: flex; align-items: flex-start; gap: 10px; }
body.study main .checklist input { accent-color: var(--ac); margin-top: 5px; }

/* ---- motion and print ---- */
@media (prefers-reduced-motion: reduce) {
  .study-progress, .study-toc .toc-bar i, .copybtn, .donebtn { transition: none; }
}
@media print {
  .study-progress, .study-pill, .study-resume, .copybtn, .donebtn, .study-how, .modnav { display: none !important; }
  .study-toc { box-shadow: none; }
  body.study main pre { white-space: pre-wrap; }
}

/* ---- folded code files in the long guides ---- */
details.code-fold { margin-top: 14px; border: 1px solid var(--ln); border-radius: var(--r); background: var(--bg2); }
details.code-fold > summary {
  cursor: pointer; list-style: none; padding: 10px 14px; display: flex; justify-content: space-between; gap: 10px;
  font-family: var(--font-mono); font-size: .74rem; letter-spacing: .06em; color: var(--ac);
}
details.code-fold > summary::-webkit-details-marker { display: none; }
details.code-fold > summary::after { content: "show"; color: var(--tx2); text-transform: uppercase; font-size: .66rem; letter-spacing: .12em; }
details.code-fold[open] > summary::after { content: "hide"; }
details.code-fold > pre { margin: 0; border: none; border-top: 1px solid var(--ln); border-radius: 0 0 var(--r) var(--r); }
body.study main .msgflow { font-family: var(--font-mono); font-size: .8rem; line-height: 1.5; white-space: pre; overflow-x: auto; padding: 14px 16px; border: 1px dashed var(--ln); border-radius: var(--r); background: var(--bg2); margin-top: 14px; color: var(--tx); }

/* ---- Warning callouts, self-check quizzes and folded blocks (added 2026-09-21) ---- */
.callout.warn { border-left-color: #d9480f; }
.callout.warn .lbl { color: #d9480f; }
details.quiz { margin: 18px 0; border: 1px solid var(--ln); border-left: 4px solid var(--ok); border-radius: var(--r); background: var(--bg2); }
details.quiz > summary { cursor: pointer; list-style: none; padding: 12px 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
details.quiz > summary::-webkit-details-marker { display: none; }
details.quiz > summary .hint { font-family: var(--font-mono); font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--tx2); }
details.quiz[open] > summary .hint { display: none; }
details.quiz ol { margin: 0; padding: 0 16px 12px 36px; }
details.quiz li { margin: 8px 0; }
details.quiz p.q { margin: 0; font-weight: 500; }
details.quiz p.a { margin: 4px 0 0; color: var(--tx2); font-size: .92rem; border-left: 2px solid var(--ln); padding-left: 10px; }
details.code-fold > .fold-body { padding: 4px 16px 12px; border-top: 1px solid var(--ln); }
details.code-fold > .fold-body pre { margin: 12px 0 0; }
body.study .prose .msgflow { font-size: .76rem; line-height: 1.35; width: auto; max-width: 100%; }

/* ---- Wide reading layout (added 2026-09-21) ----
   The 72ch cap is right for paragraphs and wrong for tables, diagrams, code and interactive blocks: they were
   forced into a narrow column and needed horizontal scrolling on a wide screen. On study pages the page wrapper
   grows with the viewport, the prose column is uncapped, and only the text-like children keep a readable measure. */
body.study main .wrap { max-width: min(1280px, 100% - 48px); }
body.study main .prose { max-width: none; }
body.study main .prose > p,
body.study main .prose > ul,
body.study main .prose > ol,
body.study main .prose > h3,
body.study main .prose > h4,
body.study main .prose > blockquote,
body.study main .prose > .callout,
body.study main .prose > details.quiz { max-width: 78ch; }
body.study main .prose > .lede,
body.study main .subhero .lede { max-width: 82ch; }
body.study main .tablewrap { max-width: none; }
body.study main .tablewrap table { width: 100%; }
body.study main .tablewrap td, body.study main .tablewrap th { white-space: normal; overflow-wrap: anywhere; }
body.study main .tablewrap td code { white-space: normal; }
body.study main .prose > pre, body.study main .prose details.code-fold { max-width: none; }
body.study .prose .wb, body.study .prose .dd { width: auto; max-width: none; }
body.study .prose .wb .wb-grid { grid-template-columns: 220px 280px minmax(0, 1fr); }
@media (max-width: 900px) {
  body.study main .wrap { max-width: none; }
  body.study .prose .wb .wb-grid { grid-template-columns: 1fr; }
}

/* ---- glossary: click-to-reveal definitions for abbreviations (study.js) ----
   The term itself stays inline text with a quiet dotted underline; nothing
   appears on hover, so scanning a paragraph is undisturbed. One popover is
   shared by every term and positioned under (or above) the clicked word. */
.gl {
  all: unset; cursor: pointer; font: inherit; color: inherit;
  text-decoration: underline dotted;
  text-decoration-color: color-mix(in srgb, var(--ac) 55%, transparent);
  text-decoration-thickness: 1.5px; text-underline-offset: 3px;
  border-radius: 3px; transition: text-decoration-color .15s ease, background-color .15s ease;
}
.gl:hover, .gl[aria-expanded="true"] { text-decoration-color: var(--ac); text-decoration-style: solid; }
.gl[aria-expanded="true"] { background: color-mix(in srgb, var(--ac) 12%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ac) 12%, transparent); }
.gl:focus-visible { outline: 2px solid var(--ac); outline-offset: 2px; }

.glpop {
  position: fixed; z-index: 80; width: min(340px, calc(100vw - 24px));
  padding: 12px 14px 12px; font-size: .88rem; line-height: 1.5; color: var(--tx);
  background: var(--bg2); border: 1px solid var(--ln); border-radius: var(--r); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(-4px); transition: opacity .14s ease, transform .14s ease;
}
.glpop.above { transform: translateY(4px); }
.glpop.show { opacity: 1; transform: none; }
.glpop::before {
  content: ""; position: absolute; left: var(--gl-arrow, 50%); top: -6px; width: 10px; height: 10px;
  margin-left: -5px; transform: rotate(45deg);
  background: var(--bg2); border-left: 1px solid var(--ln); border-top: 1px solid var(--ln);
}
.glpop.above::before { top: auto; bottom: -6px; border: 0; border-right: 1px solid var(--ln); border-bottom: 1px solid var(--ln); }
.glpop .glhead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.glpop .glterm { font-family: var(--font-mono); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ac); }
.glpop .glx { font-family: var(--font-head); font-weight: 700; font-size: .98rem; margin-top: 2px; }
.glpop p { margin: 6px 0 0; color: var(--tx2); }
.glpop .glclose {
  all: unset; cursor: pointer; flex: none; width: 24px; height: 24px; margin: -4px -6px 0 0;
  display: inline-grid; place-items: center; border-radius: 999px; font-size: 1.1rem; line-height: 1; color: var(--tx2);
}
.glpop .glclose:hover { color: var(--tx); background: var(--chip); }
.glpop .glclose:focus-visible { outline: 2px solid var(--ac); outline-offset: 1px; }
.glpop:focus { outline: none; }
@media (prefers-reduced-motion: reduce) { .glpop, .gl { transition: none; } .glpop { transform: none; } }
@media print { .gl { text-decoration: none; } .glpop { display: none; } }
