/* styles.css — Kid-first design system.
   CSS custom properties make theming a one-line change.
   All interactive targets ≥ 64px. WCAG AAA contrast on text. */

/* ─── Fonts ────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

/* ─── Custom properties ────────────────────────────────────────────────── */
:root {
  --col-primary:  #FFB84D;
  --col-sky:      #4DB8FF;
  --col-leaf:     #7FD67F;
  --col-cream:    #FFF8E7;
  --col-ink:      #2F2A24;
  --col-ink-soft: #6B5E4E;
  --col-rose:     #FF8FA3;
  --col-lavender: #C8A8FF;
  --col-sun:      #FFE066;
  --col-danger:   #FF4D4D;

  --radius:       16px;
  --radius-sm:    10px;
  --radius-pill:  999px;

  --transition:   250ms cubic-bezier(0.2, 0.8, 0.2, 1);
  --shadow:       0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.18);

  --font-body:    'Fredoka', 'Baloo 2', 'Arial Rounded MT Bold', Arial, sans-serif;
  --font-size:    clamp(18px, 2.2vw, 24px);
  --font-size-sm: clamp(14px, 1.6vw, 18px);
  --font-size-lg: clamp(28px, 4vw, 48px);
  --font-size-xl: clamp(40px, 7vw, 80px);
}

/* ─── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  /* Prevent accidental pinch-zoom double-tap on tablets */
  touch-action: manipulation;
}

body {
  min-height: 100%;
  background: var(--col-cream);
  color: var(--col-ink);
  font-family: var(--font-body);
  font-size: var(--font-size);
  line-height: 1.4;
  /* Prevent rubber-band scroll during puzzle drag */
  overflow: hidden;
}

/* Dyslexia font override */
body.dys-font {
  --font-body: 'OpenDyslexic', 'Lexend', 'Comic Sans MS', sans-serif;
}

/* Left-handed mode flips tray to left */
body.lefty #puzzle-area {
  flex-direction: row-reverse;
}

/* ─── App shell ────────────────────────────────────────────────────────── */
#app {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

/* ─── Screen transition system ─────────────────────────────────────────── */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen--active {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Enter: slide up from below */
.screen--enter {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform: translateY(28px);
  opacity: 0;
}
.screen--active.screen--enter {
  transform: translateY(0);
  opacity: 1;
  transition: transform var(--transition), opacity var(--transition);
}

/* Exit: fade and slide up */
.screen--exiting {
  transform: translateY(-16px);
  opacity: 0;
  transition: transform var(--transition), opacity var(--transition);
  pointer-events: none;
}

/* ─── Page layout wrapper ───────────────────────────────────────────────── */
.page-content {
  width: 100%;
  max-width: 960px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  margin: auto;
}

/* Vertically centre the splash on tall screens. */
.splash-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: inherit;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  /* Stay anchored when the page scrolls on small screens. */
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--col-bg, #FFFDF5);
  padding: 8px 0;
}

.page-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--col-ink);
  flex: 1;
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 64px;
  min-height: 64px;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-pill);
  font-family: var(--font-body);
  font-size: var(--font-size);
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:focus-visible {
  outline: 4px solid var(--col-primary);
  outline-offset: 3px;
}

.btn:active { transform: scale(0.96); }

.btn--primary {
  background: var(--col-primary);
  color: var(--col-ink);
  box-shadow: 0 4px 12px rgba(255,184,77,0.4);
}
.btn--primary:hover { background: #FFA030; box-shadow: 0 6px 18px rgba(255,184,77,0.5); }

.btn--secondary {
  background: var(--col-sky);
  color: white;
  box-shadow: 0 4px 12px rgba(77,184,255,0.4);
}
.btn--secondary:hover { background: #2A9FE0; }

.btn--ghost {
  background: transparent;
  color: var(--col-ink-soft);
  border: 2.5px solid var(--col-ink-soft);
}
.btn--ghost:hover { background: rgba(0,0,0,0.06); }

.btn--back {
  background: transparent;
  color: var(--col-ink-soft);
  font-size: var(--font-size-sm);
  min-width: 64px;
  min-height: 64px;
  padding: 12px 16px;
  border: 2px solid #DDD;
  border-radius: var(--radius);
}

.btn--danger {
  background: var(--col-danger);
  color: white;
  border-radius: var(--radius-pill);
  padding: 14px 28px;
  font-family: var(--font-body);
  font-size: var(--font-size);
  font-weight: 700;
  border: none;
  cursor: pointer;
}

/* ─── Splash screen ─────────────────────────────────────────────────────── */
#screen-splash {
  background: linear-gradient(135deg, #FFE8B0, #FFF0F5, #E8F5FF);
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
  padding: 40px 24px;
}

.splash-logo {
  font-size: clamp(80px, 15vw, 140px);
  line-height: 1;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,0.15));
}

