/* Stage opening for guide pages, matching the Critical Path "stage" look:
   a radial field with a faint drafting grid that fades toward the edges, then
   an accent label, a 120px accent rule, the title, the short answer (the hook a
   search result can quote), and a quiet footer line.
   Colors come from civil.css tokens, so day and night both work. The entrance
   rises and staggers once on load (about 1.2s) and is off under reduced motion.
   Further down, scripts/stage.js draws section icons and rails as they scroll in. */
.stage-open {
  --stage-pad: clamp(24px, 4vw, 48px);
  position: relative; isolation: isolate; overflow: hidden;
  margin: calc(-1 * clamp(8px, 2vw, 20px)) calc(-1 * var(--stage-pad)) 0;
  padding: clamp(48px, 7vw, 88px) var(--stage-pad) clamp(36px, 5vw, 56px);
  border-bottom: 1px solid var(--border-line);
  background: radial-gradient(circle at 50% 30%, var(--bg-card), color-mix(in srgb, var(--bg-canvas) 70%, var(--bg-card)) 75%);
  text-align: center;
}
.stage-open::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px; background-position: center top;
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 40%, #000 25%, transparent 100%);
          mask-image: radial-gradient(ellipse 70% 70% at 50% 40%, #000 25%, transparent 100%);
}
body.night .stage-open {
  background: radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--accent) 9%, var(--bg-card)), var(--bg-canvas) 78%);
}

.stage-open-inner { width: min(680px, 100%); margin: 0 auto; }
.stage-label {
  margin: 0; color: var(--accent-strong);
  font: 700 .72rem/1.3 "IBM Plex Mono", ui-monospace, monospace; letter-spacing: .24em; text-transform: uppercase;
}
.stage-rule { display: block; width: 120px; height: 2px; margin: 16px auto 22px; background: var(--accent); transform-origin: center; }
.stage-open h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); }

/* The short answer: plain text right under the title. */
.stage-answer { margin: 26px auto 0; }
.stage-answer-label {
  margin: 0 0 8px; color: var(--ink-muted);
  font: 700 .6rem/1.3 "IBM Plex Mono", ui-monospace, monospace; letter-spacing: .16em; text-transform: uppercase;
}
.stage-answer p:not(.stage-answer-label) {
  margin: 0; color: var(--ink); font-size: clamp(1.02rem, 1.5vw, 1.14rem); font-weight: 500; line-height: 1.65; text-wrap: pretty;
}
.stage-foot {
  margin: 26px 0 0; color: var(--ink-muted);
  font: 700 .62rem/1.4 "IBM Plex Mono", ui-monospace, monospace; letter-spacing: .1em; text-transform: uppercase;
}

/* The first line of the body picks up where the opening leaves off. */
.stage-open + .prose { margin-top: clamp(32px, 4vw, 48px); }
.prose .prose-lead { color: var(--ink); font-size: 1.15rem; font-weight: 650; line-height: 1.55; }

/* One closing row that sends the reader to the matching Critical Path module. */
.stage-try { margin: 56px 0 0; }
.stage-try .stage-label { margin-bottom: 10px; text-align: left; letter-spacing: .14em; font-size: .62rem; color: var(--ink-muted); }
.stage-row {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border-line); background: var(--bg-card);
  color: var(--ink); text-decoration: none;
  transition: border-color .15s ease, background-color .15s ease;
}
.stage-row:hover, .stage-row:focus-visible { border-color: var(--accent); }
.stage-row b {
  flex: none; display: grid; place-items: center; width: 28px; height: 28px;
  border: 1px solid var(--accent); color: var(--accent-strong);
  font: 700 .8rem/1 "IBM Plex Mono", ui-monospace, monospace;
}
.stage-row-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.stage-row-name { font-size: .95rem; font-weight: 650; line-height: 1.3; }
.stage-row-text small { color: var(--ink-muted); font-size: .8rem; line-height: 1.4; }
.stage-row-go { flex: none; color: var(--ink-muted); font: 700 .85rem/1 "IBM Plex Mono", ui-monospace, monospace; }
.stage-row:hover .stage-row-go { color: var(--accent-strong); }

body.night .stage-label, body.night .stage-row b { text-shadow: 0 0 9px color-mix(in srgb, currentColor 60%, transparent); }
body.night .stage-rule { box-shadow: 0 0 10px var(--accent); }

/* Entrance: rise and stagger, once. */
@keyframes stage-rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes stage-draw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.stage-open-inner > * { animation: stage-rise .6s cubic-bezier(.22, 1, .36, 1) both; animation-delay: calc(var(--i, 0) * 150ms); }
.stage-open .stage-rule { animation: stage-draw .7s cubic-bezier(.22, 1, .36, 1) both; animation-delay: 150ms; }
.stage-open-inner > :nth-child(3) { --i: 2; }
.stage-open-inner > :nth-child(4) { --i: 3.5; }
.stage-open-inner > :nth-child(5) { --i: 4.5; }

/* Scroll drawing, set up by scripts/stage.js only when motion is allowed:
   a section's icon strokes draw in and its rail line fills downward, and the
   closing Critical Path row rises into place. Interactive figures never fade. Each plays once. Without the script nothing is hidden. */
