:root {
  --cream: #fff6e9;
  --cream-deep: #ffeccb;
  --coral: #ff6b5e;
  --coral-deep: #e8503f;
  --teal: #2ec4b6;
  --teal-deep: #1ba294;
  --gold: #ffc857;
  --gold-deep: #f0ad26;
  --ink: #34303a;
  --ink-soft: #5b5560;
  --white: #fffdf8;

  --border: 4px;
  --radius: 22px;
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 4px 4px 0 var(--ink);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  font-weight: 700;
  -webkit-text-size-adjust: 100%;
}

body {
  /* dotted "sticker book" backdrop */
  background-image: radial-gradient(var(--cream-deep) 18%, transparent 18%);
  background-size: 26px 26px;
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

h1, h2, h3, .display {
  font-family: "Baloo 2", "Nunito", sans-serif;
  font-weight: 800;
  line-height: 1.05;
  margin: 0;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}
.logo {
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo .spark { font-size: 1.6rem; }
.who {
  font-size: 0.95rem;
  background: var(--gold);
  border: var(--border) solid var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Cards ---------- */
.card {
  background: var(--white);
  border: var(--border) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.25rem;
  margin: 22px 4px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--white);
  border: var(--border) solid var(--ink);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 13px 18px;
  cursor: pointer;
  transition: transform .05s ease, box-shadow .05s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
}
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn.coral { background: var(--coral); color: var(--white); }
.btn.teal  { background: var(--teal);  color: var(--white); }
.btn.gold  { background: var(--gold); }
.btn.ghost { background: var(--cream); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }

/* ---------- Profile picker ---------- */
.profiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.profile {
  border: var(--border) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 10px;
  text-align: center;
  cursor: pointer;
  background: var(--white);
  transition: transform .05s ease, box-shadow .05s ease;
}
.profile:active { transform: translate(4px,4px); box-shadow: 0 0 0 var(--ink); }
.profile.selected { outline: 4px dashed var(--ink); outline-offset: 4px; }
.profile .avatar {
  width: 64px; height: 64px; margin: 0 auto 8px;
  border-radius: 50%;
  border: var(--border) solid var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem;
}
.profile .pname { font-family: "Baloo 2"; font-weight: 800; font-size: 1.15rem; }
.profile .page  { color: var(--ink-soft); font-size: .9rem; }
.av-coral { background: var(--coral); }
.av-teal  { background: var(--teal); }
.av-gold  { background: var(--gold); }

/* ---------- Subjects ---------- */
.subjects { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.subject {
  border: var(--border) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: transform .05s ease, box-shadow .05s ease;
}
.subject:active { transform: translate(4px,4px); box-shadow: 0 0 0 var(--ink); }
.subject.locked { cursor: default; opacity: .8; }
.subject.locked:active { transform: none; box-shadow: var(--shadow-sm); }
.subject .emoji { font-size: 2.4rem; display: block; margin-bottom: 6px; }
.subject .label { font-family: "Baloo 2"; font-weight: 800; font-size: 1.15rem; }
.subject.math { background: var(--coral); color: var(--white); }
.subject.lang { background: var(--teal);  color: var(--white); }
.subject.sci  { background: var(--gold); }
.subject.art  { background: #c9a4ff; color: var(--white); }
.subject .soon {
  position: absolute; top: -10px; right: -8px;
  background: var(--ink); color: var(--white);
  font-size: .65rem; padding: 4px 8px; border-radius: 999px;
  transform: rotate(8deg);
}

/* ---------- Forms ---------- */
label { display: block; font-size: .9rem; margin: 10px 0 4px; }
input[type="text"], input[type="number"], input[type="password"] {
  width: 100%;
  font-family: "Nunito"; font-weight: 700; font-size: 1.1rem;
  padding: 12px 14px;
  border: var(--border) solid var(--ink);
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
}
input:focus { outline: none; background: var(--white); box-shadow: var(--shadow-sm); }

/* ---------- Quiz ---------- */
.quiz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pill {
  background: var(--gold); border: var(--border) solid var(--ink);
  border-radius: 999px; padding: 4px 12px; font-size: .85rem;
  box-shadow: var(--shadow-sm);
}
.progress-track {
  height: 16px; background: var(--cream-deep);
  border: var(--border) solid var(--ink); border-radius: 999px;
  overflow: hidden; margin-bottom: 16px;
}
.progress-fill { height: 100%; background: var(--teal); width: 0; transition: width .3s ease; }
.question {
  font-family: "Baloo 2"; font-weight: 800;
  font-size: 2.8rem; text-align: center; margin: 18px 0 22px;
}
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  font-family: "Baloo 2"; font-weight: 800; font-size: 1.8rem;
  padding: 22px 10px;
  border: var(--border) solid var(--ink); border-radius: 18px;
  box-shadow: var(--shadow-sm); background: var(--white);
  cursor: pointer;
  transition: transform .05s ease, box-shadow .05s ease;
}
.choice:active { transform: translate(4px,4px); box-shadow: 0 0 0 var(--ink); }
.choice.correct { background: var(--teal); color: var(--white); }
.choice.wrong   { background: var(--coral); color: var(--white); }
.choice.disabled { pointer-events: none; }

/* ---------- Result ---------- */
.result { text-align: center; }
.result .big-stars { font-size: 3.4rem; margin: 6px 0; }
.result h2 { font-size: 2rem; margin-bottom: 6px; }
.result .tally { color: var(--ink-soft); margin-bottom: 16px; }

/* ---------- Leaderboard ---------- */
.lb-row {
  display: flex; align-items: center; gap: 12px;
  border: var(--border) solid var(--ink); border-radius: 18px;
  box-shadow: var(--shadow-sm); padding: 12px 14px; margin-bottom: 12px;
  background: var(--white);
}
.lb-rank { font-family: "Baloo 2"; font-weight: 800; font-size: 1.4rem; width: 34px; text-align: center; }
.lb-av {
  width: 46px; height: 46px; border-radius: 50%;
  border: var(--border) solid var(--ink);
  display:flex; align-items:center; justify-content:center; font-size: 1.4rem;
}
.lb-main { flex: 1; }
.lb-name { font-family: "Baloo 2"; font-weight: 800; font-size: 1.15rem; }
.lb-sub { color: var(--ink-soft); font-size: .82rem; }
.lb-stars { font-family: "Baloo 2"; font-weight: 800; font-size: 1.3rem; white-space: nowrap; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card { max-width: 380px; width: 100%; text-align: center; }
.login-card .spark { font-size: 3rem; }
.login-card h1 { font-size: 2.2rem; margin: 6px 0 2px; }
.login-card p { color: var(--ink-soft); margin: 0 0 18px; }
.err { color: var(--coral-deep); min-height: 1.2em; margin-top: 10px; font-size: .9rem; }

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.spacer { height: 8px; }
.pop { animation: pop .25s ease; }
@keyframes pop { 0% { transform: scale(.9); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* ===================== Hub-specific ===================== */
.people { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.person {
  position: relative;
  border: var(--border) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--white);
  padding: 18px 10px 16px;
  text-align: center;
  cursor: pointer;
  transition: transform .05s ease, box-shadow .05s ease;
}
.person:active { transform: translate(5px,5px); box-shadow: 0 0 0 var(--ink); }
.person .emoji-big {
  font-size: 3.2rem; line-height: 1; margin-bottom: 8px;
  width: 84px; height: 84px; margin-inline: auto;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; border: var(--border) solid var(--ink); background: var(--cream-deep);
}
.person .pname { font-family: "Baloo 2"; font-weight: 800; font-size: 1.3rem; }
.person .edit-btn {
  position: absolute; top: -10px; right: -10px;
  width: 40px; height: 40px; border-radius: 50%;
  border: var(--border) solid var(--ink); background: var(--gold);
  box-shadow: var(--shadow-sm); font-size: 1.1rem; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.person .edit-btn:active { transform: translate(3px,3px); box-shadow: 0 0 0 var(--ink); }

/* Edit sheet (emoji + name) */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(52,48,58,.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  padding: 0; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--cream); width: 100%; max-width: 560px;
  border: var(--border) solid var(--ink); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -6px 0 var(--ink);
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 85dvh; overflow-y: auto;
}
.sheet h2 { font-size: 1.4rem; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; margin: 10px 0 6px;
}
.emoji-grid .ebtn {
  font-size: 1.6rem; padding: 6px 0; line-height: 1;
  border: 3px solid var(--ink); border-radius: 12px; background: var(--white);
  cursor: pointer; text-align: center;
}
.emoji-grid .ebtn.sel { background: var(--gold); box-shadow: var(--shadow-sm); }
.emoji-grid .ebtn:active { transform: translate(2px,2px); }

/* App chooser */
.apps { display: grid; grid-template-columns: 1fr; gap: 16px; }
.app-tile {
  display: block; text-decoration: none; color: var(--ink); position: relative;
  border: var(--border) solid var(--ink); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 20px;
  transition: transform .05s ease, box-shadow .05s ease;
}
.app-tile:active { transform: translate(5px,5px); box-shadow: 0 0 0 var(--ink); }
/* coming-soon placeholder: greyed + non-clickable, matching the Learn subject treatment */
.app-tile.locked { background: var(--cream-deep); color: var(--ink-soft); opacity: .7; cursor: default; pointer-events: none; }
.app-tile.locked .at-desc { color: var(--ink-soft); }
.app-tile.locked:active { transform: none; box-shadow: var(--shadow); }
.app-tile .soon {
  position: absolute; top: -10px; right: -8px;
  background: var(--ink); color: var(--white);
  font-family: "Baloo 2"; font-weight: 800; font-size: .72rem;
  padding: 5px 11px; border-radius: 999px; transform: rotate(8deg);
}
.app-tile .at-emoji { font-size: 2.8rem; }
.app-tile .at-name { font-family: "Baloo 2"; font-weight: 800; font-size: 1.6rem; margin-top: 4px; }
.app-tile .at-desc { color: var(--ink-soft); font-size: .95rem; }
.app-tile.learn { background: var(--coral); color: var(--white); }
.app-tile.learn .at-desc { color: rgba(255,255,255,.9); }
.app-tile.games { background: var(--teal); color: var(--white); }
.app-tile.games .at-desc { color: rgba(255,255,255,.9); }
