/* Layout ownership: content stays in its reading area; controls remain stationary. */
main > *, .screen-head > div, .screen-content > *, .case-focus > *, .lab-layout > *, .lecture-workspace > * { min-width: 0; }
.screen-head > div { flex: 1; }
.screen-head h1, .lesson-chunk h2, .lecture-narration h2, .example-title h2 { overflow-wrap: anywhere; }
.screen-content { justify-content: safe center; overflow: auto; overscroll-behavior: contain; }
.screen-content > .panel { flex: none; }
.screen-content:focus-visible { outline: 2px solid var(--purple); outline-offset: -3px; }
.lecture-workspace { grid-template-rows: minmax(0,1fr); }
.lecture-visual { min-height: 0; max-height: 100%; height: 100%; display: flex; flex-direction: column; }
.lecture-visual-top, .lecture-transport, .lecture-time { flex: none; }
.lecture-stage { flex: 1; min-height: 0; }
.lecture-diagram { height: 100%; max-height: 100%; }
.lecture-narration { max-height: 100%; overflow: auto; overscroll-behavior: contain; }
.lecture-explanation-open { display: none; }
.paged-reference { padding: 24px; }
.paged-reference .ref-row { padding: 14px 0; }
.paged-reference .ref-row:first-child { padding-top: 0; }
.ref-command { min-width: 0; }
.ref-command code { min-width: 0; flex: 1; }
.ref-command .copy-button { flex: none; }
.lab-layout { grid-template-rows: minmax(0,1fr); }
.lab-layout > aside, .lab-layout > section { min-height: 0; }
@media (min-width: 721px) and (max-width: 1100px), (min-width: 721px) and (max-height: 820px) {
  .flow-controls { display: grid; grid-template-columns: minmax(0,1.15fr) minmax(0,1fr); align-items: center; gap: 16px; }
  .flow-main .flow-step-links { display: none; }
  .flow-step-mobile { display: flex; align-items: center; width: 100%; gap: 12px; }
  .flow-step-mobile select { flex: 1; min-width: 0; }
  .flow-progress { display: flex; gap: 4px; width: 90px; max-width: 90px; flex: none; }
  .flow-progress i { height: 4px; flex: 1; border-radius: 2px; background: var(--line); }
  .flow-progress i.reached { background: var(--purple); }
  .flow-group { display: none; }
  .flow-main .chunk-insight > p { display: none; }
  .flow-main .chunk-insight [data-module-pitfall] { display: flex; align-items: center; min-height: 44px; font-size: 11px; }
  .flow-main .lesson-chunk { padding: 22px 26px; }
}
@media (min-width: 721px) and (max-width: 1100px) {
  .lecture-workspace { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 20px; align-items: center; }
  .lecture-caption { font-size: 13px; line-height: 1.65; }
  .lecture-narration h2 { font-size: 26px; }
  .lab-layout { display: flex; flex-direction: column; justify-content: center; align-items: stretch; gap: 12px; }
  .lab-layout > aside { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.4fr); gap: 12px; align-items: start; }
  .lab-menu { margin: 0; }
  .lab-instructions { padding: 16px; }
  .terminal-body { height: 180px; max-height: 180px; }
}
@media (max-width: 720px) {
  .screen-head:has(.workspace-switch) { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,132px); column-gap: 12px; row-gap: 4px; align-items: center; }
  .screen-head:has(.workspace-switch) > div { display: contents; }
  .screen-head:has(.workspace-switch) .eyebrow { padding-right: 0; margin-bottom: 0; min-height: 0; grid-column: 1; grid-row: 1; }
  .screen-head:has(.workspace-switch) .workspace-switch { position: static; width: 100%; grid-column: 2; grid-row: 1; padding: 0; }
  .screen-head:has(.workspace-switch) h1 { grid-column: 1 / -1; margin-top: 0; }
  .screen-head:has(.workspace-switch) p { grid-column: 1 / -1; margin-top: 0; }
  .screen-head .workspace-switch select { min-height: 30px; }
  .screen-navigation { flex-wrap: wrap; }
  .screen-navigation .button { min-height: 44px; }
  .screen-navigation .step-gate { flex: 1; min-width: 80px; }
  .case-focus { overflow: auto; overscroll-behavior: contain; align-content: safe center; grid-template-rows: auto auto; }
  .case-focus > * { min-height: auto; }
  .lecture-workspace { display: flex; flex-direction: column; align-items: stretch; justify-content: start; gap: 12px; }
  .lecture-visual { height: auto; flex: 1; min-height: 180px; }
  .lecture-stage { min-height: 95px; }
  .lecture-diagram { max-height: 200px; }
  .lecture-narration { flex: none; max-height: none; overflow: visible; padding: 0; }
  .lecture-narration > .eyebrow, .lecture-narration > .lecture-caption, .lecture-narration > .code-block, .lecture-narration > .lecture-principle, .lecture-narration > .lecture-links { display: none; }
  .lecture-narration h2 { font-size: 21px; line-height: 1.25; }
  .lecture-explanation-open { display: inline-flex; align-items: center; gap: 7px; min-height: 44px; font-size: 11px; }
  .paged-reference { padding: 20px; }
  .paged-reference .ref-row { padding: 12px 0; }
  .case-browser { flex: 1; min-height: 0; margin: 0 auto; justify-content: safe center; }
  .case-browser > .situation-card { min-height: 0; overflow: auto; overscroll-behavior: contain; }
  .case-browser-head { flex: none; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; }
  .case-browser-head .ref-search { grid-column: 1 / -1; }
  .case-browser-head select { max-width: none; width: 100%; }
  .case-browser-head .text-button { white-space: normal; justify-self: end; text-align: right; }
  .dashboard-content { justify-content: start; }
  .dashboard-metrics > div:first-child { position: relative; padding-right: 24px; }
  .dashboard-metrics > div:first-child a { position: absolute; right: 8px; top: 8px; font-size: 0; }
  .dashboard-metrics > div:first-child a::after { content: '↗'; font-size: 14px; }
}
@media (max-width: 380px) { .topbar .avatar { display: none; } }
@media (max-height: 610px) {
  .screen-content, .case-focus, .lecture-narration { overflow: visible; }
  .lecture-workspace { flex: none; }
  .lecture-visual { height: 260px; flex: none; }
  .screen-navigation { margin-top: 16px; }
}
@media (min-width: 721px) {
  .dashboard-metrics { grid-template-columns: repeat(4,minmax(0,1fr)); }
  .dashboard-metrics > div:first-child { position: relative; padding-right: 30px; }
  .dashboard-metrics > div:first-child a { position: absolute; top: 12px; right: 10px; }
  .dashboard-metrics > div:first-child .icon { width: 15px; }
}
@media (min-width: 721px) and (max-height: 820px) {
  .lecture-narration > .eyebrow { display: none; }
  .lecture-narration h2 { font-size: 26px; line-height: 1.2; }
  .lecture-caption { font-size: 13px; line-height: 1.6; margin: 8px 0 10px; }
  .lecture-narration .code-block { font-size: 10px; padding: 11px 13px; }
  .lecture-principle { margin-top: 12px; }
  .lecture-principle p { font-size: 12px; margin-top: 4px; }
  .lecture-links { margin-top: 10px; }
}
@media (max-width: 720px) {
  .dashboard-metrics > div:first-child a { font-size: 11px; }
  .dashboard-metrics > div:first-child a::after { content: none; }
  .dashboard-metrics > div:first-child a .icon { width: 15px; }
}
@media (max-width: 720px) and (max-height: 700px) {
  main { padding-top: 10px; padding-bottom: 8px; gap: 7px; }
  .onboarding-form { padding: 16px; }
  .onboarding-form .text-button { margin-top: 12px; }
  .onboarding-screen { gap: 16px; }
  .flow-main .lesson-chunk, .flow-main .worked-example { padding: 16px 18px; }
  .flow-main .chunk-prose { margin-top: 12px; margin-bottom: 12px; }
  .flow-main .lesson-chunk .code-block { margin: 12px 0; }
  .screen-head h1, .flow-main .screen-head h1 { font-size: 23px; }
  .screen-navigation { padding-top: 9px; }
  .dashboard-evidence .habit-grid { margin: 8px 0; gap: 8px; }
  .dashboard-evidence { padding: 14px; }
}
.lecture-explanation-detail > p { line-height: 1.7; color: var(--muted); }
.lecture-explanation-detail .code-block { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.6; margin: 20px 0; }
.lecture-explanation-detail .lecture-links { flex-wrap: wrap; }
.lecture-explanation-detail .lecture-links > a { min-height: 44px; align-items: center; }
@media (max-width: 720px) {
  .dashboard-evidence .section-head { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 12px; align-items: start; }
  .dashboard-evidence .section-head > div { min-width: 0; }
  .dashboard-evidence .section-head h2 { overflow-wrap: anywhere; }
  .dashboard-evidence .section-head > a { max-width: 90px; }
}
@media (max-width: 720px) {
  .case-context > .eyebrow:first-child { display: none; }
  .checkpoint-chunk .quiz-option { min-height: 44px; padding: 8px 11px; margin: 6px 0; }
}
@media (max-width: 720px) and (max-height: 700px) {
  .checkpoint-chunk .quiz-question { margin: 8px 0; }
  .flow-main .example-story { margin: 8px 0; }
  .flow-main .worked-example .code-block { margin: 10px 0; }
  .flow-main .example-foot { margin-top: 8px; }
  .flow-main .worked-example > .learning-note { margin-top: 2px; }
  .dashboard-evidence .habit-grid { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; }
  .dashboard-evidence .habit-grid strong { font-size: 22px; overflow-wrap: anywhere; }
}
/* Charts use the remaining dashboard height rather than an intrinsic SVG height. */
.analytics-content#teacher-results { overflow: auto; overscroll-behavior: contain; }
.analytics-content#teacher-results > .analytics-chart-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 18px; }
.analytics-chart-head, .chart-footer, .analytics-column-head { flex: none; }
.analytics-bars { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; grid-auto-rows: minmax(20px,1fr); gap: 4px; }
.analytics-bar-row { min-height: 0; padding: 1px 0; }
.analytics-bar-row > small { white-space: nowrap; }
.analytics-column-head { display: grid; grid-template-columns: minmax(125px,1fr) minmax(100px,2.5fr) 48px 75px; gap: 14px; font-size: 10px; color: var(--muted); margin-bottom: 7px; }
.analytics-column-head b, .analytics-column-head small { text-align: right; font-size: 10px; font-weight: 500; }
.analytics-bars.without-notes .analytics-bar-row { grid-template-columns: minmax(125px,1fr) minmax(100px,2.5fr) 65px; }
.analytics-line { min-height: 0; width: 100%; flex: 1; display: flex; flex-direction: column; }
.analytics-line svg { width: 100%; height: 100%; max-height: 190px; min-height: 0; flex: 1; }
.analytics-line p { flex: none; }
.analytics-line text { font-size: 16px; }
@media (min-width: 721px) {
  .teaching-metrics { grid-template-columns: repeat(4,minmax(0,1fr)); }
}
@media (max-width: 1100px), (max-height: 820px) {
  .bar-label-long { display: none; }
  .bar-label-short { display: inline; }
  .teacher-main .screen-head p { display: none; }
  .teacher-main { gap: 10px; }
  .analytics-chart-head { margin-bottom: 8px; }
  .analytics-content#teacher-results { gap: 10px; }
  .analytics-content#teacher-results > .analytics-chart-panel { padding: 16px; }
  .chart-footer { margin-top: 8px; padding-top: 8px; }
}
@media (max-width: 720px) {
  .analytics-chart-head { display: grid; grid-template-columns: minmax(0,1fr); gap: 8px; }
  .analytics-chart-head:has(#teacher-trend-metric) { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .analytics-chart-head label[for=teacher-chart] { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
  .analytics-chart-head select { width: 100%; }
  .analytics-column-head { grid-template-columns: minmax(75px,1fr) minmax(35px,1fr) 34px 38px; gap: 7px; font-size: 9px; }
  .analytics-column-head b, .analytics-column-head small { font-size: 9px; }
  .analytics-bar-row { grid-template-columns: minmax(75px,1fr) minmax(35px,1fr) 34px 38px; gap: 7px; }
  .analytics-bars.without-notes .analytics-bar-row { grid-template-columns: minmax(75px,1fr) minmax(35px,1fr) 42px; }
  .analytics-line text { font-size: 26px; }
}
@media (max-width: 720px) and (max-height: 700px) {
  .teaching-metrics { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 6px; }
  .teaching-metric { padding: 8px; }
  .teaching-metric small { font-size: 9px; }
  .teaching-metric strong { font-size: 18px; overflow-wrap: anywhere; }
  .teaching-metric span { font-size: 8px; }
}
@media (max-height: 610px) {
  .analytics-content#teacher-results > .analytics-chart-panel { flex: none; }
  .analytics-line { height: 220px; }
  .analytics-bars { grid-auto-rows: minmax(24px,auto); }
}
/* One scroll owner per dialog, and a reserved column for its close control. */
dialog { width: min(720px,calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: hidden; }
.modal-content { --modal-padding: 28px; max-height: calc(100dvh - 34px); overflow: auto; overscroll-behavior: contain; padding: var(--modal-padding); scroll-padding-block: var(--modal-head-inset,calc(var(--modal-padding) + 66px)) 16px; }
.modal-head { display: grid; grid-template-columns: minmax(0,1fr) 44px; align-items: start; gap: 14px; position: sticky; top: calc(-1 * var(--modal-padding)); margin-top: calc(-1 * var(--modal-padding)); margin-inline: calc(-1 * var(--modal-padding)); background: var(--surface); z-index: 2; padding: var(--modal-padding) var(--modal-padding) 10px; }
.modal-head h2 { min-width: 0; overflow-wrap: anywhere; }
.modal-close { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; flex: none; border: 1px solid var(--line); background: var(--surface-soft); border-radius: 8px; }
.modal-content table { width: 100%; table-layout: fixed; }
.modal-content th, .modal-content td { overflow-wrap: anywhere; }
.button:hover:not(:disabled) { transform: none; }
@media (max-width: 720px) { .modal-content { --modal-padding: 20px; } }
#modal .modal-content :is(input,textarea,select,button,a,[tabindex]) { scroll-margin-block: 12px; }

.analytics-chart-panel .analytics-chart-head h2 { font-size: 18px; line-height: 1.3; }

.challenge-review-limit{font-size:12px;color:var(--muted);line-height:1.6;margin-top:13px}
