:root {
  color-scheme: light;
  --bg: #f6fbff;
  --paper: #fffdf4;
  --surface: #ffffff;
  --ink: #253047;
  --muted: #627086;
  --line: #253047;
  --sky: #7dd9ff;
  --mint: #72d6bd;
  --lemon: #ffd84d;
  --coral: #ff6b5e;
  --blue: #5278ff;
  --plum: #8b63d9;
  --green: #20a66a;
  --bad: #f05a4f;
  --soft-sky: #dff6ff;
  --soft-lemon: #fff2a8;
  --soft-mint: #d8fff3;
  --shadow-hard: 0 6px 0 rgba(37, 48, 71, 0.16);
  --shadow-soft: 0 18px 36px rgba(37, 48, 71, 0.13);
  font-family:
    ui-rounded, "Nunito", "Comic Sans MS", "PingFang SC", "Microsoft YaHei",
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    repeating-linear-gradient(0deg, transparent 0 31px, rgba(82, 120, 255, 0.08) 31px 32px),
    repeating-linear-gradient(90deg, transparent 0 31px, rgba(114, 214, 189, 0.1) 31px 32px),
    linear-gradient(180deg, #e8f8ff 0%, #fff8c9 52%, #f8fffb 100%);
  color: var(--ink);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    linear-gradient(45deg, transparent 0 47%, rgba(255, 107, 94, 0.1) 47% 53%, transparent 53%),
    linear-gradient(-45deg, transparent 0 48%, rgba(255, 216, 77, 0.16) 48% 52%, transparent 52%);
  background-size: 96px 96px, 132px 132px;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(255, 216, 77, 0.72);
  outline-offset: 4px;
}

.app {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.setup-view {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 44px 0 42px;
  display: grid;
  align-content: center;
  gap: 26px;
}

.setup-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 28px;
  align-items: center;
}

.eyebrow {
  width: fit-content;
  margin: 0 0 14px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--soft-mint);
  box-shadow: 0 4px 0 rgba(37, 48, 71, 0.12);
  color: var(--ink);
  font-size: 0.94rem;
  font-weight: 900;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: 4.9rem;
  line-height: 0.98;
  letter-spacing: 0;
  text-wrap: balance;
  text-shadow:
    0 5px 0 #fff,
    0 8px 0 rgba(37, 48, 71, 0.08);
}

.intro {
  width: min(690px, 100%);
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 1.13rem;
  line-height: 1.75;
  font-weight: 750;
}

.mascot-scene {
  position: relative;
  min-height: 292px;
}

.sun-token,
.paper-tile,
.pencil-shape,
.spark,
.score-badge {
  position: absolute;
}

.sun-token {
  top: 4px;
  right: 32px;
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  clip-path: polygon(
    50% 0,
    60% 24%,
    86% 14%,
    76% 40%,
    100% 50%,
    76% 60%,
    86% 86%,
    60% 76%,
    50% 100%,
    40% 76%,
    14% 86%,
    24% 60%,
    0 50%,
    24% 40%,
    14% 14%,
    40% 24%
  );
  background: var(--lemon);
  color: var(--ink);
  font-size: 2.4rem;
  font-weight: 950;
  filter: drop-shadow(0 7px 0 rgba(37, 48, 71, 0.14));
}

.paper-tile {
  display: grid;
  place-items: center;
  width: 104px;
  height: 92px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(0deg, rgba(125, 217, 255, 0.16) 1px, transparent 1px),
    var(--surface);
  background-size: 100% 18px;
  box-shadow: var(--shadow-hard);
  color: var(--blue);
  font-size: 2.2rem;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.tile-one {
  top: 76px;
  right: 154px;
  transform: rotate(-8deg);
}

.tile-two {
  top: 58px;
  right: 28px;
  transform: rotate(8deg);
  color: var(--coral);
}

.pencil-shape {
  right: 104px;
  bottom: 52px;
  width: 164px;
  height: 30px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--lemon);
  box-shadow: var(--shadow-hard);
  transform: rotate(-13deg);
}

.pencil-shape::before,
.pencil-shape::after {
  content: "";
  position: absolute;
  top: -3px;
  height: 30px;
  border: 3px solid var(--line);
}

.pencil-shape::before {
  left: -30px;
  width: 30px;
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
  background: #ffd4a3;
}

.pencil-shape::after {
  right: -20px;
  width: 20px;
  border-radius: 0 8px 8px 0;
  background: var(--coral);
}

