/* YKYMF Kids: the bright kid theme shared by every kids page (hub, runner, grown-ups area).
   Tokens come from the architecture README ("Theme"). Pages stay light on purpose: no dark mode.
   Mobile first, portrait touch UI: tap targets are at least 64px and text is at least 18px.
   Colour variants (sun, coral, sky, mint, grape, tangerine, bubblegum, leaf) are classes that only set
   --c; buttons, card headers, chips, badges and progress bars read it, so a topic class on a card
   also colours its header and any .btn-primary inside it. Text on colour is always --ink (best contrast).
   Activities add their own small stylesheets later through ui.loadCss. Print rules live at the end;
   the paper preview for worksheets is in print.css. */

/* Fonts (vendored, latin subset, see fonts/OFL-*.txt) */

@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../fonts/fredoka-latin.woff2") format("woff2");
}

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

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

/* Tokens */

:root {
  --paper: #FFFDF7;
  --panel: #FFFFFF;
  --ink: #1E2235;
  --ink-2: #4B5168;
  --ink-3: #8A90A6;
  --line: #E8E4D8;

  --sun: #FFD23F;
  --coral: #FF6B57;
  --sky: #3FB8F0;
  --mint: #2ECC8F;
  --grape: #9B6BF2;
  --tangerine: #FF9F1C;
  --bubblegum: #FF7AB6;
  --leaf: #7BC043;

  --good: #2ECC8F;
  --bad: #FF6B57;
  --link: #1673A8;

  --font-ui: "Fredoka", system-ui, sans-serif;
  --font-read: "Andika", "Fredoka", sans-serif;

  --radius: 22px;
  --radius-sm: 14px;
  --tap: 64px;
  --max: 1100px;
  --topbar-h: 64px;
  --edge: 0 6px 0 rgba(0, 0, 0, 0.18);
}

/* Base */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 400 18px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5em;
  font-weight: 600;
  line-height: 1.15;
}
h1 { font-size: clamp(30px, 7vw, 44px); }
h2 { font-size: clamp(26px, 5.5vw, 32px); }
h3 { font-size: 24px; }
h4 { font-size: 20px; }

p { margin: 0 0 1em; }

a { color: var(--link); }

img, canvas { display: block; max-width: 100%; }
svg { flex: none; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

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

main, .wrap {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px;
}

.muted { color: var(--ink-2); }
.centre { text-align: center; }

/* Colour variants: each only sets --c */

.btn-sun, .topic-sun, .card-sun { --c: var(--sun); }
.btn-coral, .topic-coral, .card-coral { --c: var(--coral); }
.btn-sky, .topic-sky, .card-sky { --c: var(--sky); }
.btn-mint, .topic-mint, .card-mint { --c: var(--mint); }
.btn-grape, .topic-grape, .card-grape { --c: var(--grape); }
.btn-tangerine, .topic-tangerine, .card-tangerine { --c: var(--tangerine); }
.btn-bubblegum, .topic-bubblegum, .card-bubblegum { --c: var(--bubblegum); }
.btn-leaf, .topic-leaf, .card-leaf { --c: var(--leaf); }

/* Buttons: chunky, with a darker bottom edge that presses down */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 26px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font: 600 22px/1.1 var(--font-ui);
  text-align: center;
  text-decoration: none;
  box-shadow: var(--edge);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.btn:active, .btn.is-pressed {
  transform: translateY(5px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}

.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.btn.btn-primary, .btn.btn-sun, .btn.btn-coral, .btn.btn-sky, .btn.btn-mint,
.btn.btn-grape, .btn.btn-tangerine, .btn.btn-bubblegum, .btn.btn-leaf {
  background: var(--c, var(--sky));
  border-color: rgba(30, 34, 53, 0.14);
}

.btn.is-correct {
  background: var(--good);
  border-color: rgba(30, 34, 53, 0.14);
}

.btn.is-wrong {
  background: var(--bad);
  border-color: rgba(30, 34, 53, 0.14);
}

.btn-big {
  min-height: 80px;
  padding: 0 34px;
  border-radius: 26px;
  font-size: 28px;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-round {
  flex: none;
  width: 64px;
  height: 64px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
}

.btn > svg { width: 1.3em; height: 1.3em; }
.btn-round > svg { width: 34px; height: 34px; }

.btn .pic {
  --pic-size: 1.7em;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}

/* Cards */

.card {
  display: block;
  overflow: hidden;
  border: 3px solid var(--c, var(--line));
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.08);
}

a.card, button.card {
  width: 100%;
  padding: 0;
  font: inherit;
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

a.card:active, button.card:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  min-height: 52px;
  padding: 10px 18px;
  background: var(--c, var(--sky));
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
  line-height: 1.15;
}

.card-header .badge { margin-left: auto; }

.card-body { padding: 16px 18px; }

.card.is-correct { border-color: var(--good); }
.card.is-wrong { border-color: var(--bad); }

/* Chips and badges */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 22px;
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: 600 20px/1.1 var(--font-ui);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.1);
  transition: transform 0.08s ease-out, box-shadow 0.08s ease-out;
}

