/* learn.css — the Learn course page. Builds on rubiks.css; colours are site tokens. */

.learn-hero { margin-bottom: 16px; }
.learn-hero h1 { margin-bottom: 0.3em; }

.learn-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

/* ── table of contents ─────────────────────────────────────────────────── */
.learn-toc {
  position: sticky; top: calc(var(--bar-h) + 12px);
  max-height: calc(100vh - var(--bar-h) - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 10px 14px 14px;
  scrollbar-width: thin;
}
.learn-toc-toggle { display: none; }
.course-progress { padding: 0 4px 10px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.course-progress p { margin: 6px 0 0; }
.course-meter {
  height: 8px; border-radius: var(--radius-pill);
  background: var(--surface-sunken); border: 1px solid var(--line); overflow: hidden;
}
.course-meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.3s; }

.toc-chapters, .toc-sections { list-style: none; margin: 0; padding: 0; }
.toc-chapter + .toc-chapter { margin-top: 10px; }
.toc-chapter-head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 4px 4px;
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-dim);
}
.toc-chapter-title { flex: 1; }
.toc-chapter-count { font-family: var(--font-mono); font-weight: 600; letter-spacing: 0; color: var(--ink-faint); }
.toc-chapter.is-complete .toc-chapter-count { color: var(--safe-text); }

.toc-link {
  display: flex; align-items: center; gap: 10px;
  min-height: 36px; padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--ink); text-decoration: none; font-size: 0.92rem; line-height: 1.3;
}
.toc-link:hover { background: var(--surface-hi); }
.toc-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.toc-tick {
  flex: none; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line-strong);
  display: grid; place-items: center;
}
.toc-link.is-done .toc-tick { background: var(--safe); border-color: var(--safe); }
.toc-link.is-done .toc-tick::after {
  content: ''; width: 8px; height: 4px; margin-top: -2px;
  border: solid #fff; border-width: 0 0 2px 2px; transform: rotate(-45deg);
}
.toc-guides { margin: 14px 4px 0; }

/* ── a lesson ──────────────────────────────────────────────────────────── */
.learn-main { min-width: 0; max-width: 860px; }
.lesson-head h2 { font-size: clamp(1.4rem, 1.15rem + 1vw, 1.9rem); outline: none; }
.lesson-head { margin-bottom: 14px; }
.lesson-help { text-decoration: none; min-height: 32px; }
.lesson-help:hover { border-color: var(--accent); }
.lesson-body > * { max-width: 72ch; }
.lesson-body > .lfigs, .lesson-body > .lp, .lesson-body > .practice,
.lesson-body > .algtable, .lesson-body > .movedemo { max-width: none; }
.lesson-body p, .lesson-list { font-size: 1.02rem; }
.lesson-h { margin-top: 1.6em; font-size: 1.15rem; }
.lesson-list { padding-left: 1.4em; margin: 0 0 1em; }
.lesson-list li + li { margin-top: 0.35em; }
.lesson-body code.alg { white-space: nowrap; }
.lesson-links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.callout {
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  background: var(--surface); border-radius: var(--radius);
  padding: 10px 14px; margin: 1.2em 0;
}
.callout p { margin: 0; }
.callout .callout-title {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--accent-text); margin-bottom: 4px;
}
.callout.mistake { border-left-color: var(--warn); }
.callout.mistake .callout-title { color: var(--warn); }

/* figures */
.lfigs {
  display: grid; gap: 14px; margin: 1.2em 0;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
}
.lfigs.is-single { grid-template-columns: minmax(0, 360px); }
.lfig { margin: 0; text-align: center; }
.lfig-pic {
  background: var(--surface-sunken); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 12px;
  display: grid; place-items: center;
}
.lfig-pic svg { width: 100%; max-width: 200px; height: auto; display: block; }
.lfigs.is-single .lfig-pic svg { max-width: 300px; }
.lfig figcaption { font-size: var(--fs-small); color: var(--ink-dim); margin-top: 6px; line-height: 1.4; }
.lfig figcaption strong { color: var(--ink); }

