/*
 * sections/why-rag.css -- section-specific shells for the "Зачем он нужен"
 * comparison page (AtlasMD 3.10). LOADED IN ADDITION to base.css + the theme
 * (atlas.css). It NEVER redefines a base.css shell and carries NO literal
 * color/size/font/duration -- only var(--...) tokens supplied by the theme.
 *
 * What lives here (section-only; not generic enough for base.css):
 *   - the two-track comparison grid (.tracks / .track / .flow / .conn)
 *   - comparison node body (.cmp-node + kind variants + reveal states)
 *   - the freeze badge, grounding land-pulse, flag pills
 *   - the "why B is better" takeaways grid
 *   - the centered modal drill camera shell (.drill-layer / .drill-stage /
 *     .drill-card) wrapping the consumed drilldown-zoom breadcrumb/zoom-out
 *   - drill-detail body blocks (.kv / .chunkcard / detail-body)
 *
 * Drill camera state machine, breadcrumb (.breadcrumb / .crumb-link), the
 * lens-minus zoom-out (.zoomout) and lens-plus (.deeper) buttons all come from
 * base.css + drilldown-zoom.js -- this file only frames them in the modal.
 *
 * Reduced-motion: base.css already kills all animation/transition under
 * prefers-reduced-motion; the reveal/freeze/grounding/modal states below add
 * an explicit static end-state so JS-off + reduce both read complete.
 */

/* ===========================================================
   BACK-TO-MAP CRUMB (page header trail back to index.html)
   =========================================================== */
.back-to-map {
  display: flex;
  align-items: center;
  gap: var(--sp-0);
  margin: 0 0 var(--sp-1);
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  letter-spacing: 0.04em;
}
.back-to-map .crumb-link {
  color: var(--c-link);
  text-decoration: none;
  border-bottom: var(--bw-1) dotted var(--c-link);
  padding: 2px 2px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.back-to-map .crumb-link:hover { color: var(--c-link-hover); border-bottom-color: var(--c-link-hover); }
.back-to-map .crumb-link:focus-visible { outline: var(--bw-2) solid var(--c-focus); outline-offset: 1px; }
.back-to-map .crumb-current { color: var(--c-link-hover); font-weight: var(--fw-bold); }
.back-to-map .sep { color: var(--c-border); user-select: none; }

/* ===========================================================
   QUESTION LEAD (shared question + stale-memory note)
   =========================================================== */
.cmp-question {
  position: relative;
  z-index: 3;
  max-width: 720px;
  margin: var(--sp-3) auto 0;
  padding: var(--sp-1) var(--sp-3);
  border: var(--bw-1) dashed var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-accent-3-soft);
  color: var(--c-heading);
  font-family: var(--font-body);
  font-size: var(--fs-2);
  line-height: var(--lh-body);
  text-align: center;
}
.cmp-question b { color: var(--c-text); }
.cmp-question .note {
  display: block;
  margin-top: var(--sp-0);
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  font-style: italic;
  color: var(--c-text-muted);
}

/* ===========================================================
   TWO-TRACK GRID
   =========================================================== */
