/* WeTeachMath v1.5.3 visual-integrity layer.
   Loaded last so shared learner-workspace repairs apply to every Grade 8–12 lesson. */

/* Viewport integrity: Safari/browser chrome must not make the footer cover lesson content. */
.lesson-page{height:100vh;height:100dvh}
.lesson-app{height:100vh;height:100dvh;min-height:0}
.sr-only{position:absolute!important;width:1px!important;height:1px!important;padding:0!important;margin:-1px!important;overflow:hidden!important;clip:rect(0,0,0,0)!important;white-space:nowrap!important;border:0!important}

/* Mathematical expressions must never wrap like ordinary prose. If a rare expression is wider
   than its card, the card scrolls horizontally rather than splitting numerator/denominator. */
.formula-box{min-width:0;overflow-x:auto;overflow-y:hidden;scrollbar-width:thin}
.formula-row{flex-wrap:nowrap;white-space:nowrap;width:max-content;min-width:100%;max-width:none;line-height:1.08}
.formula-row>*{flex:0 0 auto;white-space:nowrap}
.fraction,.fraction .num,.fraction .den,.mobile-fraction{white-space:nowrap;word-break:keep-all;overflow-wrap:normal}
.mathline,.quadratic-formula,.integer-equation,.phase3-result-strip strong,.phase3-focus-card strong{overflow-wrap:anywhere}

/* SVG/graph integrity shared by all visual families. */
.math-visual{max-width:100%;height:auto;shape-rendering:geometricPrecision;text-rendering:geometricPrecision}
.phase3-visual-card>.math-visual,
.phase3-visual-card>.connected-story-wrap,
.phase3-visual-card>.quadratic-story,
.phase3-visual-card>.integer-story,
.phase3-visual-card>.toolkit-visual,
.toolkit-graph>.math-visual,
.integer-graph>.math-visual,
.quadratic-graph>.math-visual{width:100%;height:100%;min-width:0;min-height:0}
.straight-line-visual{width:100%;height:100%;min-height:0}
.story-connector{vector-effect:non-scaling-stroke}

/* Desktop is a bounded learning workspace: header, content and footer each own their space.
   Content can scroll inside scene-main when necessary, but it can never disappear under footer nav. */
@media (min-width:1101px){
  .lesson-layout{height:100%;min-height:0;overflow:hidden}
  .learning-column{height:100%;min-height:0;overflow:hidden}
  .teaching-workspace{height:100%;min-height:0;overflow:hidden}
  .scene-shell{height:100%;max-height:100%;min-height:0;isolation:isolate;overflow:hidden}
  .scene-header{position:relative;z-index:2;min-width:0}
  .scene-main{position:relative;z-index:1;min-width:0;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-gutter:stable;padding-bottom:14px}
  .scene-footer{position:relative!important;inset:auto!important;z-index:3;flex:none;min-height:50px;transform:none!important}
  .phase3-scene .scene-main{overflow:auto}
  .phase3-stage-layout,.phase5-worked-grid,.phase5-solve-grid{min-width:0;max-width:100%}
  .phase3-teach-card,.phase3-visual-card,.worked-method-card,.worked-visual-card,.worked-notebook,.solve-card,.solve-visual-card{min-width:0}
}

/* Compact laptop geometry. This is intentionally broader than the old 1200px rule because
   real browser chrome/zoom can leave a MacBook with an effective workspace between 1100–1360px. */
