/* ============================================================
   First Doodles — Trail Engine (UI da criança)
   Um único CSS serve todas as trilhas. Grande, colorido, touch-first.
   ============================================================ */
:root {
  --ink: #4f2f18;
  --muted: #8a6b55;
  --bg: #fef8ee;
  --bg-alt: #faf0dc;
  --brand: #2cb1c7;
  --brand-soft: #e3f6fa;
  --accent: #f6c24a;
  --coral: #ff744b;
  --leaf: #5bbb93;
  --sky: #46c9dd;
  --radius: 1.25rem;
  --shadow: 0 4px 0 0 rgba(79, 47, 24, 0.85);
}

.fd-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 12% 18%, rgba(246, 194, 74, 0.16), transparent 32%),
    radial-gradient(circle at 88% 78%, rgba(44, 177, 199, 0.12), transparent 34%),
    var(--bg);
}

/* ---------- Barra superior ---------- */
.fd-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 2.5px solid var(--ink);
  background: rgba(254, 248, 238, 0.95);
  position: sticky;
  top: 0;
  z-index: 20;
}
.fd-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 800;
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  color: var(--ink);
  text-decoration: none;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  padding: 0.4rem 0.9rem;
}
.fd-topbar-title {
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1rem;
  text-align: center;
  margin: 0;
}
.fd-topbar-spacer { width: 88px; }
@media (max-width: 480px) {
  .fd-topbar-title { font-size: 0.85rem; }
  .fd-topbar-spacer { display: none; }
  .fd-back span { display: none; }
}

/* ---------- App ---------- */
.fd-app {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  font-family: "Nunito Variable", "Nunito", sans-serif;
  color: var(--ink);
}
.fd-loading { text-align: center; font-weight: 800; padding: 3rem 0; }

