/* ── the lesson card ───────────────────────────────────────────────────
 *
 * Fixed to the viewport and dragged by its title bar, so it can be put
 * anywhere on the window — over the rail, the inspector or the terminal.
 * Overlap is the point: the learner decides what matters right now. It starts
 * at the top-left of the canvas, scrolls inside itself, and is clamped to the
 * viewport so it can never be dragged somewhere it cannot be dragged back from.
 */

.lesson {
  position: fixed;
  top: 58px;
  left: 248px;
  z-index: 60;
  width: min(460px, calc(100vw - 2 * var(--sp-3)));
  max-height: calc(100vh - 70px);
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--bg-1) 94%, transparent);
  border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(3px);
  font-size: 12px;
  line-height: 1.55;
}

/* ── head ──────────────────────────────────────────────────────────── */
.lsn__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 7px var(--sp-3);
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  flex: none;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.lesson--dragging { cursor: grabbing; }
.lesson--dragging .lsn__head { cursor: grabbing; }
/* No transition while dragging, or the card lags a frame behind the pointer. */
.lesson--dragging * { transition: none !important; }
/* the drag affordance, left of the number */
.lsn__grip {
  color: var(--fg-2);
  font-size: 11px;
  line-height: 1;
  letter-spacing: -1px;
}
.lsn__num {
  font-size: var(--label-size);
  letter-spacing: var(--label-track);
  color: var(--accent);
  border: 1px solid var(--line);
  padding: 1px 5px;
}
.lsn__title {
  font-size: 12px;
  color: var(--fg);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lsn__proto {
  font-size: var(--label-size);
  letter-spacing: var(--label-track);
  color: var(--fg-2);
}
.lsn__close {
  color: var(--fg-2);
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}
.lsn__close:hover { color: var(--accent); }

/* ── body ──────────────────────────────────────────────────────────── */
.lsn__body {
  padding: var(--sp-3);
  overflow-y: auto;
  min-height: 0;
}

/* the question the previous chapter left open */
.lsn__question {
  color: var(--fg-2);
  font-style: italic;
  border-left: 2px solid var(--line);
  padding-left: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.lsn__intro {
  color: var(--fg-1);
  margin-bottom: var(--sp-3);
}

/* ── tier 1: story beats ───────────────────────────────────────────── */
.lsn__beat { margin-bottom: var(--sp-3); }
.lsn__beat--new { animation: lsn-in var(--t-med) both; }

@keyframes lsn-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .lsn__beat--new { animation: none; }
}

.lsn__line { color: var(--fg); }
.lsn__line + .lsn__line { color: var(--fg-1); }

.lsn__art {
  margin-top: var(--sp-2);
  padding: var(--sp-2);
  background: var(--bg);
  border: 1px solid var(--line-soft);
  color: var(--fg-1);
  font-size: 10px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
}

.lsn__hook {
  margin: var(--sp-3) 0;
  padding: var(--sp-2) var(--sp-3);
  border-left: 2px solid var(--accent);
  background: var(--accent-soft);
  color: var(--fg);
}

.lsn__actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line-soft);
}
.lsn__cta {
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 12px;
  font-size: 11px;
  letter-spacing: 0.04em;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.lsn__cta:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.lsn__count {
  font-size: var(--label-size);
  letter-spacing: var(--label-track);
  color: var(--fg-2);
  margin-left: auto;
}

/* the story hands over the first real command instead of ending on advice */
.lsn__handoff {
  margin-top: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border: 1px dashed var(--line);
}
.lsn__handoffSay {
  color: var(--fg-1);
  margin-bottom: var(--sp-2);
}

/* ── tier 2: guided steps ──────────────────────────────────────────── */
.lsn__steps {
  list-style: none;
  counter-reset: lsn-step;
  margin: 0;
  padding: 0;
}
.lsn__step {
  counter-increment: lsn-step;
  position: relative;
  padding-left: var(--sp-5);
  padding-bottom: var(--sp-3);
  margin-bottom: var(--sp-3);
  border-bottom: 1px solid var(--line-soft);
}
.lsn__step:last-child { border-bottom: none; }
.lsn__step::before {
  content: counter(lsn-step);
  position: absolute;
  left: 0; top: 1px;
  width: 16px; height: 16px;
  display: grid; place-items: center;
  font-size: 10px;
  color: var(--fg-2);
  border: 1px solid var(--line);
}
.lsn__step--done::before {
  color: var(--ok);
  border-color: var(--ok);
}
.lsn__step--running::before { color: var(--accent); border-color: var(--accent); }
.lsn__step--failed::before  { color: var(--err); border-color: var(--err); }

.lsn__stepSay { color: var(--fg); margin-bottom: var(--sp-2); }

.lsn__stepRow { display: flex; align-items: center; gap: var(--sp-2); }

.lsn__run {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 4px 9px;
  color: var(--accent);
  font-size: 11px;
  max-width: 100%;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.lsn__run:hover { border-color: var(--accent); background: var(--accent-soft); }
.lsn__run code { color: inherit; }
.lsn__runIcon { color: var(--fg-2); font-size: 9px; }
.lsn__run:hover .lsn__runIcon { color: var(--accent); }
.lsn__tick  { color: var(--ok); font-size: 11px; }
.lsn__cross { color: var(--err); font-size: 11px; }
.lsn__spin  { color: var(--accent); font-size: 10px; letter-spacing: 0.06em; }

.lsn__run--busy { opacity: 0.55; cursor: progress; }
.lsn__run:disabled:hover { border-color: var(--line); background: var(--bg); }

/* what the network actually did, measured — not written in advance */
.lsn__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: var(--sp-2);
}
.lsn__chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 2px 6px;
  font-size: 10px;
  max-width: 100%;
  overflow: hidden;
}
.lsn__chipLabel {
  color: var(--fg-2);
  letter-spacing: var(--label-track);
  text-transform: uppercase;
  font-size: 8.5px;
  flex: none;
}
.lsn__chipValue {
  color: var(--in);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lsn__stepFailed {
  margin-top: var(--sp-2);
  padding-left: var(--sp-2);
  border-left: 2px solid var(--err);
  color: var(--fg-1);
}

.lsn__stepAfter {
  margin-top: var(--sp-2);
  padding-left: var(--sp-2);
  border-left: 2px solid var(--ok);
  color: var(--fg-1);
  animation: lsn-in var(--t-med) both;
}

/* ── tier 3: points and byte experiments ───────────────────────────── */
.lsn__points { list-style: none; margin: 0; padding: 0; }
.lsn__point {
  position: relative;
  padding-left: var(--sp-4);
  margin-bottom: var(--sp-3);
  color: var(--fg-1);
}
.lsn__point::before {
  content: '›';
  position: absolute;
  left: 2px;
  color: var(--accent);
}

.lsn__edits {
  margin-top: var(--sp-4);
  border: 1px solid var(--line);
}
.lsn__editsHead {
  padding: 4px var(--sp-2);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  font-size: var(--label-size);
  letter-spacing: var(--label-track);
  color: var(--hl);
}
.lsn__editsHow {
  padding: var(--sp-2);
  color: var(--fg-2);
  border-bottom: 1px solid var(--line-soft);
}
.lsn__edit {
  padding: var(--sp-2);
  border-bottom: 1px solid var(--line-soft);
}
.lsn__edit:last-child { border-bottom: none; }
.lsn__editField { color: var(--fg-1); font-size: 11px; }
.lsn__editArrow { color: var(--fg-2); margin: 0 6px; }
.lsn__editTo { color: var(--hl); font-size: 11px; }
.lsn__editResult { color: var(--fg-1); margin-top: 3px; }

/* ── challenge ─────────────────────────────────────────────────────── */
.lsn__challenge {
  margin-top: var(--sp-4);
  border: 1px solid var(--line);
  border-left: 2px solid var(--mag);
}
.lsn__challengeHead {
  padding: 4px var(--sp-2);
  font-size: var(--label-size);
  letter-spacing: var(--label-track);
  color: var(--mag);
  border-bottom: 1px solid var(--line-soft);
}
.lsn__challengeBody { padding: var(--sp-2); color: var(--fg); }
.lsn__challengeRun {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: 0 var(--sp-2) var(--sp-2);
}
.lsn__challengeStart {
  font-size: var(--label-size);
  letter-spacing: var(--label-track);
  color: var(--fg-2);
}

.iconbtn--on { color: var(--accent); border-color: var(--line); }

/* On a narrow stage the card would cover the whole canvas, so let it sit
   flush and shorter rather than floating over everything. */
@media (max-width: 820px) {
  .lesson { max-height: 60vh; }
}


/* ── glossary ──────────────────────────────────────────────────────────
 *
 * Every term the lessons use is clickable. The underline has to be quiet
 * enough that a paragraph with six terms in it still reads as a paragraph.
 */
.gl {
  color: inherit;
  font: inherit;
  padding: 0;
  border-bottom: 1px dotted var(--fg-2);
  cursor: help;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.gl:hover, .gl:focus-visible {
  color: var(--accent);
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}

.glpop {
  position: fixed;
  z-index: 90;
  width: min(320px, calc(100vw - 16px));
  background: var(--bg-1);
  border: 1px solid var(--accent-dim);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  line-height: 1.55;
}
.glpop__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 5px var(--sp-2);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.glpop__term {
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.06em;
  flex: 1;
}
.glpop__close { color: var(--fg-2); font-size: 14px; line-height: 1; }
.glpop__close:hover { color: var(--err); }
.glpop__body { padding: var(--sp-2) var(--sp-3); color: var(--fg); }
.glpop__see {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px var(--sp-3);
  border-top: 1px solid var(--line-soft);
  color: var(--fg-2);
  font-size: 10px;
  letter-spacing: 0.06em;
  transition: color var(--t-fast), background var(--t-fast);
}
.glpop__see:hover { color: var(--accent); background: var(--accent-soft); }

/* ── the syllabus rail ─────────────────────────────────────────────────
 *
 * Two tabs, because the app has two ways in: a story taken once, and a
 * reference entered anywhere. The whole syllabus is listed including what
 * is not written yet — a rail that hid the gaps would misrepresent how far
 * along this is.
 */
.side__tabs {
  display: flex;
  gap: 1px;
  margin: 0 var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
}
.sidetab {
  flex: 1;
  padding: 5px 4px;
  font-size: 9.5px;
  letter-spacing: 0.12em;
  color: var(--fg-2);
  background: var(--bg-1);
  transition: color var(--t-fast), background var(--t-fast);
}
.sidetab:hover { color: var(--fg); }
.sidetab--on { color: var(--accent); background: var(--accent-soft); }

.side__pane { display: contents; }
.side__count { color: var(--fg-2); letter-spacing: 0; }

.topicgroup { margin-bottom: var(--sp-4); }
.topicgroup__head {
  font-size: 9.5px;
  letter-spacing: var(--label-track);
  text-transform: uppercase;
  color: var(--accent);
  padding: 0 var(--sp-3) 3px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 3px;
}
.topicgroup ul { display: flex; flex-direction: column; }

.topic {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  text-align: left;
  padding: 5px var(--sp-3);
  font-size: 11.5px;
  color: var(--fg-1);
  border-left: 2px solid transparent;
  transition: background var(--t-fast), color var(--t-fast);
}
.topic:hover { background: var(--bg-2); color: var(--fg); }
.topic--active { background: var(--bg-2); border-left-color: var(--accent); color: var(--fg); }
.topic__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topic__lab {
  margin-left: auto;
  font-size: 8px;
  letter-spacing: 0.08em;
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  padding: 0 3px;
  flex: none;
}
/* Listed, dimmed, and still openable — it opens onto a page that says so. */
.topic--todo { color: var(--fg-2); opacity: 0.62; }
.topic--todo .topic__lab { border-color: var(--line); color: var(--fg-2); }

/* ── inside the card ───────────────────────────────────────────────────── */
.lsn__seeChapter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line-soft);
  color: var(--fg-1);
}