@media (min-width:1101px) and (max-width:1365px){
  :root{--journey-w:226px}
  .lesson-layout{gap:12px;padding:12px 14px 12px}
  .journey-rail{padding:14px 10px;border-radius:18px}
  .journey-title{padding-bottom:10px}
  .journey-nav{gap:5px}
  .journey-item{grid-template-columns:34px minmax(0,1fr) 24px;gap:8px;padding:8px 8px}
  .journey-icon{width:32px;height:32px;border-radius:10px}
  .journey-copy strong{font-size:13px}.journey-copy small{font-size:10px;margin-top:2px}
  .support-launch{padding:9px}.support-icon{width:32px;height:32px}
  .learning-column{grid-template-rows:27px minmax(0,1fr)}
  .lesson-breadcrumbs{font-size:11px;padding-top:1px}
  .scene-header{gap:12px;padding:13px 16px 8px}
  .scene-badge{width:39px;height:39px;font-size:19px}
  .scene-title{font-size:clamp(25px,2.25vw,30px)}
  .scene-sub{font-size:12px;line-height:1.35;margin-top:4px}
  .scene-tools{gap:10px}.listen-button{padding:8px 11px}.scene-main{padding:5px 12px 10px}
  .phase3-stage-layout{grid-template-columns:minmax(285px,.78fr) minmax(0,1.22fr);gap:11px}
  .scene-grid{grid-template-columns:minmax(285px,.8fr) minmax(0,1.2fr);gap:11px}
  .practice-panel{grid-template-columns:minmax(285px,.84fr) minmax(0,1.16fr);gap:11px;padding:11px}
  .phase3-teach-card{padding:12px;gap:8px}.phase3-teach-card h3{font-size:17px}
  .phase3-visual-card{padding:7px}
  .phase3-visual-caption{padding-bottom:5px}.phase3-visual-caption strong{font-size:9.5px}
  .formula-box{padding:10px}.formula-row{font-size:clamp(27px,2.7vw,34px);gap:8px}
  .formula-legend{font-size:10px;margin-top:7px;gap:4px}
  .phase5-worked-grid,.phase5-solve-grid{grid-template-columns:minmax(205px,.68fr) minmax(285px,1fr) minmax(215px,.72fr);gap:8px}
  .worked-method-card,.solve-card{padding:9px;gap:6px}
  .worked-static-step{padding:5px 7px;gap:6px}.worked-static-step p{font-size:8.6px;line-height:1.3}
  .notebook-top{padding:6px 8px}.notebook-paper{padding:10px 9px 10px 29px}.notebook-line{margin:4px 0 6px}.notebook-line p{font-size:8.8px;line-height:1.35}
  .scene-footer{padding:8px 14px;min-height:48px}
}

/* Short laptop screens: preserve maths size, reduce chrome/spacing, and allow main area to scroll.
   We do not shrink mathematical notation into unreadable text just to force one screen. */
@media (min-width:1101px) and (max-height:720px){
  .lesson-topbar{height:58px;min-height:58px}
  .lesson-app{grid-template-rows:58px minmax(0,1fr)}
  .lesson-layout{padding-top:8px;padding-bottom:8px}
  .journey-rail{padding-top:10px;padding-bottom:10px}
  .journey-title{font-size:9px;padding-bottom:7px}.journey-nav{gap:3px}
  .journey-item{padding-top:6px;padding-bottom:6px}.support-launch{padding-top:7px;padding-bottom:7px}
  .learning-column{grid-template-rows:23px minmax(0,1fr)}
  .lesson-breadcrumbs{font-size:10px}
  .scene-header{padding-top:9px;padding-bottom:6px}
  .scene-badge{width:36px;height:36px;font-size:18px}
  .scene-kicker{font-size:9px}.scene-title{font-size:26px}.scene-sub{font-size:11px}
  .scene-main{padding-top:3px;padding-bottom:7px}
  .scene-footer{min-height:44px;padding-top:6px;padding-bottom:6px}
  .nav-button,.nav-button.primary{padding-top:7px;padding-bottom:7px}
  .phase2-hero-visual{padding:3px 5px}
  .phase3-teach-card{padding-top:10px;padding-bottom:10px}
  .phase3-action-row{margin-top:2px}
}

/* Tablet/mobile: document scroll is intentional, content stacks. No fixed-height footer overlay. */
@media (max-width:1100px){
  .lesson-page,.lesson-app{height:auto;min-height:100vh;min-height:100dvh;overflow-x:hidden}
  .learning-column,.teaching-workspace,.scene-shell{height:auto;max-height:none;overflow:visible}
  .scene-main,.phase3-scene .scene-main{overflow:visible}
  .scene-footer{position:relative!important;inset:auto!important;transform:none!important}
  .formula-row{font-size:clamp(25px,7vw,34px);gap:7px}
  .formula-box{overflow-x:auto}
  .math-visual{max-width:100%;height:auto}
  .phase3-visual-card>.math-visual{height:auto;min-height:340px}
}

