/* The lesson page: the text at a reading width, the calculator beside it (above it on a narrow screen). */

.top {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--s-4) var(--s-4) 0;
}
.brand { font-weight: 600; white-space: nowrap; color: var(--ink); text-decoration: none; }

/* The footer every page carries (the licence line and the trademark line, decision 60). */
.foot {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--s-5) var(--s-4) var(--s-7);
  font-size: var(--t-xs);
  color: var(--ink-soft);
  border-top: 1px solid var(--line);
}
.foot p { max-width: 90ch; margin: 0; }
.foot a, .index a { color: var(--accent); }

/* The lesson index and the licence page: text at a reading width. */
.index { max-width: 70ch; margin: 0 auto; padding: var(--s-5) var(--s-4) var(--s-8); }
.index h1 { font-size: var(--t-2xl); line-height: var(--lh-tight); margin: var(--s-5) 0 var(--s-3); }
.index h2 { font-size: var(--t-lg); margin: var(--s-6) 0 var(--s-2); }
.lede { color: var(--ink-soft); margin: 0 0 var(--s-5); }
.lesson-list { padding-left: var(--s-5); }
.lesson-list li { margin: 0 0 var(--s-2); }
.tag { font-size: var(--t-xs); color: var(--ink-soft); }
@media (max-width: 599px) { .tag { display: none; } }

/* The mode switch: one segmented radio group for the page (decision 56), like an API doc's tabs. */
.mode-switch { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }
.mode-label { font-size: var(--t-xs); color: var(--ink-soft); }
.mode-group { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.mode-opt { position: relative; font-size: var(--t-sm); font-weight: 600; padding: var(--s-1) var(--s-3); cursor: pointer; }
.mode-opt + .mode-opt { border-left: 1px solid var(--line); }
.mode-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: inherit; }
.mode-opt:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.mode-opt:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.mode-opt:has(input:disabled) { color: var(--ink-faint); cursor: not-allowed; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-6);
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--s-5) var(--s-4) var(--s-9);
}
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 70ch) 380px; justify-content: center; }
  .calc-col { order: 2; position: sticky; top: var(--s-5); align-self: start; }
  .lesson { order: 1; }
}

.calc-actions { display: flex; align-items: center; gap: var(--s-3); margin-top: var(--s-3); }
.btn-keys { display: none; }

/* A narrow screen: the calculator's screen stays in view while the lesson scrolls under it, so "Try it"
   shows its result where the student is reading; the keypad opens on demand. */
@media (max-width: 999px) {
  .calc-col {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg);
    padding: var(--s-2) 0;
    box-shadow: 0 1px 0 var(--line);
  }
  .calc-col .calc { max-width: none; padding: var(--s-2); }
  .calc-col .lcd { margin-bottom: 0; }
  .calc-col:not(.open) .keypad { display: none; }
  .calc-col.open .lcd { margin-bottom: var(--s-3); }
  .calc-actions { margin-top: var(--s-2); }
  .btn-keys { display: inline-block; }
  .layout { gap: var(--s-4); padding-top: 0; }
}
.note { font-size: var(--t-sm); color: var(--err-strong); }

.lesson { max-width: 70ch; }
.prose h1 { font-size: var(--t-2xl); line-height: var(--lh-tight); margin: 0 0 var(--s-5); }
.prose h2 { font-size: var(--t-lg); line-height: var(--lh-tight); margin: var(--s-7) 0 var(--s-3); }
.prose p { margin: 0 0 var(--s-4); }
.prose code { font-family: var(--font-mono); font-size: 0.9em; }
.prose disp, disp {
  font-family: var(--font-mono);
  background: var(--dev-lcd);
  color: var(--dev-lcd-ink);
  border-radius: var(--r-sm);
  padding: 0 var(--s-1);
  white-space: nowrap;
}

.keys {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  margin: 0 0 var(--s-4);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--quick);
}
.keys.active { box-shadow: 0 0 0 2px var(--accent); }
.keys-row { display: flex; flex-wrap: wrap; gap: var(--s-1); }
.keys-side { display: flex; align-items: center; gap: var(--s-2); }
.mode-tag { font-size: var(--t-xs); font-weight: 600; color: var(--accent); }
.chip {
  font-family: var(--font);
  font-size: var(--t-sm);
  font-weight: 600;
  padding: 2px var(--s-2);
  border-radius: var(--r-sm);
  background: var(--dev-key);
  color: var(--dev-key-ink);
}
.chip-gold { background: var(--dev-gold); color: var(--dev-body); }
.chip-blue { background: var(--dev-blue); color: var(--dev-body); }

.btn {
  font: inherit;
  font-size: var(--t-sm);
  font-weight: 600;
  padding: var(--s-1) var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn-try { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.draft {
  font-size: var(--t-sm);
  color: var(--ink-soft);
  margin: 0 0 var(--s-5);
}
.state { color: var(--ink-soft); }
.state-error { color: var(--err-strong); }
