/* ==========================================================================
   Classroom: the bookshelf, the sample-lesson strip and the lesson pages
   (classroom.html, lessons/*.html; js/classroom.js). 2026-11-09.

   Paper style: light-grey page, hairline frames, steel-blue / terracotta ink,
   each book carrying its track colour as a thin band (graphics only, never
   text). The lesson animations are paper line art on the soft 'water' blue
   of js/motifs.js, with no box around them.
   ========================================================================== */

/* --- Track colours (decorative: bands, icons) ---------------------------- */

.book, .shelf-group, .lesson-card {
  --track: var(--accent-deco);
}
.t-found  { --track: #d9a52a; }
.t-neuro  { --track: #5980a6; }
.t-deep   { --track: #b4643c; }
.t-nai    { --track: #8a63c9; }
.t-nmr    { --track: #2a8bb0; }
.t-review { --track: #3c9a72; }
:root[data-theme="dark"] .t-found { --track: #e2b54a; }
:root[data-theme="dark"] .t-neuro { --track: #7fa5ca; }
:root[data-theme="dark"] .t-deep  { --track: #d0855d; }
:root[data-theme="dark"] .t-nai   { --track: #a888de; }
:root[data-theme="dark"] .t-nmr   { --track: #4fb0d4; }
:root[data-theme="dark"] .t-review { --track: #5cc49a; }

/* --- The bookshelf ------------------------------------------------------- */

.shelf {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  row-gap: var(--space-12);
  margin: 0;
  padding: 0;
  list-style: none;
}

.shelf-group {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
}

.shelf-books {
  display: flex;
  align-items: flex-end;
  gap: clamp(6px, 0.9vw, 12px);
  margin: 0;
  padding: 0 clamp(10px, 1.6vw, 26px);
  list-style: none;
  /* The board: a hairline plank with a soft shadow under it, joined across groups. */
  border-bottom: 5px solid color-mix(in srgb, var(--text) 16%, var(--bg));
  box-shadow: 0 10px 14px -12px rgba(29, 31, 32, 0.45);
}
.shelf-books > li { margin: 0; display: flex; }

.shelf-label {
  margin: var(--space-3) 0 0;
  padding-inline: clamp(10px, 1.6vw, 26px);
  font-family: var(--font-label);
  font-size: var(--fs-label);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  max-width: 100%;
}
.shelf-label::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 3px;
  margin-right: 7px;
  vertical-align: middle;
  background: var(--track);
}

/* A book: a button drawn as a spine. Paper, a track-colour band, the title
   running top to bottom, a small line-art emblem at the foot. */
.book {
  --w: 66px;
  --h: 252px;
  --paper: #f8f6f1;
  --paper-edge: #e4e0d6;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: var(--w);
  height: var(--h);
  margin: 0;
  padding: 26px 0 12px;
  border: 1px solid var(--rule-strong);
  border-bottom: 0;
  border-radius: 3px 3px 0 0;
  background:
    linear-gradient(90deg, rgba(29, 31, 32, 0.07), transparent 16%, transparent 80%, rgba(29, 31, 32, 0.09)),
    var(--paper);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transform-origin: 0% 100%;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
:root[data-theme="dark"] .book {
  --paper: #303135;
  --paper-edge: #3a3b40;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.28), transparent 16%, transparent 80%, rgba(0, 0, 0, 0.32)),
    var(--paper);
}

/* Two bands of the track colour near the head, one at the foot. */
.book::before,
.book::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--track);
}
.book::before { top: 10px; box-shadow: 0 7px 0 -2px var(--track); }
.book::after { bottom: 46px; height: 1px; opacity: 0.8; }

.book-title {
  writing-mode: vertical-rl;
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: var(--fs-h3);
  line-height: 1.05;
  letter-spacing: 0.01em;
  max-height: calc(var(--h) - 92px);
  overflow: hidden;
}
.book-mark {
  width: 30px;
  height: 30px;
  color: var(--track);
  flex: none;
}
.book-mark svg { display: block; width: 100%; height: 100%; }

/* A bookmark ribbon: this book has an open lesson. */
.book-ribbon {
  position: absolute;
  top: -14px;
  left: 8px;
  width: 9px;
  height: 30px;
  background: var(--highlight-deco);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
}

.book:hover,
.book:focus-visible {
  transform: rotate(-5deg) translateY(-6px);
  box-shadow: 6px 10px 18px -10px rgba(29, 31, 32, 0.5);
}
.book:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.book:active { transform: rotate(-3deg) translateY(-3px); }

/* Sizes, so the row reads as real books. */
.book.s1 { --w: 76px; --h: 300px; }
.book.s2 { --w: 84px; --h: 280px; }
.book.s3 { --w: 80px; --h: 312px; }
.book.s4 { --w: 72px; --h: 270px; }
.book.s5 { --w: 82px; --h: 292px; }

.shelf-hint {
  margin: var(--space-8) auto 0;
  max-width: 62ch;
  text-align: center;
  font-size: var(--fs-small);
  color: var(--muted);
}

@media (max-width: 600px) {
  .shelf { row-gap: var(--space-8); }
  .shelf-books { gap: 5px; padding-inline: 8px; }
  .shelf-label { padding-inline: 8px; font-size: var(--fs-label); }
  .book { --w: 46px; --h: 200px; padding-top: 22px; }
  .book.s1 { --w: 46px; --h: 206px; }
  .book.s2 { --w: 50px; --h: 192px; }
  .book.s3 { --w: 48px; --h: 212px; }
  .book.s4 { --w: 44px; --h: 186px; }
  .book.s5 { --w: 50px; --h: 200px; }
  .book-title { font-size: var(--fs-small); max-height: calc(var(--h) - 78px); }
  .book-mark { width: 22px; height: 22px; }
  .book::after { bottom: 38px; }
  .book-ribbon { left: 5px; width: 8px; height: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .book { transition: none; }
  .book:hover, .book:focus-visible { transform: translateY(-4px); }
}

/* --- The contents sheet (one <dialog> per book) --------------------------- */

.book-sheet {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(540px, 100vw);
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  padding: var(--space-8) clamp(var(--space-6), 4vw, var(--space-12));
  border: 0;
  border-left: 1px solid var(--rule-strong);
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.book-sheet::backdrop {
  background: rgba(29, 31, 32, 0.38);
  backdrop-filter: blur(2px);
}
.book-sheet[open] { animation: sheet-in var(--dur-slow) var(--ease); }
@keyframes sheet-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.sheet-head {
  position: relative;
  padding: 0 44px var(--space-6) 0;
  border-bottom: 1px solid var(--rule);
  margin-bottom: var(--space-6);
}
.sheet-head::before {
  content: "";
  display: block;
  width: 44px;
  height: 4px;
  margin-bottom: var(--space-4);
  background: var(--track);
}
.sheet-kicker {
  margin: 0 0 var(--space-2);
  font-family: var(--font-label);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.sheet-head h2 { margin: 0 0 var(--space-3); }
.sheet-head p { margin: 0; color: var(--muted); }

.sheet-close {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.sheet-close:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }

.chapters {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: ch;
}
.chapters > li {
  counter-increment: ch;
  display: grid;
  grid-template-columns: 2.1em minmax(0, 1fr) auto;
  align-items: baseline;
  gap: var(--space-3);
  margin: 0;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--rule);
}
.chapters > li::before {
  content: counter(ch);
  font-family: var(--font-label);
  font-size: var(--fs-small);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.chapters .ch-title { font-size: var(--fs-body); line-height: 1.35; }
.chapters a.ch-title { color: var(--accent); font-weight: 600; }
.chapters .chip { font-size: var(--fs-label); }

.sheet-open { margin: var(--space-4) 0 0; }
.sheet-foot { margin: var(--space-6) 0 0; font-size: var(--fs-small); color: var(--muted); }

@media (max-width: 600px) {
  .book-sheet {
    inset: auto 0 0 0;
    width: 100vw;
    height: auto;
    max-height: 88dvh;
    border-left: 0;
    border-top: 1px solid var(--rule-strong);
    padding: var(--space-6) var(--space-4) var(--space-8);
  }
  .book-sheet[open] { animation-name: sheet-up; }
  @keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
  .chapters > li { grid-template-columns: 1.6em minmax(0, 1fr); }
  .chapters .chip { grid-column: 2; justify-self: start; }
}

@media (prefers-reduced-motion: reduce) {
  .book-sheet[open] { animation: none; }
}

/* Without JavaScript the sheets are shown in the page (a <noscript> style in classroom.html). */

/* --- Sample lessons strip -------------------------------------------------- */

.lesson-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-6);
}
.lesson-card { padding: 0; border-color: var(--rule-strong); }
.lesson-card .lesson-thumb {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 1;
  border-bottom: 1px solid var(--rule);
  background:
    radial-gradient(ellipse 70% 60% at 50% 55%, color-mix(in srgb, #9fc0e2 34%, transparent), transparent 72%);
}
:root[data-theme="dark"] .lesson-card .lesson-thumb {
  background: radial-gradient(ellipse 70% 60% at 50% 55%, color-mix(in srgb, #335478 55%, transparent), transparent 72%);
}
.lesson-thumb .ink { stroke: var(--accent); }
.lesson-thumb .ink-2 { stroke: var(--accent-deco); }
.lesson-thumb .warm { stroke: var(--highlight-deco); }
.lesson-thumb .fill { fill: color-mix(in srgb, var(--accent-deco) 26%, transparent); }
.lesson-thumb text { fill: var(--accent); font-family: var(--font-label); font-size: 12px; }
.lesson-card-body { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-6); flex: 1; }
.lesson-card .card-title { font-size: var(--fs-h3); }
.lesson-card .card-body { font-size: var(--fs-body); }


@media (max-width: 760px) {
  .lesson-cards { grid-template-columns: 1fr; }
}

/* --- Lesson pages ----------------------------------------------------------- */

.crumbs { padding-top: var(--space-6); }
.crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 0;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--font-label);
  font-size: var(--fs-small);
  letter-spacing: 0.04em;
}
.crumbs li { margin: 0; color: var(--muted); }
.crumbs li + li::before { content: "›"; margin: 0 0.55em; color: var(--muted); }
.crumbs a { color: var(--accent); }

.lesson-hero { padding-block: var(--space-6) var(--space-8); }
.lesson-hero h1 { margin: var(--space-3) 0 var(--space-4); max-width: 22ch; }
.lesson-hero .lede { max-width: 68ch; font-size: var(--fs-lead); margin: 0; }
.lesson-meta { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-4);
  font-size: var(--fs-small); color: var(--muted); }

/* The player: canvas on the water, controls under it, the steps listed. */
.player { margin: 0; }
.player-stage {
  position: relative;
  width: 100%;
  max-width: 1180px;
  margin-inline: auto;
  aspect-ratio: 16 / 8;
}
.player-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
@media (max-width: 760px) { .player-stage { aspect-ratio: 4 / 3.4; } }

.player-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  max-width: 820px;
  margin: var(--space-4) auto 0;
}
.player-bar[hidden] { display: none; }
.player-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.player-btn[hidden] { display: none; }
.player-btn svg { width: 16px; height: 16px; display: block; }
.player-btn:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.player-play { width: 48px; height: 48px; border-color: var(--accent); color: var(--accent); }
.player-play .i-pause { display: none; }
.player-play[aria-pressed="true"] .i-play { display: none; }
.player-play[aria-pressed="true"] .i-pause { display: block; }
.player-scrub { flex: 1 1 200px; display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.player-scrub input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); height: 28px; }
.player-count { font-family: var(--font-label); font-size: var(--fs-small); color: var(--muted);
  font-variant-numeric: tabular-nums; min-width: 4.5ch; text-align: right; }

.player-caption {
  max-width: 820px;
  margin: var(--space-4) auto 0;
  min-height: 3.2em;
  font-size: var(--fs-body);
}
.player-caption b { color: var(--accent); font-family: var(--font-heading); font-weight: var(--font-heading-weight); }

.player-steps {
  max-width: 820px;
  margin: var(--space-6) auto 0;
  padding: 0;
  list-style: none;
  counter-reset: st;
  border-top: 1px solid var(--rule);
}
.player-steps > li {
  counter-increment: st;
  display: grid;
  grid-template-columns: 2em minmax(0, 1fr);
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--rule);
  font-size: var(--fs-small);
}
.player-steps > li::before { content: counter(st); font-family: var(--font-label); color: var(--muted); padding-top: 2px; }
.player-steps button {
  all: unset;
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: var(--font-heading-weight);
  font-size: var(--fs-body);
  color: var(--text);
}
.player-steps button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.player-steps button:hover { color: var(--accent); }
.player-steps button, .player-steps .st-text { grid-column: 2; }
.player-steps .st-text { display: block; color: var(--muted); }
.player-steps > li::before { grid-row: 1 / span 2; }
.player-steps > li[aria-current="step"]::before { color: var(--highlight); font-weight: 700; }
.player-steps > li[aria-current="step"] button { color: var(--accent); }
.player-note { max-width: 820px; margin: var(--space-3) auto 0; font-size: var(--fs-small); color: var(--muted); }

/* The written lesson. */
.lesson-body { max-width: 74ch; }
.lesson-body h2 { margin: var(--space-12) 0 var(--space-4); }
.lesson-body h2:first-child { margin-top: 0; }
.lesson-body p, .lesson-body li { font-size: var(--fs-body); line-height: 1.65; }
.lesson-body .key-ideas { padding-left: 0; list-style: none; }
.lesson-body .key-ideas > li { position: relative; padding-left: 1.4em; margin-bottom: var(--space-3); }
.lesson-body .key-ideas > li::before {
  content: ""; position: absolute; left: 0; top: 0.62em; width: 8px; height: 8px;
  border: 1.5px solid var(--highlight-deco); border-radius: 50%;
}
.lesson-body .walk > li { margin-bottom: var(--space-3); padding-left: 0.3em; }

.formula {
  margin: var(--space-6) 0;
  padding: var(--space-6) var(--space-4);
  border-block: 1px solid var(--rule-strong);
  overflow-x: auto;
  text-align: center;
}
.formula math { font-size: var(--fs-lead); }
.formula + .formula { margin-top: calc(-1 * var(--space-6) + 1px); border-top: 0; }
.formula-note { font-size: var(--fs-small); color: var(--muted); }

.table-wrap { overflow-x: auto; }
.lesson-table { border-collapse: collapse; margin: var(--space-4) 0; font-variant-numeric: tabular-nums; }
.lesson-table th, .lesson-table td { padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--rule); text-align: left; }
.lesson-table th { font-family: var(--font-label); font-weight: 600; letter-spacing: 0.04em; color: var(--muted); }

.code {
  position: relative;
  margin: var(--space-4) 0;
  border: 1px solid var(--rule-strong);
  background: var(--surface-raised);
}
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-label);
  font-size: var(--fs-label);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.code pre {
  margin: 0;
  padding: var(--space-4);
  overflow-x: auto;
  font-size: var(--fs-small);
  line-height: 1.55;
  tab-size: 4;
}
.code pre code { font-size: inherit; }
.code-out pre { color: var(--muted); }
.code .c { color: var(--muted); font-style: italic; }
.code .k { color: var(--accent); font-weight: 600; }
.code .s { color: var(--highlight); }

.check { margin: var(--space-4) 0; border-top: 1px solid var(--rule); }
.check details { border-bottom: 1px solid var(--rule); padding: var(--space-3) 0; }
.check summary { cursor: pointer; font-weight: 600; }
.check details p { margin: var(--space-2) 0 0; }

/* Licence line (owner, 2026-11-09: lesson text under CC BY-NC 4.0; the badge in CSS, no image). */
.lesson-license {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  margin: var(--space-8) 0 var(--space-4); font-size: var(--fs-small); color: var(--muted);
}
.shelf-license { margin-top: var(--space-4); justify-content: center; }
.cc-badge {
  display: inline-flex; flex: none; text-decoration: none;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-md); overflow: hidden;
  font-family: var(--font-label); font-weight: 600; font-size: var(--fs-label); letter-spacing: 0.04em; line-height: 1;
}
.cc-badge span { padding: 4px 6px; color: var(--text); }
.cc-badge span:first-child { background: var(--text); color: var(--bg); text-transform: lowercase; font-weight: 700; }
.cc-badge span + span { border-left: 1px solid var(--rule-strong); }

.lesson-next {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: 1px solid var(--rule-strong);
}
