/* Sumas Aventura — "El Cuaderno de Sumas"
   A Spanish squared-paper math notebook, marked up with marker pens. */

:root {
  --paper: #FBF8EF;        /* warm notebook paper */
  --note: #FFFFFF;         /* card / cut-out note */
  --grid: #D9E8F2;         /* pencil-blue cuadrícula line */
  --margin-red: #F2A9A0;   /* soft red margin line */
  --ink: #22314F;          /* blue-black ballpoint ink */
  --ink-soft: #66739033;   /* faded ink (used with alpha where needed) */
  --ink-mute: #5B6B8C;
  --coral: #FF6B5E;
  --sun: #FFC24B;
  --grass: #43B581;
  --sky: #3FA7E0;
  --violet: #7A6CFF;
  --primary: #3FA7E0;
  --good: #2Fa06f;
  --bad: #E5564A;
  --warn: #E8951B;
  --radius: 18px;
  --lip: 0 6px 0 rgba(34, 49, 79, .18);
  --lip-sm: 0 4px 0 rgba(34, 49, 79, .18);
  --card-shadow: 0 2px 0 rgba(34, 49, 79, .05), 0 18px 34px -20px rgba(34, 49, 79, .55);
  --font-display: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Segoe UI Rounded', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  /* Versorum portal brand — the teal ink that ties the kids notebook to
     versorum.com (its --accent / logo tile color). */
  --versorum: #15a08a;
  --versorum-deep: #0c6557;
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  margin: 0;
  min-height: 100vh;
  text-align: center;
  background-color: var(--paper);
  /* squared paper */
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 27px 27px;
  background-position: center top;
}

#app {
  position: relative;
  max-width: 760px;
  min-height: 100vh; /* so the red margin line always reaches the bottom */
  margin: 0 auto;
  padding: 26px 22px 56px;
}
/* red margin line, like a school cuaderno */
#app::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 8px;
  width: 2px;
  background: var(--margin-red);
  opacity: .75;
}

.screen { animation: rise .28s ease both; }
.screen.hidden { display: none; }
.hidden { display: none; }

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

/* ---------- Type ---------- */
h1 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  font-size: clamp(30px, 6vw, 44px);
  line-height: 1.05;
  letter-spacing: .2px;
  margin: 10px 0 6px;
}
h3 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  margin: 4px 0 12px;
}
.tagline {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--ink-mute);
  font-size: clamp(16px, 3.4vw, 20px);
  margin: 0 0 20px;
}

/* ---------- Portal brand: the notebook cover's name-label ----------
   Spanish school notebooks carry a white sticker label on the cover where
   you write your name and subject. The portal wordmark IS that label:
   white sticker, teal double rule (like label stationery), the versorum
   book mark on its teal tile, and "Versorum Kids" in the display face. */
.brand-label {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  background: var(--note);
  border: 2px solid var(--versorum);
  border-radius: 16px;
  /* inner second rule, like printed label stationery */
  box-shadow: inset 0 0 0 3px var(--note), inset 0 0 0 4.5px rgba(21, 160, 138, .38), var(--lip-sm);
  padding: 12px 22px 13px 16px;
  margin: 14px auto 6px;
}
.brand-label svg { width: 46px; height: 46px; display: block; border-radius: 11px; }
.brand-word {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(28px, 6.5vw, 40px);
  line-height: 1.02;
  letter-spacing: .2px;
  color: var(--versorum-deep);
  text-align: left;
}
.brand-word .kids { color: var(--coral); }
@media (max-width: 420px) {
  .brand-label { gap: 10px; padding: 10px 16px 11px 12px; }
  .brand-label svg { width: 38px; height: 38px; }
}

/* ---------- Cards / notes ---------- */
.card {
  position: relative;
  background: var(--note);
  border: 1px solid #EEEBDF;
  border-radius: var(--radius);
  padding: 24px 22px;
  margin: 16px auto;
  max-width: 520px;
  box-shadow: var(--card-shadow);
}

/* ---------- Buttons: marker-key tiles ---------- */
button {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 14px;
  padding: 14px 22px;
  margin: 6px;
  cursor: pointer;
  box-shadow: var(--lip-sm);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(34, 49, 79, .18); }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

button.big { font-size: clamp(22px, 5vw, 30px); padding: 18px 32px; }

/* ghost / pencil-outline secondary */
button.secondary {
  background: transparent;
  color: var(--ink);
  border: 2px dashed #C4CDDC;
  box-shadow: none;
  font-weight: 500;
}
button.secondary:hover { filter: none; background: rgba(63, 167, 224, .07); }
button.secondary:active { transform: none; box-shadow: none; }