.tracks {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
  margin-top: var(--sp-4);
}
.track {
  position: relative;
  border: var(--bw-1) solid var(--c-border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28), rgba(0,0,0,0.012)),
    var(--c-surface);
  box-shadow: var(--shadow-1);
  padding: var(--sp-3) var(--sp-3) var(--sp-3);
}
.track--A { border-color: var(--c-accent-2); }
.track--B { border-color: var(--c-accent-1); }
.track__tag {
  position: absolute;
  top: -11px;
  left: var(--sp-3);
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  font-weight: var(--fw-bold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  border: var(--bw-1) solid var(--c-heading);
  background: linear-gradient(180deg, var(--c-surface), var(--c-surface-2));
}
.track--A .track__tag { color: var(--c-accent-2); border-color: var(--c-accent-2); }
.track--B .track__tag { color: var(--c-accent-1); border-color: var(--c-accent-1); }
.track__sub {
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  color: var(--c-text-muted);
  margin: var(--sp-0) 0 var(--sp-2) 2px;
}

.flow {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* connectors between nodes (dashed, themed per track) */
.conn {
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}
.conn svg { overflow: visible; }

/* ===========================================================
   COMPARISON NODE (reuses base .node hover/focus; adds body layout)
   =========================================================== */
.cmp-node { padding: var(--sp-1) var(--sp-2); }
.cmp-node__k {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--c-text-muted);
  margin-bottom: 2px;
}
.cmp-node__t {
  display: block;
  font-family: var(--font-body);
  font-size: var(--fs-2);
  font-weight: var(--fw-bold);
  color: var(--c-heading);
  line-height: 1.25;
}
.cmp-node__d {
  display: block;
  font-family: var(--font-ui);
  font-size: var(--fs-1);
  color: var(--c-text-muted);
  margin-top: var(--sp-0);
  line-height: 1.45;
}
.cmp-node .mono { font-family: var(--font-mono); font-size: var(--fs-0); color: var(--c-heading); }
.cmp-node .cite { font-family: var(--font-mono); font-size: var(--fs-0); color: var(--c-accent-1); }
.cmp-node .fresh { font-family: var(--font-ui); font-size: var(--fs-0); color: var(--green-text); font-weight: var(--fw-bold); }
.cmp-node .stale { font-family: var(--font-ui); font-size: var(--fs-0); color: var(--c-accent-2); font-weight: var(--fw-bold); }

/* a non-drill div node must not show the pointer/hover lift */
div.cmp-node { cursor: default; }
div.cmp-node:hover { transform: none; box-shadow: var(--shadow-1); border-color: var(--c-border); }

/* main-path (с-RAG) nodes are clickable steps: visited = earned green ring,
   next-step = themed gold glow (base .node.visited / .node.next-step supply the
   core look; here we ensure they read over the kind-variant surfaces). */
button.cmp-node.visited { border-color: var(--c-progress); box-shadow: 0 0 0 1px var(--c-visited-ring), var(--shadow-1); }
button.cmp-node.next-step { border-color: var(--c-accent-3); }

/* kind variants -- border/surface accents only */
.cmp-node--llmA { border-color: var(--c-accent-2); }
.cmp-node--out-bad {
  border-color: var(--c-accent-2);
  background: linear-gradient(180deg, var(--c-accent-2-soft), var(--c-surface));
}
.cmp-node--out-good {
  border-color: var(--c-progress);
  background: linear-gradient(180deg, var(--c-visited-bg-1), var(--c-visited-bg-2));
}

/* drill hint (lens-plus + label) */
.drillhint {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-0);
  margin-top: var(--sp-1);
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--c-accent-3-text);
  font-weight: var(--fw-bold);
}
.drillhint svg { width: 14px; height: 14px; flex: 0 0 auto; }

/* freeze badge (Без RAG, static accent, no motion) */
.freezetag {
  display: inline-block;
  margin-top: var(--sp-1);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  font-weight: var(--fw-bold);
  letter-spacing: 0.04em;
  border: var(--bw-1) solid var(--c-accent-2);
  color: var(--c-accent-2);
  background: var(--c-accent-2-soft);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--dur-2) var(--ease-1), transform var(--dur-2) var(--ease-1);
}
.freezetag.shown { opacity: 1; transform: translateY(0); }

/* flag pill */
.cmp-flag {
  display: inline-block;
  margin-top: var(--sp-1);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  font-weight: var(--fw-bold);
  letter-spacing: 0.04em;
  border: var(--bw-1) solid var(--c-accent-2);
  color: var(--c-accent-2);
  background: var(--c-accent-2-soft);
}
.cmp-flag.good {
  border-color: var(--c-progress);
  color: var(--green-text);
  background: rgba(23,166,115,0.1);
}

/* the С-RAG retrieval moment: context node accents green as the source lands */
.cmp-node--grounding { position: relative; }
.cmp-node--grounding::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-md);
  pointer-events: none;
  border: var(--bw-2) solid var(--c-progress);
  opacity: 0;
}
.cmp-node--grounding.land::after { animation: cmpLandPulse 1.1s var(--ease-1) forwards; }
@keyframes cmpLandPulse {
  0% { opacity: 0; }
  22% { opacity: 0.95; }
  100% { opacity: 0; }
}

/* ---- progressive reveal: hidden on load, stepped in (transform/opacity) ---- */
.reveal .cmp-node { opacity: 0; transform: translateY(8px); }
.reveal .conn { opacity: 0; }
.cmp-node.shown {
  opacity: 1;
  transform: translateY(0);
  transition: opacity var(--dur-2) var(--ease-1), transform var(--dur-2) var(--ease-1);
}
.conn.shown { opacity: 1; transition: opacity var(--dur-1) var(--ease-1); }

/* ===========================================================
   TAKEAWAYS (why B is better)
   =========================================================== */
