:root {
  --blue: #5B8DEF;
  --orange: #E8734A;
  --teal: #3FA796;
  --bg: #fef9f3;
  --ink: #33314a;
  --card: #ffffff;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  --radius: 22px;
  --accent: var(--blue);
}

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

html, body {
  margin: 0;
  height: 100%;
  font-family: "Baloo 2", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
}

#app {
  position: relative;
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 20px;
  animation: fade .35s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.center { justify-content: center; align-items: center; text-align: center; gap: 18px; }

h1.logo { font-size: 2.6rem; margin: 0; letter-spacing: 1px; }
h1.logo .emoji { display: inline-block; animation: bounce 1.6s infinite; }
@keyframes bounce { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-10px)} }

.subtitle { opacity: .7; margin: 0; }

/* ---------- Buttons & forms ---------- */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

.btn {
  background: var(--accent);
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 16px 26px;
  box-shadow: var(--shadow);
  transition: transform .12s;
}
.btn:active { transform: scale(.95); }
.btn.secondary { background: #fff; color: var(--ink); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--ink); opacity: .8; font-weight: 600; }

.btn-huge {
  width: 120px; height: 120px; border-radius: 50%;
  font-size: 3.2rem; display: grid; place-items: center;
  background: var(--accent); color: #fff; box-shadow: var(--shadow);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.06)} }

input {
  font-family: inherit; font-size: 1.05rem;
  padding: 14px 16px; border: 2px solid #e7e0d8; border-radius: 16px;
  width: 100%; background: #fff; outline: none;
}
input:focus { border-color: var(--accent); }

form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 340px; }
.field-label { text-align: left; font-size: .85rem; opacity: .7; margin: 4px 0 -6px 6px; }
.error-msg { color: var(--orange); font-weight: 600; min-height: 1.2em; }

.link { color: var(--accent); font-weight: 700; cursor: pointer; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.topbar .back { font-size: 1.6rem; background: #fff; border-radius: 50%; width: 46px; height: 46px; box-shadow: var(--shadow); }
.topbar .who { font-size: 1.8rem; }
.topbar .spacer { flex: 1; }

/* ---------- Profile grid ---------- */
.grid { display: grid; gap: 16px; width: 100%; }
.grid.profiles { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

.profile-card, .game-card, .avatar-pick {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; padding: 18px 8px;
  transition: transform .12s;
}
.profile-card:active, .game-card:active, .avatar-pick:active { transform: scale(.94); }
.profile-card .face, .game-card .face { font-size: 3rem; }
.profile-card .name { font-weight: 700; font-size: 1rem; }
.game-card { border-bottom: 6px solid var(--accent); }
.game-card .label { font-size: .8rem; opacity: .7; text-align: center; }
.game-card .diff { font-size: .7rem; letter-spacing: 1px; line-height: 1; }

.avatar-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; max-width: 340px; }
.avatar-pick { font-size: 2rem; padding: 10px; }
.avatar-pick.selected { outline: 4px solid var(--accent); }

/* ---------- Game HUD ---------- */
.game-screen { padding: 0; background: var(--bg); }
.hud { padding: 14px 18px 6px; display: flex; align-items: center; gap: 10px; position: relative; }
.hearts { font-size: 1.5rem; letter-spacing: 2px; }
.hearts .lost { filter: grayscale(1); opacity: .35; }
.hud .score { margin-left: auto; font-weight: 800; font-size: 1.3rem; transform-origin: right center; }
.hud .score.bump { animation: scorePop .5s ease; }
.hud .level {
  font-weight: 800; font-size: 1.05rem; background: #fff; padding: 4px 12px;
  border-radius: 999px; box-shadow: var(--shadow);
}
.hud .level.bump { animation: scorePop .5s ease; }
@keyframes scorePop {
  0% { transform: scale(1); color: var(--ink); }
  40% { transform: scale(1.45); color: var(--accent); }
  100% { transform: scale(1); color: var(--ink); }
}
.score-pop {
  position: absolute; right: 18px; top: 6px; font-weight: 800; font-size: 1.1rem;
  color: var(--accent); pointer-events: none; animation: floatUp .8s ease-out forwards;
}
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-28px); } }
.timer-track { height: 12px; background: #eadfd3; border-radius: 8px; margin: 4px 18px 0; overflow: hidden; }
.timer-bar { height: 100%; width: 100%; background: var(--accent); border-radius: 8px; transition: width .1s linear; }

#stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; position: relative; }

/* ---------- Choice activity ---------- */
.activity { display: flex; flex-direction: column; align-items: center; gap: 26px; width: 100%; }
.stimulus { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center;
  background: #fff; padding: 14px 18px; border-radius: var(--radius); box-shadow: var(--shadow); }
.token { font-size: 2.6rem; line-height: 1; }
.stimulus .token { font-size: 2.4rem; }

.options { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; }
.option {
  position: relative;
  font-size: 3rem; width: 96px; height: 96px; display: grid; place-items: center;
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .12s, background .2s, outline-color .12s;
}
.option .num {
  position: absolute; top: 5px; left: 9px; font-size: .85rem; font-weight: 800;
  line-height: 1; opacity: .4; color: var(--ink);
}
.option .glyph { font-size: 3rem; line-height: 1; }
.option:active { transform: scale(.92); }
.option.selected { outline: 4px solid var(--accent); transform: scale(1.04); }
.option.selected .num { opacity: .9; color: var(--accent); }
.option.correct { background: #b8f0c8; animation: pop .4s; }
.option.wrong { background: #ffc2b8; animation: shake .4s; }
.option.hint { outline: 5px solid var(--accent); transform: scale(1.05); }

/* Group options (counting game): several small symbols in one button. */
.option.multi { width: 118px; }
.option.multi .glyph {
  font-size: 1.5rem; line-height: 1.35; word-break: break-all;
  text-align: center; max-width: 98px;
}

/* Memory game: "look!" cue shown while the items can still be studied. */
.peek-eyes { font-size: 2.2rem; animation: pop 1.2s ease-in-out infinite; }

/* ---------- Level up ---------- */
.level-up { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: pop .5s; }
.level-up .rocket { font-size: 4.2rem; line-height: 1; }
.level-up .lvl { font-size: 3.4rem; font-weight: 900; color: var(--accent); line-height: 1; }
.level-up .extra { font-size: 1.3rem; font-weight: 800; opacity: .65; }
.level-line { font-size: 1.3rem; font-weight: 800; opacity: .8; }

/* Simon game: a pad flashing during playback or after a correct tap. */
.option.lit { background: #ffe9a8; outline: 5px solid var(--accent); transform: scale(1.1); }

/* ---------- Memo ---------- */
.memo-grid { display: grid; gap: 12px; }
.memo-card {
  position: relative; width: 84px; height: 84px; display: grid; place-items: center;
  border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .12s, background .2s;
}
.memo-card .num {
  position: absolute; top: 5px; left: 9px; font-size: .85rem; font-weight: 800;
  line-height: 1; opacity: .55; color: #fff;
}
.memo-card .face { font-size: 2.4rem; line-height: 1; }
.memo-card.down { background: var(--accent); }
.memo-card.down .face { opacity: .85; }
.memo-card.up { background: #fff; animation: pop .3s; }
.memo-card.up .num, .memo-card.matched .num { color: var(--ink); opacity: .35; }
.memo-card.matched { background: #b8f0c8; }
.memo-card.wrong { background: #ffc2b8; animation: shake .4s; }
.memo-card:active { transform: scale(.93); }

@keyframes pop { 0%{transform:scale(1)} 50%{transform:scale(1.25)} 100%{transform:scale(1)} }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-8px)} 75%{transform:translateX(8px)} }

.hand { position: absolute; font-size: 2.4rem; pointer-events: none; transition: all .5s ease; z-index: 5; }

/* ---------- Maze ---------- */
.maze-wrap { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.maze {
  display: grid; gap: 0; background: #2c2450; padding: 6px; border-radius: 16px;
  box-shadow: var(--shadow);
}
.maze.bump { animation: shake .3s; }
.cell { width: var(--cs, 26px); height: var(--cs, 26px); display: grid; place-items: center; font-size: calc(var(--cs, 26px) * .78); }
.cell.wall { background: #2c2450; }
.cell.path { background: #f4ecff; }
.cell.exit { background: #fff2b8; }

.dpad { display: grid; grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(3, 64px); gap: 6px; }
.dpad button { font-size: 1.8rem; background: #fff; box-shadow: var(--shadow); border-radius: 16px; }
.dpad button:active { transform: scale(.9); }
.dpad .up { grid-area: 1 / 2; } .dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; } .dpad .down { grid-area: 3 / 2; }

/* ---------- Scrollable page body (trophies, leaderboard) ---------- */
.scroll-area {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  text-align: center; padding: 6px 6px 24px;
  scrollbar-width: thin; scrollbar-color: var(--accent) transparent;
}
.scroll-area::-webkit-scrollbar { width: 8px; }
.scroll-area::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 8px; }
.scroll-area::-webkit-scrollbar-track { background: transparent; }

.bottom-links { margin-top: auto; padding-top: 10px; display: flex; justify-content: center; gap: 6px; }

/* ---------- Leaderboard ---------- */
.rank-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 18px;
}
.rank-row .rank { flex: none; width: 36px; font-size: 1.4rem; font-weight: 800; text-align: center; }
.rank-row .face { font-size: 1.9rem; line-height: 1; }
.rank-row .name { flex: 1; font-weight: 700; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .pts { font-weight: 800; }
.rank-row.me { outline: 4px solid var(--accent); }

/* ---------- Overlays / results ---------- */
.overlay {
  position: absolute; inset: 0; background: rgba(255,255,255,.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; text-align: center; z-index: 20; animation: fade .35s ease; padding: 20px;
}
.big-emoji { font-size: 5rem; animation: bounce 1.4s infinite; }
.big-score { font-size: 3rem; font-weight: 800; }
.stars-row { font-size: 2.4rem; letter-spacing: 6px; }
.ready-emoji { font-size: 4rem; }

/* Falling confetti / celebration */
.fx-piece { position: fixed; top: -40px; font-size: 1.6rem; pointer-events: none; z-index: 999; }
@keyframes fall { to { transform: translateY(110vh) rotate(360deg); opacity: .9; } }

/* Floating sound on/off toggle */
#mute {
  position: fixed; right: 12px; bottom: 12px; z-index: 60;
  width: 46px; height: 46px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow);
  font-size: 1.25rem; display: grid; place-items: center; opacity: .85;
  transition: transform .12s;
}
#mute:active { transform: scale(.88); }

.hidden { display: none !important; }
