:root {
  --ipad-safe-top: max(10px, env(safe-area-inset-top));
  --ipad-safe-right: max(14px, env(safe-area-inset-right));
  --ipad-safe-bottom: max(10px, env(safe-area-inset-bottom));
  --ipad-safe-left: max(14px, env(safe-area-inset-left));
  --ipad-touch: 44px;
}

html {
  width: 100%;
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  width: 100%;
  min-width: 0;
  min-height: 100%;
  min-height: 100dvh;
}

/* Never infer an iPad from one fixed CSS width. Chrome may expose a desktop
   layout viewport when page zoom or "desktop site" is active. All student
   shells therefore consume the available viewport at every width. */
body > .app,
body > .test-shell {
  width: 100%;
  max-width: none;
}

/* T1-A v1.1: one Chrome/iPad layout, three structural rows, no overlay. */
body > .app {
  height: 100dvh;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.app .learn-card {
  min-height: 0;
}

.app .learn-card.presentation-mode {
  grid-template-rows: minmax(0, 1fr) auto;
}

.app .learn-card.presentation-mode .stage {
  container-name: learning-stage;
  container-type: size;
  min-height: 0;
  overflow: hidden;
}

body > .app-shell {
  width: calc(100% - var(--ipad-safe-left) - var(--ipad-safe-right));
  max-width: none;
}

.app .learn-card,
.app .sequential-learning,
.app .knowledge-overview,
.app .knowledge-lens,
.app .kc-model {
  width: 100%;
  max-width: none;
}

.app .picker-controls {
  width: calc(100vw - var(--ipad-safe-left) - var(--ipad-safe-right));
  max-width: none;
}

.app .learn-card.question-only .answer-area,
.app .result-card {
  width: 92%;
  max-width: none;
}

/* Let the active learner surface use the remaining viewport height. */
.app .learn-card.presentation-mode .stage {
  width: 100%;
  height: 100%;
  min-height: 0;
  place-items: stretch;
  align-content: stretch;
}

.app .learn-card.presentation-mode .objects {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.app .learn-card.question-only {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  align-content: stretch;
}

.app .learn-card.question-only .answer-area {
  align-self: center;
}

/* One motor pattern everywhere: back on the left, optional action in the
   middle, and the action that moves learning forward on the right. */
.app .learn-card > .actions,
.app .result-actions,
.test-actions,
.app-shell .actionbar {
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  width: 100%;
}

.app .learn-card > .actions #prevButton,
.test-actions .previous,
.app-shell .secondary-button {
  grid-column: 1;
  justify-self: start;
}

.app .result-actions #againButton,
.test-actions .secondary,
.app-shell .save-status {
  grid-column: 2;
  justify-self: center;
}

.app .learn-card.presentation-mode > .actions #retryButton,
.app .result-actions #switchButton,
.test-actions .primary,
.app-shell .primary-button {
  grid-column: 3;
  justify-self: end;
}

.app .result-card {
  display: grid;
  grid-template-rows: auto auto auto auto auto auto minmax(18px, 1fr) auto;
}

.app .result-card[hidden] {
  display: none !important;
}

.app .result-card .result-actions {
  grid-row: -2;
  margin-top: auto;
}

img,
svg,
canvas {
  max-width: 100%;
}

button,
input,
select,
textarea {
  max-width: 100%;
  touch-action: manipulation;
}

button,
select,
input {
  min-height: var(--ipad-touch);
}

:focus-visible {
  outline-offset: 3px;
}

/* Login and initial-password screens. */
body > .card {
  width: min(720px, calc(100% - var(--ipad-safe-left) - var(--ipad-safe-right)));
  max-height: calc(100dvh - var(--ipad-safe-top) - var(--ipad-safe-bottom));
  overflow: auto;
  padding: clamp(28px, 5vw, 48px);
}

body > .card input,
body > .card button {
  min-height: clamp(52px, 4.5vw, 88px);
  font-size: clamp(18px, 1.7vw, 30px);
}

/* Chapter and final-test pages share a fixed viewport shell. Long reports
   scroll inside the paper card, so browser chrome never hides the controls. */
.test-shell {
  width: 100%;
  max-width: none;
  height: 100dvh;
  min-height: 0;
  padding: var(--ipad-safe-top) var(--ipad-safe-right) var(--ipad-safe-bottom) var(--ipad-safe-left);
}

.test-card {
  align-self: stretch;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.test-card > section:not([hidden]) {
  min-width: 0;
}

/* Shared student action targets. */
.test-actions button,
.account-session-button,
.back-to-knowledge,
.restart-button,
.secondary-button,
.primary-button {
  min-height: var(--ipad-touch);
}

@media (min-width: 700px) and (max-width: 1366px) {
  .test-shell {
    gap: 10px;
  }

  .test-masthead {
    min-height: 48px;
  }

  .test-card {
    width: 100%;
    padding: clamp(22px, 3vw, 40px);
    border-radius: 22px;
  }

  .question-source img {
    max-height: min(38dvh, 390px);
  }

  .test-actions {
    position: sticky;
    z-index: 4;
    bottom: -1px;
    padding: 10px 0 2px;
    background: linear-gradient(180deg, rgba(255,253,247,0), #fffdf7 28%);
  }
}

@media (min-width: 900px) and (max-width: 1366px) and (orientation: landscape) {
  .test-card {
    padding: clamp(18px, 2.3vw, 32px);
  }

  .test-choices {
    gap: 10px;
    margin-top: 14px;
  }

  .choice {
    min-height: 58px;
    padding: 11px 14px;
  }

  .test-actions {
    margin-top: 14px;
  }
}

@media (min-width: 700px) and (max-width: 899px) and (orientation: portrait) {
  .test-masthead {
    align-items: flex-start;
  }

  .masthead-leading,
  .masthead-actions {
    flex-wrap: wrap;
  }

  .test-choices,
  .answer-compare,
  .correction-choices,
  .diagnosis-answer-row {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 700px) and (min-width: 700px) {
  .test-shell {
    gap: 6px;
  }

  .test-masthead {
    min-height: 42px;
  }

  .test-card {
    padding: 16px 24px;
  }

  .question-source img {
    max-height: 30dvh;
  }
}

/* One responsive system serves Chrome on iPad and desktop-sized viewports.
   Width breakpoints may reflow content, but never swap the whole application
   to a separately scaled visual version. */

/* Comprehensive practice must use the same reading scale as the learning
   stage. The earlier 38dvh cap made its source image and controls visibly
   smaller in iPad Chrome standalone windows. */
body > .test-shell .question-source img {
  max-height: min(52dvh, 520px);
}
body > .test-shell .test-actions #submitButton,
body > .test-shell .test-actions #returnButton,
body > .test-shell .test-actions #reviewButton,
body > .test-shell .test-actions #reviewCorrectButton,
body > .test-shell .test-actions #reviewWrongButton {
  min-width: 200px;
  min-height: 58px;
  padding-inline: 28px;
  font-size: 19px;
}
body > .test-shell .test-actions #testPreviousButton {
  min-width: 120px;
  min-height: 52px;
}

.app .learn-card.question-only .progress > span {
  display: none;
}

.app .progress > span {
  display: none;
}

/* Learning Stage UI -------------------------------------------------------
   Navigation, one focused learning object, and one stable action rail. */
.app {
  --stage-reading-width: min(88%, 1500px);
  --stage-action-height: clamp(64px, 8dvh, 94px);
  gap: clamp(8px, 1.2dvh, 14px);
}

.app .lesson-picker {
  min-height: clamp(62px, 9dvh, 92px);
  padding: 10px clamp(14px, 2vw, 28px);
  border-radius: 18px;
}

.app .current-path {
  overflow: hidden;
  margin: 0;
  font-size: clamp(18px, 1.7vw, 26px);
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app .lesson-status,
.app .pilot-account {
  font-size: clamp(14px, 1.25vw, 20px);
}

.app .picker-actions {
  justify-content: flex-end;
  overflow: visible;
}

.app .picker-actions > button,
.app .utility-menu > summary {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 8px 14px;
  border: 1px solid rgba(31, 111, 71, 0.2);
  border-radius: 12px;
  color: var(--leaf-dark);
  background: #f4faf4;
  font-size: clamp(15px, 1.25vw, 20px);
  font-weight: 900;
  cursor: pointer;
  list-style: none;
}

.app .utility-menu {
  position: relative;
}

.app .utility-menu > summary::-webkit-details-marker {
  display: none;
}

.app .utility-menu-panel {
  position: absolute;
  z-index: 60;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  width: max-content;
  min-width: 180px;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffef9;
  box-shadow: 0 16px 38px rgba(35, 67, 97, 0.18);
}

.app .utility-menu:not([open]) .utility-menu-panel {
  display: none;
}

.app .utility-menu-panel button {
  width: 100%;
  min-height: 48px;
  padding: 9px 14px;
  font-size: 16px;
  text-align: left;
}

.app .more-menu > summary {
  min-width: 48px;
  color: #675747;
  background: #fffaf5;
}

.app .learn-card {
  border-radius: 22px;
}

/* Knowledge: content-sized card centered in the stage; never a huge empty
   stretched panel. Supporting content remains readable rather than becoming
   a tiny corner label. */
.app .learn-card.presentation-mode .stage,
.app .learn-card.presentation-mode .objects {
  display: grid;
  place-items: center;
}

.app .sequential-learning {
  grid-template-rows: auto auto minmax(0, 1fr);
  align-content: stretch;
  width: var(--stage-reading-width);
  height: 100%;
  max-height: 100%;
}

.app .sequential-learning-card {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  max-height: none;
}

.app .sequential-learning-card:has(.sequential-visual),
.app .sequential-learning-card:has(.sequential-mistake) {
  min-height: 0;
}

.app .sequential-route-summary {
  display: inline-grid;
  grid-template-columns: auto auto auto;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  margin: 0 auto;
  padding: 6px 16px;
  border-radius: 999px;
  color: var(--dimension-color);
  background: var(--dimension-bg);
  font-size: clamp(16px, 1.35vw, 22px);
}

.app .sequential-route-summary i {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #fff;
  background: var(--dimension-color);
  font-style: normal;
  font-weight: 900;
}

.app .sequential-route-summary small {
  color: #68778c;
  font-size: .82em;
}

.app .sequential-learning-body {
  align-content: center;
  overflow: hidden;
}

.app .sequential-example,
.app .sequential-mistake,
.app .sequential-action {
  min-height: clamp(118px, 11dvh, 154px);
  padding: clamp(14px, 1.8vw, 24px);
  font-size: clamp(18px, 1.55vw, 26px);
  overflow: visible;
}

.app .sequential-action:last-child:nth-child(2),
.app .sequential-example:last-child:nth-child(2) {
  grid-column: 1 / -1;
}

/* Practice: one question, no internal taxonomy, and the hint directly below
   the question. */
.app .learn-card.question-only .answer-area {
  display: grid;
  place-content: center;
  width: min(86%, 1420px);
  min-height: clamp(280px, 44dvh, 520px);
  max-height: 60dvh;
}

.app .learn-card.question-only .answer-area > p:first-child {
  font-size: clamp(32px, 3.2vw, 54px);
}

.app .learn-card.question-only .question-hint {
  margin: 12px auto 0;
  max-width: 860px;
  font-size: clamp(18px, 1.65vw, 27px);
}

/* Achievement screen: remove speed pressure and keep only meaningful results. */
.app .learn-card.result-mode .result-card {
  width: min(72%, 1120px);
  min-height: clamp(410px, 55dvh, 650px);
  max-height: 76dvh;
  padding: clamp(30px, 3vw, 52px);
  gap: clamp(14px, 1.8dvh, 24px);
}

.app .result-check {
  display: grid;
  place-items: center;
  width: clamp(60px, 6vw, 86px);
  height: clamp(60px, 6vw, 86px);
  margin: 0 auto;
  border-radius: 50%;
  color: #fff;
  background: var(--leaf);
  font-size: clamp(34px, 3.4vw, 48px);
  line-height: 1;
}

.app .result-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(620px, 100%);
  margin: 0 auto;
  gap: 18px;
}

.app .result-actions {
  position: static;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  width: 100%;
  margin-top: auto;
  gap: 18px;
}

.app .result-actions #againButton {
  grid-column: 2;
  justify-self: center;
  min-width: 230px;
  border-radius: 16px;
}

.app .result-actions #switchButton {
  grid-column: 3;
  justify-self: end;
  min-width: 230px;
  border-radius: 16px;
}

.app .result-actions #againButton {
  border: 2px solid rgba(31, 111, 71, 0.28);
  color: var(--leaf-dark);
  background: #f4faf4;
}