.spark {
  width: 28px;
  height: 28px;
  clip-path: polygon(50% 0, 60% 37%, 100% 50%, 60% 63%, 50% 100%, 40% 63%, 0 50%, 40% 37%);
  background: var(--mint);
  filter: drop-shadow(0 4px 0 rgba(37, 48, 71, 0.12));
}

.spark-one {
  left: 34px;
  top: 36px;
}

.spark-two {
  right: 12px;
  bottom: 98px;
  width: 22px;
  height: 22px;
  background: var(--plum);
}

.score-badge {
  right: 18px;
  bottom: 6px;
  min-width: 168px;
  padding: 16px 18px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--soft-lemon);
  box-shadow: var(--shadow-hard), var(--shadow-soft);
  display: grid;
  justify-items: center;
  gap: 4px;
  color: var(--ink);
  font-weight: 900;
  transform: rotate(3deg);
}

.badge-number {
  color: var(--coral);
  font-size: 3.2rem;
  line-height: 1;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.selector-band {
  display: grid;
  gap: 14px;
}

.section-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
}

.section-label span {
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 950;
}

.section-label small {
  text-align: right;
  font-weight: 760;
}

.grade-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.grade-btn,
.type-btn,
.primary-action,
.ghost-action,
.icon-btn,
.submit-action {
  border: 3px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

.grade-btn,
.type-btn {
  background: var(--surface);
  box-shadow: var(--shadow-hard);
}

.grade-btn {
  min-height: 88px;
  padding: 12px;
  display: grid;
  place-items: center;
  gap: 2px;
}

.grade-btn strong {
  font-size: 1.65rem;
  line-height: 1;
  font-weight: 950;
}

.grade-btn span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 850;
}

.type-btn {
  min-height: 124px;
  padding: 15px;
  text-align: left;
  display: grid;
  align-content: space-between;
  gap: 12px;
}

.type-btn strong {
  font-size: 1.04rem;
  font-weight: 950;
}

.type-btn small {
  color: var(--muted);
  line-height: 1.45;
  font-weight: 740;
}

.type-mark {
  width: 38px;
  height: 38px;
  border: 2px solid var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--soft-sky);
  color: var(--blue);
  font-weight: 950;
  box-shadow: 0 3px 0 rgba(37, 48, 71, 0.14);
}

.grade-btn:hover,
.type-btn:hover,
.primary-action:hover,
.ghost-action:hover,
.icon-btn:hover,
.submit-action:hover {
  transform: translateY(-3px);
  box-shadow: 0 9px 0 rgba(37, 48, 71, 0.14), var(--shadow-soft);
}

.grade-btn:active,
.type-btn:active,
.primary-action:active,
.ghost-action:active,
.icon-btn:active,
.submit-action:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 rgba(37, 48, 71, 0.16);
}

.grade-btn.active,
.type-btn.active {
  color: var(--surface);
  background: linear-gradient(135deg, var(--blue), var(--mint));
}

.grade-btn.active span,
.type-btn.active small {
  color: rgba(255, 255, 255, 0.88);
}

.type-btn.active .type-mark {
  background: var(--lemon);
  color: var(--ink);
}

.start-row {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.primary-action,
.ghost-action {
  min-height: 58px;
  padding: 0 26px;
  font-weight: 950;
  box-shadow: var(--shadow-hard);
}

.primary-action {
  min-width: 188px;
  color: var(--surface);
  background: var(--coral);
}

.ghost-action {
  background: var(--soft-sky);
}

.practice-view {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background:
    repeating-linear-gradient(0deg, transparent 0 35px, rgba(82, 120, 255, 0.11) 35px 36px),
    repeating-linear-gradient(90deg, transparent 0 35px, rgba(255, 107, 94, 0.08) 35px 36px),
    var(--paper);
}

.practice-header {
  min-height: 82px;
  padding: 16px 34px;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 14px;
  align-items: center;
  border-bottom: 3px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 5px 0 rgba(37, 48, 71, 0.1);
  backdrop-filter: blur(10px);
}

.icon-btn,
.submit-action {
  display: grid;
  place-items: center;
}

.icon-btn {
  width: 48px;
  height: 48px;
  background: var(--soft-mint);
  font-size: 1.35rem;
  font-weight: 950;
  box-shadow: 0 4px 0 rgba(37, 48, 71, 0.16);
}

.practice-meta {
  min-width: 0;
  display: flex;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-weight: 900;
}

.practice-meta span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.timer-pill {
  min-width: 88px;
  padding: 10px 13px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--lemon);
  color: var(--ink);
  text-align: center;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 0 rgba(37, 48, 71, 0.16);
}

