/* Word Play — English for young learners (A1, ages 7–10)
   Design notes: large touch targets (min 64px), high contrast, no timers,
   no red "wrong" states harsher than a gentle wobble. Light theme only —
   classroom projectors and school tablets are almost always in light mode,
   and a fixed background keeps the emoji artwork legible either way. */

:root {
  --bg: #fff8ef;
  --bg-2: #ffeedd;
  --ink: #2c2440;
  --ink-soft: #6b6180;
  --card: #ffffff;
  --line: #e8ddd0;

  --green: #22a06b;
  --green-soft: #d8f5e8;
  --orange: #f08c2e;
  --orange-soft: #ffead4;
  --blue: #3b82d6;
  --blue-soft: #ddeafc;
  --purple: #8b5cf6;
  --purple-soft: #ece5fe;

  --good: #22a06b;
  --good-soft: #d8f5e8;
  --oops: #e8734a;
  --oops-soft: #ffe4da;

  --radius: 22px;
  --shadow: 0 4px 0 rgba(44, 36, 64, .12);
  --shadow-lift: 0 8px 0 rgba(44, 36, 64, .12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: linear-gradient(170deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Nunito", "Quicksand", "Trebuchet MS", "Avenir Next", system-ui, -apple-system, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  background: var(--card);
  padding: 10px 16px;
  border-radius: 12px;
}

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

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  max-width: 900px;
  margin: 0 auto;
}

.bar-title {
  flex: 1;
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -.01em;
  text-align: center;
}

.bar-btn {
  flex: none;
  width: 52px;
  height: 52px;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.bar-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.bar-btn:active { transform: translateY(2px); box-shadow: none; }
.bar-btn[hidden] { visibility: hidden; display: block; }
.bar-btn[aria-pressed="false"] { opacity: .45; }

/* ---------------- screens ---------------- */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 64px;
}

.screen { display: none; }
.screen.is-active { display: block; animation: rise .25s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.lead {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 8px 0 24px;
}

/* ---------------- topic / activity cards ---------------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 150px;
  padding: 20px 16px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: inherit;
  font: inherit;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.card:hover  { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.card:active { transform: translateY(2px); box-shadow: none; }

.card-icon { font-size: 3.2rem; line-height: 1; }
.card-name { font-size: 1.25rem; font-weight: 800; }
.card-hint { font-size: .92rem; color: var(--ink-soft); text-align: center; }

.card[data-colour="green"]  { border-color: var(--green);  background: var(--green-soft); }
.card[data-colour="orange"] { border-color: var(--orange); background: var(--orange-soft); }
.card[data-colour="blue"]   { border-color: var(--blue);   background: var(--blue-soft); }
.card[data-colour="purple"] { border-color: var(--purple); background: var(--purple-soft); }

/* ---------------- progress ---------------- */

.progress {
  height: 14px;
  border-radius: 99px;
  background: #ffffffcc;
  border: 2px solid var(--line);
  overflow: hidden;
  margin-top: 4px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green), #4ecf9a);
  transition: width .3s ease;
}
.progress-text {
  text-align: center;
  font-size: .95rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin: 8px 0 4px;
}

.task {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 800;
  margin: 4px 0 20px;
}

/* ---------------- play stage ---------------- */

.stage { display: grid; gap: 18px; justify-items: center; }

/* the big prompt: a picture, or a speaker button */
.prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  max-width: 340px;
  min-height: 170px;
  border: 4px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 6rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  transition: transform .14s ease;
}
.prompt:hover  { transform: translateY(-3px); }
.prompt:active { transform: translateY(2px); }
.prompt.is-speaker { font-size: 4.5rem; }
.prompt.is-speaker.is-speaking { animation: pulse .7s ease infinite; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

/* the word being spelled, e.g.  c _ t */
.spell-word {
  margin: 0;
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: .18em;
  font-family: "Menlo", "Consolas", monospace;
}
.spell-blank {
  display: inline-block;
  min-width: .8em;
  border-bottom: 6px solid var(--orange);
  color: var(--orange);
}

/* answer options */
.options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 560px;
}
.options.is-letters { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 420px; }

.option {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 110px;
  padding: 12px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: inherit;
  font-family: inherit;
  font-size: 3.4rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .14s ease, box-shadow .14s ease, background .2s ease, border-color .2s ease;
}
.option.is-text { font-size: 1.7rem; }
.option:hover:not(:disabled)  { transform: translateY(-3px); box-shadow: var(--shadow-lift); }
.option:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }

.option.is-right {
  border-color: var(--good);
  background: var(--good-soft);
  animation: bounce .45s ease;
}
.option.is-wrong {
  border-color: var(--oops);
  background: var(--oops-soft);
  animation: wobble .4s ease;
}
.option:disabled { cursor: default; opacity: .55; }
.option.is-right:disabled, .option.is-wrong:disabled { opacity: 1; }

@keyframes bounce {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.09); }
  100% { transform: scale(1); }
}
@keyframes wobble {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-7px); }
  75%      { transform: translateX(7px); }
}