.app .result-actions #switchButton {
  background: linear-gradient(135deg, #58b84c, #3f9f42);
}

/* The action rail does not move between knowledge pages. */
.app .learn-card > .actions {
  min-height: var(--stage-action-height);
  align-self: end;
  padding: 8px clamp(12px, 2vw, 30px) max(12px, env(safe-area-inset-bottom));
}

.app .learn-card > .actions #prevButton,
.app .learn-card > .actions #retryButton {
  min-height: clamp(54px, 6.5dvh, 74px);
  padding: 12px clamp(22px, 2.2vw, 36px);
  border-radius: 16px;
  font-size: clamp(19px, 1.55vw, 28px);
}

.app .learn-card > .actions #prevButton {
  min-width: clamp(180px, 18vw, 300px);
}

.app .learn-card > .actions #retryButton {
  min-width: clamp(260px, 30vw, 460px);
}

.app .auto-notice:empty {
  display: none !important;
}

.app .learn-card.presentation-mode {
  padding-bottom: max(18px, env(safe-area-inset-bottom));
}

.app .result-actions { bottom: auto; }

@container learning-stage (max-height: 620px) {
  .sequential-learning {
    gap: 6px;
  }

  .sequential-learning-body {
    gap: 8px;
    padding-block: 12px;
  }

  .sequential-route {
    gap: 6px;
  }
}