.feedback-strip {
  min-height: 62px;
  padding: 10px 16px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 1.12rem;
  font-weight: 950;
}

.feedback-strip.good,
.feedback-strip.bad {
  width: min(740px, calc(100% - 32px));
  min-height: 48px;
  margin: 10px auto 0;
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 0 rgba(37, 48, 71, 0.12);
}

.feedback-strip.good {
  background: var(--soft-mint);
  color: #126c4b;
}

.feedback-strip.bad {
  background: #ffe0dd;
  color: #b9312c;
}

.question-stage {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 30px;
  display: grid;
  place-items: center;
  gap: 28px;
}

.math-card {
  position: relative;
  width: 100%;
  min-height: 390px;
  border: 4px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(0deg, rgba(125, 217, 255, 0.13) 1px, transparent 1px),
    var(--surface);
  background-size: 100% 30px;
  box-shadow: var(--shadow-hard), var(--shadow-soft);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 48px;
  overflow: hidden;
  text-align: center;
}

.math-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 18px;
  background: repeating-linear-gradient(
    90deg,
    var(--coral) 0 48px,
    var(--lemon) 48px 96px,
    var(--mint) 96px 144px,
    var(--sky) 144px 192px
  );
  border-bottom: 4px solid var(--line);
}

.math-card::after {
  content: "?";
  position: absolute;
  right: 22px;
  bottom: 16px;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--soft-lemon);
  color: var(--coral);
  font-size: 2rem;
  font-weight: 950;
  transform: rotate(8deg);
  box-shadow: 0 4px 0 rgba(37, 48, 71, 0.14);
}

.question-label {
  margin: 0;
  padding: 8px 14px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--soft-mint);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 950;
  box-shadow: 0 4px 0 rgba(37, 48, 71, 0.12);
}

.question-text {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 6rem;
  line-height: 1.06;
  letter-spacing: 0;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 5px 0 rgba(255, 216, 77, 0.5);
}

.answer-form {
  width: min(620px, 100%);
  display: grid;
  gap: 10px;
}

.answer-label {
  color: var(--ink);
  font-weight: 950;
}

.answer-row {
  --answer-content-height: 66px;
  position: relative;
  height: 74px;
  display: grid;
  grid-template-columns: 1fr 74px;
  border: 4px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-hard);
}

.answer-placeholder {
  position: absolute;
  inset: 4px 74px 4px 0;
  z-index: 1;
  display: flex;
  align-items: center;
  padding: 0 20px;
  color: #8d9bae;
  font-size: 1.05rem;
  font-weight: 850;
  line-height: 1;
  pointer-events: none;
}

.answer-input {
  position: relative;
  z-index: 2;
  min-width: 0;
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  padding: 0 20px;
  background: transparent;
  color: var(--ink);
  font-size: 2rem;
  font-weight: 950;
  line-height: var(--answer-content-height);
}

.answer-input::placeholder {
  color: transparent;
  font-size: inherit;
  font-weight: 850;
  line-height: inherit;
}

.answer-input:not(:placeholder-shown) + .answer-placeholder {
  display: none;
}

.answer-input:disabled {
  cursor: not-allowed;
  opacity: 1;
  -webkit-text-fill-color: var(--muted);
}

.answer-row:has(.answer-input:disabled) {
  background: #eef3f7;
}

.answer-input:disabled + .answer-placeholder {
  color: #9aa7b8;
}

.submit-action {
  position: relative;
  z-index: 3;
  border: 0;
  border-left: 4px solid var(--line);
  border-radius: 0;
  color: var(--surface);
  background: var(--blue);
  font-size: 2rem;
  font-weight: 950;
}

.answer-help {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 760;
}

.stats-row {
  min-height: 92px;
  padding: 14px 30px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  border-top: 3px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -5px 0 rgba(37, 48, 71, 0.08);
}

.stats-row div {
  min-width: 0;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 0 rgba(37, 48, 71, 0.12);
}

.stats-row div:nth-child(1) {
  background: var(--soft-mint);
}

.stats-row div:nth-child(2) {
  background: #ffe2df;
}

.stats-row div:nth-child(3) {
  background: var(--soft-lemon);
}

.stats-row div:nth-child(4) {
  background: var(--soft-sky);
}