.fd-card {
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.fd-h1 {
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  text-align: center;
  margin: 0.5rem 0 0.25rem;
}
.fd-sub { text-align: center; color: var(--muted); font-weight: 700; margin: 0 0 1.5rem; }

/* ---------- Botões ---------- */
.fd-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--ink);
  background: var(--accent);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0.7rem 1.6rem;
  cursor: pointer;
  transition: transform 0.15s ease;
  touch-action: manipulation;
}
.fd-btn:hover { transform: translateY(-2px); }
.fd-btn:active { transform: translateY(1px); box-shadow: 0 2px 0 0 rgba(79, 47, 24, 0.85); }
.fd-btn--ghost { background: #fff; }
.fd-btn--round {
  width: 3rem;
  height: 3rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.3rem;
}

/* ---------- Mapa da trilha ---------- */
.fd-map { display: grid; gap: 1rem; margin-top: 1rem; }
.fd-node {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  text-align: left;
  padding: 1rem 1.25rem;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.fd-node:hover:not(:disabled) { transform: translateY(-2px); }
.fd-node:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.fd-node-emoji {
  font-size: 2rem;
  width: 3.5rem;
  height: 3.5rem;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  flex-shrink: 0;
}
.fd-node-title {
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.15rem;
  margin: 0;
}
.fd-node-step { color: var(--brand); font-weight: 800; font-size: 0.75rem; text-transform: uppercase; margin: 0; }
.fd-node-lock { color: var(--muted); font-weight: 700; font-size: 0.8rem; margin: 0.15rem 0 0; }
.fd-node-stars { margin-left: auto; font-size: 1.1rem; letter-spacing: 0.1em; flex-shrink: 0; }
.fd-medal {
  text-align: center;
  font-weight: 800;
  padding: 1rem 1.25rem;
  background: var(--bg-alt);
}
.fd-medal-art {
  display: block;
  width: min(280px, 80%);
  margin: 0.75rem auto 0;
  border: 2.5px solid var(--ink);
  border-radius: 1rem;
  background: #fff;
}
.fd-node--next {
  text-decoration: none;
  color: var(--ink);
  background: var(--brand-soft);
}
.fd-node--next[aria-disabled="true"] { opacity: 0.6; cursor: default; }
.fd-next-trail {
  display: inline-flex;
  margin-top: 0.6rem;
  text-decoration: none;
  font-size: 0.95rem;
}
.fd-next-trail[aria-disabled="true"] { opacity: 0.6; cursor: default; }

/* ---------- Estúdio de desenho ---------- */
.fd-draw-stage { padding: 0.6rem; }
.fd-draw-stage canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 1rem;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
}
.fd-brushes {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.fd-brush {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  cursor: pointer;
  padding: 0;
}
.fd-brush span {
  display: block;
  border-radius: 999px;
  background: var(--ink);
}
.fd-brush.selected {
  outline: 4px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- Chrome da atividade ---------- */
.fd-act-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.fd-act-title {
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.25rem;
  margin: 0;
  flex: 1;
  text-align: center;
}
.fd-progress-chip {
  font-weight: 800;
  background: var(--brand-soft);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.9rem;
}

/* ---------- Colorir ---------- */
.fd-page-picker {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.fd-page-tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 4.6rem;
  padding: 0.5rem 0.8rem;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: "Nunito Variable", "Nunito", sans-serif;
  color: var(--ink);
  transition: transform 0.12s ease;
}
.fd-page-tab:hover { transform: translateY(-2px); }
.fd-page-tab.selected { background: var(--accent); }
.fd-page-emoji { font-size: 1.6rem; line-height: 1; }
.fd-page-name { font-size: 0.72rem; font-weight: 800; }
.fd-page-check {
  position: absolute;
  top: -0.5rem;
  right: -0.5rem;
  display: grid;
  place-items: center;
  width: 1.4rem;
  height: 1.4rem;
  font-size: 0.8rem;
  color: #fff;
  background: var(--leaf);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.fd-page-tab.fd-page-locked { opacity: 0.6; }
.fd-locked-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
}
.fd-locked-scene-icon { font-size: 2.6rem; margin: 0; }
.fd-locked-scene-msg {
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.05rem;
  max-width: 22rem;
  margin: 0 0 0.5rem;
}
.fd-color-stage { padding: 0.75rem; }
.fd-raster-wrap { position: relative; }
.fd-raster-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 0.75rem;
}
.fd-raster-wrap .fd-paint {
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}
.fd-raster-wrap .fd-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.fd-tools {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.fd-tool {
  position: relative;
  display: grid;
  place-items: center;
  width: 2.9rem;
  height: 2.9rem;
  font-size: 1.25rem;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 0;
}
.fd-tool.selected { background: var(--accent); }
.fd-tool-dot {
  position: absolute;
  right: 0.3rem;
  bottom: 0.3rem;
  border-radius: 999px;
  background: var(--ink);
}
.fd-sticker {
  display: block;
  width: 100%;
  border: 6px solid #fff;
  outline: 2.5px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transform: rotate(-2deg);
  background: #fff;
}
.fd-color-stage svg { width: 100%; height: auto; display: block; }
.fd-color-stage [data-region] { cursor: pointer; transition: opacity 0.1s ease; }
.fd-color-stage [data-region]:hover { opacity: 0.85; }
.fd-palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin: 1rem 0;
}
.fd-swatch {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 2.5px solid var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  padding: 0;
}
.fd-swatch:hover { transform: scale(1.1); }
.fd-swatch { position: relative; }
.fd-sw-tag {
  display: none;
  position: absolute;
  right: -0.35rem;
  bottom: -0.35rem;
  padding: 0 0.2rem;
  font-size: 0.6rem;
  font-weight: 800;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 0.5rem;
  line-height: 1.1;
}
body.fd-cb .fd-sw-tag { display: block; }
.fd-cb-toggle { background: #fff; font-size: 1rem; }
body.fd-cb .fd-cb-toggle {
  background: var(--brand-soft);
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}
.fd-palette[data-mode="raster"] .fd-eraser { display: none; }
.fd-swatch.selected {
  outline: 4px solid var(--brand);
  outline-offset: 2px;
  transform: scale(1.12);
}

/* ---------- Letras ---------- */
.fd-letter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.4rem, 1fr));
  gap: 0.6rem;
  margin-top: 1rem;
}
.fd-letter {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.5rem;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
  padding: 0;
  color: var(--ink);
}
.fd-letter:hover { transform: translateY(-2px); }
.fd-letter.focus { background: var(--accent); }
.fd-letter.visited { background: var(--leaf); color: #fff; }
.fd-letter .mini {
  position: absolute;
  bottom: 0.15rem;
  right: 0.25rem;
  font-size: 0.8rem;
}

/* Painel de traçar */
.fd-trace-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(79, 47, 24, 0.55);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.fd-trace-panel {
  width: min(420px, 94vw);
  padding: 1rem;
  text-align: center;
  background: #fff;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.fd-trace-wrap { position: relative; margin: 0.5rem auto; width: min(300px, 80vw); }
.fd-trace-wrap svg, .fd-trace-wrap canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 1rem;
}
.fd-trace-wrap canvas {
  position: absolute;
  inset: 0;
  touch-action: none;
  cursor: crosshair;
}
.fd-trace-actions { display: flex; justify-content: center; gap: 0.6rem; margin-top: 0.6rem; flex-wrap: wrap; }
.fd-trace-panel.wrong { animation: fd-shake 0.5s ease; }

/* ---------- Memória ---------- */
.fd-mem-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.7rem;
  margin-top: 1rem;
}
@media (max-width: 480px) { .fd-mem-grid { grid-template-columns: repeat(3, 1fr); } }
.fd-mem-card {
  aspect-ratio: 3 / 3.4;
  perspective: 600px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.fd-mem-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.4s ease;
}
.fd-mem-card.flipped .fd-mem-inner { transform: rotateY(180deg); }
.fd-mem-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  border: 2.5px solid var(--ink);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  font-weight: 800;
}
.fd-mem-front {
  background: var(--brand);
  color: #fff;
  font-size: 1.6rem;
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
}
.fd-mem-back {
  background: #fff;
  transform: rotateY(180deg);
  font-size: clamp(2.2rem, 9vw, 4rem);
}
.fd-mem-back.word {
  font-size: clamp(1.1rem, 4.5vw, 1.8rem);
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  color: var(--brand);
}
.fd-mem-card.matched .fd-mem-face { background: var(--leaf); color: #fff; border-color: var(--ink); }
.fd-mem-card.matched { animation: fd-pop 0.4s ease; }

/* ---------- Frases ---------- */
.fd-sentence-pic { text-align: center; font-size: 3rem; margin: 0.5rem 0; }
.fd-slots, .fd-tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin: 1rem 0;
}
.fd-slot {
  min-width: 4.2rem;
  height: 3.2rem;
  padding: 0 0.8rem;
  display: grid;
  place-items: center;
  border: 2.5px dashed var(--muted);
  border-radius: 1rem;
  background: #fff;
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.2rem;
  cursor: pointer;
}
.fd-slot.filled { border-style: solid; border-color: var(--ink); background: var(--brand-soft); box-shadow: var(--shadow); }
.fd-tile {
  padding: 0.6rem 1.1rem;
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.2rem;
  background: var(--accent);
  border: 2.5px solid var(--ink);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
  color: var(--ink);
}
.fd-tile:hover:not(:disabled) { transform: translateY(-2px); }
.fd-tile:disabled { opacity: 0.25; cursor: default; box-shadow: none; }
.fd-sentence-area.wrong { animation: fd-shake 0.5s ease; }

