:root {
  color-scheme: light;
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #20313a;
  --muted: #66757d;
  --paper: #fffdf7;
  --page: #f7f1e3;
  --blue: #2b6f89;
  --blue-dark: #1f5368;
  --blue-soft: #e9f5f8;
  --green: #397150;
  --green-soft: #e4f3e8;
  --red: #9b4033;
  --line: #d9d5c9;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: var(--page); color: var(--ink); touch-action: manipulation; -webkit-text-size-adjust: 100%; }
button { font: inherit; touch-action: manipulation; cursor: pointer; }

.math-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1100px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.top-bar, .profile-summary, .setup-heading, .setup-actions, .practice-heading, .finish-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.top-bar { min-height: 64px; padding: 0 4px 10px; }
.reading-link { color: var(--blue-dark); font-size: 13px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
h1 { margin: 1px 0 0; font-size: clamp(27px, 3.3vw, 38px); line-height: 1.05; }
h2 { margin: 0; font-size: clamp(27px, 3.3vw, 38px); }
.profile-summary { font-size: 17px; font-weight: 800; }
.quiet-button, .text-button { min-height: 44px; padding: 7px 13px; border: 2px solid #b8c6ca; border-radius: 12px; background: var(--paper); color: var(--blue-dark); font-weight: 800; }

.setup-card, .practice-card, .finish-card {
  min-height: 0;
  border: 3px solid white;
  border-radius: 24px;
  background: var(--paper);
  box-shadow: 0 7px 22px rgb(69 67 57 / 14%);
}

.setup-card { align-self: center; padding: clamp(18px, 2.6vw, 28px); }
.eyebrow { margin: 0 0 4px; color: var(--blue-dark); font-size: 13px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.save-note { max-width: 280px; margin: 0; color: var(--muted); font-weight: 700; text-align: right; }
.activity-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0 12px; }
.activity-button { min-height: 64px; padding: 9px 15px; border: 3px solid var(--line); border-radius: 16px; background: white; color: var(--ink); text-align: left; }
.activity-button strong, .activity-button span { display: block; }
.activity-button strong { font-size: 20px; }
.activity-button span { margin-top: 2px; color: var(--muted); font-size: 14px; }
.activity-button.is-selected { border-color: var(--blue); background: var(--blue-soft); }

.mode-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 12px 0 12px; }
.mode-button { min-height: 78px; padding: 12px 16px; border: 3px solid var(--line); border-radius: 16px; background: white; color: var(--ink); text-align: left; }
.mode-button strong, .mode-button span { display: block; }
.mode-button strong { font-size: 20px; }
.mode-button span { margin-top: 3px; color: var(--muted); font-size: 14px; }
.mode-button.is-selected { border-color: var(--blue); background: var(--blue-soft); }
.class-picker > p { margin: 0 0 8px; color: var(--muted); font-weight: 750; }
.class-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 9px; }
.class-button { position: relative; min-height: 68px; padding: 7px 3px; border: 3px solid var(--line); border-radius: 14px; background: white; color: var(--ink); font-size: clamp(20px, 2.5vw, 28px); font-weight: 850; }
.class-button.is-selected { border-color: var(--blue); background: var(--blue-soft); }
.class-button small { display: block; margin-top: 1px; color: var(--green); font-size: 10px; line-height: 1.1; }
.comparison-setup {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  min-height: 150px;
  padding: 17px 22px;
  border: 2px solid #c9dde3;
  border-radius: 17px;
  background: #f8fcfd;
}
.comparison-setup > p { margin: 0; color: var(--muted); font-size: 18px; font-weight: 730; }
.comparison-completion { color: var(--green) !important; text-align: right; }
.comparison-range-picker { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.comparison-range-picker .mode-button { padding: 10px; }
.comparison-preview { display: flex; align-items: center; gap: 14px; color: var(--blue-dark); font-size: 35px; font-weight: 850; }
.comparison-preview span { display: grid; place-items: center; min-width: 70px; min-height: 60px; border-radius: 13px; background: white; }

.setup-actions { margin-top: 16px; }
.setup-actions p { margin: 0; color: var(--muted); font-size: 18px; font-weight: 720; }

.primary-button, .secondary-button, .next-button {
  min-width: 150px;
  min-height: 56px;
  padding: 9px 22px;
  border-radius: 15px;
  font-size: 20px;
  font-weight: 850;
}
.primary-button, .next-button { border: 0; background: var(--blue); color: white; box-shadow: 0 3px 0 var(--blue-dark); }
.secondary-button { border: 2px solid var(--blue); background: white; color: var(--blue-dark); }

.practice-card { display: grid; grid-template-rows: auto minmax(0, 1fr); padding: 14px 18px 18px; }
.practice-heading { min-height: 43px; border-bottom: 1px solid var(--line); }
.practice-heading > div { display: flex; align-items: center; gap: 14px; }
.practice-heading strong { font-size: 19px; }
.math-journey {
  --journey-position: 0;
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  align-items: center;
  width: min(330px, 38vw);
  height: 38px;
  padding: 0 8px;
}
.math-journey::before {
  position: absolute;
  right: 18px;
  left: 18px;
  height: 6px;
  border-radius: 99px;
  background: #cad4d7;
  content: "";
}
.math-journey-step {
  position: relative;
  z-index: 1;
  width: 18px;
  height: 18px;
  justify-self: center;
  border: 4px solid #91a5ab;
  border-radius: 50%;
  background: var(--paper);
}
.math-journey-step.is-complete { border-color: var(--green); background: var(--green); }
.math-journey-finish { position: relative; z-index: 1; justify-self: center; font-size: 23px; }
.math-journey-traveler {
  position: absolute;
  z-index: 3;
  top: 1px;
  left: var(--journey-position, 5%);
  display: grid;
  place-items: center;
  width: 36px;
  height: 34px;
  border: 2px solid white;
  border-radius: 10px;
  background: #fff5cd;
  box-shadow: 0 2px 6px rgb(32 49 58 / 20%);
  font-size: 21px;
  transform: translateX(-50%);
  transition: left 500ms ease-in-out;
}
.practice-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .65fr); gap: clamp(18px, 3vw, 34px); min-height: 0; padding-top: 14px; }
.problem-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; }
.practice-layout.is-comparison { grid-template-columns: 1fr; padding-top: 8px; }
.addition-problem { display: grid; justify-items: center; }
.math-question-line { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 56px; }
.comparison-prompt { margin: 0; font-size: clamp(26px, 3.5vw, 38px); font-weight: 850; }
.math-audio-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 54px;
  height: 50px;
  padding: 9px;
  border: 2px solid #9bb5be;
  border-radius: 14px;
  background: white;
  color: var(--blue-dark);
}
.math-audio-button svg { width: 29px; height: 29px; fill: currentColor; }
.math-audio-button svg path:last-child { fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }
.math-audio-button:active { background: var(--blue-soft); }
.math-audio-button:disabled { cursor: default; opacity: .38; }
.comparison-problem { display: grid; justify-items: center; width: min(780px, 100%); }
.comparison-problem .math-question-line { margin-bottom: 13px; }
.comparison-target {
  padding: .04em .2em .08em;
  border-radius: .24em;
}
.comparison-target.is-hint {
  background: #ffd966;
  color: #2b2518;
  box-shadow: inset 0 0 0 2px #b97900;
}
.comparison-row { display: grid; grid-template-columns: minmax(190px, 260px) 80px minmax(190px, 260px); align-items: center; justify-content: center; gap: 18px; width: 100%; }
.comparison-number {
  display: grid;
  place-items: center;
  min-height: 160px;
  padding: 13px;
  border: 5px solid #8ea8b1;
  border-radius: 22px;
  background: white;
  color: var(--ink);
}
.comparison-number strong { font-size: clamp(68px, 9vw, 102px); line-height: 1; }
.comparison-number small { min-height: 25px; margin-top: 6px; font-size: 19px; font-weight: 850; text-transform: lowercase; }
.comparison-number.is-wrong { border-color: #c46c5d; background: #fff1ee; color: var(--red); }
.comparison-number.is-larger { border-color: var(--blue); background: var(--blue-soft); color: var(--blue-dark); }
.comparison-number.is-smaller { border-color: #c68a2c; background: #fff4d9; color: #795217; }
.comparison-number:disabled { cursor: default; opacity: 1; }
.comparison-sign { min-width: 80px; color: var(--ink); font-size: clamp(65px, 8vw, 94px); font-weight: 850; line-height: 1; text-align: center; }
.comparison-sentence { min-height: 32px; margin: 11px 0 3px; color: var(--ink); font-size: clamp(21px, 2.6vw, 29px); font-weight: 800; }
.comparison-next { width: 220px; min-height: 58px; margin-top: 5px; }

.equation { display: flex; align-items: center; justify-content: center; gap: clamp(14px, 2.5vw, 30px); font-size: clamp(64px, 10vw, 112px); font-weight: 850; line-height: 1; }
.answer-display { display: inline-flex; align-items: center; justify-content: center; min-width: 1.5em; height: 1.18em; padding: 0 .1em; border: 4px solid #8ea8b1; border-radius: 17px; background: white; color: var(--blue-dark); }
.answer-display.is-wrong { border-color: #c46c5d; background: #fff1ee; color: var(--red); }
.answer-display.is-correct { border-color: #7fa88d; background: var(--green-soft); color: var(--green); }
.math-feedback { min-height: 31px; margin: 12px 0 5px; color: var(--muted); font-size: 20px; font-weight: 750; text-align: center; }
.math-feedback.is-wrong { color: var(--red); }
.math-feedback.is-correct { color: var(--green); font-size: 25px; font-weight: 850; }
.stick-help { display: flex; align-items: center; justify-content: center; gap: 24px; width: 100%; min-height: 170px; padding: 10px 12px; border-radius: 16px; background: #faf6ea; pointer-events: none; user-select: none; }
.stick-group-wrap { display: grid; justify-items: center; gap: 6px; min-width: 260px; }
.stick-group { display: flex; align-items: center; justify-content: center; gap: 13px; width: 260px; min-height: 112px; }
.stick { width: 17px; height: 90px; border: 3px solid #805e2f; border-radius: 9px; background: #e2aa4c; box-shadow: inset -3px 0 rgb(137 87 24 / 25%); }
.stick-group.second .stick { border-color: #38677b; background: #6aa8c1; box-shadow: inset -2px 0 rgb(25 79 100 / 25%); }
.stick-label { color: var(--muted); font-size: 17px; font-weight: 800; }
.stick-plus { font-size: 42px; font-weight: 850; }

.answer-panel { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.number-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.number-pad button { min-height: 70px; border: 2px solid #b4c4c9; border-radius: 14px; background: white; color: var(--ink); font-size: 31px; font-weight: 850; }
.number-pad button:active { background: var(--blue-soft); }
.number-pad button:disabled { cursor: default; opacity: .48; }
.number-pad .clear-button { color: var(--muted); font-size: 16px; }
.number-pad .check-button { border-color: var(--blue); background: var(--blue); color: white; font-size: 20px; }
.next-button { width: 100%; min-height: 66px; margin-top: 12px; }

.finish-card { align-self: center; justify-self: center; width: min(620px, 100%); padding: 42px; text-align: center; }
.finish-card h2 { font-size: clamp(42px, 6vw, 64px); }
.finish-card > p:not(.eyebrow) { margin: 14px 0 26px; color: var(--muted); font-size: 23px; font-weight: 700; }
.finish-actions { justify-content: center; }

button:focus-visible, a:focus-visible { outline: 4px solid #f2c94c; outline-offset: 3px; }
.practice-card:focus { outline: none; }
.rotate-message { display: none; }

@media (max-height: 700px) and (orientation: landscape) {
  .math-shell { padding-top: max(7px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .top-bar { min-height: 52px; padding-bottom: 7px; }
  .reading-link { display: none; }
  h1 { font-size: 28px; }
  .setup-card { padding: 15px 20px; }
  .activity-picker { margin: 8px 0; }
  .activity-button { min-height: 55px; padding: 6px 12px; }
  .mode-picker { margin: 8px 0; }
  .mode-button { min-height: 57px; padding: 6px 12px; }
  .comparison-setup { min-height: 120px; padding: 10px 18px; }
  .comparison-number { min-height: 125px; }
  .comparison-number strong { font-size: clamp(58px, 8vw, 82px); }
  .comparison-problem .math-question-line { margin-bottom: 8px; }
  .class-button { min-height: 59px; }
  .setup-actions { margin-top: 12px; }
  .number-pad button { min-height: 58px; }
  .equation { font-size: clamp(58px, 9vw, 90px); }
  .stick-help { min-height: 148px; }
  .stick-group { min-height: 96px; }
  .stick { height: 76px; }
}

@media (max-width: 850px) and (orientation: landscape) {
  .practice-layout { grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); gap: 15px; }
  .class-grid { gap: 6px; }
  .class-button { min-height: 61px; }
  .profile-summary { font-size: 14px; }
  .math-journey { width: 270px; }
}

@media (orientation: portrait) {
  .rotate-message { display: grid; position: fixed; z-index: 100; inset: 0; place-items: center; padding: 28px; background: var(--page); }
  .rotate-card { display: grid; justify-items: center; gap: 14px; max-width: 420px; padding: 32px; border-radius: 24px; background: var(--paper); box-shadow: 0 6px 22px rgb(69 67 57 / 14%); font-size: 20px; text-align: center; }
  .rotate-card strong { font-size: 28px; }
  .rotate-icon { color: var(--blue); font-size: 54px; line-height: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
  .math-journey-traveler { transition: none !important; }
}

.emet-motion-disabled .math-journey-traveler {
  transition: none !important;
}
