:root {
  color-scheme: light;
  --paper: #f7f6f1;
  --ink: #252922;
  --muted: #878b81;
  --green: #426a4e;
  --line: #e5e6de;
  --viewport-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@supports (height: 100dvh) {
  :root { --viewport-height: 100dvh; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 320px; min-height: var(--viewport-height); margin: 0; color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid #a8b99d; outline-offset: 4px; }

.app-shell {
  display: grid;
  width: min(100%, 760px);
  min-height: var(--viewport-height);
  margin: 0 auto;
  padding: 32px 28px;
  place-items: center;
}

.landing { width: min(100%, 450px); padding: 30px 0; }
.eyebrow { margin: 0 0 18px; color: var(--green); font-size: 11px; font-weight: 700; letter-spacing: 1.8px; }
h1 { margin: 0; font-size: clamp(34px, 7vw, 48px); font-weight: 650; letter-spacing: -2px; line-height: 1.08; }
.landing-copy { margin: 13px 0 36px; color: var(--muted); font-size: 15px; }
.level-list { border-top: 1px solid var(--line); }
.level-choice {
  display: flex;
  width: 100%;
  min-height: 83px;
  padding: 13px 5px;
  align-items: center;
  gap: 19px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: padding .16s ease, color .16s ease;
}
.level-choice:hover { padding-right: 0; padding-left: 11px; color: var(--green); }
.level-number { color: #a2a69d; font-size: 11px; font-variant-numeric: tabular-nums; }
.level-text { display: grid; flex: 1; gap: 3px; }
.level-name { font-size: 19px; font-weight: 600; letter-spacing: -.35px; }
.level-detail { color: var(--muted); font-size: 12px; }
.level-arrow { color: #9ea398; font-size: 20px; transition: transform .16s ease; }
.level-choice:hover .level-arrow { transform: translate(2px, -2px); color: var(--green); }

.exercise { display: flex; width: 100%; min-height: calc(var(--viewport-height) - 64px); flex-direction: column; }
.exercise-header { display: flex; min-height: 36px; align-items: center; justify-content: space-between; }
.back-button { padding: 6px 0; border: 0; color: var(--muted); background: transparent; cursor: pointer; font-size: 13px; }
.back-button:hover { color: var(--ink); }
.back-button span { padding-right: 6px; }
.level-indicator { color: var(--muted); font-size: 12px; }
.exercise-content { width: 100%; margin: auto; padding: 36px 0 52px; text-align: center; }
.operation-picker { display: flex; margin: 48px auto 0; align-items: center; justify-content: center; gap: 4px; }
.operation-button {
  min-width: 34px;
  height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  color: #999d94;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  transition: color .14s ease, background .14s ease;
}
.operation-button:first-child { min-width: auto; font-size: 11px; }
.operation-button:hover { color: var(--green); }
.operation-button.is-active { color: var(--green); background: transparent; box-shadow: inset 0 -1px var(--green); border-radius: 0; }
.problem-label { margin: 0 0 20px; color: #a0a399; font-size: 10px; font-weight: 600; letter-spacing: 1.5px; }
.problem { display: flex; min-height: 90px; align-items: center; justify-content: center; gap: clamp(12px, 4vw, 28px); font-size: clamp(54px, 11vw, 82px); font-weight: 500; letter-spacing: -4px; line-height: 1; font-variant-numeric: tabular-nums; }
.problem .operator { color: var(--green); font-weight: 400; }
.problem .equals { color: #c2c5bc; font-weight: 300; }
.problem .question-mark { color: #c98760; font-weight: 400; }
.answer-form input.is-correct { animation: correct-flash 320ms ease-out; }
.answer-form input.is-incorrect { animation: incorrect-flash 320ms ease-out; }
@keyframes correct-flash {
  0% { background-color: #dcebd8; }
  100% { background-color: transparent; }
}
@keyframes incorrect-flash {
  0% { background-color: #f3d7d2; }
  100% { background-color: transparent; }
}
.answer-form { display: flex; width: min(100%, 340px); margin: 34px auto 0; gap: 10px; }
.answer-form input { width: 100%; min-width: 0; height: 58px; padding: 0 16px; border: 0; border-bottom: 2px solid #c9cec2; border-radius: 0; color: var(--ink); background: transparent; font-size: 24px; font-variant-numeric: tabular-nums; text-align: center; transition: border-color .15s ease; }
.answer-form input::placeholder { color: #b3b6ad; font-size: 16px; }
.answer-form input:focus { border-color: var(--green); outline: 0; }
.answer-form input::-webkit-inner-spin-button, .answer-form input::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; }
.answer-form input[type=number] { -moz-appearance: textfield; }
.submit-button { display: grid; width: 55px; height: 55px; flex: 0 0 55px; place-items: center; border: 0; border-radius: 50%; color: #fff; background: var(--green); cursor: pointer; font-size: 22px; transition: background .15s ease, transform .15s ease; }
.submit-button:hover { background: #34573f; transform: translateX(2px); }
.feedback { min-height: 23px; margin: 16px 0 0; color: var(--muted); font-size: 14px; }
.feedback.is-wrong { color: #b6614d; font-weight: 600; }
.stats { display: flex; margin: 31px 0 0; justify-content: center; gap: 7px; color: var(--muted); font-size: 12px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

@media (max-width: 520px) {
  .app-shell { padding: 24px 22px; }
  .exercise { min-height: calc(var(--viewport-height) - 48px); }
  .exercise-content { padding: 26px 0 36px; }
  .operation-picker { margin-top: 38px; gap: 2px; }
  .operation-button { min-width: 38px; padding: 0 8px; }
  .problem { gap: clamp(9px, 3vw, 18px); letter-spacing: -3px; }
  .answer-form { width: min(100%, 310px); margin-top: 26px; }
}

@media (max-height: 650px) {
  .app-shell { padding-top: 12px; padding-bottom: 12px; }
  .exercise { min-height: 0; }
  .exercise-header { min-height: 36px; }
  .exercise-content { margin: 0 auto; padding: 20px 0 16px; }
  .problem-label { margin-bottom: 10px; }
  .problem { min-height: 64px; font-size: clamp(46px, 9vw, 60px); }
  .answer-form { margin-top: 16px; }
  .answer-form input { height: 52px; font-size: 22px; }
  .submit-button { width: 50px; height: 50px; flex-basis: 50px; }
  .feedback { min-height: 20px; margin-top: 8px; font-size: 13px; }
  .stats { margin-top: 14px; }
  .operation-picker { margin-top: 18px; }
}

.app-shell.keyboard-open {
  place-items: start center;
  min-height: var(--viewport-height);
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.app-shell.keyboard-open .exercise { min-height: 0; }
.app-shell.keyboard-open .exercise-header { min-height: 36px; }
.app-shell.keyboard-open .exercise-content { margin: 0 auto; padding: 20px 0 16px; }
.app-shell.keyboard-open .problem-label { margin-bottom: 10px; }
.app-shell.keyboard-open .problem { min-height: 64px; font-size: clamp(46px, 9vw, 60px); }
.app-shell.keyboard-open .answer-form { margin-top: 16px; }
.app-shell.keyboard-open .answer-form input { height: 52px; font-size: 22px; }
.app-shell.keyboard-open .submit-button { width: 50px; height: 50px; flex-basis: 50px; }
.app-shell.keyboard-open .feedback { min-height: 20px; margin-top: 8px; font-size: 13px; }
.app-shell.keyboard-open .stats { margin-top: 14px; }
.app-shell.keyboard-open .operation-picker { margin-top: 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .answer-form input.is-correct,
  .answer-form input.is-incorrect { animation: none; }
}