.lsn__topicNav {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--line-soft);
}
.lsn__navBtn {
  font-size: 10.5px;
  color: var(--fg-2);
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color var(--t-fast);
}
.lsn__navBtn:hover { color: var(--accent); }


/* ── challenge state ───────────────────────────────────────────────────
 *
 * Two kinds, and the card says which. One is settled by the network and
 * ticks itself; the other asks for an explanation and never ticks, because
 * nothing here can confirm one.
 */
.lsn__challengeHead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}
.lsn__challengeState {
  font-size: 8.5px;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--fg-2);
}
.lsn__challengeState--done { color: var(--ok); }

.lsn__challenge--done { border-left-color: var(--ok); }
.lsn__challenge--done .lsn__challengeHead { color: var(--ok); }


/* ── the doubt box ─────────────────────────────────────────────────────
 *
 * Bottom-right, above the terminal, small until it is wanted. The glossary
 * answers most questions instantly and offline; anything else is labelled as
 * coming from a model rather than from netlens.
 */
.ask {
  position: fixed;
  right: var(--sp-3);
  bottom: calc(var(--term-h, 248px) + var(--sp-3));
  z-index: 55;
  display: flex;
  justify-content: flex-end;
}

.ask__open {
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-1) 92%, transparent);
  backdrop-filter: blur(3px);
  color: var(--fg-2);
  padding: 5px 11px;
  font-size: 11px;
  letter-spacing: 0.04em;
  transition: color var(--t-fast), border-color var(--t-fast);
}
.ask__open:hover { color: var(--accent); border-color: var(--accent); }