.splash-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--col-ink);
  text-shadow: 2px 3px 0 rgba(255,184,77,0.5);
}

.splash-sub {
  font-size: var(--font-size-lg);
  color: var(--col-ink-soft);
}

.splash-start {
  font-size: clamp(22px, 3.5vw, 36px);
  padding: 20px 56px;
  min-height: 72px;
}

/* ─── Age picker ────────────────────────────────────────────────────────── */
.age-grid {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.age-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  min-height: 180px;
  padding: 24px 20px;
  background: white;
  border: 3px solid #EEE;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-body);
  transition: border-color 150ms, box-shadow 150ms, transform 120ms;
  box-shadow: var(--shadow);
}

.age-btn:hover, .age-btn:focus-visible {
  border-color: var(--col-primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
  outline: none;
}

.age-btn--selected { border-color: var(--col-primary); background: #FFF8E7; }

.age-emoji  { font-size: 56px; line-height: 1; }
.age-label  { font-size: var(--font-size-lg); font-weight: 700; color: var(--col-ink); }
.age-range  { font-size: var(--font-size-sm); color: var(--col-ink-soft); }

.settings-gear {
  margin-top: 8px;
  font-size: var(--font-size-sm);
  min-height: 52px;
}

/* ─── Category grid ─────────────────────────────────────────────────────── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  width: 100%;
}

.category-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 160px;
  border-radius: var(--radius);
  background: white;
  border: 3px solid var(--accent, #EEE);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform 120ms, box-shadow 120ms;
  padding: 20px;
}

.category-card:hover, .category-card:focus-visible {
  transform: translateY(-4px) scale(1.03);
  box-shadow: var(--shadow-lg);
  outline: none;
}

.category-emoji { font-size: 56px; line-height: 1; }
.category-label { font-size: var(--font-size); font-weight: 700; color: var(--col-ink); }

/* ─── Image picker ──────────────────────────────────────────────────────── */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 20px;
  width: 100%;
}

.image-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: white;
  border: 3px solid #EEE;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform 120ms, box-shadow 120ms, border-color 120ms;
}

.image-card:hover, .image-card:focus-visible {
  border-color: var(--col-primary);
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  outline: none;
}

.image-thumb img {
  width: 160px;
  height: 160px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  display: block;
}

.image-label {
  font-size: var(--font-size);
  font-weight: 700;
  color: var(--col-ink);
}

.image-stars { display: flex; gap: 4px; }
.star        { font-size: 20px; filter: grayscale(1) opacity(0.3); }
.star--earned { filter: none; }

/* ─── Difficulty picker ─────────────────────────────────────────────────── */
.diff-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
}

.diff-btn {
  min-width: 160px;
  min-height: 80px;
  background: var(--col-sky);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: var(--font-size-lg);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 120ms, background 120ms;
}

.diff-btn:hover, .diff-btn:focus-visible {
  background: #2A9FE0;
  transform: translateY(-3px);
  outline: 4px solid var(--col-primary);
  outline-offset: 3px;
}

/* ─── Game screen ───────────────────────────────────────────────────────── */
#screen-game {
  background: #EDE8DA;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: white;
  border-bottom: 2px solid #DDD0B0;
  width: 100%;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  min-height: 52px;
  padding: 10px 16px;
  background: var(--col-cream);
  border: 2px solid #DDD;
  border-radius: var(--radius);
  font-size: var(--font-size);
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 120ms, border-color 120ms;
}

.hud-btn:hover, .hud-btn:focus-visible {
  background: #FFE8B0;
  border-color: var(--col-primary);
  outline: none;
}

.hud-btn[aria-pressed="true"] {
  background: var(--col-primary);
  border-color: #E07000;
}

.hud-progress {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 120px;
}

.progress-bar {
  width: 100%;
  height: 16px;
  background: #EEE;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--col-leaf), #4CAF50);
  border-radius: var(--radius-pill);
  transition: width 300ms ease;
}

.progress-text {
  font-size: var(--font-size-sm);
  color: var(--col-ink-soft);
  font-weight: 600;
}

.puzzle-area {
  flex: 1;
  width: 100%;
  position: relative;
  display: flex;
  overflow: hidden;
}

#puzzle-canvas {
  flex: 1;
  display: block;
  cursor: grab;
  touch-action: none; /* prevent browser scroll from cancelling pointer capture */
}
#puzzle-canvas:active { cursor: grabbing; }

