:root {
  --sky: #4DB8FF;
  --sun: #FFE066;
  --leaf: #7FD67F;
  --coral: #FF8FA3;
  --plum: #8A6CFF;
  --teal: #3CC9B0;
  --orange: #FFB84D;
  --cream: #FFF8E7;
  --snow: #FFFFFF;
  --ink: #2F2A24;
  --ink-soft: #6B5E4E;
  --radius: 26px;
  --radius-sm: 16px;
  --shadow: 0 10px 26px rgba(47, 42, 36, 0.16);
  --touch: 64px;
  font-family: 'Nunito', 'Segoe UI', 'Trebuchet MS', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background: linear-gradient(160deg, #eafaff 0%, #fff7ea 55%, #fdeef6 100%);
}

body {
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.game-site-header {
  position: sticky;
  top: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(77, 184, 255, 0.22);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(47, 42, 36, 0.08);
}

.game-site-brand,
.game-site-nav {
  display: inline-flex;
  align-items: center;
}

.game-site-brand {
  gap: 10px;
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.game-site-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: linear-gradient(135deg, var(--sun), var(--sky));
  font-family: 'Fredoka', 'Nunito', sans-serif;
}

.game-site-nav {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.game-site-nav a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(77, 184, 255, 0.14);
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.game-site-nav a:hover,
.game-site-nav a:focus-visible {
  background: rgba(77, 184, 255, 0.28);
  outline: 3px solid rgba(77, 184, 255, 0.34);
  outline-offset: 2px;
}

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

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--snow);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 100;
}
.skip-link:focus { left: 8px; }

#particles {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 60;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 28px);
  min-height: calc(100vh - 64px);
}

h1, h2, h3 { font-family: 'Fredoka', 'Nunito', sans-serif; font-weight: 700; margin: 0; }

button { font-family: inherit; cursor: pointer; }

/* ---------- Buttons ---------- */
.big-button {
  min-height: var(--touch);
  border: none;
  border-radius: var(--radius);
  padding: 14px 26px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--snow);
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.big-button:active { transform: scale(0.95); }
.big-button.primary { background: var(--sky); color: var(--snow); }
.big-button.secondary { background: var(--sun); }
.big-button.ghost { background: rgba(255, 255, 255, 0.75); }
.big-button.danger { color: #c0392b; }

.icon-button {
  min-width: var(--touch);
  min-height: var(--touch);
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  background: var(--snow);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}
.icon-button:active { transform: scale(0.92); }

/* ---------- Top bars ---------- */
.top-bar, .play-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.top-bar h2 { flex: 1; text-align: center; font-size: 1.5rem; }
.top-spacer { min-width: var(--touch); }

/* ---------- Home ---------- */
.home-header {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
  text-align: center;
  margin-top: 8px;
}
.home-title h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); color: var(--ink); }
.home-title p { color: var(--ink-soft); margin: 6px 0 0; font-size: 1.05rem; }
.home-stars {
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  margin: 14px 0;
}
.home-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 10px 0 22px;
}
.daily-card {
  background: linear-gradient(135deg, var(--plum), var(--sky));
  color: var(--snow);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}
.daily-card.done { background: linear-gradient(135deg, var(--leaf), var(--teal)); }
.daily-card h2 { font-size: 1.4rem; margin: 6px 0; }
.daily-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  padding: 4px 14px;
  font-weight: 700;
  font-size: 0.85rem;
}
.daily-card .big-button { margin-top: 12px; }

/* ---------- Mode select ---------- */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}
.mode-card {
  border: none;
  border-radius: var(--radius);
  padding: 22px 16px;
  color: var(--snow);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  text-align: center;
  min-height: 160px;
  transition: transform 0.14s ease;
}
.mode-card:active { transform: scale(0.96); }
.mode-emoji { font-size: 2.6rem; }
.mode-name { font-size: 1.2rem; font-weight: 800; }
.mode-blurb { font-size: 0.9rem; opacity: 0.95; }