.cmp-takeaways {
  position: relative;
  z-index: 2;
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-3) var(--sp-1);
  border: var(--bw-1) solid var(--c-border);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.24), rgba(0,0,0,0.012)),
    var(--c-surface);
  box-shadow: var(--shadow-1);
}
.cmp-takeaways h2 {
  margin: 0 0 var(--sp-2);
  font-family: var(--font-body);
  font-size: var(--fs-3);
  font-weight: var(--fw-bold);
  color: var(--c-heading);
  letter-spacing: 0.01em;
}
.tk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-1) var(--sp-4); }
.tk {
  display: flex;
  gap: var(--sp-1);
  align-items: flex-start;
  font-family: var(--font-ui);
  font-size: var(--fs-1);
  line-height: 1.45;
  color: var(--c-heading);
  padding: var(--sp-1) 0;
}
.tk__body b { color: var(--c-text); font-weight: var(--fw-bold); }
.tk__body .cite { font-family: var(--font-mono); color: var(--c-accent-1); }
.tk__mk {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: var(--bw-1) solid var(--c-accent-1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-accent-1);
  font-family: var(--font-ui);
  font-size: var(--fs-0);
  font-weight: var(--fw-bold);
  margin-top: 1px;
}

/* ===========================================================
   MODAL DRILL CAMERA SHELL (AtlasMD 3.6 strategy 2)
   The breadcrumb (.breadcrumb), zoom-out (.zoomout) + lens-plus (.deeper)
   come from base.css; this only frames them in the centered overlay.
   =========================================================== */
.drill-layer {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: radial-gradient(circle at 50% 40%, rgba(243,234,212,0.93), rgba(60,46,26,0.55));
}
/* closed state via :not(.open) so it beats .has-js .js-only{display:revert}
   and stays hidden with JS off (the .open class is only ever added by JS). */
.drill-layer:not(.open) { display: none; }
.drill-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(560px, 90vw);
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translate(-50%, -50%) scale(0.7);
  opacity: 0;
  transition: transform var(--dur-zoom) var(--ease-1), opacity var(--dur-2) var(--ease-1);
}
.drill-stage.in { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.drill-card {
  border: var(--bw-2) solid var(--c-heading);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.3), rgba(0,0,0,0.02)),
    var(--c-surface-2);
  box-shadow: var(--shadow-plate);
  padding: var(--sp-4) var(--sp-4) var(--sp-4);
}

/* breadcrumb + zoom-out share one row inside the card head */
.drill-card .drill-toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
  margin-bottom: var(--sp-2);
}
.drill-card .drill-toolbar .breadcrumb { flex: 1 1 auto; }
.drill-card .drill-toolbar .zoomout { margin-left: auto; }

/* the rendered detail body */
.drill-detail__h {
  margin: 0 0 var(--sp-0);
  font-family: var(--font-body);
  font-size: var(--fs-3);
  font-weight: var(--fw-bold);
  color: var(--c-heading);
}
.drill-detail__h:focus { outline: none; }
.drill-detail__lead {
  margin: 0 0 var(--sp-2);
  font-family: var(--font-ui);
  font-size: var(--fs-1);
  color: var(--c-text-muted);
  line-height: var(--lh-body);
}
.detail-body {
  font-family: var(--font-ui);
  font-size: var(--fs-1);
  line-height: 1.55;
  color: var(--c-heading);
}
.detail-body p { margin: 0 0 var(--sp-1); }
.detail-body b { color: var(--c-text); }
.detail-body .cite { font-family: var(--font-mono); color: var(--c-accent-1); }

.kv {
  font-family: var(--font-mono);
  font-size: var(--fs-1);
  color: var(--c-text);
  background: var(--c-accent-1-soft);
  border: var(--bw-1) solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-2);
  margin: 0 0 var(--sp-2);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.kv-inline {
  font-family: var(--font-mono);
  background: var(--c-accent-1-soft);
  border: var(--bw-1) solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}
.chunkcard {
  border: var(--bw-1) solid var(--c-accent-1);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-2);
  margin: 0 0 var(--sp-2);
  background: var(--c-accent-1-soft);
}
.chunkcard .src {
  font-family: var(--font-mono);
  font-size: var(--fs-0);
  color: var(--c-accent-1);
  display: flex;
  justify-content: space-between;
  gap: var(--sp-1);
  flex-wrap: wrap;
}
.chunkcard .txt {
  font-family: var(--font-body);
  font-size: var(--fs-2);
  color: var(--c-text);
  margin: var(--sp-1) 0 0;
  font-style: italic;
}

/* deeper lens-plus drill (base .deeper already styles it; add top margin) */
.drill-detail .deeper { margin-top: var(--sp-0); }

/* while a drill is open, neutralise the background tracks -- but NOT the modal
   itself, which is a child of the comparison .plate (re-enable it + its tree). */