/* ---------------- sentence builder ---------------- */

.answer-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 620px;
  min-height: 82px;
  padding: 12px;
  border: 3px dashed var(--line);
  border-radius: var(--radius);
  background: #ffffff99;
}
.answer-line.is-right { border-style: solid; border-color: var(--good); background: var(--good-soft); }
.answer-line.is-wrong { border-style: solid; border-color: var(--oops); background: var(--oops-soft); animation: wobble .4s ease; }
.answer-line:empty::before {
  content: "Tap the words below";
  color: var(--ink-soft);
  font-size: 1rem;
}

.tiles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 620px;
}

.tile {
  padding: 14px 20px;
  min-height: 58px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: inherit;
  font-family: inherit;
  font-size: 1.35rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, opacity .2s ease;
}
.tile:hover:not(:disabled)  { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.tile:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.tile.is-used { opacity: .25; pointer-events: none; }
.tile.in-answer { border-color: var(--purple); }

/* ---------------- feedback ---------------- */

.feedback {
  min-height: 2.4em;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  margin: 20px 0 0;
}
.feedback.is-good { color: var(--good); animation: bounce .45s ease; }
.feedback.is-oops { color: var(--oops); }

/* ---------------- results ---------------- */

#screen-done { text-align: center; padding-top: 24px; }
.done-emoji { font-size: 5.5rem; line-height: 1; animation: bounce .6s ease; }
.done-title { font-size: 2rem; font-weight: 800; margin: 12px 0 4px; }
.done-stars { font-size: 2.2rem; margin: 4px 0; letter-spacing: .1em; }
.done-score { font-size: 1.15rem; color: var(--ink-soft); font-weight: 700; margin: 0 0 28px; }

.done-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }

.btn {
  padding: 16px 26px;
  min-height: 60px;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  color: inherit;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover  { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn-primary { border-color: var(--green); background: var(--green-soft); }

/* ---------------- teacher panel ---------------- */

/* Deliberately low-key: it sits in the child's field of view all lesson, so it
   should read as furniture, not as another game to tap. */
.bar-btn-quiet {
  font-size: 1.1rem;
  opacity: .4;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
.bar-btn-quiet:hover { opacity: 1; background: var(--card); box-shadow: var(--shadow); }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(44, 36, 64, .45);
  padding: 0;
}
.sheet[hidden] { display: none; }

.sheet-box {
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 3px solid var(--line);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  animation: slide-up .22s ease both;
}

@keyframes slide-up {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 2px solid var(--line);
}
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.3rem; font-weight: 800; }

.sheet-body {
  overflow-y: auto;
  padding: 4px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  -webkit-overflow-scrolling: touch;
}

.block { padding: 16px 0; border-bottom: 2px solid var(--line); }
.block:last-child { border-bottom: none; }
.block h3 {
  margin: 0 0 10px;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.muted { color: var(--ink-soft); font-size: .92rem; margin: 0 0 8px; display: block; }
.muted[hidden] { display: none; }   /* the class would otherwise beat the UA rule for [hidden] */

.stat-row { margin: 0; font-size: 1.05rem; font-weight: 700; }
.stat-row .big { font-size: 1.9rem; font-weight: 800; color: var(--green); }

.weak-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.weak-list li {
  padding: 7px 13px;
  border: 2px solid var(--oops);
  background: var(--oops-soft);
  border-radius: 99px;
  font-weight: 800;
  font-size: .98rem;
}
.weak-list li span { color: var(--ink-soft); font-weight: 700; font-size: .85rem; }

.log-wrap { max-height: 210px; overflow: auto; border: 2px solid var(--line); border-radius: 14px; background: var(--card); }
.log { width: 100%; border-collapse: collapse; font-size: .92rem; }
.log th, .log td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.log th { position: sticky; top: 0; background: var(--card); font-weight: 800; color: var(--ink-soft); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.log tr:last-child td { border-bottom: none; }
.log td.tries-ok   { color: var(--good); font-weight: 800; }
.log td.tries-miss { color: var(--oops); font-weight: 800; }
.log .empty { color: var(--ink-soft); text-align: center; padding: 18px; }

#voiceSelect {
  width: 100%;
  padding: 12px 14px;
  min-height: 52px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: inherit;
  font: inherit;
  font-weight: 700;
}

.block-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.btn-small { padding: 11px 17px; min-height: 48px; font-size: .95rem; border-radius: 14px; }

/* ---------------- focus + motion ---------------- */

:focus-visible {
  outline: 4px solid var(--purple);
  outline-offset: 3px;
}

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

/* ---------------- small screens ---------------- */

@media (max-width: 480px) {
  body { font-size: 17px; }
  .card { min-height: 128px; }
  .card-icon { font-size: 2.7rem; }
  .prompt { min-height: 140px; font-size: 5rem; }
  .option { min-height: 92px; font-size: 2.9rem; }
  .option.is-text { font-size: 1.4rem; }
  .options.is-letters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tile { font-size: 1.15rem; padding: 12px 15px; }
  .spell-word { font-size: 2.3rem; }
}