.ask__panel {
  width: min(360px, calc(100vw - 2 * var(--sp-3)));
  border: 1px solid var(--accent-dim);
  background: color-mix(in srgb, var(--bg-1) 96%, transparent);
  backdrop-filter: blur(4px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-size: 12px;
}

.ask__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 6px var(--sp-3);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  font-size: var(--label-size);
  letter-spacing: var(--label-track);
  text-transform: uppercase;
  color: var(--fg-2);
}
.ask__close { color: var(--fg-2); font-size: 14px; line-height: 1; }
.ask__close:hover { color: var(--err); }

.ask__form { display: flex; gap: 1px; padding: var(--sp-2); }
.ask__input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
}
.ask__input:focus { outline: none; border-color: var(--accent); }
.ask__send {
  border: 1px solid var(--accent-dim);
  background: var(--accent-soft);
  color: var(--accent);
  padding: 5px 12px;
  font-size: 11px;
}
.ask__send:hover:not(:disabled) { background: var(--accent); color: var(--bg); }
.ask__send:disabled { opacity: 0.5; cursor: progress; }

.ask__answer {
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
  border-top: 1px solid var(--line-soft);
  border-left: 2px solid var(--ok);
  color: var(--fg);
  animation: lsn-in var(--t-med) both;
}
/* A model's answer is marked as one. It is not netlens speaking. */
.ask__answer--model { border-left-color: var(--warn); }
.ask__answer--none { border-left-color: var(--fg-2); color: var(--fg-1); }

.ask__from {
  font-size: 9px;
  letter-spacing: var(--label-track);
  text-transform: uppercase;
  color: var(--fg-2);
  margin-bottom: 4px;
}
.ask__answer--ok .ask__from { color: var(--ok); }
.ask__answer--model .ask__from { color: var(--warn); }
.ask__reason { color: var(--fg-2); font-size: 10.5px; margin-top: 4px; }

@media (max-width: 620px) {
  .ask { left: var(--sp-3); justify-content: stretch; }
  .ask__panel { width: 100%; }
}