/* animated algorithm */
.lp {
  margin: 1.2em 0; padding: 14px;
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.lp-cap h4 { margin: 0 0 6px; font-size: 1.05rem; }
.lp-cap p { margin: 0 0 8px; color: var(--ink-dim); }
.lp-cap .lp-alg { margin-top: 10px; }
.lp-cap .lp-alg code.alg { font-size: 1.05rem; white-space: normal; display: inline-block; }
.lp-host { min-width: 0; }
.lp-still {
  aspect-ratio: 1 / 1; border-radius: var(--radius-lg);
  background: var(--surface-sunken); border: 1px solid var(--line);
  display: grid; place-items: center; padding: 18%;
}
.lp-still svg { width: 100%; height: auto; }
.lp .ap-moves { max-height: 120px; overflow: auto; }

/* practice */
.practice { margin: 1.6em 0; }
.practice-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.practice-head h3 { margin: 0; }
.practice-goal { color: var(--ink-dim); }
.practice-stage { max-width: 420px; max-height: 420px; margin: 0 auto 12px; }
.practice-buttons { justify-content: center; margin-bottom: 8px; }
.practice-answer { text-align: center; }
.practice-answer code.alg { white-space: nowrap; }
.practice .muted.small { text-align: center; margin: 6px 0 0; }
.practice-head { flex-wrap: wrap; }
.practice-modes { display: inline-flex; gap: 4px; padding: 3px; margin-left: auto; border-radius: var(--radius-pill); background: var(--surface-sunken); border: 1px solid var(--line); }
.practice-modes .btn { border-radius: var(--radius-pill); min-height: 32px; }
.practice-modes .btn:not(.primary) { background: transparent; border-color: transparent; }
.practice-coach[hidden] { display: none; }
/* coached: the cube and the coach side by side when there is room, else stacked */
.practice { container-type: inline-size; }
.practice.is-coached .practice-body { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.practice.is-coached .practice-stage { max-width: 360px; max-height: 360px; }
@container (min-width: 640px) {
  .practice.is-coached .practice-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); align-items: start; }
  .practice.is-coached .practice-cube { position: sticky; top: calc(var(--learn-bar-h, 64px) + 12px); }
}
/* narrow: the cube stays in view (under the app bar and the contents bar) while you
   scroll through the coach below it */
@container (max-width: 639.98px) {
  .practice.is-coached .practice-cube {
    position: sticky; top: calc(var(--learn-bar-h, 64px) + 50px); z-index: 3;
    background: var(--surface); padding: 6px 0 2px; border-bottom: 1px solid var(--line);
  }
  .practice.is-coached .practice-stage { width: min(100%, 34vh, 260px); margin-bottom: 8px; }
  .practice.is-coached .practice-buttons { margin-bottom: 6px; }
}
/* the coach inside a practice panel: one card, not a card in a card */
.practice-coach .coach { padding: 12px; box-shadow: none; background: var(--surface-sunken); }
.practice-coach .coach-more { gap: 10px; }

/* a case of the white layer (picture, words, player, positions, practice) */
.lesson-body > .lcase { max-width: none; }
.lcase {
  margin: 1.2em 0; padding: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.lcase-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.lcase-title { margin: 0; font-size: 1.12rem; }
.lcase-head .chip { font-size: 0.75rem; }
.lcase-grid { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 18px; align-items: start; }
.lcase-grid:has(.lcase-pics:not(.is-single)) { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); }
.lcase-pics.lfigs { margin: 0; }
.lcase-pics.lfigs.is-single { grid-template-columns: minmax(0, 1fr); }
.lcase-pics .lfig-pic { padding: 10px; }
.lcase-text p { margin: 0 0 0.6em; font-size: 0.98rem; line-height: 1.5; }
.lcase-text p:last-child { margin-bottom: 0; }
.lcase-disturbs { color: var(--ink-dim); }
.lcase .lp { margin: 14px 0 0; background: var(--surface-sunken); }
.lcase-table { width: 100%; border-collapse: collapse; margin: 14px 0 0; font-size: 0.95rem; }
.lcase-table th, .lcase-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lcase-table th { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-dim); }
.lcase-table td:first-child { width: 42%; }
.lcase-table code.alg { white-space: normal; display: inline-block; }
.lcase-actions { margin: 14px 0 0; }
.lcase-practice .practice { margin: 12px 0 0; }

/* optional lessons (the daisy) */
.toc-badge {
  display: inline-block; margin-left: 6px; padding: 0 6px;
  font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; line-height: 1.6;
  border: 1px solid var(--line-strong); border-radius: var(--radius-pill); color: var(--ink-dim);
  vertical-align: 1px;
}
.toc-link.is-optional .toc-tick { border-style: dashed; }
.toc-link.is-optional[aria-current="page"] .toc-badge { border-color: var(--accent-line); color: var(--accent-text); }
.lesson-head.is-optional .eyebrow { color: var(--ink-dim); }

