:root {
  color-scheme: light;
  --canvas: #f3efe6;
  --paper: #fffdf8;
  --ink: #232b2d;
  --muted: #657074;
  --line: #4d565b;
  --line-soft: #d8d3c8;
  --teal: #176d64;
  --teal-dark: #0f544d;
  --gold: #f1bf55;
  --shadow: 0 22px 55px rgba(39, 45, 47, 0.12);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
}

button {
  font: inherit;
}

.page-shell {
  width: min(1100px, calc(100% - 40px));
  margin: 0 auto;
  padding: 58px 0 64px;
}

.intro {
  max-width: 720px;
  margin: 0 auto 30px;
  text-align: center;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.intro h1 {
  margin: 9px 0 13px;
  font-family: "STKaiti", "KaiTi", "Songti SC", serif;
  font-size: clamp(2.4rem, 6vw, 4.4rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.08;
}

.intro-copy {
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
  font-size: clamp(0.98rem, 2vw, 1.1rem);
  line-height: 1.75;
}

.lesson-card {
  padding: clamp(22px, 4vw, 42px);
  border: 1px solid rgba(77, 86, 91, 0.2);
  border-radius: 26px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.lesson-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  max-width: 830px;
  margin: 0 auto;
}

.lesson-toolbar h2 {
  margin: 7px 0 0;
  font-size: clamp(1.18rem, 2.6vw, 1.55rem);
  line-height: 1.35;
}

.order-control {
  display: grid;
  flex: 0 0 auto;
  gap: 7px;
}

.control-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: right;
}

.segmented-control {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: #f0ede5;
}

.order-button {
  min-height: 38px;
  padding: 7px 15px;
  border: 0;
  border-radius: 8px;
  color: #526064;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 700;
  transition: color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.order-button:hover {
  color: var(--ink);
}

.order-button:focus-visible {
  outline: 3px solid rgba(23, 109, 100, 0.25);
  outline-offset: 2px;
}

.order-button.is-active {
  color: #fff;
  background: var(--teal);
  box-shadow: 0 3px 9px rgba(23, 109, 100, 0.2);
}

.counting-hint {
  max-width: 830px;
  margin: 16px auto 22px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.board-stage {
  --frame-pad: clamp(5px, 1vw, 9px);
  --axis-inset: calc(var(--frame-pad) + 1px);
  --number-size: clamp(0.78rem, 1.9vw, 1.18rem);
  --current-axis-size: clamp(0.96rem, 2.35vw, 1.42rem);
  display: grid;
  grid-template-columns: minmax(38px, 52px) minmax(0, 600px) minmax(38px, 52px);
  grid-template-rows: 42px auto;
  align-items: stretch;
  justify-content: center;
  column-gap: clamp(5px, 1.4vw, 12px);
  width: 100%;
  margin: 0 auto;
}

.axis-corner {
  display: grid;
  place-items: end center;
  padding-bottom: 6px;
  color: #8a9294;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}

.axis-labels {
  display: grid;
  color: #b5bbbd;
  font-size: var(--number-size);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.column-labels {
  grid-template-columns: repeat(10, minmax(0, 1fr));
  margin-inline: var(--axis-inset);
}

.row-labels {
  grid-template-rows: repeat(10, minmax(0, 1fr));
  margin-block: var(--axis-inset);
}

.axis-number {
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  place-items: center;
  line-height: 1;
}

.axis-number.is-current {
  color: var(--ink);
  font-size: var(--current-axis-size);
  font-weight: 900;
}

.grid-frame {
  width: 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  padding: var(--frame-pad);
  border: 1px solid #c8c1b4;
  background: #e9e4da;
  box-shadow: 0 12px 30px rgba(42, 50, 52, 0.1);
  contain: layout;
}

.multiplication-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 2px solid var(--line);
  background: var(--line);
  contain: strict;
}

.grid-cell {
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: transparent;
  background: #fff;
  cursor: pointer;
  font-size: var(--number-size);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  line-height: 1;
  appearance: none;
  contain: layout paint;
}

.grid-cell:nth-child(10n) {
  border-right: 0;
}

.grid-cell:nth-last-child(-n + 10) {
  border-bottom: 0;
}

.grid-cell:hover {
  background: #e8f0ed;
}

.grid-cell:focus-visible {
  position: relative;
  z-index: 2;
  outline: 3px solid var(--gold);
  outline-offset: -3px;
}

.grid-cell.is-filled {
  color: #fff;
  background: var(--teal);
}

.grid-cell.is-filled:hover {
  background: var(--teal-dark);
}

.grid-cell.is-corner {
  position: relative;
  z-index: 1;
  box-shadow: inset 0 0 0 3px var(--gold);
}

.result-panel {
  max-width: 600px;
  margin: 26px auto 0;
  padding-top: 22px;
  border-top: 1px solid var(--line-soft);
  text-align: center;
}

.equation {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: clamp(10px, 2.5vw, 22px);
  color: var(--ink);
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.12;
}

.equation .operator {
  color: #849094;
  font-weight: 400;
}

.equation strong {
  color: var(--teal);
  font-weight: 800;
}

.result-sentence {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.96rem;
}

.grid-help {
  margin: 20px 0 0;
  color: #7c8588;
  font-size: 0.8rem;
  line-height: 1.6;
  text-align: center;
}

@media (max-width: 700px) {
  .page-shell {
    width: min(100% - 22px, 620px);
    padding: 30px 0 34px;
  }

  .intro {
    margin-bottom: 21px;
  }

  .intro h1 {
    margin-top: 7px;
  }

  .lesson-card {
    padding: 20px 12px 24px;
    border-radius: 20px;
  }

  .lesson-toolbar {
    align-items: start;
    flex-direction: column;
    gap: 16px;
    padding: 0 4px;
  }

  .order-control {
    width: 100%;
  }

  .control-label,
  .counting-hint {
    text-align: left;
  }

  .segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .counting-hint {
    margin: 13px 4px 18px;
  }

  .board-stage {
    --frame-pad: 4px;
    grid-template-columns: 32px minmax(0, 1fr) 32px;
    grid-template-rows: 36px auto;
    column-gap: 4px;
  }

  .axis-corner {
    padding-bottom: 4px;
    font-size: 0.56rem;
  }

  .multiplication-grid {
    border-width: 1.5px;
  }

}

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