:root {
  color-scheme: light;
  --paper: #f5f1e8;
  --card: rgba(255, 253, 248, 0.94);
  --ink: #26352f;
  --muted: #6b756f;
  --sage: #6f8f7c;
  --sage-dark: #496858;
  --sage-pale: #e3ece5;
  --sand: #e5d2ad;
  --terracotta: #c87f61;
  --error: #a9544b;
  --line: #deded4;
  --shadow: 0 22px 60px rgba(67, 76, 66, 0.12);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 18%, rgba(229, 210, 173, 0.42) 0 9%, transparent 9.2%),
    radial-gradient(circle at 93% 82%, rgba(166, 194, 175, 0.34) 0 12%, transparent 12.2%),
    var(--paper);
}

body::before,
body::after {
  position: fixed;
  z-index: -1;
  color: rgba(73, 104, 88, 0.08);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

body::before {
  content: "+";
  top: 18%;
  left: 6%;
  font-size: 8rem;
  transform: rotate(-12deg);
}

body::after {
  content: "−";
  right: 6%;
  bottom: 16%;
  font-size: 10rem;
  transform: rotate(10deg);
}

button,
input {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

.page-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(100% - 32px, 920px);
  min-height: 100vh;
  margin: 0 auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 2px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  color: white;
  background: var(--sage-dark);
  border-radius: 13px 13px 13px 5px;
  box-shadow: 0 6px 16px rgba(73, 104, 88, 0.2);
}

.quick-settings {
  display: flex;
  gap: 10px;
}

.header-tools {
  display: grid;
  justify-items: end;
  gap: 5px;
}

.creator-sign {
  padding-right: 8px;
  color: var(--sage-dark);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.switch-control {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 6px 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(111, 143, 124, 0.14);
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
}

.switch-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  background: #cfd2cc;
  border-radius: 999px;
  transition: background 180ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform 180ms ease;
}

.switch-control input:checked + .switch {
  background: var(--sage);
}

.switch-control input:checked + .switch::after {
  transform: translateX(14px);
}

.switch-control:focus-within {
  outline: 3px solid rgba(111, 143, 124, 0.22);
}

.app-card {
  align-self: center;
  width: 100%;
  min-height: 590px;
  overflow: hidden;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 34px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.screen {
  width: 100%;
  min-height: 590px;
  padding: clamp(34px, 6vw, 64px);
}

.screen[hidden] {
  display: none;
}

.screen-enter {
  animation: screen-in 360ms ease-out both;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--sage-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.13em;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.lead {
  margin: 12px 0 32px;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.55;
}

.setup-form {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 25px 34px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 13px;
  font-size: 0.88rem;
  font-weight: 750;
}

.mode-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.mode-card {
  position: relative;
  display: grid;
  min-height: 102px;
  padding: 13px 8px;
  place-items: center;
  align-content: center;
  gap: 5px;
  color: var(--muted);
  background: #f9f7f1;
  border: 1px solid var(--line);
  border-radius: 17px;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.mode-card:hover {
  transform: translateY(-2px);
  border-color: #a9bbae;
}

.mode-card input {
  position: absolute;
  opacity: 0;
}

.mode-card:has(input:checked) {
  color: var(--sage-dark);
  background: var(--sage-pale);
  border-color: var(--sage);
  box-shadow: inset 0 0 0 1px var(--sage);
}

.mode-card:has(input:focus-visible) {
  outline: 3px solid rgba(111, 143, 124, 0.22);
  outline-offset: 2px;
}

.mode-symbol {
  font-size: 1.9rem;
  font-weight: 600;
  line-height: 1;
}

.amount-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.stepper-button,
.quick-amounts button {
  border: 1px solid var(--line);
  background: #f9f7f1;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.stepper-button {
  width: 44px;
  border-radius: 14px;
  font-size: 1.35rem;
}

.stepper-button:hover,
.quick-amounts button:hover,
.quick-amounts button.active {
  color: var(--sage-dark);
  background: var(--sage-pale);
  border-color: #a6bbaa;
}

.amount-field {
  display: grid;
  flex: 1;
  min-width: 100px;
  padding: 7px 8px 6px;
  place-items: center;
  color: var(--muted);
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 0.72rem;
}

.amount-field:focus-within {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(111, 143, 124, 0.14);
}

.amount-field input {
  width: 100%;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 1.4rem;
  font-weight: 800;
  text-align: center;
  appearance: textfield;
}

.amount-field input::-webkit-inner-spin-button {
  appearance: none;
}

.quick-amounts {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.quick-amounts button {
  flex: 1;
  min-height: 31px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
}

.timer-option {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 13px;
  padding: 14px 16px;
  background: #f8f5ed;
  border: 1px solid var(--line);
  border-radius: 16px;
  cursor: pointer;
}

.timer-option input {
  width: 19px;
  height: 19px;
  accent-color: var(--sage-dark);
}

.timer-icon {
  color: var(--sage-dark);
  font-size: 1.6rem;
}

.timer-option span:last-child {
  display: grid;
  gap: 2px;
}

.timer-option strong {
  font-size: 0.88rem;
}

.timer-option small {
  color: var(--muted);
  line-height: 1.35;
}

.primary-button,
.secondary-button {
  min-height: 52px;
  padding: 0 25px;
  border-radius: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary-button {
  color: white;
  background: var(--sage-dark);
  border: 0;
  box-shadow: 0 9px 20px rgba(73, 104, 88, 0.22);
}

.primary-button:hover {
  background: #3f5d4e;
  transform: translateY(-2px);
  box-shadow: 0 11px 24px rgba(73, 104, 88, 0.27);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(0);
}

.start-button {
  grid-column: 1 / -1;
  justify-self: end;
  min-width: 225px;
}

.field-error {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: var(--error);
  font-size: 0.78rem;
}

.quiz-screen {
  display: grid;
  grid-template-rows: auto 1fr;
}

.quiz-topline {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 30px;
}

.progress-text {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.progress-track {
  width: min(320px, 55vw);
  height: 7px;
  margin-top: 9px;
  overflow: hidden;
  background: #e6e7e0;
  border-radius: 99px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--sage);
  border-radius: inherit;
  transition: width 300ms ease;
}

.timer-display {
  min-width: 78px;
  padding: 8px 12px;
  color: var(--sage-dark);
  background: var(--sage-pale);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: center;
}

.problem-area {
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 42px 0 25px;
  text-align: center;
}

.gentle-prompt {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.problem {
  margin-bottom: 28px;
  font-size: clamp(3.2rem, 10vw, 6.2rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
}

.problem-pop {
  animation: problem-pop 260ms ease-out both;
}

.answer-form {
  display: grid;
  grid-template-columns: minmax(130px, 190px) auto;
  gap: 10px;
}

.answer-input {
  width: 100%;
  min-height: 58px;
  padding: 8px 15px;
  color: var(--ink);
  background: white;
  border: 2px solid #cfd6cf;
  border-radius: 15px;
  outline: 0;
  font-size: 1.65rem;
  font-weight: 800;
  text-align: center;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.answer-input:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 4px rgba(111, 143, 124, 0.15);
}

.answer-input.input-error {
  border-color: var(--error);
  animation: shake 260ms ease-in-out;
}

.answer-button {
  min-height: 58px;
}

.answer-hint {
  margin: 12px 0 0;
  color: #8a918d;
  font-size: 0.76rem;
}

.result-screen {
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
}

.result-badge {
  display: grid;
  width: 68px;
  height: 68px;
  margin-bottom: 22px;
  place-items: center;
  color: white;
  background: var(--sage);
  border-radius: 24px 24px 24px 8px;
  box-shadow: 0 12px 25px rgba(111, 143, 124, 0.24);
  font-size: 1.8rem;
  font-weight: 900;
}

.result-screen .lead {
  max-width: 520px;
  margin-bottom: 26px;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 30px;
}

.stat-card {
  display: grid;
  width: 130px;
  padding: 18px 12px;
  gap: 3px;
  background: #f7f5ef;
  border: 1px solid var(--line);
  border-radius: 17px;
}

.stat-card strong {
  color: var(--sage-dark);
  font-size: 1.7rem;
  line-height: 1;
}

.stat-card span {
  color: var(--muted);
  font-size: 0.76rem;
}

.error-stat strong {
  color: var(--terracotta);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.secondary-button {
  color: var(--sage-dark);
  background: transparent;
  border: 1px solid #b8c5ba;
}

.secondary-button:hover {
  background: var(--sage-pale);
}

.correction-label {
  padding: 7px 11px;
  color: var(--terracotta);
  background: #f7e8df;
  border-radius: 9px;
  font-size: 0.73rem;
  font-weight: 800;
}

.correction-track span {
  background: var(--terracotta);
}

.feedback {
  min-height: 1.4em;
  margin: 12px 0 0;
  color: var(--error);
  font-size: 0.86rem;
  font-weight: 750;
}

.feedback.success {
  color: var(--sage-dark);
}

.complete-badge {
  background: var(--sand);
  color: #735d35;
}

.final-summary {
  margin: -8px 0 28px;
  padding: 11px 16px;
  color: var(--muted);
  background: #f7f5ef;
  border-radius: 12px;
  font-size: 0.85rem;
}

footer {
  padding: 18px 0 22px;
  color: rgba(38, 53, 47, 0.48);
  font-size: 0.72rem;
  text-align: center;
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  animation: confetti-fall 1.8s ease-in forwards;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(73, 104, 88, 0.25);
  outline-offset: 3px;
}

body.reduce-motion *,
body.reduce-motion *::before,
body.reduce-motion *::after {
  scroll-behavior: auto !important;
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

@keyframes screen-in {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes problem-pop {
  0% { opacity: 0; transform: scale(0.96); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-6px); }
  65% { transform: translateX(5px); }
}

@keyframes confetti-fall {
  to { transform: translate3d(var(--drift), 105vh, 0) rotate(540deg); opacity: 0.3; }
}

@media (max-width: 680px) {
  .page-shell {
    width: min(100% - 20px, 920px);
  }

  .site-header {
    padding-top: 14px;
  }

  .creator-sign {
    padding-right: 4px;
    font-size: 0.6rem;
  }

  .setting-label {
    display: none;
  }

  .app-card,
  .screen {
    min-height: 610px;
  }

  .app-card {
    border-radius: 25px;
  }

  .screen {
    padding: 30px 20px;
  }

  .setup-form {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .timer-option,
  .start-button {
    grid-column: 1;
  }

  .start-button {
    justify-self: stretch;
  }

  .problem {
    margin-bottom: 24px;
  }

  .answer-form {
    grid-template-columns: minmax(110px, 1fr) 1fr;
    width: 100%;
  }

  .result-stats {
    gap: 7px;
  }

  .stat-card {
    width: auto;
    min-width: 0;
    flex: 1;
  }
}

@media (max-width: 390px) {
  .mode-card {
    min-height: 92px;
    padding-inline: 4px;
    font-size: 0.7rem;
  }

  .quick-settings {
    gap: 5px;
  }

  .switch-control {
    padding-inline: 7px;
  }

  .answer-form {
    grid-template-columns: 1fr;
  }

  .answer-button {
    min-height: 50px;
  }

  .result-actions {
    width: 100%;
  }

  .result-actions button {
    width: 100%;
  }
}

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