:root {
  --navy: #063f86;
  --ink: #10294a;
  --muted: #637287;
  --line: #d8e2ec;
  --page: #f6f8fb;
  --blue: #0b67b2;
  --blue-soft: #eaf5ff;
  --teal: #08aaa5;
  --teal-soft: #e8f8f5;
  --orange: #f58220;
  --orange-soft: #fff2e7;
  --violet: #7b42b4;
  --violet-soft: #f5edff;
}

* { box-sizing: border-box; }
html { min-height: 100%; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--page);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
button, input { font: inherit; }
[hidden] { display: none !important; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 20; padding: 10px 14px; border-radius: 8px; color: #fff; background: var(--navy); }
.skip-link:focus { top: 12px; }
.page-shell {
  --stage-min-height: clamp(390px, calc(100svh - 455px), 610px);
  width: min(1480px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
.page-shell > main { min-height: 0; flex: 1; display: flex; flex-direction: column; }

.site-header { min-height: 96px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 22px; padding: 12px 4px 8px; }
.brand-nav { justify-self: start; display: grid; justify-items: start; gap: 3px; }
.brand { width: 148px; }
.brand img { display: block; width: 100%; height: auto; }
.back-link { color: var(--navy); font-size: .78rem; font-weight: 800; text-decoration: none; }
.back-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.title-lockup { text-align: center; }
.title-lockup p { margin: 0 0 2px; color: var(--teal); font-size: .72rem; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.title-lockup h1 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.55rem, 2.6vw, 2.45rem); line-height: 1.05; }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }

.button, .icon-button {
  border: 0;
  border-radius: 12px;
  font-weight: 780;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 9px 16px; }
.button:hover, .icon-button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .38; cursor: default; transform: none; }
.button-primary { color: #fff; background: var(--navy); box-shadow: 0 7px 16px rgba(6, 63, 134, .18); }
.button-secondary { color: var(--navy); background: #eef4fb; }
.button-light, .button-quiet { color: var(--navy); background: #fff; border: 1px solid var(--line); }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; padding: 0; color: var(--navy); background: #fff; border: 1px solid var(--line); }
.icon-button svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.button:focus-visible, .icon-button:focus-visible, input:focus-visible, .back-link:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 32%, transparent); outline-offset: 3px; }

.controls-card, .board-card { border: 1px solid var(--line); border-radius: 22px; background: #fff; box-shadow: 0 9px 24px rgba(19, 49, 83, .07); }
.controls-card { padding: 15px 18px; }
#multiplication-form { display: grid; grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr) minmax(165px, auto) auto; align-items: end; gap: 12px; }
.number-field { display: grid; gap: 6px; color: var(--muted); font-size: .73rem; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.number-field input { width: 100%; height: 46px; border: 2px solid var(--role); border-radius: 11px; padding: 6px 12px; color: var(--ink); background: #fff; font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; outline: none; }
.number-field input:focus { box-shadow: 0 0 0 4px color-mix(in srgb, var(--role) 18%, transparent); }
.number-field input[aria-invalid="true"] { border-color: #b83242; box-shadow: 0 0 0 3px rgba(184, 50, 66, .12); }
.role-first { --role: var(--blue); }
.role-second { --role: var(--teal); }
.multiplication-form-symbol { align-self: center; padding-top: 16px; color: var(--navy); font-size: 1.5rem; font-weight: 900; }
.rank-control { min-height: 46px; display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr 1fr; column-gap: 9px; align-items: center; padding: 5px 10px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #fff; cursor: pointer; }
.rank-control input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.rank-switch { grid-row: 1 / 3; width: 34px; height: 20px; position: relative; border-radius: 999px; background: #dce4ed; transition: background .18s ease; }
.rank-switch::after { content: ""; width: 14px; height: 14px; position: absolute; top: 3px; left: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(16, 41, 74, .25); transition: transform .18s ease; }
.rank-control input:checked + .rank-switch { background: var(--teal); }
.rank-control input:checked + .rank-switch::after { transform: translateX(14px); }
.rank-control input:focus-visible + .rank-switch { outline: 3px solid color-mix(in srgb, var(--blue) 28%, transparent); outline-offset: 2px; }
.rank-copy { display: contents; }
.rank-copy strong { align-self: end; font-size: .76rem; line-height: 1.05; white-space: nowrap; }
.rank-copy small { align-self: start; color: var(--muted); font-size: .65rem; font-weight: 800; letter-spacing: .1em; }
.form-error { margin: 9px 0 0; color: #a22c38; font-weight: 700; }

.projection-recap { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 8px; padding: 6px 9px 6px 15px; border: 1px solid var(--line); border-radius: 15px; color: var(--navy); background: #fff; box-shadow: 0 7px 18px rgba(19, 49, 83, .06); }
.projection-recap strong { overflow: hidden; font-size: 1.02rem; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.projection-recap .button { min-height: 44px; flex: none; padding: 5px 12px; font-size: .78rem; }

.workspace { min-height: 0; flex: 1; display: flex; margin-top: 15px; }
.board-card { min-width: 0; flex: 1; display: grid; grid-template-rows: 122px minmax(var(--stage-min-height), 1fr) auto; padding: 15px; }
.instruction { height: 100%; min-height: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 17px; border-radius: 15px; background: #f3f7fc; }
.instruction-copy { min-width: 0; }
.instruction p { margin: 0 0 3px; color: var(--teal); font-size: .75rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.instruction h2 { margin: 0; color: var(--ink); font-size: clamp(1rem, 1.7vw, 1.28rem); line-height: 1.28; }
.instruction .step-detail { margin: 5px 0 0; color: var(--muted); font-size: clamp(.8rem, 1.2vw, .94rem); font-weight: 650; letter-spacing: 0; line-height: 1.3; text-transform: none; }
.instruction > span { flex: none; color: var(--muted); font-size: .82rem; font-weight: 800; }

.multiplication-stage { min-width: 0; min-height: var(--stage-min-height); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; align-items: center; padding: 12px 22px 10px; overflow: hidden; }
.decimal-preparation { width: min(100%, 760px); display: grid; grid-template-columns: auto minmax(160px, 1fr) auto; align-items: center; gap: 16px; margin: 0 auto 7px; padding: 11px 14px; border: 1px solid #d9c4ef; border-radius: 14px; background: var(--violet-soft); }
.decimal-preparation:not(.is-compact) { align-self: center; grid-template-columns: 1fr; justify-items: center; gap: 13px; padding: 23px; }
.decimal-preparation-title { margin: 0; color: var(--violet); font-size: .75rem; font-weight: 900; letter-spacing: .09em; text-transform: uppercase; white-space: nowrap; }
.decimal-original-expression { color: var(--navy); font-family: "DejaVu Sans Mono", Consolas, monospace; font-size: clamp(1.4rem, 3.2vw, 2.3rem); font-variant-numeric: tabular-nums; text-align: center; }
.decimal-counts { display: flex; justify-content: center; gap: 7px; }
.decimal-count { min-width: 64px; display: grid; grid-template-columns: auto auto; align-items: center; gap: 6px; padding: 6px 8px; border: 1px solid color-mix(in srgb, var(--role) 35%, #fff); border-radius: 9px; color: var(--role); background: #fff; }
.decimal-count small { color: var(--muted); font-size: .65rem; font-weight: 750; white-space: nowrap; }
.decimal-count strong { min-width: 1.25em; font-size: 1rem; text-align: center; }
.decimal-count strong:not(.is-visible) { color: #9aa7b6; }
.decimal-count-1 { --role: var(--blue); }
.decimal-count-2 { --role: var(--teal); }
.decimal-count-3 { --role: var(--orange); }

.multiplication-scroll { min-width: 0; width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden; padding: 9px 2px 13px; scrollbar-color: #b5c5d7 transparent; scrollbar-width: thin; }
#posed-multiplication { width: max-content; min-width: 0; margin: 0 auto; }
.posed-multiplication {
  display: grid;
  grid-template-columns: var(--sign-width) repeat(var(--column-count), var(--column-width));
  grid-template-rows: repeat(2, var(--row-height)) 14px repeat(var(--partial-count), var(--row-height)) 14px var(--row-height);
  align-items: center;
  width: max-content;
  padding: 8px 9px 7px 0;
  font-family: "DejaVu Sans Mono", Consolas, monospace;
  font-size: var(--digit-size);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.digit-cell, .multiplication-sign, .addition-sign, .partial-label { min-width: 0; height: 100%; display: grid; place-items: center; line-height: 1; }
.digit-cell { position: relative; border-radius: 9px; }
.factor-1-cell { color: var(--blue); }
.factor-2-cell { color: var(--teal); }
.partial-cell { color: var(--ink); padding-top: .14em; }
.result-cell, .result-number-text { color: var(--orange); }
.factor-cell.is-active { box-shadow: inset 0 0 0 2px color-mix(in srgb, currentColor 28%, transparent); }
.factor-1-cell.is-active { background: var(--blue-soft); }
.factor-2-cell.is-active { background: var(--teal-soft); }
.factor-cell.is-aligned { background: #f2f7fc; box-shadow: inset 0 -3px color-mix(in srgb, currentColor 42%, transparent); }
.multiplication-sign, .addition-sign { align-items: end; padding-bottom: .14em; color: var(--navy); }
.operation-rule { width: 100%; align-self: center; border-top: 4px solid var(--navy); }
.partial-label { color: var(--muted); font-family: "Segoe UI", system-ui, sans-serif; font-size: .34em; font-weight: 850; }
.partial-label.is-active { color: var(--teal); }
.partial-cell.is-target, .result-cell.is-target { background: #f6f8fb; box-shadow: inset 0 -3px #b8c7d7; }
.partial-cell.is-visible { animation: reveal-digit .25s ease-out both; }
.partial-cell.is-shift-zero { color: var(--teal); background: var(--teal-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--teal) 32%, transparent); }
.result-cell.is-visible { animation: reveal-digit .25s ease-out both; }
.carry-chip { position: absolute; z-index: 2; top: 1px; left: 50%; min-width: 1.35em; transform: translateX(-50%); padding: 2px 4px; border-radius: 6px; color: var(--violet); background: var(--violet-soft); font-family: "Segoe UI", system-ui, sans-serif; font-size: .34em; font-weight: 900; line-height: 1.05; text-align: center; }
.carry-chip.is-fresh, .carry-chip.is-active { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--violet) 32%, transparent); }
.carry-chip.is-used { opacity: .38; background: transparent; text-decoration: line-through; text-decoration-thickness: 2px; }
.result-number-text { align-self: center; justify-self: end; padding-right: calc(var(--column-width) * .08); font-size: 1em; line-height: 1; }
.rank-marker { position: absolute; top: 2px; left: 50%; transform: translateX(-50%); color: #718198; font-family: "Segoe UI", system-ui, sans-serif; font-size: clamp(.6rem, .24em, .75rem); font-weight: 900; letter-spacing: 0; line-height: 1; white-space: nowrap; }
.has-rank-guides .factor-1-cell { padding-top: .19em; }
@keyframes reveal-digit { from { opacity: .2; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.vocabulary-strip { width: min(100%, 760px); display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1.05fr); align-items: center; gap: 8px; margin: 3px auto 0; padding: 9px 14px; border: 1px solid var(--line); border-radius: 13px; background: #f8fafc; text-align: center; }
.vocabulary-strip > strong { color: var(--navy); font-size: 1.15rem; }
.vocabulary-role { min-width: 0; display: grid; gap: 2px; line-height: 1.1; }
.vocabulary-role strong { overflow: hidden; font-family: "DejaVu Sans Mono", Consolas, monospace; font-size: clamp(.8rem, 1.3vw, 1rem); text-overflow: ellipsis; white-space: nowrap; }
.vocabulary-role small { color: currentColor; font-size: .66rem; font-weight: 850; text-transform: uppercase; }
.first-role { color: var(--blue); }
.second-role { color: var(--teal); }
.product-role { color: var(--orange); }

.step-controls { display: grid; grid-template-columns: auto minmax(80px, 1fr) auto auto; align-items: center; gap: 10px; padding-top: 12px; border-top: 1px solid #e7edf4; }
.progress { height: 6px; overflow: hidden; border-radius: 999px; background: #e9eef5; }
.progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--blue)); transition: width .2s ease; }
.site-footer { margin-top: auto; display: flex; flex-wrap: wrap; justify-content: center; gap: 7px; padding: 19px 10px 24px; color: #718096; font-size: .8rem; text-align: center; }
.site-footer a, .site-footer button { padding: 0; border: 0; color: #526d8d; background: transparent; font: inherit; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

body.is-projection { height: 100svh; overflow: hidden; }
body.is-projection .page-shell { --stage-min-height: 0px; width: min(1700px, calc(100% - 18px)); height: 100svh; min-height: 0; overflow: hidden; }
body.is-projection .site-header { min-height: 66px; padding-block: 5px 3px; }
body.is-projection .brand { width: 118px; }
body.is-projection .title-lockup p { display: none; }
body.is-projection .title-lockup h1 { font-size: clamp(1.4rem, 2.2vw, 2rem); }
body.is-projection .workspace { min-height: 0; margin-top: 8px; }
body.is-projection .board-card { min-height: 0; grid-template-rows: 92px minmax(0, 1fr) auto; padding: 10px; }
body.is-projection .instruction { padding: 9px 13px; }
body.is-projection .instruction h2 { font-size: clamp(1rem, 1.5vw, 1.2rem); }
body.is-projection .instruction .step-detail { margin-top: 3px; font-size: clamp(.74rem, 1.05vw, .86rem); }
body.is-projection .multiplication-stage { min-height: 0; padding: 5px 16px 3px; }
body.is-projection .decimal-preparation { margin-bottom: 3px; padding-block: 6px; }
body.is-projection .multiplication-scroll { padding-block: 2px 5px; }
body.is-projection .vocabulary-strip { padding-block: 7px; }
body.is-projection .step-controls { padding-top: 7px; }
body.is-projection .step-controls .button { min-height: 44px; padding-block: 6px; }
body.is-projection .site-footer { flex: none; gap: 5px; padding: 5px 8px 6px; font-size: .68rem; }

@media (min-width: 1280px) {
  .board-card { grid-template-columns: minmax(350px, .48fr) minmax(0, 1fr); grid-template-rows: minmax(var(--stage-min-height), 1fr) auto; column-gap: 18px; }
  .instruction { grid-column: 1; grid-row: 1 / 3; position: relative; align-items: flex-start; padding: 24px 55px 24px 24px; }
  .instruction p { font-size: .86rem; }
  .instruction > span { position: absolute; top: 23px; right: 20px; font-size: .95rem; }
  .instruction h2 { margin-top: 6px; font-size: clamp(1.42rem, 1.8vw, 2.08rem); line-height: 1.24; overflow-wrap: anywhere; }
  .instruction .step-detail { margin-top: 14px; font-size: clamp(1.05rem, 1.2vw, 1.24rem); line-height: 1.4; }
  .multiplication-stage { grid-column: 2; grid-row: 1; }
  .step-controls { grid-column: 2; grid-row: 2; }

  body.is-projection .board-card { grid-template-columns: minmax(360px, .48fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; column-gap: 16px; }
  body.is-projection .instruction { padding: 23px 56px 23px 23px; }
  body.is-projection .instruction p { font-size: .9rem; }
  body.is-projection .instruction h2 { font-size: clamp(1.55rem, 1.9vw, 2.18rem); }
  body.is-projection .instruction .step-detail { margin-top: 14px; font-size: clamp(1.08rem, 1.22vw, 1.3rem); }
}

@media (max-width: 1080px) {
  #multiplication-form { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) minmax(165px, auto); }
  #multiplication-form > .button-primary { grid-column: 4; }
  .rank-control { grid-column: 1 / 4; grid-row: 2; justify-self: start; }
}

@media (max-width: 780px) {
  .page-shell { width: min(100% - 18px, 1480px); }
  .site-header { grid-template-columns: auto 1fr auto; gap: 10px; }
  .brand { width: 112px; }
  .back-link { font-size: .72rem; }
  .title-lockup p { display: none; }
  .title-lockup h1 { font-size: 1.35rem; }
  #multiplication-form { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 9px; }
  .rank-control { grid-column: 1 / 3; grid-row: auto; justify-self: stretch; }
  #multiplication-form > .button-primary { grid-column: 3; }
  .board-card { grid-template-rows: minmax(148px, auto) minmax(390px, 1fr) auto; }
  .instruction { align-items: flex-start; }
  .multiplication-stage { min-height: 390px; padding-inline: 4px; }
  .decimal-preparation { grid-template-columns: 1fr; justify-items: center; gap: 7px; }
  .decimal-preparation.is-compact { grid-template-columns: auto 1fr; }
  .decimal-preparation.is-compact .decimal-counts { justify-self: end; }
  body.is-projection { height: auto; min-height: 100svh; overflow-y: auto; }
  body.is-projection .page-shell { height: auto; min-height: 100svh; overflow-y: visible; }
  body.is-projection .board-card { grid-template-rows: minmax(108px, auto) minmax(390px, 1fr) auto; }
  body.is-projection .multiplication-stage { min-height: 390px; }
}

@media (max-width: 520px) {
  .page-shell { width: min(100% - 10px, 1480px); }
  .site-header { min-height: 88px; gap: 7px; }
  .brand { width: 101px; }
  .back-link { font-size: .68rem; }
  .title-lockup h1 { font-size: 1.12rem; }
  .controls-card { padding: 12px; }
  .number-field input { height: 44px; padding-inline: 9px; font-size: 1.02rem; }
  .multiplication-form-symbol { padding-top: 15px; font-size: 1.28rem; }
  #multiplication-form > .button-primary { grid-column: 1 / -1; }
  .rank-control { grid-column: 1 / -1; }
  .board-card { grid-template-rows: minmax(162px, auto) minmax(390px, 1fr) auto; padding-inline: 9px; }
  .instruction { padding: 12px; }
  .instruction h2 { font-size: .96rem; }
  .instruction .step-detail { font-size: .78rem; }
  .multiplication-stage { min-height: 390px; padding-inline: 0; }
  .decimal-preparation { width: calc(100% - 4px); padding: 9px 7px; }
  .decimal-preparation.is-compact { grid-template-columns: 1fr; }
  .decimal-preparation.is-compact .decimal-counts { justify-self: center; }
  .decimal-count { min-width: 0; padding-inline: 6px; }
  .decimal-count small { font-size: .59rem; }
  .vocabulary-strip { gap: 4px; padding-inline: 7px; }
  .vocabulary-strip > strong { font-size: .92rem; }
  .step-controls { grid-template-columns: 1fr 1fr; gap: 8px; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  #previous { grid-column: 1; grid-row: 1; }
  #next { grid-column: 2; grid-row: 1; }
  #show-all { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
  .progress { grid-column: 1 / -1; grid-row: 3; }
  .step-controls .button { padding-inline: 8px; font-size: .82rem; }
  body.is-projection .site-header { min-height: 62px; }
  body.is-projection .brand { width: 91px; }
  body.is-projection .back-link { display: none; }
  body.is-projection .board-card { grid-template-rows: minmax(104px, auto) minmax(390px, 1fr) auto; }
  body.is-projection .site-footer { display: none; }
}

@media (max-width: 360px) {
  .site-header { grid-template-columns: 96px minmax(0, 1fr) 44px; }
  .brand { width: 94px; }
  .title-lockup h1 { font-size: 1rem; }
  .board-card { padding-inline: 7px; }
  .instruction { padding-inline: 10px; }
  .instruction > span { font-size: .74rem; }
  .decimal-count small { font-size: .54rem; }
  .vocabulary-role small { font-size: .58rem; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .site-header { min-height: 66px; padding-block: 5px; }
  .brand { width: 104px; }
  .title-lockup h1 { font-size: 1.15rem; }
  .site-footer { padding-block: 8px; }
  body.is-projection .site-footer { display: none; }
}

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