@media (max-width:640px){
  .scene-header{align-items:start}
  .scene-tools{width:100%;justify-content:space-between}
  .scene-counter{margin-left:auto}
  .formula-row{font-size:clamp(24px,8vw,31px)}
  .mobile-gradient-formula{overflow-x:auto;justify-content:flex-start;padding-inline:14px}
  .mobile-gradient-formula>*{flex:0 0 auto}
  .scene-footer{gap:8px}
  .scene-footer .nav-button{min-height:42px}
}

/* 125% zoom / reduced effective width should still remain stable before tablet mode. */
@media (min-width:1101px) and (max-width:1240px){
  :root{--journey-w:210px}
  .journey-copy small{display:none}
  .journey-title{font-size:9px}
  .scene-header{padding-inline:14px}
  .phase3-stage-layout{grid-template-columns:minmax(270px,.82fr) minmax(0,1.18fr)}
  .phase5-worked-grid,.phase5-solve-grid{grid-template-columns:minmax(195px,.67fr) minmax(270px,1fr) minmax(205px,.70fr)}
}

/* Readability guard for worked examples on short laptops. Do not reduce teacher-style working
   below a useful reading size merely to force everything into one viewport; the cards can scroll. */
@media (min-width:1101px) and (max-height:820px){
  .worked-static-step p{font-size:9.5px;line-height:1.34}
  .worked-static-step strong{font-size:11px}
  .notebook-question{font-size:10.5px;line-height:1.45}
  .notebook-line strong{font-size:10px}
  .notebook-line p{font-size:10px;line-height:1.42}
  .notebook-answer strong{font-size:13px}
}

/* v1.5.2 all-lesson runtime/viewport integrity repairs. */
.learning-column{scroll-margin-top:76px}
.scene-main{scroll-behavior:auto}

/* Mathematical display is content, never ordinary wrapping prose. */
.mathline,.quadratic-formula,.integer-equation{
  white-space:nowrap!important;
  overflow-x:auto;
  overflow-y:hidden;
  overflow-wrap:normal!important;
  word-break:normal!important;
  scrollbar-width:thin;
}
.phase3-result-strip strong,.phase3-focus-card strong{
  overflow-wrap:break-word;
  word-break:normal;
}
.formula-box,.mobile-gradient-formula,.phase3-result-strip{min-width:0}
.formula-row,.mobile-gradient-formula{font-variant-numeric:lining-nums tabular-nums}

/* Every visual must size from the available teaching canvas instead of clipping itself. */
.phase2-hero-visual,
.phase3-visual-card,
.visual-panel,
.worked-visual-card,
.solve-visual-card{min-width:0;min-height:0}
.phase2-hero-visual>.connected-story-wrap,
.phase3-visual-card>.connected-story-wrap{width:100%;height:100%;min-width:0;min-height:0}
.connected-story-wrap .desktop-gradient-story,
.connected-story-wrap .connected-story{width:100%;height:100%;min-width:0;min-height:0;max-width:100%;max-height:100%}
.phase3-visual-card svg,.visual-panel svg,.worked-visual-card svg,.solve-visual-card svg{max-width:100%;max-height:100%}

