@font-face {
  font-family: 'Andika';
  src: url('fonts/andika-bold-latin.woff2') format('woff2');
  font-weight: 700;
  font-display: block;
}

:root {
  color-scheme: light;
  --bg: #fff4d6;
  --bg-2: #ffe6a8;
  --ink: #3b2a14;
  --ink-soft: #7a6448;
  --card: #ffffff;
  --accent: #ff7a59;
  --accent-dark: #e25a38;
  --good: #3cb371;
  --miss: #e0685a;
  --learning: #ffb347;
  --mastered: #ffc933;
  --new: #e9dfc9;
  --letter-color: #4a7bd8;
  --shadow: 0 6px 0 rgba(59, 42, 20, 0.15);
  --font: 'Andika', 'Chalkboard SE', 'Comic Sans MS', system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 50% 0%, var(--bg) 40%, var(--bg-2) 100%) fixed;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 700;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

[hidden] { display: none !important; }

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 16px);
  max-width: 640px;
  margin: 0 auto;
}

/* ---- top bar ---- */

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 1.25rem;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.parent-btn, .icon-btn {
  margin-left: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  font-size: 1.4rem;
}
.icon-btn { margin-left: 0; background: var(--card); box-shadow: var(--shadow); }
.parent-btn {
  touch-action: none;
  /* Fills with a ring while held, so it's clear holding is doing something. */
  background: conic-gradient(var(--accent) calc(var(--hold, 0) * 1turn), transparent 0);
  transition: --hold 0s;
}
.parent-btn.holding { --hold: 1; color: #fff; transition: --hold 0.8s linear; }
@property --hold { syntax: '<number>'; inherits: false; initial-value: 0; }

.topbar { position: relative; }
.hold-hint {
  position: absolute;
  right: 0;
  top: 52px;
  background: var(--ink);
  color: #fff;
  font-size: 0.95rem;
  padding: 8px 12px;
  border-radius: 12px;
  white-space: nowrap;
  z-index: 5;
  animation: pop 0.3s;
}

/* ---- home ---- */

.home-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 8px;
}
.mascot { width: 110px; height: 110px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(4deg); } }

.title {
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  margin: 4px 0 12px;
  color: var(--accent-dark);
  letter-spacing: 1px;
}

.big-btn {
  background: var(--accent);
  color: #fff;
  font-size: clamp(1.8rem, 8vw, 2.4rem);
  padding: 18px 44px;
  border-radius: 999px;
  box-shadow: 0 8px 0 var(--accent-dark);
  transition: transform 0.08s, box-shadow 0.08s;
}
.big-btn:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--accent-dark); }

.note {
  color: var(--ink-soft);
  text-align: center;
  margin: 14px 0;
  min-height: 1.4em;
  font-size: 1.05rem;
}
.note.big { font-size: 1.4rem; }

.grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  margin-top: auto;
  padding-top: 12px;
}
.tile {
  background: var(--card);
  border-radius: 14px;
  padding: 6px 0;
  text-align: center;
  font-size: 1.6rem;
  box-shadow: 0 3px 0 rgba(59, 42, 20, 0.12);
  line-height: 1.2;
}
.tile span { display: inline-block; min-width: 1.1em; border-radius: 8px; padding: 0 2px; }
.tile .new { color: #cbbd9f; }
.tile .learning { color: var(--ink); background: #ffe2b8; }
.tile .mastered { color: var(--ink); background: var(--mastered); }

/* ---- lesson ---- */

.progress {
  flex: 1;
  height: 18px;
  background: var(--card);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 2px 0 rgba(59, 42, 20, 0.1);
}
.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #ffc933, #ff9b59);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 10px;
}

.badge {
  background: var(--good);
  color: #fff;
  padding: 6px 18px;
  border-radius: 999px;
  font-size: 1.2rem;
  animation: pop 0.4s;
}
.badge.practice { background: #8a7bd8; }

.card {
  width: min(78vw, 360px, 46dvh);
  aspect-ratio: 1;
  background: var(--card);
  border-radius: 40px;
  box-shadow: 0 10px 0 rgba(59, 42, 20, 0.15);
  display: grid;
  place-items: center;
  transition: transform 0.15s;
}
.card:active { transform: scale(0.97); }
.card.pop { animation: pop 0.5s; }
.card.shake { animation: shake 0.5s; }
.card.correct { box-shadow: 0 10px 0 var(--good), 0 0 0 8px var(--good); }

.letter {
  font-size: min(58vw, 270px, 34dvh);
  line-height: 1;
  color: var(--letter-color);
  /* Andika's metrics sit a bit high; nudge to optical center. */
  transform: translateY(-4%);
}

.heard {
  margin: 0;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(59, 42, 20, 0.08);
  color: var(--ink-soft);
  font-family: ui-monospace, Menlo, monospace;
  font-weight: 400;
  font-size: 0.85rem;
  text-align: center;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.miss-log {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 180px;
  overflow-y: auto;
  font-weight: 400;
  font-size: 0.9rem;
}
.miss-log li { padding: 4px 0; border-bottom: 1px solid #efe6d4; }
.miss-log small { color: var(--ink-soft); }

.prompt {
  font-size: 1.5rem;
  margin: 8px 0 0;
  min-height: 2.2em;
  text-align: center;
  color: var(--ink);
}

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  margin: 6px 0 12px;
}

.round-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.round-btn.spacer { visibility: hidden; }

.mic-btn {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 0 var(--accent-dark);
  transition: transform 0.08s;
}
.mic-btn:active { transform: translateY(4px); }
.mic-btn.ready { animation: breathe 1.8s ease-in-out infinite; }
.mic-btn.listening {
  background: var(--good);
  box-shadow: 0 8px 0 #2a8a55, 0 0 0 0 rgba(60, 179, 113, 0.6);
  animation: listen 1.1s ease-out infinite;
}
.mic-btn:disabled { opacity: 0.5; animation: none; }
@keyframes breathe { 50% { transform: scale(1.07); } }
@keyframes listen {
  0% { box-shadow: 0 8px 0 #2a8a55, 0 0 0 0 rgba(60, 179, 113, 0.6); }
  100% { box-shadow: 0 8px 0 #2a8a55, 0 0 0 28px rgba(60, 179, 113, 0); }
}

.grownup {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  opacity: 0.55;
}
.grownup.prominent { opacity: 1; }
.grownup-label { color: var(--ink-soft); font-size: 0.9rem; }
.grownup-btn {
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--card);
  font-size: 1rem;
  box-shadow: 0 3px 0 rgba(59, 42, 20, 0.12);
}
.grownup.prominent .grownup-btn { font-size: 1.3rem; padding: 14px 22px; }
.grownup-btn.good { color: var(--good); }
.grownup-btn.miss { color: var(--miss); }

/* ---- done ---- */

.done-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.done-stars { font-size: 7rem; animation: spin-pop 1s ease-out; }
@keyframes spin-pop { from { transform: scale(0) rotate(-180deg); } 70% { transform: scale(1.2) rotate(10deg); } }

@keyframes pop { 0% { transform: scale(0.8); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
@keyframes shake {
  20%, 60% { transform: translateX(-12px) rotate(-2deg); }
  40%, 80% { transform: translateX(12px) rotate(2deg); }
}

/* ---- confetti / flying star ---- */

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
.fly-star {
  position: fixed;
  font-size: 3rem;
  z-index: 11;
  pointer-events: none;
  transition: transform 0.7s cubic-bezier(0.5, -0.4, 0.7, 1), opacity 0.7s;
}

/* ---- grown-up dialog ---- */

.parent-dialog {
  border: 0;
  border-radius: 20px;
  padding: 0;
  width: min(92vw, 460px);
  max-height: 88dvh;
  color: var(--ink);
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 400;
  -webkit-user-select: text;
  user-select: text;
}
.parent-dialog::backdrop { background: rgba(59, 42, 20, 0.45); }
.parent-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.parent-form h2 { margin: 0; font-size: 1.3rem; }
.summary { margin: 0; color: var(--ink-soft); }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; font-weight: 600; }
.field legend { padding: 0; margin-bottom: 6px; }
.field small, .hint { font-weight: 400; color: var(--ink-soft); }
.field.check { flex-direction: row; align-items: center; gap: 10px; }
.field.check input { width: 22px; height: 22px; }
.parent-form select, .backup-text {
  font: inherit;
  font-weight: 400;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #d8ccb4;
  background: #fffdf8;
  color: var(--ink);
}
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.spread { justify-content: space-between; margin-top: 6px; }
.small-btn {
  padding: 10px 16px;
  border-radius: 10px;
  background: #f3ead7;
  font-weight: 600;
}
.small-btn.primary { background: var(--accent); color: #fff; }
.small-btn.danger { color: var(--miss); }
.mic-test-out {
  margin: 0;
  min-height: 1.2em;
  white-space: pre-wrap;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

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