/* move buttons */
.movedemo {
  display: grid; gap: 16px; align-items: center; margin: 1.2em 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 300px);
}
.movedemo-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.movedemo-buttons .btn { min-inline-size: 52px; font-family: var(--font-mono); font-size: 1rem; }
.movedemo-said { margin: 12px 0 0; min-height: 2.6em; }
.movedemo-stage { max-height: 300px; }
.lesson-body > .freecube { max-width: 380px; margin: 1em 0; }
.freecube .row { margin-top: 10px; }

/* algorithm tables */
.algtable { margin: 1em 0 1.6em; }
.algtable-group { display: flex; align-items: center; gap: 8px; margin: 1.4em 0 0.6em; font-size: 1.05rem; }
.algtable-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 168px), 1fr));
}
.algtable-grid.is-wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.case-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 10px; text-align: center; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  cursor: pointer; transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
}
.case-card:hover { border-color: var(--accent-line); box-shadow: var(--shadow-1); transform: translateY(-1px); }
.case-card:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.case-pic { display: flex; gap: 6px; justify-content: center; width: 100%; }
.case-pic svg { width: 100%; max-width: 112px; height: auto; }
.case-pic.is-pair svg { max-width: 96px; }
.case-name { font-weight: 700; font-size: 0.92rem; }
.case-alg {
  font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600; line-height: 1.4;
  color: var(--ink); word-spacing: 0.1em;
}
.case-rec { font-size: 0.78rem; color: var(--ink-dim); line-height: 1.35; }

.case-dialog .rk-dialog-body { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.case-dlg-info code.alg { font-size: 1.05rem; }

/* footer */
.lesson-foot {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center;
  margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line);
}
.lesson-foot > :last-child { justify-self: end; }
.lesson-foot > :first-child { justify-self: start; }
.lesson-foot .btn { max-width: 100%; }
.lf-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 18ch; display: inline-block; vertical-align: bottom; }

/* ── phones and tablets: the contents become a drop-down at the top ─────── */
@media (max-width: 900px) {
  .learn-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .learn-hero .lede { font-size: 1rem; }
  .learn-toc {
    position: sticky; top: var(--learn-bar-h, var(--bar-h)); z-index: 20;
    max-height: none; overflow: visible; padding: 0;
    margin: 0 -16px; border-radius: 0; border-left: 0; border-right: 0;
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  }
  .learn-toc-toggle {
    display: flex; align-items: center; gap: 10px; width: 100%;
    min-height: 48px; padding: 0 16px;
    font: inherit; color: var(--ink); background: transparent; border: 0; cursor: pointer; text-align: left;
  }
  .ltt-label { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent-text); }
  .ltt-current { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
  .learn-toc-toggle svg { transition: transform 0.2s; flex: none; }
  .learn-toc.is-open .learn-toc-toggle svg { transform: rotate(180deg); }
  .learn-toc-body {
    display: none;
    max-height: calc(100vh - var(--learn-bar-h, var(--bar-h)) - 60px); overflow: auto; overscroll-behavior: contain;
    padding: 6px 16px 16px; border-top: 1px solid var(--line);
  }
  .learn-toc.is-open .learn-toc-body { display: block; }
  .lp { grid-template-columns: minmax(0, 1fr); }
  .lcase-grid, .lcase-grid:has(.lcase-pics:not(.is-single)) { grid-template-columns: minmax(0, 1fr); }
  .lcase-pics.lfigs.is-single { grid-template-columns: minmax(0, 260px); }
  .lp-host { max-width: 360px; width: 100%; justify-self: center; }
  .movedemo { grid-template-columns: minmax(0, 1fr); }
  .movedemo-stage { max-width: 300px; margin: 0 auto; }
  .case-dialog .rk-dialog-body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .lesson-foot { grid-template-columns: 1fr 1fr; }
  .lesson-foot > :nth-child(2) { grid-column: 1 / -1; grid-row: 1; justify-self: stretch; }
  .lf-label { max-width: 11ch; }
  .lfigs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lfigs.is-single { grid-template-columns: minmax(0, 1fr); }
  .algtable-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .algtable-grid.is-wide { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .course-meter span, .case-card, .learn-toc-toggle svg { transition: none; }
}