/* ---------- Login card: versorum form language inside the sumas note ----------
   Boxed inputs with a teal focus ring and a teal-gradient primary (versorum's
   hero ramp) wearing the notebook's 3D lip — the two brands in one control. */
.login-card { max-width: 400px; padding: 26px 24px 20px; }
.login-card input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  font-size: 17px;
  padding: 13px 14px;
  margin: 0 0 12px;
  border: 1.5px solid #D8DEE9;
  border-bottom: 1.5px solid #D8DEE9;
  border-radius: 12px;
  background: #fff;
}
.login-card input:focus {
  outline: none;
  border-color: var(--versorum);
  box-shadow: 0 0 0 3px rgba(21, 160, 138, .16);
  background: #fff;
}
.login-card button.big {
  display: block;
  width: 100%;
  margin: 4px 0 0;
  font-size: 22px;
  padding: 15px 22px;
  background: linear-gradient(135deg, #15705d, #15a08a 65%, #14b89a);
}
.login-card .login-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 10px;
  color: var(--ink-mute);
  font-size: 14px;
  line-height: 1;
}
.login-card .login-sep::before,
.login-card .login-sep::after { content: ""; flex: 1; height: 1px; background: #E6E2D4; }
.login-card .google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1.5px solid #D8DEE9;
  box-shadow: var(--lip-sm);
}
.login-card .google-btn:hover { filter: none; background: #FAFBFD; }
.login-card .login-foot {
  font-family: var(--font-display);
  font-size: 15.5px;
  color: var(--ink-mute);
  margin: 18px 0 0;
}
.login-card .login-foot.subtle { margin: 8px 0 0; font-size: 14px; }
.login-card button.linklike {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  color: var(--versorum);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.login-card button.linklike:hover { filter: none; color: var(--versorum-deep); }
.login-card button.linklike:active { transform: none; box-shadow: none; }
.login-card button.linklike.muted { color: var(--ink-mute); font-weight: 500; }
.login-card #li-msg:not(:empty) { margin-top: 12px; font-weight: 600; }

/* ---------- Login screen: the notebook cover ---------- */
#screen-login { position: relative; padding-top: 14px; }
#screen-login::before,
#screen-login::after {
  content: "＋";
  position: absolute;
  font-family: var(--font-display);
  font-weight: 600;
  color: rgba(63, 167, 224, .12);
  z-index: 0;
  pointer-events: none;
}
#screen-login::before { content: "＋"; font-size: 150px; top: 40px; left: -6px; transform: rotate(-12deg); }
#screen-login::after  { content: "＝"; font-size: 130px; bottom: 8px; right: -4px; transform: rotate(8deg); color: rgba(255, 107, 94, .12); }
#screen-login > * { position: relative; z-index: 1; }

/* Google button reads as a distinct white card, not another marker key */
#li-google {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--lip-sm);
  border: 1px solid #E6E3D8;
}
#li-google:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(34, 49, 79, .18); }
/* forgot-password is a quiet link, not a button */
#li-forgot {
  background: none;
  border: none;
  box-shadow: none;
  color: var(--ink-mute);
  font-weight: 500;
  font-size: 15px;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px;
}
#li-forgot:active { transform: none; }
#li-msg, #pa-msg, #k-msg, #pin-msg { min-height: 22px; margin-top: 8px; color: var(--ink-mute); font-weight: 500; }
button:disabled { opacity: .7; cursor: default; }

/* inline loading spinner (inherits the button's text colour) */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid rgba(127, 127, 127, .35);
  border-top-color: currentColor;
  border-radius: 50%;
  vertical-align: middle;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Inputs: notebook underline ---------- */
input, select {
  font-family: var(--font-body);
  font-size: 18px;
  color: var(--ink);
  padding: 11px 12px;
  margin: 7px;
  border: none;
  border-bottom: 2px solid #C4CDDC;
  border-radius: 9px 9px 0 0;
  background: rgba(255, 255, 255, .65);
}
input:focus, select:focus { outline: none; border-bottom-color: var(--primary); background: #fff; }
input::placeholder { color: #9AA6BC; }

#pin-input {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 40px;
  text-align: center;
  letter-spacing: 14px;
  width: 200px;
  padding-left: 26px; /* balance the letter-spacing */
}

/* ---------- Avatars: paper chips ---------- */
.avatar-pick { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 12px 0; }
.avatar-pick button, .avatar-pick .av {
  font-size: 30px;
  width: 58px; height: 58px;
  padding: 0;
  background: #fff;
  color: inherit;
  border-radius: 50%;
  box-shadow: var(--lip-sm);
}
.avatar-pick button.selected, .avatar-pick .av.selected { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- Game ---------- */
#screen-game { padding-top: 8px; }

#session {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--ink);
  font-size: clamp(18px, 4.5vw, 22px);
  margin: 2px 0 8px;
  letter-spacing: .3px;
}
#mastery { font-family: var(--font-display); color: var(--ink-mute); font-size: 15px; margin: 8px 0 4px; }

#bar {
  height: 18px;
  max-width: 520px;
  margin: 6px auto;
  background: #ECE7D6;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(34, 49, 79, .10);
}
#fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--grass), var(--sky)); transition: width .4s ease; }