.stats-row span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  font-size: 1.62rem;
  font-weight: 950;
  font-variant-numeric: tabular-nums;
}

.stats-row small {
  color: var(--muted);
  font-weight: 900;
}

@media (max-width: 900px) {
  .setup-view {
    align-content: start;
    gap: 22px;
    padding-top: 24px;
  }

  .setup-top {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  h1 {
    font-size: 3.8rem;
  }

  .mascot-scene {
    min-height: 130px;
    max-width: 400px;
  }

  .sun-token {
    width: 66px;
    height: 66px;
    left: 10px;
    right: auto;
    font-size: 1.65rem;
  }

  .paper-tile {
    width: 78px;
    height: 66px;
    font-size: 1.62rem;
  }

  .tile-one {
    top: 52px;
    left: 76px;
    right: auto;
  }

  .tile-two {
    top: 28px;
    left: 170px;
    right: auto;
  }

  .pencil-shape {
    left: 72px;
    right: auto;
    bottom: 12px;
    width: 126px;
  }

  .score-badge {
    right: 10px;
    bottom: 0;
    min-width: 132px;
    padding: 10px 12px;
  }

  .badge-number {
    font-size: 2.15rem;
  }

  .grade-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .type-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  body {
    background-size: auto;
  }

  .setup-view,
  .question-stage {
    width: min(100% - 24px, 1120px);
  }

  .setup-view {
    gap: 20px;
    padding-top: 24px;
  }

  h1 {
    font-size: 2.75rem;
  }

  .intro {
    font-size: 1rem;
  }

  .mascot-scene {
    min-height: 112px;
  }

  .sun-token {
    width: 54px;
    height: 54px;
    font-size: 1.35rem;
  }

  .paper-tile {
    width: 66px;
    height: 56px;
    font-size: 1.35rem;
  }

  .tile-one {
    top: 44px;
    left: 62px;
  }

  .tile-two {
    top: 22px;
    left: 142px;
  }

  .pencil-shape {
    left: 56px;
    bottom: 10px;
    width: 112px;
  }

  .score-badge {
    min-width: 118px;
    padding: 8px 10px;
    right: 2px;
    transform: rotate(2deg);
  }

  .badge-number {
    font-size: 1.9rem;
  }

  .section-label {
    align-items: start;
    flex-direction: column;
    gap: 4px;
  }

  .section-label small {
    text-align: left;
  }

  .grade-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .type-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grade-btn {
    min-height: 68px;
  }

  .type-btn {
    min-height: 104px;
    padding: 13px;
  }

  .start-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-action,
  .ghost-action {
    width: 100%;
  }

  .practice-header {
    grid-template-columns: 44px 1fr auto;
    gap: 10px;
    padding: 12px;
  }

  .icon-btn {
    width: 44px;
    height: 44px;
  }

  .practice-meta {
    display: grid;
    gap: 2px;
    font-size: 0.88rem;
  }

  .timer-pill {
    min-width: 76px;
    padding-inline: 8px;
  }

  .feedback-strip {
    font-size: 1rem;
  }

  .question-stage {
    gap: 18px;
  }

  .math-card {
    min-height: 300px;
    padding: 38px 18px 44px;
  }

  .math-card::after {
    right: 12px;
    bottom: 12px;
    width: 42px;
    height: 42px;
    font-size: 1.5rem;
  }

  .question-text {
    font-size: 3.35rem;
  }

  .answer-row {
    --answer-content-height: 58px;
    height: 66px;
    grid-template-columns: 1fr 64px;
  }

  .answer-placeholder {
    inset: 4px 64px 4px 0;
    padding-inline: 14px;
  }

  .answer-input {
    font-size: 1.7rem;
    padding-inline: 14px;
  }

  .stats-row {
    min-height: 84px;
    padding: 10px;
    gap: 6px;
  }

  .stats-row div {
    border-width: 2px;
  }

  .stats-row span {
    font-size: 1.26rem;
  }

  .stats-row small {
    font-size: 0.78rem;
  }
}

@media (max-width: 390px) {
  h1 {
    font-size: 2.42rem;
  }

  .mascot-scene {
    min-height: 160px;
  }

  .tile-one {
    left: 58px;
  }

  .tile-two {
    left: 142px;
  }

  .grade-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .score-badge {
    min-width: 120px;
    font-size: 0.82rem;
  }

  .question-text {
    font-size: 2.8rem;
  }
}
