:root {
  color-scheme: dark;
  --night: #091610;
  --deep: #10251a;
  --moss: #b5c5a8;
  --light: #f1f0e5;
  --sun: #dfaf6e;
  --leaf: #9fd8a6;
  --line: rgba(181, 197, 168, .28);
  --gutter: clamp(16px, 3vw, 40px);
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--night);
  color: var(--light);
  font: 400 1rem/1.55 var(--sans);
}

a { color: inherit; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* The page is one screen on a desktop: bar, work area, lesson strip. */
.app {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
}

/* Header */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 20px;
  padding: 8px var(--gutter);
}
.brand {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  text-decoration: none;
  white-space: nowrap;
}
.bar h1 {
  margin: 0;
  font: 400 1.25rem/1.2 var(--serif);
  color: var(--moss);
}
.bar nav { margin-left: auto; font-size: .9rem; }
.bar nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
.bar nav a:hover { border-color: currentColor; }
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: .875rem;
  color: var(--moss);
  white-space: nowrap;
}
.progress .track {
  width: 5rem;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.progress .fill { display: block; height: 100%; width: 0; background: var(--sun); transition: width .3s; }

/* Work area: the model, then the lesson */
.work {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding: 0 var(--gutter);
}
.stage {
  position: relative;
  height: clamp(20rem, 56svh, 34rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0b1a13;
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.stage canvas.drag { cursor: grab; touch-action: none; }
.stage canvas.dragging { cursor: grabbing; }
.hint {
  position: absolute;
  top: 10px;
  right: 12px;
  margin: 0;
  padding: 4px 12px;
  font-size: .8125rem;
  color: var(--sun);
  background: rgba(9, 22, 16, .85);
  border: 1px solid rgba(223, 175, 110, .4);
  border-radius: 999px;
  pointer-events: none;
}

.lesson {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: clamp(16px, 2vw, 24px);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.kicker {
  margin: 0;
  font-size: .8125rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--sun);
}
.lesson h2 {
  margin: 0;
  font: 400 clamp(1.6rem, 1.3rem + 1vw, 2.1rem)/1.1 var(--serif);
  letter-spacing: -.01em;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}
.tabs button {
  min-height: 44px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--moss);
  font-size: .9375rem;
  cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--light); border-color: var(--sun); }
.tabs button:disabled { opacity: .55; cursor: not-allowed; }

.pane { flex: 1 0 auto; }
.pane p { margin: 0 0 .8em; }
.pane .term { color: var(--sun); font-weight: 600; }
.pane .note { font-size: .875rem; color: var(--moss); }
.pane .task { border-left: 2px solid var(--sun); padding-left: 12px; }
.pane h3 { margin: 0 0 .5em; font: 400 1.25rem/1.2 var(--serif); }
.pane ul.facts { margin: 0 0 1em; padding-left: 1.1em; }
.pane ul.facts li { margin: .3em 0; }

.ctl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0 12px;
  align-items: baseline;
  margin: 12px 0 4px;
}
.ctl label { font-size: .875rem; color: var(--moss); }
.ctl output { font-size: .9375rem; font-variant-numeric: tabular-nums; text-align: right; }
.ctl input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 44px;
  margin: 0;
  accent-color: var(--sun);
}
.ends {
  display: flex;
  justify-content: space-between;
  margin: -6px 0 8px;
  font-size: .8125rem;
  color: var(--moss);
}

.btn {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--moss); }
.btn.primary {
  background: var(--sun);
  border-color: var(--sun);
  color: var(--night);
  font-weight: 600;
}
.btn.primary:hover:not(:disabled) { background: #ebc084; border-color: #ebc084; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.goals { list-style: none; margin: 12px 0 0; padding: 0; }
.goals li {
  display: grid;
  grid-template-columns: 1.4em 1fr;
  padding: 5px 0;
  color: var(--moss);
}
.goals li::before { content: "\25CB"; }
.goals li.ok { color: var(--leaf); }
.goals li.ok::before { content: "\2713"; }
.done-line {
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.q { border: 0; margin: 0 0 18px; padding: 0; min-width: 0; }
.q legend {
  padding: 0;
  margin-bottom: 6px;
  font: 400 1.15rem/1.3 var(--serif);
}
.opt {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 6px 0;
  padding: 8px 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.opt:hover:not(:disabled) { border-color: var(--moss); }
.opt:disabled { cursor: default; }
.opt.right { border-color: var(--leaf); color: var(--leaf); }
.opt.wrong { color: var(--moss); text-decoration: line-through; }
.fb { min-height: 1.55em; margin: 6px 0 0; font-size: .9375rem; color: var(--moss); }

.now { border-top: 1px solid var(--line); padding-top: 12px; }
.now h3 {
  margin: 0 0 8px;
  font-size: .8125rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--moss);
}
.now dl {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr;
  gap: 8px;
  margin: 0;
}
.now dt { font-size: .8125rem; color: var(--moss); }
.now dd {
  margin: 0;
  min-height: 1.6em;
  font: 400 1.1rem/1.3 var(--serif);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dock { display: grid; gap: 12px; }
.steps { display: flex; justify-content: space-between; gap: 12px; }
.steps .primary { margin-left: auto; }

/* Lesson strip */
.strip { padding: 12px var(--gutter) 14px; min-width: 0; }
.strip .model { margin: 8px 0 0; font-size: .8125rem; color: var(--moss); }
.strip ol {
  list-style: none;
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 2px;
  overflow-x: auto;
}
.strip button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  color: var(--moss);
  white-space: nowrap;
  cursor: pointer;
}
.strip button:hover { border-color: var(--moss); }
.strip button[aria-current] { border-color: var(--sun); color: var(--light); }
.strip .n { font: 400 1.2rem/1 var(--serif); color: var(--sun); }
.strip .tick { font-size: .8125rem; color: var(--leaf); }

@media (min-width: 60rem) {
  .app { height: 100vh; height: 100svh; }
  .work {
    grid-template-columns: minmax(0, 1fr) minmax(21rem, 27rem);
    min-height: 0;
  }
  .stage { position: relative; top: auto; height: auto; min-height: 0; }
  .lesson { min-height: 0; overflow-y: auto; }
  /* the readout and the Back and Next buttons stay in view while the text scrolls */
  .dock {
    position: sticky;
    bottom: 0;
    margin-bottom: calc(-1 * clamp(16px, 2vw, 24px));
    padding-bottom: clamp(16px, 2vw, 24px);
    background: var(--night);
  }
}

/* On a phone the model stays at the top while the lesson scrolls below it. */
@media (max-width: 59.99rem) and (min-height: 36rem) {
  .stage { position: sticky; top: 8px; z-index: 2; height: clamp(17rem, 46svh, 26rem); }
}

@media (prefers-reduced-motion: reduce) {
  .progress .fill { transition: none; }
}