.tone-sky { background: linear-gradient(135deg, #4DB8FF, #6ED0FF); }
.tone-plum { background: linear-gradient(135deg, #8A6CFF, #A98CFF); }
.tone-leaf { background: linear-gradient(135deg, #6BC96B, #9BE29B); color: var(--ink); }
.tone-orange { background: linear-gradient(135deg, #FFB84D, #FFD08A); color: var(--ink); }
.tone-coral { background: linear-gradient(135deg, #FF8FA3, #FFB0C0); color: var(--ink); }
.tone-teal { background: linear-gradient(135deg, #3CC9B0, #6FE0CC); }

/* ---------- Level select ---------- */
.tier-block { margin-bottom: 20px; }
.tier-heading { font-size: 1.15rem; margin-bottom: 10px; color: var(--ink-soft); }
.level-chips { display: flex; flex-wrap: wrap; gap: 12px; }
.level-chip {
  min-width: 76px;
  min-height: 76px;
  border: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-sm);
  color: var(--snow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: var(--shadow);
}
.level-chip .chip-number { font-size: 1.4rem; font-weight: 800; }
.level-chip .chip-stars { font-size: 0.75rem; min-height: 1em; }
.level-chip.done { border-color: var(--sun); }

/* ---------- Play ---------- */
.play-prompt {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  margin: 4px 0 16px;
  color: var(--ink);
}
.progress-pips { flex: 1; display: flex; gap: 8px; justify-content: center; }
.pip {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(47, 42, 36, 0.18);
}
.pip.filled { background: var(--leaf); }
.play-controls { display: flex; gap: 10px; }

.mode-mount {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.play-board {
  position: relative;
  background: rgba(255, 255, 255, 0.55);
  border-radius: var(--radius);
  min-height: 320px;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.6);
  overflow: hidden;
}
.play-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  padding: 12px;
  background: rgba(255, 255, 255, 0.4);
  border-radius: var(--radius);
  min-height: 96px;
}
.mode-mount.lefty { direction: rtl; }
.mode-mount.lefty .play-tray, .mode-mount.lefty .play-board { direction: ltr; }

.shape-piece {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  display: inline-flex;
  transition: transform 0.12s ease;
}
.shape-piece svg { pointer-events: none; }
.shape-piece.dragging { cursor: grabbing; transition: none; }
.shape-piece.selected { outline: 4px dashed var(--plum); outline-offset: 4px; border-radius: 12px; }
.shape-piece.returning { transition: transform 0.3s ease; }

/* Shape Match board slots */
.shape-slot, .shadow-slot {
  position: absolute;
  width: clamp(92px, 15vw, 132px);
  height: clamp(92px, 15vw, 132px);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 4px;
}
.shape-slot > svg,
.shadow-slot > svg {
  max-width: 100%;
  max-height: 100%;
}
.shape-slot.drop-near, .shadow-slot.drop-near,
.basket.drop-near, .build-slot.drop-near {
  background: rgba(127, 214, 127, 0.35);
  box-shadow: 0 0 0 4px rgba(127, 214, 127, 0.6);
}
.shape-slot.filled, .shadow-slot.filled { opacity: 1; }

.shadow-board { min-height: 340px; }

/* Sorting */
.sorting-board {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  justify-content: center;
  padding: 20px 12px;
}
.basket {
  min-width: 120px;
  min-height: 130px;
  background: linear-gradient(160deg, var(--orange), #e79a2e);
  border-radius: 18px 18px 26px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 10px;
  color: var(--snow);
  box-shadow: var(--shadow);
}
.basket-label { font-weight: 800; }
.basket-count { font-weight: 700; min-height: 1em; }

/* Build */
.build-board { min-height: 380px; }
.build-slot {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(47, 42, 36, 0.25);
  border-radius: 8px;
}
.build-slot.filled { border-color: transparent; }
.build-slot svg { display: block; }
.build-piece { width: 76px; height: 76px; }
.build-piece svg { width: 100%; height: 100%; }

/* Pattern */
.pattern-board {
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.pattern-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.pattern-cell {
  width: 84px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 16px;
}
.pattern-gap {
  border: 3px dashed var(--plum);
  background: rgba(138, 108, 255, 0.12);
}
.pattern-question { font-size: 2.4rem; font-weight: 800; color: var(--plum); }
.pattern-choices { align-items: center; }
.pattern-choice {
  min-width: 92px;
  min-height: 92px;
  border: none;
  border-radius: 18px;
  background: var(--snow);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}
.pattern-choice:active { transform: scale(0.94); }
.pattern-choices.disabled { pointer-events: none; opacity: 0.7; }

/* Memory */
.memory-board {
  display: grid;
  gap: 12px;
  padding: 16px;
  justify-content: center;
}
.memory-card {
  width: clamp(64px, 18vw, 96px);
  aspect-ratio: 1;
  border: none;
  background: transparent;
  perspective: 600px;
  padding: 0;
}
.memory-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s ease;
  transform-style: preserve-3d;
}
.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner { transform: rotateY(180deg); }
.memory-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.memory-back {
  background: linear-gradient(135deg, var(--teal), var(--sky));
  color: var(--snow);
  font-size: 2rem;
  font-weight: 800;
}
.memory-front { background: var(--snow); transform: rotateY(180deg); }
.memory-card.matched { opacity: 0.75; }

/* ---------- Celebrate ---------- */
.screen-celebrate { display: flex; align-items: center; justify-content: center; min-height: 80vh; }
.celebrate-card {
  background: var(--snow);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 460px;
  width: 100%;
}
.celebrate-card h2 { font-size: 2rem; margin: 8px 0; }
.celebrate-stars { display: flex; justify-content: center; gap: 12px; margin: 10px 0; }
.big-star { font-size: 3rem; color: rgba(47, 42, 36, 0.15); }
.big-star.earned { color: var(--sun); }
.reward-banner {
  background: var(--sun);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 800;
  display: inline-block;
  margin: 12px 0 6px;
}
.reward-row { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.reward-sticker { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 0.85rem; font-weight: 700; }
.celebrate-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }

/* ---------- Sticker book ---------- */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.sticker-cell {
  border: none;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}
.sticker-cell.locked { filter: grayscale(1) opacity(0.5); }

/* ---------- Settings ---------- */
.settings-list { display: flex; flex-direction: column; gap: 12px; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-size: 1.1rem;
  font-weight: 700;
}
.settings-row input { width: 28px; height: 28px; }

/* ---------- Parent overlay ---------- */
.parent-overlay {
  position: fixed;
  inset: 0;
  background: rgba(47, 42, 36, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 16px;
}
.parent-panel {
  background: var(--snow);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.parent-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.parent-note { color: var(--ink-soft); }
.parent-error { color: #c0392b; min-height: 1.2em; font-weight: 700; }
.parent-pin {
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.5em;
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--sky);
  margin-bottom: 8px;
}
.parent-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 10px; margin-bottom: 16px; }
.parent-stats .stat { background: rgba(77, 184, 255, 0.14); border-radius: 14px; padding: 12px 6px; text-align: center; }
.parent-stats .stat span { display: block; font-size: 1.6rem; font-weight: 800; }
.parent-stats .stat label { font-size: 0.75rem; color: var(--ink-soft); }
.parent-mode-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.parent-mode-row { display: flex; justify-content: space-between; padding: 8px 12px; background: rgba(255, 255, 255, 0.6); border-radius: 12px; }
.parent-panel h3 { margin: 14px 0 8px; }
.parent-panel .big-button { width: 100%; margin-top: 12px; }

/* ---------- Hints ---------- */
.hint-arrow {
  position: fixed;
  z-index: 70;
  pointer-events: none;
}

@media (max-width: 520px) {
  .game-site-header {
    align-items: flex-start;
    flex-direction: column;
  }
  .game-site-nav {
    width: 100%;
    justify-content: flex-start;
  }
  .home-actions { grid-template-columns: 1fr 1fr; }
  .play-board { min-height: 280px; }
  .pattern-cell { width: 64px; height: 64px; }
}
