/* reftrainer.css — single-viewport app layout and panel styling.
   Loaded by app.js; the host page only provides the mount div.
   Deliberately the same visual language as lxtrainer.css / pytrainer.css. */

html, body {
  height: 100%;
  margin: 0;
}

.rt-app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  /* Columns/areas are written inline by app.js (nav 240 | lesson 1fr |
     reference 380, with 8px divider columns). */
  grid-template-rows: 1fr;
  gap: 8px;
  padding: 8px;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  overflow-anchor: none;
  background: #f2f3f5;
  color: #1d2129;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

/* ---- pane dividers (created by app.js) ---- */

.rt-divider {
  cursor: col-resize;
  touch-action: none;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.rt-divider::after {
  content: "";
  width: 2px;
  border-radius: 1px;
  background: #d5d9de;
}

.rt-divider:hover::after,
.rt-divider.rt-dragging::after {
  background: #7aa7e8;
}

/* ---- panels ---- */

.rt-panel {
  background: #fff;
  border: 1px solid #d5d9de;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.rt-panel h2 {
  margin: 0;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5b6470;
  background: #f6f7f8;
  border-bottom: 1px solid #e3e6ea;
  flex: none;
  white-space: nowrap;
}

/* A− / A+ text-size controls in each panel header (added by app.js). */
.rt-font-controls {
  float: right;
  display: inline-flex;
  gap: 4px;
  margin: -2px 0;
  text-transform: none;
  letter-spacing: normal;
}

.rt-font-controls button {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  padding: 3px 6px;
  border: 1px solid #c2c8cf;
  border-radius: 4px;
  background: #fafbfc;
  color: #3c4652;
  cursor: pointer;
}

.rt-font-controls button:hover { background: #eef1f4; }

/* ---- course navigation panel ---- */

.rt-nav-body {
  overflow: auto;
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
}

.rt-nav-foot {
  flex: none;
  border-top: 1px solid #e3e6ea;
  padding: 6px 10px;
}

.rt-nav-foot button {
  font: inherit;
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid #c2c8cf;
  border-radius: 5px;
  background: #fafbfc;
  color: #5b6470;
  cursor: pointer;
}

.rt-nav-foot button:hover { background: #eef1f4; }

/* The outline is a browser: expanded/collapsed is a viewing preference,
   independent of which lesson is current. "You are here" is a quiet left
   stripe (.rt-here) carried by the deepest row still visible on the path
   to the current step, so collapsing hands it up rather than losing it. */

.rt-nav-twisty {
  display: inline-block;
  width: 14px;
  flex: none;
  color: #98a2ad;
  font-size: 10px;
  line-height: inherit;
  text-align: center;
  user-select: none;
}

/* The lesson twisty is a real button: its own hit target, so it can
   expand without selecting. */
.rt-nav-twisty-btn {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

.rt-nav-twisty-btn:hover { color: #3c4652; }

.rt-nav-twisty-btn:focus-visible {
  outline: 2px solid #7aa7e8;
  outline-offset: 1px;
  border-radius: 3px;
}

.rt-nav-chapter {
  display: flex;
  align-items: center;
  gap: 2px;
  font-weight: 700;
  color: #3c4652;
  margin: 10px 0 2px;
  padding: 3px 6px 3px 2px;
  border-left: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
}

.rt-nav-chapter:first-child { margin-top: 0; }
.rt-nav-chapter:hover { background: #eef1f4; }

.rt-nav-chapter:focus-visible {
  outline: 2px solid #7aa7e8;
  outline-offset: -2px;
}

.rt-nav-chapter-title { flex: 1; min-width: 0; }

.rt-nav-count {
  flex: none;
  font-weight: 400;
  font-size: 11px;
  color: #98a2ad;
  font-variant-numeric: tabular-nums;
}

.rt-nav-lessons {
  list-style: none;
  margin: 0 0 4px;
  padding: 0 0 0 8px;
}

.rt-nav-lesson-row {
  display: flex;
  align-items: baseline;
  gap: 2px;
  padding: 3px 6px 3px 2px;
  border-left: 2px solid transparent;
  border-radius: 4px;
}

.rt-nav-lesson-label {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.rt-nav-lesson-row:hover { background: #f4f6f8; }
.rt-nav-lesson-label:hover { text-decoration: underline; }

.rt-nav-badge {
  flex: none;
  font-size: 11px;
  color: #5b6470;
  font-variant-numeric: tabular-nums;
}

/* Quiet position marker — not a filled block. */
.rt-here {
  border-left-color: #4b8ee0;
  background: #f2f6fc;
}

.rt-nav-steps {
  list-style: none;
  margin: 2px 0 4px;
  padding: 0 0 0 22px;
}

.rt-nav-step {
  padding: 2px 6px;
  border-radius: 4px;
  color: #5b6470;
  cursor: pointer;
}

.rt-nav-step:hover { background: #eef1f4; }

/* The current STEP keeps a real highlight: neither the breadcrumb nor a
   lesson-level marker can say which of the steps you are on. */
.rt-nav-step.rt-current {
  color: #1d2129;
  font-weight: 600;
  background: #eaf1fc;
}

/* Outline numbering (courses that set `numberedOutline`). The digits are a
   column the eye runs down, so they stay quiet and tabular instead of
   thickening the title they sit beside. */
.rt-nav-num {
  margin-right: 0.45em;
  color: #98a2ad;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

/* Reveal from the breadcrumb: a brief pulse so the eye catches the row. */
@keyframes rt-flash {
  0%, 100% { background: transparent; }
  25%      { background: #ffe9a8; }
}

.rt-flash { animation: rt-flash 1.1s ease-in-out 1; }

@media (prefers-reduced-motion: reduce) {
  .rt-flash { animation-duration: 0.01s; }
}

/* ---- lesson panel ---- */

/* This panel's header is the path to the current step, with each segment a
   control that re-orients the outline. That needs to be readable and
   clickable, so it drops the uppercase micro-label treatment the other
   panel headers use. */
.rt-lesson-title {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: #3c4652;
}

/* The crumbs live in their own container so that re-rendering the
   breadcrumb cannot remove the font controls beside them. */
.rt-crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
}

.rt-crumb {
  font: inherit;
  color: #2c6cc4;
  background: none;
  border: 0;
  margin: 0;
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* When the pane is narrow the chapter gives up room first — the lesson is
   the more useful half of the path to keep readable. */
.rt-crumb { flex: 0 1 auto; min-width: 4ch; }
.rt-crumb:first-of-type { flex-shrink: 4; }

/* This header is a flex container, and `float: right` does nothing to a
   flex item, so the A−/A+ controls have to be pushed to the edge. */
.rt-lesson-title > .rt-font-controls { flex: none; margin-left: auto; }

.rt-crumb:hover { background: #e6eefb; text-decoration: underline; }

.rt-crumb:focus-visible {
  outline: 2px solid #7aa7e8;
  outline-offset: 1px;
}

.rt-crumb-sep { flex: none; color: #98a2ad; }

.rt-lesson-text {
  flex: 1;
  overflow-y: auto;
  padding: 10px 16px;
  line-height: 1.55;
  /* The lesson is the elastic column, so on a wide screen it would run to
     an unreadable measure without a cap. */
  max-width: 46em;
}

.rt-lesson-text h1, .rt-lesson-text h2, .rt-lesson-text h3 {
  margin: 0.3em 0 0.5em;
  font-size: 16px;
  /* Beat the panel-h2 chrome styling for headings inside markdown. */
  text-transform: none;
  letter-spacing: 0;
  color: #1d2129;
  background: none;
  border: none;
  padding: 0;
}

.rt-lesson-text p { margin: 0.6em 0; }
.rt-lesson-text ul, .rt-lesson-text ol { margin: 0.5em 0; padding-left: 22px; }
.rt-lesson-text li { margin: 0.25em 0; }

.rt-lesson-text code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #eef1f4;
  padding: 1px 4px;
  border-radius: 3px;
}

.rt-lesson-text pre {
  background: #f4f5f7;
  border: 1px solid #e3e6ea;
  border-radius: 5px;
  padding: 8px 10px;
  overflow-x: auto;
}

.rt-lesson-text pre code {
  background: none;
  padding: 0;
}

.rt-lesson-foot {
  border-top: 1px solid #e3e6ea;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: none;
}

.rt-step-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rt-lesson-foot button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid #c2c8cf;
  border-radius: 5px;
  background: #fafbfc;
  cursor: pointer;
}

.rt-lesson-foot button:hover:not(:disabled) { background: #eef1f4; }
.rt-lesson-foot button:disabled { opacity: 0.45; cursor: default; }

.rt-step-pos {
  font-size: 12px;
  color: #7a828d;
  white-space: nowrap;
}

.rt-hint summary {
  cursor: pointer;
  color: #2563eb;
  font-size: 13px;
}

/* ---- the confirmation box ----

   This is the Check button's replacement, and it is deliberately NOT
   dressed up as one. There is no sandbox here, so nothing in this page
   verified anything: the tick records the student's own word that what
   they see matches what the step described. It stays quiet and neutral
   until ticked, then turns green — the same success colour the other
   trainers use for a real pass, because to the student the meaning is the
   same: this step is done. */

.rt-confirm {
  border: 1px solid #d5d9de;
  border-left: 3px solid #a8b3bf;
  border-radius: 6px;
  background: #fafbfc;
  padding: 8px 10px;
  font-size: 13px;
}

.rt-confirm-head {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #7a828d;
  margin-bottom: 3px;
}

.rt-confirm-text { color: #1d2129; }

.rt-confirm-text code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #eef1f4;
  padding: 1px 4px;
  border-radius: 3px;
}

.rt-confirm-tick {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 13px;
  color: #5b6470;
  cursor: pointer;
  user-select: none;
}

.rt-confirm-tick input { cursor: pointer; }

.rt-confirm.rt-confirmed {
  background: #e6f6e8;
  border-color: #79c284;
  border-left-color: #2e7d32;
}

.rt-confirm.rt-confirmed .rt-confirm-head,
.rt-confirm.rt-confirmed .rt-confirm-tick { color: #1d6b2a; }

/* ---- reference panel ---- */

.rt-ref-body {
  overflow: auto;
  flex: 1;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}

/* Folded: the column is a sliver, so hide its contents rather than let
   them reflow into an unreadable strip. What is left has to look
   deliberate — a clipped half-word and a stray button read as a broken
   pane, not a closed one — so the header collapses to a single chevron
   pointing at the divider that reopens it. */
.rt-ref.rt-folded .rt-ref-body { display: none; }

.rt-ref.rt-folded h2 {
  font-size: 0;
  padding: 6px 0;
  text-align: center;
}

.rt-ref.rt-folded h2 .rt-font-controls { display: none; }

.rt-ref.rt-folded h2::after {
  content: "\2039";
  font-size: 14px;
  color: #98a2ad;
}

.rt-ref-item + .rt-ref-item {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #eceff2;
}

.rt-ref-item h3 {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #7a828d;
}

.rt-ref-figure {
  margin: 0;
}

.rt-ref-figure img {
  display: block;
  max-width: 100%;
  height: auto;
  border: 1px solid #e3e6ea;
  border-radius: 5px;
  background: #fff;
  cursor: zoom-in;
}

.rt-ref-figure img:focus-visible {
  outline: 2px solid #4b8ee0;
  outline-offset: 2px;
}

/* Full-page view of one diagram. The pane's A+ cannot enlarge a figure —
   it is clamped to the pane width at any zoom — so a click escapes the pane
   entirely. SVG scales losslessly, so this is as large as the screen allows. */
.rt-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  background: rgba(29, 33, 41, 0.74);
  cursor: zoom-out;
}

.rt-lightbox img {
  width: min(96vw, 1200px);
  height: min(80vh, 820px);
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  padding: 14px;
  box-sizing: border-box;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

.rt-lightbox-cap {
  margin: 0;
  max-width: 76ch;
  text-align: center;
  color: #f4f5f7;
  font-size: 13px;
  line-height: 1.45;
}

.rt-lightbox-hint {
  margin: 0;
  color: #98a2ad;
  font-size: 11px;
}

.rt-ref-figure figcaption {
  margin-top: 5px;
  font-size: 12px;
  color: #5b6470;
}

.rt-ref-note p:first-child { margin-top: 0; }
.rt-ref-note p:last-child { margin-bottom: 0; }

.rt-ref-note code {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #eef1f4;
  padding: 1px 4px;
  border-radius: 3px;
}

.rt-ref-note pre {
  background: #f4f5f7;
  border: 1px solid #e3e6ea;
  border-radius: 5px;
  padding: 8px 10px;
  overflow-x: auto;
  margin: 0;
}

.rt-ref-note pre code { background: none; padding: 0; }

.rt-ref-links {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rt-ref-links li { margin: 4px 0; }

.rt-ref-links a {
  color: #2c6cc4;
  text-decoration: none;
}

.rt-ref-links a:hover { text-decoration: underline; }

/* An external link leaves the course, which is worth signalling. */
.rt-ref-links a::after {
  content: " ↗";
  color: #98a2ad;
  font-size: 0.9em;
}

/* ---- error / small-screen states ---- */

.rt-course-error {
  margin: 40px auto;
  max-width: 640px;
  background: #fff;
  border: 1px solid #d5d9de;
  border-radius: 6px;
  padding: 20px 24px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1d2129;
}

.rt-course-error h2 {
  margin: 0 0 10px;
  font-size: 17px;
}

.rt-course-error pre {
  background: #fdecea;
  border: 1px solid #f2a49e;
  border-radius: 5px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: #a8352a;
}

.rt-small-screen p { line-height: 1.5; }

.rt-small-screen button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid #c2c8cf;
  border-radius: 5px;
  background: #fafbfc;
  cursor: pointer;
}

/* Standing course-wide banner at the top of the nav pane, from the course
   file's optional `notice`. Yellow so it reads as a caveat, not chrome.
   No `display` property here on purpose: the element carries the `hidden`
   attribute when there is no notice, and a display rule would override it. */
.rt-nav-notice {
  margin: 0;
  padding: 7px 10px;
  flex: none;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 600;
  color: #6b5200;
  background: #fff3bf;
  border-bottom: 1px solid #ecd77a;
}

/* ---- narrow screens ----------------------------------------------------

   Below the breakpoint in app.js the three columns stack into one and the
   page scrolls, instead of the course refusing to run. This is what makes
   the lesson readable on a phone AND at 200-400% browser zoom, which is
   the same thing as far as the layout is concerned (WCAG 1.4.10 Reflow).

   app.js clears the inline grid-template-columns/areas below this width;
   inline styles would otherwise beat everything here. */
@media (max-width: 859px) {
  .rt-app {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    overflow-x: hidden;
    overflow-y: visible;
  }
  /* Nothing to drag when the panes are stacked. */
  .rt-divider { display: none; }
  /* The outline would otherwise push the lesson off the first screen, so
     it scrolls within a capped height and the lesson stays reachable. */
  .rt-nav { max-height: 42vh; }
  /* A folded reference column is a deliberate sliver in the split layout;
     stacked, a sliver is just a stray box, so it goes entirely. */
  .rt-ref.rt-folded { display: none; }
  /* app.js writes grid-area on each pane inline. With the template areas
     cleared, `grid-area: nav` resolves to line names that do not exist and
     the grid invents implicit COLUMNS for them — which is exactly the
     side-by-side layout we are trying to leave. Inline styles can only be
     beaten with !important here. */
  .rt-panel { grid-area: auto !important; min-height: 0; }
}