.stage-motion .section-icon svg * { stroke-dasharray: 1; stroke-dashoffset: 1; transition: stroke-dashoffset .9s cubic-bezier(.4, 0, .2, 1) .1s; }
.stage-motion .section-rail-line { transform: scaleY(0); transform-origin: top; transition: transform 1.2s cubic-bezier(.22, 1, .36, 1) .35s; }
.stage-motion .section-icon { transition: border-color .4s ease; }
.stage-motion .is-drawn .section-icon svg * { stroke-dashoffset: 0; }
.stage-motion .is-drawn .section-rail-line { transform: none; }
.stage-motion .stage-try:not(.is-drawn) { opacity: 0; transform: translateY(16px); }
.stage-motion .stage-try { transition: opacity .6s ease, transform .7s cubic-bezier(.22, 1, .36, 1); }

@media (max-width: 520px) {
  .stage-open { --stage-pad: 20px; margin-top: 0; padding-top: 40px; }
  .stage-row { padding: 8px 10px; gap: 10px; }
  .stage-answer p:not(.stage-answer-label) { text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  .stage-open-inner > *, .stage-open .stage-rule { animation: none; }
}

/* Tool pages: a shorter opening so the tool itself is on the first screen. */
.stage-open.stage-tool { padding-block: clamp(32px, 4.5vw, 52px) clamp(26px, 3.5vw, 38px); margin-bottom: clamp(20px, 3vw, 28px); }
.stage-tool .stage-rule { margin: 12px auto 16px; }
.stage-tool h1 { font-size: clamp(2rem, 4.2vw, 3.1rem); }
.stage-tool .stage-intro { max-width: 600px; margin: 14px auto 0; color: var(--ink-muted); font-size: clamp(1rem, 1.4vw, 1.08rem); line-height: 1.6; }
.stage-tool .stage-foot { margin-top: 16px; }
.stage-label a { color: inherit; text-decoration: none; }
.stage-label a:hover { text-decoration: underline; text-underline-offset: 4px; }
.stage-tool-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 0 0 clamp(20px, 3vw, 28px); }
.stage-foot a { color: inherit; text-underline-offset: 3px; }

/* Use / Learn switch on tool pages (scripts/track-switch.js). Two full-color
   choices: blue for using the tool on your own numbers, green for the
   step-by-step practice. The pressed one fills with its color. */
.track-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 18px; }
.track-btn {
  --t: #2563eb; --t-ink: #fff;
  display: grid; align-content: start; gap: 4px; padding: 12px 16px; min-height: 44px;
  border: 2px solid var(--t); background: var(--bg-card); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.track-learn { --t: #15803d; }
body.night .track-btn { --t: #4da3ff; --t-ink: #06101f; }
body.night .track-learn { --t: #2ff08f; }
.track-btn strong { display: flex; align-items: center; gap: 9px; font-size: 1rem; line-height: 1.25; }
.track-btn strong::before { content: ""; flex: none; width: 9px; height: 9px; background: var(--t); }
.track-btn span { color: var(--ink-muted); font-size: .84rem; line-height: 1.4; }
.track-btn:hover { background: color-mix(in srgb, var(--t) 10%, var(--bg-card)); }
.track-btn:focus-visible { outline: 2px solid var(--t); outline-offset: 3px; }
.track-btn[aria-pressed="true"] { background: var(--t); color: var(--t-ink); }
.track-btn[aria-pressed="true"] span { color: color-mix(in srgb, var(--t-ink) 82%, transparent); }
.track-btn[aria-pressed="true"] strong::before { background: var(--t-ink); }
.mode-tabs[style*="--tab-count"] { grid-template-columns: repeat(var(--tab-count), minmax(0, 1fr)); }
[data-track="learn"] .mode-tab[aria-selected="true"] { box-shadow: inset 0 -3px 0 var(--track-learn, #15803d); }
body.night [data-track="learn"] .mode-tab[aria-selected="true"] { --track-learn: #2ff08f; }
@media (max-width: 640px) {
  .track-switch { gap: 8px; }
  .track-btn { padding: 10px 12px; }
  .track-btn span { display: none; }
  .mode-tabs[style*="--tab-count"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Learning steps that point to sections further down the page. */
.track-steps { list-style: none; padding: 0; }
.track-steps li { display: grid; }
.track-steps a.mode-tab { color: var(--ink); text-decoration: none; }
.track-steps a.mode-tab[aria-current] { background: var(--bg-canvas); box-shadow: inset 0 -3px 0 #15803d; }
body.night .track-steps a.mode-tab[aria-current] { box-shadow: inset 0 -3px 0 #2ff08f; }
.track-steps a.mode-tab:hover .mode-num, .track-steps a.mode-tab:focus-visible .mode-num { text-decoration: underline; text-underline-offset: 3px; }

/* Full screen button (scripts/tool-fullscreen.js). */
.tool-full-btn[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--bg-card); }
body.tool-full-open { overflow: hidden; }
.is-tool-full:fullscreen { background: var(--bg-canvas); }