body.drilling .plate { pointer-events: none; }
body.drilling .plate .drill-layer,
body.drilling .plate .drill-layer * { pointer-events: auto; }
body.drilling .tracks .cmp-node[data-drill] { visibility: hidden; }

/* ===========================================================
   MOBILE -- tracks stack vertically; must hold at 390 AND 320
   =========================================================== */
@media (max-width: 760px) {
  .tracks { grid-template-columns: 1fr; gap: var(--sp-5); }
  .tk-grid { grid-template-columns: 1fr; }
  .cmp-node__t, .cmp-node__d, .cmp-question, .track__sub, .tk__body {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .kv, .cmp-node .mono { white-space: pre-wrap; overflow-wrap: anywhere; }
  .drill-stage { width: min(560px, 94vw); }
  .drill-card { padding: var(--sp-3) var(--sp-3); }
}
@media (max-width: 400px) {
  .tracks { gap: var(--sp-4); }
  .cmp-question { font-size: var(--fs-1); padding: var(--sp-1) var(--sp-2); }
  .drill-stage { width: 96vw; }
  .drill-card { padding: var(--sp-3) var(--sp-2); }
  .drill-detail__h { font-size: var(--fs-2); }
}

/* reduced-motion: base.css kills animation/transition; pin the static
   end-state so reveal/freeze/modal all read complete (same DOM). */
@media (prefers-reduced-motion: reduce) {
  .reveal .cmp-node { opacity: 1; transform: none; }
  .reveal .conn { opacity: 1; }
  .freezetag { opacity: 1; transform: none; }
  .cmp-node--grounding::after { display: none; }
  .drill-stage { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ===========================================================
   CHAPTER PROSE  (ported manuscript -- S-SB-REPORT3)
   Full chapter text rendered as semantic article content.
   Structure + spacing only; color/space/motion via var(--...).
   Lives here (section file), never in base.css. ASCII only.
   The same block is mirrored inside .no-js-only so the chapter
   reads complete with JavaScript off.
   =========================================================== */
.chapter-prose {
  max-width: 72ch;
  margin: var(--sp-4) auto 0;
  padding: 0 var(--sp-2);
  font-family: var(--font-body);
  font-size: var(--fs-2);
  line-height: var(--lh-body);
  color: var(--c-text);
}
.chapter-prose > section { margin-top: var(--sp-4); }
.chapter-prose > section:first-child { margin-top: 0; }
.chapter-prose h2 {
  font-family: var(--font-body);
  font-weight: var(--fw-bold);
  font-size: var(--fs-3);
  line-height: var(--lh-tight);
  color: var(--c-heading);
  margin: 0 0 var(--sp-2);
  padding-bottom: var(--sp-1);
  border-bottom: var(--bw-1) solid var(--c-border);
}
.chapter-prose h3 {
  font-family: var(--font-body);
  font-weight: var(--fw-bold);
  font-size: var(--fs-2);
  color: var(--c-heading);
  margin: var(--sp-3) 0 var(--sp-1);
}
.chapter-prose p { margin: var(--sp-2) 0; }
.chapter-prose ul,
.chapter-prose ol { margin: var(--sp-2) 0; padding-left: 1.4em; }
.chapter-prose li { margin: var(--sp-1) 0; }
.chapter-prose a {
  color: var(--c-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chapter-prose a:hover { color: var(--c-link-hover); }
.chapter-prose a:focus-visible { outline: var(--bw-2) solid var(--c-focus); outline-offset: 2px; }
.chapter-prose strong,
.chapter-prose b { font-weight: var(--fw-bold); color: var(--c-heading); }
.chapter-prose code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--c-accent-3-soft);
  border: var(--bw-1) solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 0.05em 0.34em;
}
.chapter-prose pre {
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  background: var(--c-code-plate-bg);
  color: var(--c-code-plate-fg);
  border: var(--bw-1) solid var(--c-heading);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
  margin: var(--sp-2) 0;
  overflow: auto;
  white-space: pre;
}
.chapter-prose pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: inherit;
}
.chapter-prose .sources,
.chapter-prose .about-recipe { font-size: var(--fs-1); }
.chapter-prose .sources a,
.chapter-prose .about-recipe a { word-break: break-word; overflow-wrap: anywhere; }
.chapter-prose .next-stop {
  border-left: 3px solid var(--c-accent-1);
  background: var(--c-accent-1-soft);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3);
}
@media (max-width: 560px) {
  .chapter-prose { font-size: var(--fs-1); }
  .chapter-prose pre { font-size: 11.5px; }
}