/* ---------- Overlay de celebração / finale ---------- */
.fd-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(79, 47, 24, 0.6);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.fd-overlay-panel {
  width: min(440px, 94vw);
  text-align: center;
  padding: 2rem 1.5rem;
  background: var(--bg);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: fd-pop 0.4s ease;
}
.fd-overlay-stars { font-size: 2.2rem; letter-spacing: 0.15em; margin: 0.5rem 0; }
.fd-overlay-msg {
  font-family: "Baloo 2 Variable", "Baloo 2", cursive;
  font-weight: 800;
  font-size: 1.5rem;
  margin: 0.25rem 0 1rem;
}
.fd-finale-sprite { width: min(260px, 70vw); margin: 0 auto 0.5rem; animation: fd-fly 2.6s ease-in-out infinite; }
.fd-finale-sprite svg { width: 100%; height: auto; }

/* ---------- Confete ---------- */
.fd-confetti {
  position: fixed;
  top: -20px;
  z-index: 70;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  pointer-events: none;
  animation: fd-fall linear forwards;
}

/* ---------- Animações ---------- */
@keyframes fd-pop {
  0% { transform: scale(0.7); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}
@keyframes fd-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}
@keyframes fd-fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0.6; }
}
@keyframes fd-fly {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-18px) rotate(4deg); }
}

@media (prefers-reduced-motion: reduce) {
  .fd-btn, .fd-node, .fd-letter, .fd-tile, .fd-swatch { transition: none; }
  .fd-mem-inner { transition: none; }
  .fd-finale-sprite, .fd-mem-card.matched, .fd-overlay-panel { animation: none; }
  .fd-confetti { display: none; }
}
