/* The router mounts this shell alongside the Atlas. Keep every rule scoped. */
body.lesson-page {
  margin: 0;
  overflow: hidden;
  background: #0b131e;
  color: #e1eaf1;
  font: 400 16px/1.65 'DM Sans', sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.lesson-page #atlas-root {
  height: 100dvh;
  min-height: 0;
}

#lesson {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto 3px;
  height: 100dvh;
  min-height: 0;
  background: #0b131e;
}

body.lesson-page #lesson-header {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  height: auto;
  min-height: 72px;
  padding: 15px clamp(22px, 3vw, 48px);
  border-bottom: 1px solid #213244;
  background: #0b131e;
}

body.lesson-page #lesson-header .wordmark {
  justify-self: start;
  font: 500 18px/1.4 'Space Grotesk', sans-serif;
  letter-spacing: -.55px;
  color: #e1eaf1;
  white-space: nowrap;
}

#lesson-name {
  margin: 0;
  color: #a0b4c4;
  font-size: 13px;
  letter-spacing: .01em;
}

#lesson-count {
  justify-self: end;
  color: #a0b4c4;
  font: 400 11px/1.5 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#lesson-main {
  display: grid;
  grid-template-columns: minmax(0, 1.86fr) minmax(320px, 1fr);
  min-height: 0;
}

#lesson-visual {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(ellipse at 50% 58%, #152839 0%, #0b131e 72%);
}

#lesson-context {
  position: absolute;
  top: clamp(22px, 4vh, 42px);
  right: 24px;
  left: 24px;
  z-index: 2;
  max-width: 640px;
  margin: 0 auto;
  color: #a3b7c7;
  font-size: clamp(12px, 1.15vw, 15px);
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

#lesson-canvas,
#lesson-labels {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#lesson-canvas {
  display: block;
  outline: none;
  touch-action: pan-y;
}

#lesson-labels {
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

#lesson-labels .lesson-scene-label,
#lesson-labels .lesson-label,
#lesson-labels .label {
  position: absolute;
  margin: 0;
  padding: 3px 7px;
  transform: translate(-50%, -50%);
  color: #d7e7f0;
  font: 500 15px/1.4 'Space Grotesk', sans-serif;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 2px 10px #07101d, 0 0 5px #07101d;
  pointer-events: none;
}

#lesson-labels .lesson-scene-label {
  max-width: min(250px, 43vw);
  padding: 4px 7px;
  border-radius: 4px;
  background: #0b131eb3;
  font-size: clamp(12px, 1.12vw, 17px);
  line-height: 1.45;
}

#lesson-labels .lesson-label small,
#lesson-labels .label small {
  display: block;
  margin-top: 5px;
  color: #a1b8c9;
  font: 400 11px/1.45 'DM Sans', sans-serif;
}

#lesson-copy {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 0;
  padding: clamp(28px, 4vw, 64px) clamp(26px, 3.7vw, 60px);
  overflow-y: auto;
  border-left: 1px solid #213244;
  scrollbar-width: thin;
  scrollbar-color: #30485b transparent;
}

#lesson-copy-inner {
  width: 100%;
  max-width: 430px;
  margin: auto;
}

#lesson-section {
  margin: 0 0 18px;
  color: #81c7bd;
  font: 400 11px/1.6 'IBM Plex Mono', monospace;
  letter-spacing: .035em;
}

#lesson-title {
  margin: 0 0 24px;
  color: #e4edf4;
  font: 500 clamp(28px, 2.8vw, 42px)/1.16 'Space Grotesk', sans-serif;
  letter-spacing: -.045em;
  text-wrap: balance;
}

#lesson-why {
  margin: 0 0 20px;
  color: #d5e0e8;
  font-size: clamp(16px, 1.4vw, 19px);
  line-height: 1.55;
}

#lesson-explanation {
  color: #9fb3c4;
  font-size: clamp(14px, 1.16vw, 17px);
  line-height: 1.8;
  overflow-wrap: anywhere;
}

#lesson-explanation p {
  margin: 0 0 14px;
}

#lesson-explanation p:last-child {
  margin-bottom: 0;
}

#lesson-equation {
  margin: 27px 0;
  padding: 18px 0 18px 18px;
  overflow: visible;
  border: 0;
  border-left: 2px solid #496e74;
  background: transparent;
  color: #bcdedb;
  font: 400 clamp(12px, 1.07vw, 15px)/1.8 'IBM Plex Mono', monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

#lesson-equation:empty {
  display: none;
}

#lesson-takeaway {
  margin: 0;
  color: #dce8ef;
  font-size: clamp(14px, 1.15vw, 16px);
  line-height: 1.65;
}

body.lesson-page #lesson-footer {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1.86fr) minmax(320px, 1fr);
  align-items: center;
  gap: 0;
  height: auto;
  min-height: 92px;
  padding: 15px clamp(22px, 3vw, 48px);
  border-top: 1px solid #213244;
  background: #0b131e;
}

#lesson-reference {
  min-width: 0;
  padding-right: 24px;
}

#lesson-reference-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 18px;
}

#lesson-basis {
  margin: 0;
  color: #839aae;
  font-size: 11px;
  line-height: 1.6;
}