/* Labels remain legible against gridlines without changing mathematical coordinates. */
.wtm-svg-label{paint-order:stroke fill;stroke:#fff;stroke-width:2px;stroke-linejoin:round}
.story-formula-card .wtm-svg-label{stroke-width:1.5px}

/* Short real-browser laptop viewports retain the scene header/footer while the middle owns scrolling. */
@media (min-width:1101px) and (max-height:680px){
  .lesson-layout{padding-top:7px;padding-bottom:7px}
  .learning-column{grid-template-rows:22px minmax(0,1fr)}
  .scene-header{padding-top:8px;padding-bottom:5px}
  .scene-title{font-size:clamp(23px,2.05vw,27px)}
  .scene-sub{font-size:10.5px;line-height:1.3;margin-top:3px}
  .scene-main{padding-top:2px;padding-bottom:6px}
  .scene-footer{min-height:42px;padding-top:5px;padding-bottom:5px}
  .phase2-hero-visual{padding:2px 4px}
  .connected-story{max-height:100%}
}

/* At browser zoom / compact laptops, preserve readable maths and let the main scene scroll if required. */
@media (min-width:1101px) and (max-width:1280px){
  .phase2-hero-visual>.connected-story-wrap{min-width:0}
  .phase3-visual-card .math-visual{width:100%;height:100%}
  .formula-row{justify-content:flex-start;padding-inline:4px}
}

/* On tablet/mobile a new scene starts at the learning column, never at an old restored scroll position. */
@media (max-width:1100px){
  .learning-column{scroll-margin-top:72px}
  .scene-main{overscroll-behavior:auto}
  .mathline,.quadratic-formula,.integer-equation{max-width:100%}
}

/* v1.5.3 global mathematical typography and micro-layout integrity.
   Coefficients and variables are mathematically grouped, but given optical breathing room so
   expressions such as y = mx + c and y = ax² + bx + c never look like colliding glyphs. */
.math-expression{
  display:inline-flex;
  align-items:baseline;
  justify-content:center;
  flex-wrap:nowrap;
  white-space:nowrap;
  max-width:100%;
  font-kerning:normal;
  font-variant-numeric:lining-nums proportional-nums;
}
.math-expression .math-op{
  display:inline-block;
  margin-inline:.16em;
  padding-inline:.02em;
  line-height:1;
}
.math-expression .math-product{
  display:inline-flex;
  align-items:baseline;
  gap:.13em;
  white-space:nowrap;
}
.math-expression .math-coefficient,
.math-expression .math-variable{display:inline-block;white-space:nowrap}
.formula-row.math-expression{gap:0!important;width:max-content;min-width:100%}
.quadratic-formula.math-expression{gap:0;padding-block:11px;overflow-x:auto}

/* Fractions and powers keep a clear internal rhythm at every lesson size. */
.fraction .num,.fraction .den{padding-inline:.18em}
.fraction .bar{margin-block:.12em}
sup{font-size:.68em;line-height:0;vertical-align:.58em;margin-left:.025em}
sub{font-size:.68em;line-height:0;vertical-align:-.22em;margin-left:.025em}

/* Small mathematical summaries should read as separate facts, not one compressed text run. */
.phase3-result-strip{column-gap:14px}
.phase3-result-strip strong{letter-spacing:.005em;line-height:1.28}
.equation-notes{column-gap:12px}

/* SVG story equation tokens are intentionally separate so their bounding boxes can be regression-tested.
   Do not use negative letter-spacing here: compact laptop scaling must preserve the same optical gaps. */
.story-equation-token{letter-spacing:0}
.story-summary-m,.story-summary-c{letter-spacing:.01em}

@media (max-width:640px){
  .math-expression .math-op{margin-inline:.13em}
  .math-expression .math-product{gap:.11em}
  .quadratic-formula.math-expression{justify-content:flex-start}
}

/* Phase 8: visual mathematics typography. Mathematical structure inside SVG
   uses dedicated groups so fractions, powers and subscripts remain textbook-like
   instead of reverting to slash/caret notation. */
.math-visual .svg-math-fraction text,
.math-visual .svg-math-power,
.math-visual .svg-math-subscript{
  font-family:Cambria Math,Georgia,"Times New Roman",serif;
  text-rendering:geometricPrecision;
}
.mobile-fraction.mobile-fraction-inline{
  display:inline-grid;
  min-width:34px;
  margin:0 4px;
  vertical-align:middle;
  font-size:1em;
  line-height:1.05;
}

@media (max-width:640px){
  /* A 760-unit SVG scales to roughly 45% on a phone. Lift the structured math
     floor so numerator/denominator glyphs stay at about 10px or larger. */
  .math-visual .svg-math-fraction text{font-size:22px!important}
  .first-principles-visual text[font-size="20"]{font-size:22px}
  .first-principles-visual text[font-size="17"]{font-size:21px}
  .special-angles-visual text[font-size="16"]{font-size:20px}
  .special-angles-visual text[font-size="15"]{font-size:19px}
}