@media (max-width: 800px) {
  .app {
    --stage-reading-width: 94%;
  }

  .app .lesson-picker {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .app .lesson-status,
  .app .pilot-account {
    display: none;
  }

  .app .picker-actions {
    gap: 5px;
  }

  .app .picker-actions > button,
  .app .utility-menu > summary {
    min-width: 48px;
    padding-inline: 9px;
  }

  .app .learn-card.result-mode .result-card {
    width: 92%;
  }
}

/* T1-A-STUDENT-LEARNING-STAGE-UI-V1 -------------------------------
   Student reading-size floor. Density fitting may reduce spacing, but it must
   never reduce meaningful text below these computed sizes. */
:root {
  --t1a-title-min: 40px;
  --t1a-definition-label-min: 30px;
  --t1a-definition-min: 32px;
  --t1a-goal-min: 28px;
  --t1a-example-min: 26px;
  --t1a-section-min: 24px;
  --t1a-question-min: 32px;
  --t1a-option-min: 26px;
  --t1a-analysis-min: 24px;
  --t1a-hint-min: 22px;
  --t1a-primary-action-min: 22px;
  --t1a-secondary-action-min: 20px;
  --t1a-aux-min: 18px;
  --t1a-math-label-min: 20px;
}

.app .picker-path,
.app .lesson-status,
.app .pilot-account,
.app .sequential-route-summary,
.app .sequential-route-summary small,
.app .sequential-learning-header > strong {
  font-size: max(var(--t1a-aux-min), 1em);
}

.app .picker-actions > button,
.app .utility-menu > summary,
.app .utility-menu-panel button {
  min-height: 54px;
  font-size: var(--t1a-secondary-action-min);
}

.app .sequential-learning,
.app .sequential-learning[data-fit="compact"],
.app .sequential-learning[data-fit="tight"],
.app .sequential-learning[data-fit="ultra"],
.app .sequential-learning[data-fit="micro"] {
  --seq-title-size: clamp(var(--t1a-title-min), 4.2vw, 56px);
  --seq-card-title-size: clamp(var(--t1a-definition-label-min), 3vw, 42px);
  --seq-definition-size: clamp(var(--t1a-definition-min), 3vw, 46px);
  --seq-explanation-size: clamp(var(--t1a-goal-min), 2.5vw, 38px);
  --seq-line-height: 1.48;
}

.app .sequential-learning-header h2 { font-size: var(--seq-title-size); }
.app .sequential-learning-card > header span,
.app .sequential-learning-card h3 { font-size: var(--seq-card-title-size); }
.app .sequential-definition { font-size: var(--seq-definition-size); }
.app .sequential-explanation,
.app .sequential-action { font-size: var(--seq-explanation-size); }
.app .sequential-question,
.app .sequential-example { font-size: clamp(var(--t1a-example-min), 2vw, 34px); }
.app .sequential-mistake { font-size: clamp(var(--t1a-analysis-min), 1.9vw, 32px); }

.app .sequential-route-step b,
.app .sequential-route-step i,
.app .sequential-learning[data-fit="tight"] .sequential-route-step i,
.app .sequential-learning[data-fit="ultra"] .sequential-route-step i,
.app .sequential-learning[data-fit="micro"] .sequential-route-step i {
  font-size: var(--t1a-aux-min);
}

.app .sequential-route-step i,
.app .sequential-learning[data-fit="tight"] .sequential-route-step i,
.app .sequential-learning[data-fit="ultra"] .sequential-route-step i,
.app .sequential-learning[data-fit="micro"] .sequential-route-step i {
  width: 34px;
  height: 34px;
}

.app .sequential-visual text,
.app .number-line-model text,
.app .number-line-card text { font-size: var(--t1a-math-label-min); }

.app .learn-card.question-only .answer-area > p:first-child {
  font-size: clamp(var(--t1a-question-min), 3.2vw, 54px);
}
.app .learn-card.question-only .choice,
.app .learn-card.question-only .choices button {
  min-height: 70px;
  font-size: clamp(var(--t1a-option-min), 2.2vw, 38px);
}
.app .learn-card.question-only .question-hint {
  font-size: clamp(var(--t1a-hint-min), 1.65vw, 29px);
}
.app .learn-card.question-only .feedback {
  font-size: clamp(var(--t1a-analysis-min), 1.8vw, 32px);
}
.app .learn-card > .actions #prevButton,
.app .learn-card > .actions #retryButton,
.app .result-actions button {
  font-size: clamp(var(--t1a-primary-action-min), 1.55vw, 30px);
}

.test-shell .path,
.test-shell .learner,
.test-shell .save-state,
.test-shell .eyebrow,
.test-shell .progress,
.test-shell .quiet-note,
.test-shell .text-answer span,
.test-shell .diagnosis-card span,
.test-shell .repair-kicker,
.test-shell .repair-progress span,
.test-shell .repair-progress strong,
.test-shell .repair-subquestion-row > span,
.test-shell .thinking-no-grade,
.test-shell .diagnosis-number,
.test-shell .diagnosis-summary-copy small,
.test-shell .diagnosis-toggle,
.test-shell .diagnosis-answer-row span { font-size: var(--t1a-aux-min); }

.test-shell .test-card h1 { font-size: clamp(var(--t1a-title-min), 4vw, 56px); }
.test-shell .test-card h2 { font-size: clamp(var(--t1a-question-min), 3.3vw, 46px); }
.test-shell .test-card .choice,
.test-shell .test-card input,
.test-shell .test-card textarea {
  font-size: clamp(var(--t1a-option-min), 2vw, 34px);
}
.test-shell .explanation,
.test-shell .inline-feedback,
.test-shell .correction-panel > p,
.test-shell .simple-thinking-card strong,
.test-shell .worked-reasoning h4,
.test-shell .worked-reasoning h5,
.test-shell .diagnosis-answer-row strong,
.test-shell .diagnosis-body h3,
.test-shell .report-next {
  font-size: clamp(var(--t1a-analysis-min), 1.8vw, 32px);
}
.test-shell .test-actions button,
.test-shell .correction-panel button,
.test-shell .repair-subquestion-row button,
.test-shell .back-to-knowledge,
.test-shell .account-session-button {
  min-height: 56px;
  font-size: var(--t1a-primary-action-min);
}

body .app-shell .title-block h1,
body .app-shell .task-panel h2,
body .app-shell .solution-card h2,
body .app-shell .loading-card h2,
body .app-shell .error-card h2,
body .app-shell .completion-card h2 {
  font-size: clamp(var(--t1a-question-min), 3vw, 46px);
}
body .app-shell .eyebrow,
body .app-shell .stage-dot small,
body .app-shell .step-kicker,
body .app-shell .save-status {
  display: block;
  font-size: var(--t1a-aux-min);
}
body .app-shell .support-text,
body .app-shell .promise {
  font-size: var(--t1a-hint-min);
  line-height: 1.5;
}
body .app-shell .choice-button,
body .app-shell .category-button,
body .app-shell .relation-node,
body .app-shell .expression {
  min-height: 60px;
  font-size: var(--t1a-option-min);
}
body .app-shell .feedback,
body .app-shell .why-box,
body .app-shell .error-box,
body .app-shell .solution-index span {
  font-size: var(--t1a-analysis-min);
  line-height: 1.5;
}
body .app-shell .restart-button,
body .app-shell .secondary-button,
body .app-shell .primary-button {
  min-height: 58px;
  font-size: var(--t1a-primary-action-min);
}

body > .card {
  box-sizing: border-box;
  width: min(540px, calc(100vw - var(--ipad-safe-left) - var(--ipad-safe-right)));
  max-height: calc(100dvh - var(--ipad-safe-top) - var(--ipad-safe-bottom));
  min-width: 0;
  overflow: auto;
  padding: clamp(20px, 4vw, 42px);
}
body > .card h1 { font-size: var(--t1a-title-min); }
body > .card p,
body > .card label { font-size: var(--t1a-secondary-action-min); line-height: 1.5; }
body > .card input { min-height: 58px; font-size: var(--t1a-primary-action-min); }
body > .card button { min-height: 60px; font-size: var(--t1a-primary-action-min); }

/* The v2 wrongbook opens the existing list, not a separately scaled layout. */
.app { grid-template-columns: minmax(0, 1fr); }
.app .lesson-picker { min-width: 0; }
.app .picker-actions { min-width: 0; flex-wrap: wrap; }
.app .picker-controls { grid-template-columns: minmax(0, 1fr); }
.app .top-notice.has-external-wrongbook,
.app .external-wrongbook-list,
.app .external-wrongbook-list details,
.app .external-wrongbook-list summary {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}