#timer {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(24px, 6vw, 34px);
  height: 46px;
  letter-spacing: .5px;
}

#q {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--ink);
  font-size: clamp(64px, 20vw, 118px);
  line-height: 1;
  letter-spacing: 1px;
  margin: 14px 0 18px;
  transform: rotate(-1.5deg); /* written-in-the-notebook tilt */
}

/* reveal modal shown after a wrong answer / timeout */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(34, 49, 79, .45);
  animation: fade .18s ease both;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--note);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: var(--card-shadow);
  animation: pop-in .26s ease both;
}
.modal-label { font-family: var(--font-body); color: var(--ink-mute); font-size: 16px; margin-bottom: 10px; }
.modal-eq {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(44px, 12vw, 66px);
  color: var(--good);
  line-height: 1;
  margin-bottom: 22px;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-card p { font-family: var(--font-body); color: var(--ink); margin: 0 0 16px; line-height: 1.5; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.modal-actions button { margin: 0; }
.modal-prompt { font-family: var(--font-body); color: var(--ink-mute); font-size: 16px; margin-bottom: 12px; }
.modal-input {
  display: block;
  width: 150px;
  max-width: 60%;
  margin: 0 auto;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(32px, 9vw, 46px);
}
.modal-input.nudge { animation: nudge .3s ease; }
@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* Concentration mode: drifting, non-interactive distractions during the game */
.distractions { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 5; }
.distractor {
  position: absolute;
  opacity: .55;
  will-change: transform;
  animation-name: drift;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}
@keyframes drift {
  from { transform: translate(0, 0) rotate(0deg); }
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 440px;
  margin: 12px auto;
}
.grid button {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(48px, 15vw, 70px);
  color: #fff;
  padding: 30px 10px;
  border-radius: 18px;
  box-shadow: var(--lip);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.grid button:active { transform: translateY(5px); box-shadow: 0 1px 0 rgba(34, 49, 79, .18); }
.grid button { touch-action: manipulation; user-select: none; -webkit-user-select: none; }

/* ---------- In-game: fit the viewport, no scroll (reliable answer taps) ---------- */
body.playing { overflow: hidden; overscroll-behavior: none; }
body.playing #app {
  min-height: 0;
  height: 100vh; height: 100dvh;
  padding: 8px 14px;
  display: flex; flex-direction: column;
}
body.playing #screen-game {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  justify-content: center;             /* centre the cluster; leftover space becomes whitespace */
  gap: clamp(8px, 2.2vh, 22px);
  animation: none;
}
/* hide the mastery bar/label mid-game to give the sum room */
body.playing #bar, body.playing #mastery { display: none; }
body.playing #session { font-size: 15px; color: var(--ink-mute); margin: 0; }
body.playing #timer { font-size: clamp(20px, 5.5vw, 30px); height: auto; margin: 0; }
/* the sum is the hero — as big as fits (game.js auto-shrinks long questions) */
body.playing #q { font-size: clamp(56px, 22vw, 150px); font-weight: 700; line-height: 1; margin: 0; white-space: nowrap; }
body.playing #answers {
  grid-template-columns: repeat(2, 1fr);
  gap: 14px; max-width: 400px; width: 100%; margin: 0 auto;
}
/* proportionate marker-keys (3:2), not full-height blocks */
body.playing .grid button {
  aspect-ratio: 3 / 2; height: auto; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(38px, 11vw, 62px); font-weight: 600;
}
body.playing #msg { height: auto; min-height: 28px; margin: 0; font-size: clamp(20px, 5vw, 28px); }
body.playing #screen-game > div:has(#c) { margin: 0; font-size: 12px; }
body.playing #g-stop { margin: 0 auto; padding: 9px 20px; }

#msg {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(22px, 5vw, 30px);
  height: 62px;
  margin: 10px;
}

/* score line */
#screen-game > div:has(#c) {
  margin: 14px 0 6px;
  color: var(--ink-mute);
  font-weight: 500;
}
#c, #w, #tm, #s { font-family: var(--font-display); font-weight: 700; }
#c { color: var(--good); }
#w { color: var(--bad); }
#tm { color: var(--warn); }
#s { color: var(--violet); }

