/* ============================================================
   Lamora — styles
   Touch-first, child-friendly, accessible, offline-only fonts.
   ============================================================ */

:root {
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 6px 18px rgba(40, 30, 90, 0.12);
  --tap: 64px;                 /* minimum touch target */
  --font-display: "Comic Sans MS", "Chalkboard SE", "Segoe UI Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ink: #2d2a45;
  --ink-soft: #5c5880;
  --paper: #ffffff;
  --speed: 0.25s;
}

/* ---------- colour themes (child selectable) ---------- */
body[data-theme="ocean"]   { --bg1:#d0f0ff; --bg2:#e8fbff; --accent:#0984e3; --accent2:#00cec9; --pop:#ffb703; }
body[data-theme="rainbow"] { --bg1:#ffe8f7; --bg2:#fff7d6; --accent:#e84393; --accent2:#6c5ce7; --pop:#00b894; }
body[data-theme="dragon"]  { --bg1:#ffe3d0; --bg2:#fff3e0; --accent:#d63031; --accent2:#e17055; --pop:#6c5ce7; }
body[data-theme="space"]   { --bg1:#dcd6ff; --bg2:#efeaff; --accent:#6c5ce7; --accent2:#0984e3; --pop:#fdcb6e; }
body[data-theme="nature"]  { --bg1:#d8f5d0; --bg2:#f0fbe8; --accent:#00b894; --accent2:#55a630; --pop:#e17055; }
body[data-theme="dino"]    { --bg1:#e0f0c8; --bg2:#fdf6d8; --accent:#588157; --accent2:#bc6c25; --pop:#0984e3; }

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 60%);
  background-attachment: fixed;
  min-height: 100dvh;
}

/* ---------- accessibility modes ---------- */
html.large-text { font-size: 120%; }
html.high-contrast body { background: #ffffff; }
html.high-contrast .card, html.high-contrast .big-btn { border: 3px solid #1a1a1a !important; box-shadow: none; }
html.high-contrast { --ink: #000; --ink-soft: #222; }
html.reduced-motion *, html.reduced-motion *::before, html.reduced-motion *::after {
  animation-duration: 0.001s !important;
  transition-duration: 0.001s !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 16px; border-radius: 0 0 12px 0;
}
.skip-link:focus { left: 0; }

button:focus-visible, a:focus-visible, [tabindex]:focus-visible, input:focus-visible, select:focus-visible {
  outline: 4px solid var(--pop, #ffb703);
  outline-offset: 2px;
}

/* ---------- layout ---------- */
#app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px calc(28px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

#statusbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; justify-content: center; gap: 10px;
  padding: 6px 10px 0;
  pointer-events: none;
  font-family: var(--font-display);
}
#statusbar .chip {
  pointer-events: auto;
  background: rgba(255,255,255,0.9);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 0.95rem;
  display: none;
  align-items: center; gap: 6px;
  border: none;
}
#statusbar .chip.show { display: inline-flex; }
#statusbar .chip.warn { background: #fff3cd; }

/* ---------- headers ---------- */
.page-head {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0 14px;
}
.page-head h1 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4.5vw, 2.2rem);
  margin: 0; flex: 1;
  color: var(--ink);
}
.icon-btn {
  min-width: var(--tap); min-height: var(--tap);
  border: none; border-radius: 50%;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 1.6rem;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform var(--speed);
}
.icon-btn:active { transform: scale(0.92); }

.page-tip {
  margin: -6px 0 10px;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 1.02rem;
  text-align: center;
}

/* ---------- home & menu grids ---------- */
.hero {
  text-align: center;
  padding: 10px 0 4px;
}
.hero .logo {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 7vw, 3.4rem);
  margin: 0;
  color: var(--accent);
  text-shadow: 2px 3px 0 rgba(255,255,255,0.8);
}
.hero .hello { font-size: 1.15rem; color: var(--ink-soft); margin: 4px 0 0; font-weight: 600; }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 14px 0;
}
@media (min-width: 700px) { .menu-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; } }

.big-btn {
  border: none;
  border-radius: var(--radius);
  min-height: 128px;
  padding: 16px 10px;
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink);
  transition: transform var(--speed), box-shadow var(--speed);
  text-align: center;
}
.big-btn .emoji { font-size: 2.8rem; line-height: 1; }
.big-btn:hover { transform: translateY(-3px); }
.big-btn:active { transform: scale(0.95); }
.big-btn.tint-a { background: linear-gradient(150deg, #fff, var(--bg1)); }
.big-btn.locked { opacity: 0.55; }
.big-btn small { font-family: var(--font-body); font-weight: 500; color: var(--ink-soft); font-size: 0.85rem; }

/* ---------- cards ---------- */
.card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin: 12px 0;
}
.card h2 { font-family: var(--font-display); margin: 0 0 8px; font-size: 1.3rem; }
.card p { line-height: 1.5; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- generic buttons ---------- */
.btn {
  min-height: var(--tap);
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 22px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform var(--speed);
}
.btn:active { transform: scale(0.95); }
.btn.secondary { background: var(--paper); color: var(--ink); }
.btn.soft { background: var(--bg1); color: var(--ink); box-shadow: none; }
.btn.danger { background: #d63031; }
.btn.small { min-height: 44px; padding: 8px 14px; font-size: 0.95rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- quiz ---------- */
.quiz-prompt {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 4vw, 1.9rem);
  text-align: center;
  margin: 10px 0 6px;
  min-height: 2.2em;
}
.quiz-visual { text-align: center; font-size: clamp(2rem, 8vw, 3.4rem); line-height: 1.35; margin: 6px 0; word-break: break-word; }
.quiz-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 14px;
}
.quiz-options.two { grid-template-columns: repeat(2, minmax(120px, 1fr)); max-width: 560px; margin-left: auto; margin-right: auto; }
.option-btn {
  min-height: 84px;
  border: 4px solid transparent;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: transform var(--speed);
  padding: 10px;
}
.option-btn:active { transform: scale(0.94); }
.option-btn.correct { border-color: #00b894; background: #e6fff5; }
.option-btn.wrong { border-color: #fdcb6e; background: #fff8e6; animation: wobble 0.4s; }
.option-btn.reveal { border-color: #00b894; box-shadow: 0 0 0 4px rgba(0,184,148,0.3); }
@keyframes wobble { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.hint-box {
  text-align: center;
  font-size: 1.05rem;
  color: var(--ink-soft);
  min-height: 1.6em;
  margin-top: 10px;
  font-weight: 600;
}
.progress-dots { display: flex; gap: 8px; justify-content: center; margin: 8px 0; flex-wrap: wrap; }
.progress-dots .dot { width: 14px; height: 14px; border-radius: 50%; background: rgba(0,0,0,0.12); }
.progress-dots .dot.done { background: var(--accent2); }
.progress-dots .dot.now { background: var(--pop); transform: scale(1.25); }

/* ---------- memory cards ---------- */
.mem-grid { display: grid; gap: 10px; margin: 14px auto; max-width: 640px; }
.mem-card {
  aspect-ratio: 3/3.4;
  border: none; border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow);
  transition: transform var(--speed);
  display: flex; align-items: center; justify-content: center;
}
.mem-card.up { background: var(--paper); }
.mem-card.matched { background: #e6fff5; border: 3px solid #00b894; cursor: default; }
.mem-card:active { transform: scale(0.94); }
.mem-card .back-icon { font-size: 1.4rem; opacity: 0.9; }

/* ---------- simon ---------- */
.simon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; max-width: 420px; margin: 16px auto; }
.simon-pad {
  aspect-ratio: 1; border: none; border-radius: var(--radius);
  cursor: pointer; box-shadow: var(--shadow); opacity: 0.75;
  font-size: 2rem;
  transition: opacity 0.15s, transform 0.15s;
}
.simon-pad.lit { opacity: 1; transform: scale(1.05); box-shadow: 0 0 0 6px rgba(255,255,255,0.7), var(--shadow); }

/* ---------- chess ---------- */
.chess-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(92vw, 520px);
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}
.chess-sq {
  border: none; padding: 0; margin: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(1.4rem, 8vw, 2.6rem);
  cursor: pointer;
  position: relative;
  line-height: 1;
}
.chess-sq.light { background: #f5e8c8; }
.chess-sq.dark { background: #8fb573; }
.chess-sq.sel { box-shadow: inset 0 0 0 5px #fdcb6e; }
.chess-sq.move::after {
  content: ""; position: absolute; width: 26%; height: 26%;
  border-radius: 50%; background: rgba(30,60,150,0.45);
}
.chess-sq.cap { box-shadow: inset 0 0 0 5px #d63031; }
.chess-sq.hintsq { box-shadow: inset 0 0 0 5px #6c5ce7; }
.chess-msg { font-family: var(--font-display); font-size: 1.15rem; text-align: center; min-height: 1.6em; font-weight: 700; }

/* ---------- drawing / colouring ---------- */
.tool-bar {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  background: var(--paper);
  padding: 10px; border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 10px 0;
}
.tool-btn {
  min-width: 52px; min-height: 52px;
  border-radius: var(--radius-sm);
  border: 3px solid transparent;
  background: var(--bg2);
  font-size: 1.4rem;
  cursor: pointer;
}
.tool-btn.on { border-color: var(--accent); background: #fff; }
.swatch {
  width: 44px; height: 44px; min-width: 44px;
  border-radius: 50%;
  border: 3px solid rgba(0,0,0,0.15);
  cursor: pointer; padding: 0;
}
.swatch.on { border-color: var(--ink); box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--accent); }
.draw-canvas-wrap { display: flex; justify-content: center; }
canvas.draw-surface {
  background: #fff;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  touch-action: none;
  max-width: 100%;
}
.colour-svg-wrap { display: flex; justify-content: center; }
.colour-svg-wrap svg {
  width: min(92vw, 560px); height: auto;
  background: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow);
  touch-action: manipulation;
}
.colour-svg-wrap svg [data-fill] { cursor: pointer; }

/* ---------- sticker book ---------- */
.sticker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px; margin-top: 12px;
}
.sticker-cell {
  aspect-ratio: 1; border-radius: var(--radius-sm);
  background: var(--paper); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem; border: none; cursor: pointer;
}
.sticker-cell.locked { filter: grayscale(1); opacity: 0.35; }
.scene-stage {
  position: relative; width: min(92vw, 640px); height: min(60vw, 420px);
  margin: 12px auto; border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; touch-action: none;
}
.scene-stage .placed { position: absolute; font-size: 2.6rem; cursor: grab; user-select: none; line-height: 1; transform: translate(-50%,-50%); }

/* ---------- parent zone ---------- */
.pin-pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; justify-content: center; margin: 16px 0; }
.pin-key {
  width: 76px; height: 76px; border-radius: 50%; border: none;
  background: var(--paper); box-shadow: var(--shadow);
  font-size: 1.6rem; font-weight: 700; cursor: pointer; font-family: var(--font-display);
}
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 10px 0; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,0.15); }
.pin-dots span.filled { background: var(--accent); }

.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid rgba(0,0,0,0.07);
  flex-wrap: wrap;
}
.setting-row:last-child { border-bottom: none; }
.setting-row label:first-child, .setting-row .lbl { font-weight: 600; }
.setting-row select, .setting-row input[type="number"], .setting-row input[type="text"] {
  min-height: 48px; border-radius: 12px; border: 2px solid rgba(0,0,0,0.15);
  font-size: 1rem; padding: 6px 12px; background: #fff; color: var(--ink);
  max-width: 100%;
}
.toggle {
  position: relative; width: 64px; height: 36px; border-radius: 999px;
  border: none; background: rgba(0,0,0,0.2); cursor: pointer; transition: background var(--speed);
  flex-shrink: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px;
  border-radius: 50%; background: #fff; transition: left var(--speed);
}
.toggle[aria-checked="true"] { background: #00b894; }
.toggle[aria-checked="true"]::after { left: 32px; }

/* ---------- overlay / celebration / break ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center;
  background: rgba(30, 20, 70, 0.55);
  padding: 20px;
}
#overlay.show { display: flex; }
.overlay-card {
  background: var(--paper); border-radius: var(--radius);
  padding: 26px 22px; max-width: 460px; width: 100%;
  text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,0.3);
  max-height: 88dvh; overflow-y: auto;
}
.overlay-card h2 { font-family: var(--font-display); font-size: 1.6rem; margin: 0 0 10px; }
.celebrate-stars { font-size: 3rem; animation: pop-in 0.5s; }
@keyframes pop-in { 0% { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }

#toast {
  position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--ink); color: #fff;
  border-radius: 999px; padding: 12px 22px;
  font-weight: 600; z-index: 60;
  transition: transform 0.35s;
  max-width: 90vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- profiles ---------- */
.profile-pick { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; padding: 18px 0; }
.profile-btn {
  border: none; border-radius: var(--radius); background: var(--paper);
  box-shadow: var(--shadow); cursor: pointer;
  width: 150px; padding: 18px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; color: var(--ink);
}
.profile-btn .avatar { font-size: 3.2rem; }
.profile-btn.active { outline: 4px solid var(--accent); }

/* ---------- progress bars ---------- */
.bar { height: 18px; border-radius: 999px; background: rgba(0,0,0,0.08); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 999px; }

/* ---------- story ---------- */
.story-page { font-size: 1.2rem; line-height: 1.7; }
.story-art { font-size: 3.4rem; text-align: center; margin: 10px 0; }

/* ---------- misc ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg1); border-radius: 999px; padding: 6px 14px;
  font-weight: 700; font-size: 0.95rem;
}
.divider { border: none; border-top: 2px dashed rgba(0,0,0,0.1); margin: 14px 0; }
.small-note { font-size: 0.85rem; color: var(--ink-soft); }
img.photo-preview { max-width: 100%; border-radius: var(--radius-sm); }

@media (max-width: 420px) {
  .menu-grid { grid-template-columns: repeat(2, 1fr); }
  .pin-pad { grid-template-columns: repeat(3, 68px); }
  .pin-key { width: 68px; height: 68px; }
}