#particle-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.preview-panel {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: white;
  border: 3px solid var(--col-primary);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.preview-panel img {
  display: block;
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

/* ─── Modal ─────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(47,42,36,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.modal[hidden] { display: none; }

.modal-box {
  background: white;
  border-radius: var(--radius);
  padding: 36px 40px;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 24px;
  font-size: var(--font-size-lg);
}

.modal-btns {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ─── Celebrate screen ──────────────────────────────────────────────────── */
#screen-celebrate {
  background: linear-gradient(135deg, #FFF0F5, #E8F5FF, #FFF8E7);
}

.celebrate-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 40px 24px;
  text-align: center;
}

.celebrate-emoji { font-size: clamp(80px, 15vw, 120px); line-height: 1; }
.celebrate-title { font-size: var(--font-size-xl); font-weight: 700; color: var(--col-ink); }

.celebrate-stars { display: flex; gap: 12px; }
.cel-star        { font-size: 52px; filter: grayscale(1) opacity(0.25); }
.cel-star--earned { filter: none; }

.celebrate-msg   { font-size: var(--font-size-lg); color: var(--col-ink-soft); }

.celebrate-btns {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.celebrate-share {
  min-width: 52px;
  min-height: 52px;
  padding: 12px;
  font-size: var(--font-size-sm);
  opacity: 0.55;
}

.celebrate-stickers {
  font-size: var(--font-size);
}

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

.sticker-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 8px;
  background: white;
  border: 3px solid #EEE;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 120ms;
  min-height: 120px;
}

.sticker-item:focus-visible { outline: 4px solid var(--col-primary); outline-offset: 3px; }
.sticker-item--earned { border-color: var(--col-sun); background: #FFFBEE; }
.sticker-item--earned:hover { transform: scale(1.06); }

.sticker-lock { font-size: 40px; opacity: 0.3; }
.sticker-lbl  { font-size: var(--font-size-sm); color: var(--col-ink); font-weight: 600; text-align: center; }

/* ─── Settings ───────────────────────────────────────────────────────────── */
.settings-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 560px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  font-size: var(--font-size);
  flex-wrap: wrap;
}

.setting-row input[type="range"] { flex: 1; min-width: 120px; accent-color: var(--col-primary); }
.setting-row input[type="checkbox"] { width: 28px; height: 28px; accent-color: var(--col-primary); cursor: pointer; }
.setting-row input[type="text"] {
  flex: 1;
  border: 2px solid #DDD;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
}
.setting-row select {
  border: 2px solid #DDD;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-family: var(--font-body);
  font-size: var(--font-size-sm);
  background: white;
  cursor: pointer;
}

.setting-row--btn { gap: 12px; justify-content: flex-start; background: transparent; box-shadow: none; padding: 0; }
.setting-hint { font-size: var(--font-size-sm); color: var(--col-ink-soft); }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--col-ink);
  color: white;
  padding: 14px 28px;
  border-radius: var(--radius-pill);
  font-size: var(--font-size);
  font-family: var(--font-body);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 300ms, transform 300ms;
  z-index: 200;
  white-space: nowrap;
  pointer-events: none;
}

.toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Focus ring ─────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 4px solid var(--col-primary);
  outline-offset: 3px;
}

/* ─── Brand link ─────────────────────────────────────────────────────────── */
.brand-link {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 20px;
  background: transparent;
  border: 2px solid var(--col-primary);
  border-radius: var(--radius-pill);
  color: var(--col-ink);
  font-family: var(--font-body);
  font-size: var(--font-size-sm, 14px);
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.03em;
  transition: background 150ms, color 150ms;
}
.brand-link:hover, .brand-link:focus-visible {
  background: var(--col-primary);
  color: #fff;
  outline: none;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .age-btn     { min-width: 140px; min-height: 140px; }
  .age-emoji   { font-size: 44px; }
  .category-grid { grid-template-columns: repeat(2, 1fr); }
  .image-grid    { grid-template-columns: repeat(2, 1fr); }
  .image-thumb img { width: 130px; height: 130px; }
  .modal-box   { padding: 24px 20px; }
  .preview-panel { bottom: 8px; right: 8px; }
  .preview-panel img { width: 100px; height: 100px; }

  /* HUD portrait: progress bar on its own row so all buttons fit. */
  .hud {
    gap: 8px;
    padding: 6px 10px;
  }
  .hud-progress {
    order: -1;
    flex: 1 1 100%;
  }
  .hud-btn {
    min-width: 48px;
    min-height: 44px;
    padding: 6px 8px;
    font-size: 16px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .page-content { padding: 12px 16px; gap: 12px; }
  .page-title   { font-size: clamp(20px, 4vw, 32px); }
  .age-btn      { min-height: 110px; }
}