/* ---------- Heatmap ---------- */
.heat {
  display: grid;
  grid-template-columns: repeat(11, 1fr);
  gap: 4px;
  max-width: 420px;
  margin: 14px auto;
}
.heat div {
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #3a4358;
  background: transparent;
}
.heat .learnt { background: var(--grass); color: #fff; }
.heat .learning { background: var(--sun); color: #6b4e07; }
.heat .struggling { background: var(--coral); color: #fff; }
.heat .empty { background: #ECE7D6; color: transparent; }

/* ---------- Settings (parents area) ---------- */
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.settings-head h1 { margin: 0; }
.head-actions {
  display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; justify-content: space-between;
}
.head-actions .secondary { padding: 8px 12px; font-size: 14px; white-space: nowrap; margin: 0; }
.head-actions .lang-pill { padding: 6px 10px; flex: 0 1 auto; min-width: 0; }
.head-actions .lang-select { font-size: 14px; max-width: 100%; }
/* on phones, stack the title over a full-width one-line action row */
@media (max-width: 560px) {
  .settings-head { flex-direction: column; align-items: stretch; }
}
.gate-card { max-width: 420px; }
.info-card { background: #EAF4FB; border-color: #CDE3F0; }
.info-card p { margin: 0; font-family: var(--font-body); font-size: 14px; color: var(--ink); line-height: 1.5; text-align: left; }

/* Add-kid form: stacked label + boxed control */
.add-kid { text-align: left; }
.add-settings-title { margin: 18px 0 4px; padding-top: 14px; border-top: 1px solid var(--grid); font-size: 16px; color: var(--ink); }
.form-row { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; margin: 12px 0; }
.form-row label { font-family: var(--font-body); font-size: 14px; color: var(--ink-mute); }
.add-kid input, .add-kid select,
.setting-row input, .setting-row select {
  border: 1.5px solid #D8DEE9;
  border-radius: 10px;
  background: #fff;
  padding: 9px 11px;
  margin: 0;
}
.form-row > input, .form-row > select { width: 100%; }

/* Kid cards */
.kid-card { text-align: left; }
.kid-head { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.kid-avatar { font-size: 34px; line-height: 1; }
.kid-name { font-family: var(--font-display); font-weight: 600; font-size: 22px; flex: 1; }
.icon-btn { background: transparent; border: none; box-shadow: none; font-size: 20px; padding: 6px; }
.icon-btn:active { transform: none; box-shadow: none; }
.kid-meta { color: var(--ink-mute); font-family: var(--font-body); margin-bottom: 12px; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--font-body);
  color: var(--ink);
  margin: 12px 0;
}
.setting-row > span:first-child { flex: 1; text-align: left; }
.setting-row > .switch { flex: 0 0 auto; }
.setting-row input[type="number"], .setting-row select { width: 90px; text-align: center; }
/* tidy, left-aligned rows with light separators inside the kid panel */
.kid-panel > td { text-align: left; }
.kid-panel .setting-row { margin: 0; padding: 6px 2px; min-height: 48px; border-bottom: 1px solid #EBE6D7; }
.kid-panel .setting-row:last-of-type { border-bottom: none; }
.kid-panel .setting-row > span:first-child { color: var(--ink); font-size: 14px; }
/* keep every settings row the same height (number inputs vs toggles) */
.kid-panel .setting-row input[type="number"] { height: 38px; }
.hint { color: var(--ink-mute); font-size: 14px; font-family: var(--font-body); margin: 8px 0 2px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #CBD3DF; border-radius: 999px; cursor: pointer; transition: background .2s; }
.slider::before {
  content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.switch input:checked + .slider { background: var(--grass); }
.switch input:checked + .slider::before { transform: translateX(14px); }
.switch input:focus-visible + .slider { outline: 3px solid var(--ink); outline-offset: 2px; }

/* Kids table */
.kids-table { width: 100%; border-collapse: collapse; font-family: var(--font-body); }
.kids-table th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-mute); padding: 4px 8px; border-bottom: 2px solid #ECE7D6;
}
.kids-table td { padding: 10px 8px; border-bottom: 1px solid #F1EDE1; vertical-align: middle; }
.kid-cell { font-weight: 500; }
.kid-cell .kid-avatar { font-size: 24px; margin-right: 8px; }
.pin-cell { color: var(--ink-mute); white-space: nowrap; font-family: var(--font-display); }
.act-cell { text-align: right; white-space: nowrap; }
.act-cell .icon-btn { font-size: 20px; padding: 4px 6px; }
.kid-panel > td { background: var(--paper); border-radius: 12px; }
.add-toggle { margin-top: 14px; }
.save-row { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 12px; }
.save-ok { color: var(--good); font-weight: 600; font-family: var(--font-display); }

/* Language selector — a rounded pill with a globe */
.lang-bar { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.lang-pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--note); border: 1px solid #E6E3D8; border-radius: 999px;
  padding: 6px 12px; box-shadow: var(--lip-sm); font-size: 15px; cursor: pointer;
}
.lang-select {
  appearance: none; -webkit-appearance: none;
  border: none; background: transparent; outline: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 500; font-size: 15px; color: var(--ink);
  padding: 0 2px;
}
.head-actions { align-items: center; }

/* Credits (parents redeem area) */
.credit-box { margin-top: 14px; padding-top: 12px; border-top: 1px dashed #D8DEE9; }
.credit-balance { font-family: var(--font-display); font-size: 18px; color: var(--ink); margin-bottom: 10px; }
.redeem-row { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.redeem-row input[type="number"],
.redeem-row input[type="text"] { width: 100%; border: 1.5px solid #D8DEE9; border-radius: 10px; background: #fff; padding: 10px 12px; }
.credit-buttons { display: flex; gap: 8px; margin-top: 10px; }
.credit-buttons button { margin: 0; flex: 1 1 0; white-space: nowrap; }
.hist-toggle { margin-top: 0; }
.credit-history { margin-top: 10px; }
.credit-history h4 { font-family: var(--font-display); font-weight: 600; margin: 0 0 8px; color: var(--ink); }
.credit-entry {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline;
  font-family: var(--font-body); font-size: 14px; color: var(--ink);
  padding: 6px 0; border-bottom: 1px solid #F1EDE1;
}
.ce-amt { font-weight: 700; color: var(--bad); }
.ce-date { color: var(--ink-mute); font-size: 13px; }
.ce-cmt { color: var(--ink); }
.credits-earned { font-family: var(--font-display); font-weight: 600; font-size: 18px; color: var(--violet); margin: 4px 0 8px; }

/* ---------- Summary (results) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* 2×2 on mobile */
  gap: 12px;
}
@media (min-width: 520px) {
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 6px;
  background: var(--paper);
  border-radius: 14px;
}
.stat-val { font-family: var(--font-display); font-weight: 700; font-size: clamp(28px, 7vw, 38px); line-height: 1; color: var(--ink); }
.stat-lab { font-family: var(--font-body); font-size: 13px; color: var(--ink-mute); margin-top: 6px; text-align: center; }
.stat.good .stat-val { color: var(--good); }
.stat.bad .stat-val { color: var(--bad); }
.stat.warn .stat-val { color: var(--warn); }
.stat.violet .stat-val { color: var(--violet); }
.stat.sky .stat-val { color: var(--sky); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  font-family: var(--font-display);
  font-weight: 500;
  background: var(--paper);
  border: 1px solid #E6E3D8;
  border-radius: 999px;
  padding: 7px 15px;
  color: var(--ink);
}
.summary-actions { margin-top: 14px; }

/* rubber approval stamp — the reward hero */
.summary-hero { display: flex; justify-content: center; margin: 6px 0 2px; }
.stamp {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 146px; height: 146px; border-radius: 50%;
  transform: rotate(-8deg);
  font-family: var(--font-display);
  animation: stamp-in .42s cubic-bezier(.2, .8, .2, 1) both;
}
.stamp-good { color: var(--good); border: 4px double var(--good); box-shadow: inset 0 0 0 3px rgba(47, 163, 107, .3); }
.stamp-ok { color: var(--violet); border: 4px double var(--violet); box-shadow: inset 0 0 0 3px rgba(122, 108, 255, .28); }
.stamp-big { font-size: 46px; font-weight: 700; line-height: 1; }
.stamp-sub { font-size: 14px; margin-top: 4px; letter-spacing: .3px; }
.stamp-word { font-size: 30px; font-weight: 700; }
@keyframes stamp-in {
  0% { transform: scale(1.7) rotate(-8deg); opacity: 0; }
  60% { transform: scale(.94) rotate(-8deg); opacity: 1; }
  100% { transform: scale(1) rotate(-8deg); }
}

/* sums to practise, circled in red like a teacher's pen */
.chip-circled {
  display: inline-block;
  font-family: var(--font-display); font-weight: 600; color: var(--ink);
  background: transparent; border: 2.5px solid var(--coral);
  border-radius: 50% / 60%; padding: 8px 16px;
}
.chip-circled:nth-child(2n) { transform: rotate(-2.5deg); }
.chip-circled:nth-child(3n) { transform: rotate(2deg); }

/* ---------- Kid picker (who's playing) ---------- */
.kid-picker { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; margin-top: 22px; }
.kid-choice {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  min-width: 130px; padding: 24px 20px;
  background: var(--note); color: var(--ink);
  border: 1px solid #EEEBDF; border-radius: 20px;
  box-shadow: var(--card-shadow); font-family: var(--font-display);
}
.kid-choice:active { transform: translateY(4px); }
.kid-choice-avatar { font-size: 60px; line-height: 1; }
.kid-choice-name { font-weight: 600; font-size: 20px; }

/* ---------- Game picker (hub) ---------- */
.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  max-width: 560px;
  margin: 8px auto 20px;
}

/* Fit the whole hub in the viewport — no scrolling past the six games. */
body[data-screen="hub"] { overflow: hidden; overscroll-behavior: none; }
body[data-screen="hub"] #app {
  min-height: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; padding: 10px 14px 14px;
}
body[data-screen="hub"] #screen-hub {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; animation: none;
}
body[data-screen="hub"] #screen-hub h1 { font-size: clamp(28px, 7vw, 40px); margin: 18px 0 4px; }
body[data-screen="hub"] #screen-hub .tagline { margin: 0 0 10px; font-size: clamp(15px, 3.6vw, 18px); }
body[data-screen="hub"] .game-grid {
  flex: 1 1 auto; min-height: 0;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 1fr;                 /* rows stretch to fill the screen */
  gap: 10px; margin: 0;
}
body[data-screen="hub"] .game-card {
  height: 100%; padding: 6px; gap: clamp(4px, 1.2vh, 10px); justify-content: center;
}
body[data-screen="hub"] .game-logo { width: clamp(42px, 9.5vh, 84px); height: clamp(42px, 9.5vh, 84px); }
body[data-screen="hub"] .game-title { font-size: clamp(14px, 3.8vw, 19px); }
body[data-screen="hub"] .game-progress { font-size: clamp(11px, 2.6vw, 13px); }
.game-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--note);
  color: var(--ink);
  border: 1px solid #EEEBDF;
  border-radius: 18px;
  padding: 20px 12px 16px;
  box-shadow: var(--card-shadow);
  font-family: var(--font-display);
}
.game-card:active { transform: translateY(4px); }
/* mastery fill rises from the bottom in a tint of the game colour */
.game-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0;
  background: var(--gc);
  opacity: .16;
  transition: height .5s ease;
  pointer-events: none;
}
.game-card.mastered { border-color: var(--gc); }
.game-card > *:not(.game-fill) { position: relative; z-index: 1; }
.game-logo { width: 56px; height: 56px; }
.game-logo svg { display: block; }
.game-title { font-weight: 600; font-size: 17px; }
.game-progress { font-family: var(--font-body); font-size: 13px; color: var(--ink-mute); }
.hub-actions { margin-top: 6px; }

/* home top bar: credit + streak pills (left), round icon buttons (right) */
.hub-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 48px; margin-bottom: 4px; }
.hub-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.hub-badge {
  font-family: var(--font-display); font-weight: 600; font-size: 17px; color: var(--ink);
  background: var(--note); border: 1px solid #E6E3D8; border-radius: 999px;
  padding: 7px 14px; box-shadow: var(--lip-sm); white-space: nowrap;
}
.hub-icons { display: flex; gap: 8px; }
.icon-round {
  width: 46px; height: 46px; padding: 0; font-size: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--note); color: var(--ink);
  border: 1px solid #E6E3D8; border-radius: 50%; box-shadow: var(--lip-sm); margin: 0;
}
.icon-round:hover { filter: none; background: #fff; }
.icon-round:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(34, 49, 79, .18); }
.ic { width: 22px; height: 22px; display: block; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Table setup (×/÷) ---------- */
.table-grid { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 12px 0; }
.table-btn {
  width: 56px; height: 56px; padding: 0;
  font-family: var(--font-display); font-weight: 600; font-size: 24px;
  background: #fff; color: var(--ink);
  border: 2px solid #D8DEE9; border-radius: 14px; box-shadow: none;
}
.table-btn.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.table-btn:active { transform: translateY(3px); }

/* ---------- Fact grid (stats) ---------- */
.fact-grid { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; }
.fact-cell {
  font-family: var(--font-body); font-size: 12px;
  padding: 5px 7px; border-radius: 7px; min-width: 34px; text-align: center;
  background: #ECE7D6; color: #3a4358;
}
.fact-cell.learnt { background: var(--grass); color: #fff; }
.fact-cell.learning { background: var(--sun); color: #6b4e07; }
.fact-cell.struggling { background: var(--coral); color: #fff; }
.fact-cell.empty { background: #ECE7D6; color: #9aa2b0; }
.legend { font-size: 13px; color: var(--ink-mute); margin-top: 12px; }

/* ---------- Achievements + leaderboard ---------- */
.day-streak {
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(22px, 6vw, 30px); color: var(--warn);
  margin: 6px 0 12px;
}
.lb-list { max-width: 460px; padding: 8px 14px; }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 6px; border-bottom: 1px solid #F1EDE1;
  font-family: var(--font-body);
}
.lb-row:last-child { border-bottom: none; }
.lb-row.lb-me { background: #EAF4FB; border-radius: 12px; }
.lb-rank { font-family: var(--font-display); font-weight: 700; font-size: 20px; min-width: 30px; text-align: center; }
.lb-av { font-size: 30px; }
.lb-name { flex: 1; display: flex; flex-direction: column; gap: 2px; font-family: var(--font-display); font-weight: 600; font-size: 18px; color: var(--ink); }
.lb-detail { display: flex; gap: 10px; font-family: var(--font-body); font-weight: 500; font-size: 12px; color: var(--ink-mute); }
.lb-score { font-family: var(--font-display); font-weight: 700; color: var(--ink); white-space: nowrap; }
.lb-howto {
  max-width: 460px; margin: 10px auto 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px;
  font-size: 13px; line-height: 1.5; color: var(--ink-mute);
}
.lb-howto-item { white-space: nowrap; }

/* ---------- Hall of fame ---------- */
.fame-records {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  gap: 14px 8px;
}
.record { display: flex; flex-direction: column; align-items: center; min-width: 88px; }
.rec-val {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(26px, 6vw, 34px);
  color: var(--ink);
  line-height: 1;
}
.rec-lab { font-family: var(--font-body); font-size: 13px; color: var(--ink-mute); margin-top: 4px; text-align: center; }

.badge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 12px;
  max-width: 520px;
  margin: 8px auto 0;
}
.badge {
  background: var(--note);
  border: 1px solid #EEEBDF;
  border-radius: 16px;
  padding: 16px 8px;
  box-shadow: var(--card-shadow);
}
.badge.locked { opacity: .5; filter: grayscale(1); box-shadow: none; }
.badge.earned { animation: pop-in .35s ease both; }
.badge-icon { font-size: 40px; line-height: 1; }
.badge-name { font-family: var(--font-display); font-weight: 500; font-size: 14px; color: var(--ink); margin-top: 6px; }

@keyframes pop-in {
  0% { transform: scale(.6); opacity: 0; }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Motion / a11y ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  #q { transform: none; }
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  #app { padding: 18px 14px 44px; }
  .card { padding: 20px 16px; }
  #screen-login::before { font-size: 110px; }
  #screen-login::after { font-size: 96px; }
}

/* ---------- English session (screens/english.js) ---------- */
body.playing #screen-english {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  gap: clamp(8px, 2vh, 18px);
  animation: none;
}
.en-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; }
.en-top #en-stop { margin: 0; padding: 9px 20px; }
.en-dots { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.en-dot { width: 10px; height: 10px; border-radius: 50%; background: #D8D2BF; }
.en-dot.done { background: var(--versorum); }
.en-dot.now { background: var(--coral); transform: scale(1.3); }
.en-stage {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(6px, 1.6vh, 14px);
  overflow-y: auto;
}

/* the concept image: a photo taped into the notebook */
.taped-photo {
  position: relative;
  width: min(64vw, 300px);
  background: #fff;
  padding: 10px 10px 14px;
  border-radius: 4px;
  box-shadow: 0 10px 24px -12px rgba(34, 49, 79, .5);
  transform: rotate(-1.5deg);
  cursor: pointer;
}
.taped-photo img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 2px; }
.taped-photo::before, .taped-photo::after {
  content: "";
  position: absolute;
  top: -10px;
  width: 72px; height: 24px;
  background: rgba(255, 226, 143, .85); /* sellotape */
  box-shadow: 0 1px 2px rgba(34, 49, 79, .18);
}
.taped-photo::before { left: -20px; transform: rotate(-38deg); }
.taped-photo::after { right: -20px; transform: rotate(38deg); }
.taped-photo-sm { width: min(38vw, 170px); padding: 7px 7px 10px; }

.en-word {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(38px, 10vw, 58px); line-height: 1.05;
  color: var(--ink); letter-spacing: .5px;
}
/* the transliteration hint, written under the word in pencil */
.en-hint {
  font-family: var(--font-display); font-weight: 500;
  font-size: clamp(17px, 4.6vw, 23px);
  color: var(--ink-mute); opacity: .8;
}
.en-meaning { font-family: var(--font-body); font-size: clamp(16px, 4.2vw, 20px); color: var(--versorum-deep); }
.en-continue { background: linear-gradient(135deg, #15705d, #15a08a 65%, #14b89a); }

.en-prompt {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(17px, 4.4vw, 22px); color: var(--ink);
}
.en-msg { font-family: var(--font-display); font-weight: 600; font-size: clamp(18px, 4.6vw, 24px); min-height: 30px; color: var(--good); }

/* ---------- Subject divider tabs (hub) ----------
   Physical notebook dividers sticking out of the page edge: Mates in sky,
   English in Versorum teal. The inactive tab sits dimmed and slightly
   tucked; tapping it flips the page. */
.subject-tabs {
  position: absolute;
  top: 118px; right: 0;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 20;
}
.subject-tab {
  writing-mode: vertical-rl;
  min-height: 96px; min-width: 48px;
  margin: 0; padding: 14px 12px;
  font-family: var(--font-display); font-weight: 600; font-size: 16px; letter-spacing: .6px;
  color: #fff; background: var(--tab);
  border-radius: 14px 0 0 14px;
  box-shadow: -3px 3px 0 rgba(34, 49, 79, .15);
  opacity: .55; transform: translateX(6px);
  transition: transform .15s ease, opacity .15s ease;
}
.subject-tab.active { opacity: 1; transform: none; box-shadow: -4px 4px 0 rgba(34, 49, 79, .18); }
.subject-tab:active { transform: translateX(2px); }
/* keep the hub content clear of the tabs */
body[data-screen="hub"] #screen-hub { padding-right: 46px; }

/* ---------- English hub page: big Play + pack progress strip ---------- */
.english-page {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: center;
}
.en-play {
  display: block;
  min-width: min(70vw, 300px);
  margin: 8px auto 12px;
  background: linear-gradient(135deg, #15705d, #15a08a 65%, #14b89a);
}
.pack-strip {
  flex: 1 1 auto; min-height: 0;
  width: 100%; max-width: 440px;
  margin: 0 auto;
  overflow-y: auto;
  text-align: left;
}
.pack-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 6px; border-bottom: 1px solid #F1EDE1;
}
.pack-name { flex: 1; font-family: var(--font-display); font-weight: 500; font-size: 16px; color: var(--ink); }
.pack-bar { flex: 0 0 84px; height: 8px; border-radius: 999px; background: #ECE7D6; overflow: hidden; }
.pack-fill { display: block; height: 100%; background: var(--versorum); }
.pack-count { font-family: var(--font-body); font-size: 13px; color: var(--ink-mute); white-space: nowrap; }

/* ---------- Feed the monster ---------- */
.monster {
  width: 104px; height: 104px;
  margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--versorum);
  border-radius: 50%;
  box-shadow: var(--lip-sm);
}
.monster-face { font-size: 52px; line-height: 1; }
.monster.chomp { animation: chomp .5s ease; }
@keyframes chomp {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.18) rotate(-6deg); }
}
.en-hear { width: 48px; height: 48px; }
.en-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%; max-width: 400px;
  margin: 0 auto;
}
.en-choice {
  margin: 0; padding: 0;
  background: #fff;
  border-radius: 14px;
  box-shadow: var(--lip-sm);
  overflow: hidden;
  min-height: 48px;
}
.en-choice img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }
.en-choice:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(34, 49, 79, .18); }
.en-choice.wrong { opacity: .35; }
.en-choice.eaten { animation: pop-in .4s ease both; outline: 4px solid var(--grass); }
.en-choice.reveal { outline: 4px solid var(--grass); animation: reveal-pulse 1s ease infinite; }
@keyframes reveal-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ---------- Sentence puzzle: scissor-cut word strips ---------- */
.strip-line {
  width: 100%; max-width: 480px;
  min-height: 64px;
  margin: 0 auto;
  padding: 6px 4px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  border-bottom: 2px dashed #C4CDDC; /* the answer line on the squared paper */
}
.strip-line.nudge { animation: nudge .3s ease; }
.strip-tray {
  width: 100%; max-width: 480px;
  margin: 4px auto 0;
  display: flex; flex-wrap: wrap; justify-content: center;
}
.word-strip {
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(17px, 4.4vw, 23px);
  color: var(--ink);
  background: #fff;
  border: 1px solid #E3DECB;
  border-radius: 3px;
  padding: 12px 14px;
  min-height: 48px;
  margin: 4px;
  box-shadow: none;
  /* scissor-cut: slightly irregular paper edges */
  clip-path: polygon(0 7%, 3% 0, 97% 2%, 100% 11%, 99% 91%, 96% 100%, 4% 98%, 0 89%);
}
.word-strip:nth-child(2n) { transform: rotate(-1.2deg); }
.word-strip:nth-child(3n) { transform: rotate(1.3deg); }
.word-strip:active { transform: translateY(2px); }
.word-strip.placed { display: inline-block; background: #F4FBF7; border-color: var(--grass); }