#lesson-source {
  color: #a4c9c4;
  font-size: 11px;
  line-height: 1.6;
  text-decoration: none;
  text-underline-offset: 4px;
}

#lesson-source:hover {
  color: #d3f0e9;
  text-decoration: underline;
}

#lesson-status {
  min-height: 15px;
  margin: 4px 0 0;
  color: #b8a989;
  font-size: 10px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

#lesson-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 350px;
  justify-self: end;
}

#lesson-controls button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 46px;
  padding: 11px 16px;
  border: 1px solid #32495b;
  border-radius: 7px;
  background: transparent;
  color: #c2d0dc;
  font: 500 13px/1.5 'DM Sans', sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

#lesson-controls button:hover:not(:disabled) {
  border-color: #658b91;
  background: #142634;
  color: #eef7fa;
}

#lesson-controls #lesson-next {
  border-color: #beded7;
  background: #beded7;
  color: #122b2c;
}

#lesson-controls #lesson-next:hover:not(:disabled) {
  border-color: #dcf3ec;
  background: #dcf3ec;
  color: #0c2425;
}

#lesson-controls #lesson-play[aria-pressed="true"] {
  border-color: #5d8d86;
  background: #142e30;
  color: #cef0e7;
}

#lesson-controls button:disabled {
  opacity: .38;
  cursor: default;
}

body.lesson-page #lesson a:focus-visible,
body.lesson-page #lesson button:focus-visible,
body.lesson-page #lesson-title:focus-visible {
  outline: 2px solid #83d9c8;
  outline-offset: 5px;
}

#lesson-progress {
  height: 3px;
  overflow: hidden;
  background: #182b3a;
}

#lesson-progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background: #83cdbf;
  transition: width 220ms ease;
}

@media (max-width: 1000px) and (min-width: 761px) {
  #lesson-main,
  body.lesson-page #lesson-footer {
    grid-template-columns: minmax(0, 1.55fr) minmax(310px, 1fr);
  }

  #lesson-copy {
    padding: 28px;
  }

  #lesson-title {
    font-size: 31px;
  }
}

@media (max-width: 760px) {
  body.lesson-page {
    overflow: auto;
  }

  body.lesson-page #atlas-root {
    height: auto;
    min-height: 100dvh;
  }

  #lesson {
    height: auto;
    min-height: 100dvh;
    grid-template-rows: auto 1fr auto 3px;
  }

  body.lesson-page #lesson-header {
    grid-template-columns: 1fr auto;
    gap: 3px 18px;
    min-height: 67px;
    padding: 11px 19px;
  }

  body.lesson-page #lesson-header .wordmark {
    font-size: 16px;
  }

  #lesson-name {
    grid-column: 1;
    grid-row: 2;
    font-size: 11px;
  }

  #lesson-count {
    grid-column: 2;
    grid-row: 1 / 3;
    font-size: 10px;
  }

  #lesson-main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
  }

  #lesson-visual {
    height: 42svh;
    min-height: 230px;
    max-height: 440px;
  }

  #lesson-context {
    top: 20px;
    right: 19px;
    left: 19px;
    font-size: 12px;
  }

  #lesson-labels .lesson-label,
  #lesson-labels .label {
    font-size: 13px;
  }

  #lesson-copy {
    display: block;
    padding: 25px 24px 32px;
    overflow: visible;
    border-top: 1px solid #213244;
    border-left: 0;
  }

  #lesson-copy-inner {
    max-width: 520px;
  }

  #lesson-section {
    margin-bottom: 12px;
    font-size: 10px;
  }

  #lesson-title {
    margin-bottom: 18px;
    font-size: clamp(27px, 7vw, 35px);
    line-height: 1.18;
  }

  #lesson-why {
    margin-bottom: 15px;
    font-size: 17px;
  }

  #lesson-explanation {
    font-size: 15px;
    line-height: 1.75;
  }

  #lesson-equation {
    margin: 22px 0;
    padding: 12px 0 12px 15px;
    font-size: 13px;
  }

  #lesson-takeaway {
    font-size: 15px;
  }

  body.lesson-page #lesson-footer {
    position: fixed;
    right: 0;
    bottom: 3px;
    left: 0;
    display: flex;
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 10px;
    min-height: 0;
    padding: 12px 19px calc(10px + env(safe-area-inset-bottom));
    background: #0b131ef5;
    backdrop-filter: blur(14px);
  }

  #lesson-controls {
    gap: 9px;
    max-width: none;
  }

  #lesson-main {
    padding-bottom: 156px;
  }

  #lesson-controls button {
    min-height: 46px;
    padding: 10px 12px;
    font-size: 13px;
  }

  #lesson-reference {
    padding: 0;
  }

  #lesson-reference-line {
    justify-content: space-between;
    gap: 5px 12px;
  }

  #lesson-basis,
  #lesson-source {
    font-size: 10px;
  }

  #lesson-status {
    min-height: 0;
    margin-top: 3px;
  }

  #lesson-status:empty {
    display: none;
  }

  #lesson-progress {
    position: fixed;
    z-index: 5;
    right: 0;
    bottom: 0;
    left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.lesson-page #lesson *,
  body.lesson-page #lesson *::before,
  body.lesson-page #lesson *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
