@font-face {
  font-family: "Andika";
  src: url("fonts/andika-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Andika";
  src: url("fonts/andika-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #f0faf3;
  --card: #ffffff;
  --line: #d3eedd;
  --green: #38a169;
  --green-dark: #276749;
  --green-soft: #e6f7ec;
  --text: #1a202c;
  --muted: #5a6778;
  --red: #e53e3e;
  --phonics: "Andika", "Comic Sans MS", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}
body { display: flex; flex-direction: column; height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

#topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }
#brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; white-space: nowrap; }
#tabs { display: flex; gap: 6px; flex: 1; }
.tab { padding: 9px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; font-weight: 800; font-size: 15px; white-space: nowrap; }
.tab.active { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); }
#phases { display: flex; align-items: center; gap: 4px; }
#phases[hidden] { display: none; }
#phases .lbl { font-size: 13px; font-weight: 700; color: var(--muted); margin-right: 2px; }
.ph { width: 40px; height: 40px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-weight: 800; font-size: 17px; }
.ph.on { border-color: var(--green); background: var(--green); color: #fff; }

#main { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px 30px; }
.page { max-width: 960px; margin: 0 auto; }
.center { display: flex; flex-direction: column; align-items: center; text-align: center; }
.counter { font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.lead { color: var(--muted); font-size: 17px; margin: 10px 0; }

/* flashcard */
.flash {
  position: relative;
  width: min(420px, 86vw);
  height: min(360px, 52vh);
  perspective: 1200px;
  cursor: pointer;
}
.face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 28px;
  background: #fff;
  border: 4px solid var(--green);
  box-shadow: 0 10px 0 var(--green-dark), 0 14px 30px rgba(0, 0, 0, .12);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform .4s;
}
.back { transform: rotateY(180deg); }
.flipped .front { transform: rotateY(-180deg); }
.flipped .back { transform: rotateY(0); }
.graph { font-family: var(--phonics); font-size: min(190px, 22vh); line-height: 1; color: var(--text); }
.pic { font-size: min(130px, 16vh); line-height: 1.1; }
.ex { font-family: var(--phonics); font-size: 52px; margin-top: 6px; }
.ex u, .hear u { text-decoration: none; color: var(--red); border-bottom: 5px solid var(--red); }

.controls { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 26px; flex-wrap: wrap; }
.controls.small { margin-top: 12px; }
.round {
  width: 64px;
  height: 64px;
  border: 0;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 26px;
  box-shadow: 0 4px 0 var(--green-dark);
}
.round:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--green-dark); }
.pill {
  height: 52px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
}
.pill.on { border-color: var(--green); background: var(--green-soft); }
.pill.dim { opacity: .55; }
.pill.big { height: 60px; font-size: 19px; background: var(--green); color: #fff; border: 0; box-shadow: 0 4px 0 var(--green-dark); }

/* blending */
.word { position: relative; display: flex; gap: 6px; margin: 16px 0 6px; padding-bottom: 26px; }
.gr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 70px;
  padding: 10px 10px 4px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 3px 0 var(--line);
  transition: background .15s, transform .15s;
}
.gr .l { font-family: var(--phonics); font-size: min(110px, 14vw); line-height: 1; }
.gr.lit { background: #fffbea; border-color: #ecc94b; transform: translateY(-6px); }
.mark { display: block; height: 14px; }
.mark.dot { width: 16px; height: 16px; border-radius: 50%; background: var(--red); }
.mark.dash { width: 80%; height: 7px; border-radius: 4px; background: var(--red); margin-top: 4px; }
.mark.split { width: 16px; height: 16px; }
.split-arc { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.is-alien .gr { background: #f3ecff; }
.alien { padding: 8px 14px; border-radius: 12px; background: #f3ecff; color: #553c9a; font-weight: 700; }

/* quiz */
.quizpic {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 40px;
  border: 4px solid var(--green);
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 6px 0 var(--green-dark);
}
.quizpic .pic { font-size: 110px; }
.hear { font-family: var(--phonics); font-size: 30px; font-weight: 700; }
.opts { display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 12px; margin-bottom: 18px; }
.opt {
  height: 120px;
  border: 4px solid var(--line);
  border-radius: 22px;
  background: #fff;
  font-family: var(--phonics);
  font-size: 64px;
  line-height: 1;
}
.opt.right { border-color: var(--green); background: #e6ffed; }
.opt.wrong { border-color: var(--red); background: #fff0f0; }
.opt:disabled:not(.right):not(.wrong) { opacity: .45; }
.end h1 { margin: 8px 0 18px; }
.bigstar { font-size: 90px; }

/* teacher */
.teacher-intro { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 14px 18px; margin-bottom: 8px; }
.teacher-intro h1 { margin: 0 0 6px; font-size: 24px; }
.teacher-intro p { margin: 6px 0; line-height: 1.5; }
.note { color: var(--muted); font-size: 14px; }
.link { border: 0; background: none; padding: 0; color: #c53030; text-decoration: underline; font-weight: 700; }
.page h2 { margin: 18px 0 8px; font-size: 20px; }
.page h2 small { font-size: 14px; color: var(--muted); font-weight: 600; margin-left: 6px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.tile.has { border-color: var(--green); background: #f4fcf6; }
.tile.rec { border-color: var(--red); background: #fff5f5; animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(229, 62, 62, .2); } }
.tg { font-family: var(--phonics); font-size: 44px; line-height: 1.1; }
.tw { font-family: var(--phonics); font-size: 16px; color: var(--muted); }
.tw u { text-decoration: none; color: var(--red); font-weight: 700; }
.tb { display: flex; gap: 4px; margin-top: 4px; }
.tb button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 15px; padding: 0; }
.tb button[data-rec] { color: var(--red); font-size: 18px; }
.tb button:disabled { opacity: .35; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(90%, 480px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(26, 32, 44, .9);
  color: #fff;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
#toast.show { opacity: 1; }

@media (max-width: 820px) {
  #brand span { display: none; }
  .opts { grid-template-columns: repeat(2, minmax(110px, 1fr)); }
  .tab { padding: 8px 10px; font-size: 14px; }
}