.chip:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

.chip.is-on {
  background: var(--c, var(--sun));
  border-color: var(--ink);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
}

.badge {
  display: inline-block;
  padding: 2px 12px;
  border-radius: 999px;
  background: var(--c, var(--sun));
  color: var(--ink);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}

/* Top bar: home button left, title centre, actions right */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(12px, calc((100% - var(--max)) / 2 + 12px)) 0;
  background: var(--paper);
  border-bottom: 3px solid var(--line);
}

.topbar-home { justify-self: start; }

.topbar-title {
  margin: 0;
  overflow: hidden;
  font-size: 26px;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
}

/* Round buttons look 52px in the bar so the shadow fits; the tap area is still 64px */
.topbar .btn-round {
  width: 52px;
  height: 52px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
}

.topbar .btn-round::after {
  content: "";
  position: absolute;
  inset: -6px;
}

/* Layout utilities */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap, 16px);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap, 12px);
}

.grid-2, .grid-3, .grid-auto {
  display: grid;
  gap: var(--gap, 16px);
}

.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: repeat(2, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

@media (min-width: 480px) {
  .grid-2 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 720px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* Reading content: big lowercase words in the literacy font (single-storey a and g) */

.read-word {
  margin: 0;
  font-family: var(--font-read);
  font-size: clamp(64px, 18vw, 120px);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-align: center;
  text-transform: none;
  overflow-wrap: anywhere;
}

/* Pictures and flags */

.pic {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: var(--pic-size, 100%);
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: inset 0 0 0 3px var(--line);
}

/* The image fills the box less an 8% margin on every side */
.pic img {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  object-fit: contain;
}

.pic.is-missing img { display: none; }

.pic.is-missing::after {
  content: "?";
  color: var(--ink-3);
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
}

.btn .pic.is-missing::after { font-size: 1em; }

.flag {
  flex: none;
  width: var(--flag-size, 100%);
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 0 0 3px var(--line);
}

/* Stars and progress */

.stars {
  display: inline-flex;
  gap: 6px;
}

.star {
  width: var(--star-size, 44px);
  height: var(--star-size, 44px);
  fill: var(--line);
}

.star.is-on {
  fill: var(--sun);
  stroke: var(--tangerine);
  stroke-width: 1.4;
  stroke-linejoin: round;
  animation: kids-pop 0.4s ease-out backwards;
  animation-delay: calc(var(--i, 0) * 120ms);
}

.progress {
  height: 20px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.progress-fill {
  width: var(--progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--c, var(--mint));
  transition: width 0.3s ease-out;
}

/* Sheet (modal), toast and confetti */

html.has-sheet { overflow: hidden; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(30, 34, 53, 0.55);
  animation: kids-fade 0.2s ease-out;
}

.sheet-panel {
  width: min(100%, 720px);
  max-height: 90vh;
  max-height: 90dvh;
  overflow: auto;
  padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--panel);
  animation: kids-rise 0.25s ease-out;
}

.sheet-panel:focus { outline: none; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.sheet-title {
  margin: 0;
  font-size: 28px;
}

@media (min-width: 720px) {
  .sheet { align-items: center; }
  .sheet-panel { border-radius: var(--radius); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  z-index: 200;
  max-width: min(92vw, 560px);
  padding: 14px 26px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
  animation: kids-toast-in 0.25s ease-out;
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 300;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Answer feedback animations (gentle: wrong answers wobble, never shake hard) */

.anim-pop { animation: kids-pop 0.4s ease-out; }
.anim-wobble { animation: kids-wobble 0.45s ease-in-out; }

@keyframes kids-pop {
  0% { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes kids-wobble {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-2.5deg); }
  75% { transform: rotate(2.5deg); }
}

@keyframes kids-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes kids-rise {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes kids-toast-in {
  from { transform: translate(-50%, 16px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* Utilities */

.hidden, [hidden] { display: none !important; }

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

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

@media print {
  body { background: #fff; }
  .topbar { display: none; }
}

/* Whole words: text sized by ui.fitWords wraps at spaces only. A word is cut only when it cannot fit even at the
   smallest size (fitWords then sets hyphens: auto and overflow-wrap: anywhere on that one element). The element
   stretches to the width its box allows, so fitWords can measure against it. */
.fit-words {
  align-self: stretch;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: normal;
  word-break: keep-all;
  hyphens: manual;
  white-space: normal;
}

@supports (text-wrap: balance) {
  .fit-words { text-wrap: balance; }
}
