:root {
  --ink: #1c2740;
  --muted: #5c6b88;
  --paper: #fffaf3;
  --card: #ffffff;
  --accent: #ff7a45;
  --accent-2: #3d8bfd;
  --good: #22a06b;
  --bad: #e24b4b;
  --shadow: 0 18px 50px rgba(28, 39, 64, 0.12);
  --radius: 28px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  touch-action: manipulation;
}

body {
  font-family: Nunito, Fredoka, system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #fff4e8 0%, #eaf4ff 55%, #f6fff8 100%);
  overflow-x: hidden;
}

.bg-blob {
  position: fixed;
  z-index: 0;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.45;
  pointer-events: none;
}

.blob-a {
  width: 340px;
  height: 340px;
  background: #ffd2b8;
  top: -80px;
  right: -60px;
}

.blob-b {
  width: 280px;
  height: 280px;
  background: #b8dcff;
  bottom: -90px;
  left: -50px;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.logo {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ff7a45, #ffb347);
  color: white;
  font-family: Fredoka, sans-serif;
  font-size: 26px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-btn,
.back-btn {
  border: 0;
  border-radius: 999px;
  background: white;
  color: var(--ink);
  padding: 10px 16px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.stats {
  display: flex;
  gap: 10px;
}

.stat {
  background: var(--card);
  padding: 10px 14px;
  border-radius: 16px;
  min-width: 72px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.stat strong {
  font-family: Fredoka, sans-serif;
  font-size: 24px;
}

.settings {
  margin-top: 22px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.settings h2 {
  margin: 16px 0 0;
  font-size: 28px;
}

.practice-setup {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  white-space: pre-line;
}

.controls {
  margin-top: 22px;
  display: grid;
  gap: 18px;
}

.setting-panel {
  display: grid;
  gap: 14px;
  padding-top: 16px;
  border-top: 1px solid #e7edf7;
}

.setting-panel h3 {
  margin: 0;
  font-size: 18px;
}

.setting-panel.is-active h3 {
  color: var(--accent-2);
}

.control-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.control-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  border: 0;
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 0 rgba(28, 39, 64, 0.08);
}

.pill.is-on {
  background: var(--ink);
  color: white;
}

.stage {
  margin-top: 22px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  text-align: center;
  min-height: 280px;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.card.is-good {
  box-shadow: 0 18px 50px rgba(34, 160, 107, 0.22);
}

.card.is-bad {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  75% {
    transform: translateX(8px);
  }
}

.card-kicker {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 13px;
}

.timer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

#timer {
  min-width: 2ch;
  font-family: Fredoka, sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-2);
}

#timer.is-low {
  color: var(--bad);
}

.timer-track {
  width: 160px;
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7edf7;
}

.timer-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--accent-2);
  transform: scaleX(1);
  transform-origin: left center;
}

.timer-fill.is-low {
  background: var(--bad);
}

.prompt {
  margin: 0;
  font-family: Fredoka, sans-serif;
  font-size: clamp(40px, 10vw, 72px);
  font-weight: 700;
  line-height: 1.1;
}

.answer-form {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  gap: 10px;
}

#answer {
  width: 140px;
  height: 64px;
  border: 3px solid var(--accent-2);
  border-radius: 18px;
  text-align: center;
  font-family: Fredoka, sans-serif;
  font-size: 36px;
  font-weight: 700;
  background: var(--paper);
  color: var(--ink);
  caret-color: transparent;
  opacity: 1;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
}

.submit {
  height: 64px;
  padding: 0 22px;
  border: 0;
  border-radius: 18px;
  background: var(--accent-2);
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.feedback {
  min-height: 28px;
  margin: 14px 0 0;
  font-weight: 700;
}

.feedback.good {
  color: var(--good);
}

.feedback.bad {
  color: var(--bad);
}

.keypad {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.keypad button {
  height: 56px;
  border: 0;
  border-radius: 16px;
  background: white;
  font-family: Fredoka, sans-serif;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 0 #d7e2f3;
}

.keypad button:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #d7e2f3;
}

.keypad .ghost {
  font-size: 16px;
  font-family: Nunito, sans-serif;
  color: var(--muted);
}

.keypad .wide {
  grid-column: 1 / -1;
  height: 46px;
}

.foot {
  margin-top: 22px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.foot-actions {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}

.text-btn {
  margin-top: 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

.misses {
  width: min(560px, calc(100vw - 24px));
  max-height: min(80vh, 720px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 24px;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.misses::backdrop {
  background: rgba(28, 39, 64, 0.45);
}

.misses-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 12px;
  background: white;
}

.misses-head h2 {
  margin: 0;
  font-size: 22px;
}

.close-misses {
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  background: #eef3fb;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.misses-empty,
.miss-list,
.miss-log,
.misses-sub {
  margin: 0;
  padding: 0 18px;
}

.misses-empty {
  padding-bottom: 18px;
  color: var(--muted);
}

.miss-list,
.miss-log {
  list-style: none;
  display: grid;
  gap: 10px;
  padding-bottom: 8px;
}

.miss-list {
  padding-bottom: 16px;
}

.miss-item,
.miss-try {
  background: #fff7f4;
  border-radius: 16px;
  padding: 12px 14px;
}

.miss-eq {
  margin: 0;
  font-family: Fredoka, sans-serif;
  font-size: 22px;
}

.miss-meta,
.miss-try p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.misses-sub {
  margin-top: 4px;
  padding-bottom: 8px;
  font-size: 14px;
  color: var(--muted);
}

.miss-log {
  padding-bottom: 18px;
}

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

@media (max-width: 520px) {
  .answer-form {
    flex-direction: column;
    align-items: stretch;
  }

  #answer,
  .submit {
    width: 100%;
  }
}
