/* Layout: una sola columna pensada para el móvil. El tablero es una manta de retales
   (cada región, un parche acolchado con su costura) metida en la cama de Draco;
   alrededor, tonos cálidos de caramelo y avena, y huellas muy suaves de fondo. */
:root {
  --bg: #f3e9de;
  --surface: #fffaf3;
  --ink: #3b2a20;
  --muted: #8b715f;
  --line: #e4d3c1;
  --accent: #d9752e;
  --accent-edge: #a9541b;
  --accent-ink: #fffaf3;
  --accent-soft: #f8dcc2;
  --btn-edge: #dcc6af;
  --rim: #a8714b;
  --rim-hi: #c99467;
  --rim-lo: #7c4e31;
  --rim-stitch: #f4dcbf;
  --cushion: #eebf93;
  --cushion-lo: #c4834f;
  --backing: #6b4630;
  --thread: rgba(255, 251, 244, 0.85);
  --seam: rgba(110, 70, 40, 0.2);
  --pat: rgba(255, 255, 255, 0.45);
  --pat-soft: rgba(255, 255, 255, 0.28);
  --lift: rgba(60, 30, 10, 0.38);
  --mark: rgba(74, 47, 31, 0.66);
  --hover: rgba(255, 255, 255, 0.35);
  --danger: #cf4338;
  --danger-tint: rgba(207, 67, 56, 0.2);
  --good: #3d8a5c;
  --heart: #e2667a;
  --backdrop: rgba(59, 42, 32, 0.42);
  --shadow: 0 1px 0 rgba(120, 80, 50, 0.06), 0 14px 30px -18px rgba(90, 55, 30, 0.55);

  --r0: #f2b3a6; --r1: #f4d68b; --r2: #bed59d; --r3: #a7d0e2; --r4: #cbbce7;
  --r5: #f0bdd2; --r6: #f5bd8b; --r7: #a6dac3; --r8: #e1d1b8; --r9: #b0c1ee;
  --r10: #c3cbd4; --r11: #d3d98a; --r12: #8fd3d3; --r13: #dfb2e8; --r14: #e6b44f;

  --paws: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cg fill='%23ecdbc8'%3E%3Cg transform='translate(36 40) rotate(-18)'%3E%3Cellipse cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-8.5' r='3'/%3E%3Ccircle cx='3' cy='-8.5' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3Cg transform='translate(102 104) rotate(16)'%3E%3Cellipse cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-8.5' r='3'/%3E%3Ccircle cx='3' cy='-8.5' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");

  --font-display: "Bagel Fat One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Baloo 2", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --draco-face: url("../assets/draco-face.webp");
  --pablo-face: url("../assets/pablo-face.webp");
  --dog-face: var(--draco-face);
  --mask-x: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6l12 12M18 6L6 18' fill='none' stroke='%23000' stroke-width='3.6' stroke-linecap='round'/%3E%3C/svg%3E");
  --mask-heart: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.2S2.5 15.6 2.5 9A5 5 0 0 1 12 6.6 5 5 0 0 1 21.5 9c0 6.6-9.5 12.2-9.5 12.2z'/%3E%3C/svg%3E");
  --mask-paw: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cellipse cx='12' cy='16' rx='4.8' ry='4'/%3E%3Ccircle cx='5.6' cy='10.4' r='2.2'/%3E%3Ccircle cx='9.4' cy='6.4' r='2.2'/%3E%3Ccircle cx='14.6' cy='6.4' r='2.2'/%3E%3Ccircle cx='18.4' cy='10.4' r='2.2'/%3E%3C/svg%3E");
  --mask-lock: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='5' y='10.5' width='14' height='10' rx='2.5'/%3E%3Cpath d='M8 10.5V8a4 4 0 0 1 8 0v2.5' fill='none' stroke='%23000' stroke-width='2.4'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #211a16;
    --surface: #2e241e;
    --ink: #f4e8dc;
    --muted: #b9a18c;
    --line: #47392f;
    --accent: #f0a05a;
    --accent-edge: #b8692b;
    --accent-ink: #2a1a0e;
    --accent-soft: #4d3220;
    --btn-edge: #15100c;
    --rim: #4c3427;
    --rim-hi: #634634;
    --rim-lo: #33231a;
    --rim-stitch: #8f6e53;
    --cushion: #6d4c38;
    --cushion-lo: #3a281e;
    --backing: #16100c;
    --thread: rgba(255, 236, 216, 0.34);
    --seam: rgba(255, 255, 255, 0.09);
    --pat: rgba(255, 255, 255, 0.1);
    --pat-soft: rgba(255, 255, 255, 0.055);
    --lift: rgba(0, 0, 0, 0.55);
    --mark: rgba(252, 238, 224, 0.72);
    --hover: rgba(255, 255, 255, 0.12);
    --danger: #ff7a6e;
    --danger-tint: rgba(255, 122, 110, 0.2);
    --good: #74d19c;
    --heart: #ff8ea0;
    --backdrop: rgba(0, 0, 0, 0.6);
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 16px 32px -16px rgba(0, 0, 0, 0.85);
    --r0: #a86a5d; --r1: #a68a4a; --r2: #6f8a57; --r3: #51819a; --r4: #7b6ba5;
    --r5: #a36787; --r6: #a87242; --r7: #4c8e75; --r8: #88775f; --r9: #6175ad;
    --r10: #6f7884; --r11: #7e8540; --r12: #3f8584; --r13: #8b5f96; --r14: #a07a2c;
    --paws: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cg fill='%232a211b'%3E%3Cg transform='translate(36 40) rotate(-18)'%3E%3Cellipse cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-8.5' r='3'/%3E%3Ccircle cx='3' cy='-8.5' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3Cg transform='translate(102 104) rotate(16)'%3E%3Cellipse cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-8.5' r='3'/%3E%3Ccircle cx='3' cy='-8.5' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #211a16;
  --surface: #2e241e;
  --ink: #f4e8dc;
  --muted: #b9a18c;
  --line: #47392f;
  --accent: #f0a05a;
  --accent-edge: #b8692b;
  --accent-ink: #2a1a0e;
  --accent-soft: #4d3220;
  --btn-edge: #15100c;
  --rim: #4c3427;
  --rim-hi: #634634;
  --rim-lo: #33231a;
  --rim-stitch: #8f6e53;
  --cushion: #6d4c38;
  --cushion-lo: #3a281e;
  --backing: #16100c;
  --thread: rgba(255, 236, 216, 0.34);
  --seam: rgba(255, 255, 255, 0.09);
  --pat: rgba(255, 255, 255, 0.1);
  --pat-soft: rgba(255, 255, 255, 0.055);
  --lift: rgba(0, 0, 0, 0.55);
  --mark: rgba(252, 238, 224, 0.72);
  --hover: rgba(255, 255, 255, 0.12);
  --danger: #ff7a6e;
  --danger-tint: rgba(255, 122, 110, 0.2);
  --good: #74d19c;
  --heart: #ff8ea0;
  --backdrop: rgba(0, 0, 0, 0.6);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 16px 32px -16px rgba(0, 0, 0, 0.85);
  --r0: #a86a5d; --r1: #a68a4a; --r2: #6f8a57; --r3: #51819a; --r4: #7b6ba5;
  --r5: #a36787; --r6: #a87242; --r7: #4c8e75; --r8: #88775f; --r9: #6175ad;
  --r10: #6f7884; --r11: #7e8540; --r12: #3f8584; --r13: #8b5f96; --r14: #a07a2c;
  --paws: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cg fill='%232a211b'%3E%3Cg transform='translate(36 40) rotate(-18)'%3E%3Cellipse cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-8.5' r='3'/%3E%3Ccircle cx='3' cy='-8.5' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3Cg transform='translate(102 104) rotate(16)'%3E%3Cellipse cy='6' rx='7' ry='6'/%3E%3Ccircle cx='-8' cy='-3' r='3'/%3E%3Ccircle cx='-3' cy='-8.5' r='3'/%3E%3Ccircle cx='3' cy='-8.5' r='3'/%3E%3Ccircle cx='8' cy='-3' r='3'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paws) 0 0 / 140px 140px repeat, var(--bg);
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.app {
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 12px 20px;
}
.screen { display: flex; flex-direction: column; gap: 16px; }

/* ---------- Botones: blanditos, con canto ---------- */
.btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 54px; padding: 10px 20px;
  border: 0; border-radius: 18px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 4px 0 var(--btn-edge), 0 10px 18px -14px rgba(90, 55, 30, 0.6);
  font-weight: 700; font-size: 1.05rem; letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-edge); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 0 var(--accent-edge), 0 12px 20px -12px var(--accent-edge); }
.btn-primary:active { box-shadow: 0 1px 0 var(--accent-edge); }
.btn-quiet { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.btn-quiet:active { box-shadow: inset 0 0 0 2px var(--line); }
.btn-danger { color: var(--danger); }
.btn.btn-danger:not(.btn-quiet) { background: var(--danger); color: var(--surface); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); }
.btn-main { font-size: 1.3rem; line-height: 1.1; }
.btn-sub { font-size: 0.85rem; font-weight: 600; opacity: 0.85; }

.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  border: 0; border-radius: 14px; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn svg, .tool svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Inicio ---------- */
.home { min-height: calc(100% - 8px); justify-content: center; padding-block: 8px; }
.home-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; }
.hero-bed { position: relative; width: min(62vw, 250px); max-width: 100%; }
.hero-bed::before {
  /* la cama de Draco: borde mullido y hueco más oscuro */
  content: ""; position: absolute; z-index: -1;
  left: -14%; right: -14%; bottom: -6%; height: 34%;
  border-radius: 50%;
  background: radial-gradient(58% 52% at 50% 46%, var(--cushion-lo) 0 62%, var(--cushion) 66% 100%);
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.28), inset 0 -6px 10px rgba(0, 0, 0, 0.18), 0 16px 24px -16px rgba(60, 35, 20, 0.7);
}
.hero-bed::after {
  content: ""; position: absolute; z-index: -1;
  left: -10%; right: -10%; bottom: -2%; height: 27%;
  border-radius: 50%; border: 2px dashed var(--rim-stitch); opacity: 0.8;
  -webkit-mask: linear-gradient(#000 0 0) top / 100% 42% no-repeat; mask: linear-gradient(#000 0 0) top / 100% 42% no-repeat;
}
.hero-draco {
  display: block; width: 100%; height: auto;
  transform-origin: 50% 90%;
  filter: drop-shadow(0 10px 10px rgba(60, 35, 20, 0.25));
  animation: hero-in 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both, breathe 4.5s ease-in-out 0.8s infinite;
}
@keyframes hero-in { from { transform: translateY(24px) rotate(-8deg) scale(0.86); } }
@keyframes breathe { 50% { transform: scale(1.018, 1.03) rotate(-0.6deg); } }
.wordmark {
  margin: 4px 0 0;
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(3.2rem, 15vw, 4.6rem); line-height: 0.95; letter-spacing: 0.01em;
  text-wrap: balance;
}
.wordmark span { color: var(--accent); }
.tagline { margin: 6px 0 0; max-width: 30ch; color: var(--muted); font-size: 1.05rem; font-weight: 600; text-wrap: balance; }
.home-actions { display: flex; flex-direction: column; gap: 12px; }
.home-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.home-progress { display: flex; flex-direction: column; gap: 6px; align-items: center; color: var(--muted); font-weight: 600; font-size: 0.92rem; }
.home-progress p { margin: 0; font-variant-numeric: tabular-nums; }
.meter { width: 100%; height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.4s ease; }
.home-sniffs { display: flex; align-items: center; gap: 6px; }
.home-sniffs::before { content: ""; width: 16px; height: 16px; background: var(--accent); -webkit-mask: var(--mask-paw) center / contain no-repeat; mask: var(--mask-paw) center / contain no-repeat; }

/* ---------- Barra superior ---------- */
.topbar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; min-height: 48px; }
.topbar-title { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.6rem; line-height: 1; }
.topbar-spacer { width: 44px; }
.game-heading { display: flex; flex-direction: column; min-width: 0; }
.game-band { color: var(--muted); font-weight: 600; font-size: 0.88rem; }
.timer {
  min-width: 64px; text-align: center;
  padding: 2px 10px; border-radius: 99px; background: var(--surface);
  box-shadow: 0 2px 0 var(--btn-edge);
  font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums;
}

/* ---------- Selector de niveles ---------- */
.level-bands { display: flex; flex-direction: column; gap: 24px; padding-bottom: 12px; }
.band-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.band-head h3 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; }
.band-meta { color: var(--muted); font-weight: 600; font-size: 0.88rem; font-variant-numeric: tabular-nums; text-align: right; }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 10px; }
.lvl {
  position: relative; aspect-ratio: 1; max-width: 100%;
  display: grid; place-items: center;
  border: 0; border-radius: 16px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 3px 0 var(--btn-edge);
  font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.lvl:active { transform: translateY(2px); }
.lvl.done { background: var(--accent-soft); box-shadow: 0 3px 0 var(--btn-edge); }
.lvl.done::after {
  content: ""; position: absolute; right: -4px; top: -4px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--dog-face) center / cover, var(--surface);
  box-shadow: 0 0 0 2px var(--surface);
}
.lvl.current { background: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 var(--accent-edge); animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: translateY(-2px); } }
.lvl.locked { color: var(--muted); background: transparent; box-shadow: inset 0 0 0 2px var(--line); cursor: not-allowed; }
.lvl.locked::after {
  content: ""; position: absolute; right: 5px; bottom: 5px; width: 12px; height: 12px;
  background: var(--muted); opacity: 0.7;
  -webkit-mask: var(--mask-lock) center / contain no-repeat; mask: var(--mask-lock) center / contain no-repeat;
}

/* ---------- Partida ---------- */
.game { gap: 12px; }
.status-row { display: flex; align-items: center; justify-content: space-between; min-height: 30px; }
.bones { display: flex; gap: 6px; color: var(--accent); }
.bone { width: 38px; height: 20px; fill: currentColor; filter: drop-shadow(0 2px 0 var(--accent-edge)); transition: opacity 0.3s ease, transform 0.3s ease; }
.bone.lost { fill: var(--line); filter: none; transform: rotate(-8deg) scale(0.86); }
.bone.just-lost { animation: bone-break 0.5s ease; }
@keyframes bone-break { 30% { transform: rotate(14deg) scale(1.2); } 60% { transform: rotate(-12deg) scale(0.8); } }
.found {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 10px 2px 4px; border-radius: 99px; background: var(--surface); box-shadow: 0 2px 0 var(--btn-edge);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.found::before { content: ""; width: 24px; height: 24px; border-radius: 50%; background: var(--dog-face) center / cover; }

/* La cama de Draco: borde mullido con costura */
.board-wrap {
  position: relative;
  align-self: center;
  width: min(100%, calc(100dvh - 270px), 540px);
  min-width: min(100%, 280px);
  padding: 14px;
  border-radius: 30px;
  background: radial-gradient(120% 90% at 30% 0%, var(--rim-hi), var(--rim) 55%, var(--rim-lo));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.22),
    inset 0 -5px 10px rgba(0, 0, 0, 0.22),
    0 5px 0 var(--rim-lo),
    0 22px 34px -20px rgba(60, 35, 20, 0.7);
  transition: box-shadow 0.6s ease;
}
.board-wrap::before {
  content: ""; position: absolute; inset: 5px; border-radius: 25px; pointer-events: none;
  border: 2px dashed var(--rim-stitch); opacity: 0.75;
}
.board-wrap.won { box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.22), inset 0 -5px 10px rgba(0, 0, 0, 0.22), 0 5px 0 var(--rim-lo), 0 0 0 6px var(--accent-soft), 0 0 48px 8px var(--accent-soft); }

.board {
  --n: 5;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  aspect-ratio: 1;
  max-width: 100%;
  border-radius: 16px;
  background: var(--backing);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.35);
  touch-action: none;
  user-select: none; -webkit-user-select: none;
}
.quilt { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.quilt .stitch { fill: none; stroke: var(--thread); stroke-linecap: round; }
.quilt .seam { stroke: var(--seam); }

.cell {
  position: relative;
  min-width: 0; min-height: 0;
  padding: 0; margin: 0; border: 0;
  border-radius: 22%;
  background: transparent;
  cursor: pointer;
}
.cell:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; z-index: 2; }
.cell::before, .cell::after { content: ""; position: absolute; pointer-events: none; }
@media (hover: hover) {
  .cell:hover::before { inset: 12%; border-radius: 30%; background: var(--hover); }
}

/* Marca ✕ */
.cell.s1::after, .cell.s3::after {
  inset: 0; margin: auto; width: 36%; height: 36%;
  background: var(--mark);
  -webkit-mask: var(--mask-x) center / contain no-repeat; mask: var(--mask-x) center / contain no-repeat;
}
.cell.s1.fresh::after { animation: mark-in 0.18s ease-out; }
@keyframes mark-in { from { transform: scale(0.3) rotate(-30deg); opacity: 0; } }
.cell.s3 { background: radial-gradient(circle, var(--danger-tint) 0 56%, transparent 58%); }
.cell.s3::after { background: var(--danger); width: 42%; height: 42%; }
.cell.s3.fresh { animation: shake 0.42s ease; }
@keyframes shake { 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }

/* Draco o Pablo: cada nivel, una pantalla o una casilla dicen cuál con data-dog */
[data-dog="pablo"] { --dog-face: var(--pablo-face); }

/* Draco */
.draco { position: absolute; inset: 6%; pointer-events: none; }
.draco::before {
  content: ""; position: absolute; left: 16%; right: 16%; bottom: 0; height: 18%;
  border-radius: 50%; background: var(--lift); filter: blur(2px);
}
.draco::after {
  content: ""; position: absolute; inset: 0;
  background: var(--dog-face) center / contain no-repeat;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25));
}
.draco.fresh::after { animation: pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes pop { 0% { transform: translateY(30%) scale(0.2) rotate(-14deg); } 65% { transform: translateY(-6%) scale(1.12) rotate(3deg); } 100% { transform: none; } }
.cell.hinted::before {
  inset: 4%; border-radius: 50%;
  box-shadow: 0 0 0 3px var(--accent), 0 0 18px 4px var(--accent-soft);
  animation: sniff 1.1s ease-out 2;
}
@keyframes sniff { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }
.board.won .draco::after { animation: hop 0.6s ease calc(var(--k, 0) * 70ms) 2; }
@keyframes hop { 40% { transform: translateY(-24%) rotate(-6deg); } 70% { transform: translateY(0) rotate(3deg); } }

/* Tableros grandes (12×12 o más): marco más fino y, en pantallas anchas, más sitio */
.board-wrap.big { padding: 8px; border-radius: 22px; }
.board-wrap.big::before { inset: 3px; border-radius: 19px; border-width: 1.5px; }
.board-wrap.big .board { border-radius: 13px; }
.board-wrap.big .cell.s1::after { width: 46%; height: 46%; }
.board-wrap.big .cell.s3::after { width: 52%; height: 52%; }
.app.wide { max-width: 780px; }
.app.wide .topbar, .app.wide .status-row, .app.wide .toast, .app.wide .toolbar { width: 100%; max-width: 560px; align-self: center; }
.app.wide .board-wrap { width: min(100%, calc(100dvh - 240px), 740px); }

/* Chispitas al encontrar a Draco */
.spark {
  position: absolute; z-index: 4; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  background: var(--heart); pointer-events: none;
  -webkit-mask: var(--mask-heart) center / contain no-repeat; mask: var(--mask-heart) center / contain no-repeat;
  animation: spark 0.9s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
.spark.paw { background: var(--accent); -webkit-mask-image: var(--mask-paw); mask-image: var(--mask-paw); }
@keyframes spark {
  0% { transform: translate(0, 0) scale(0.3); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(var(--rot)); opacity: 0; }
}

.toast {
  min-height: 1.5em; margin: 0; text-align: center;
  color: var(--muted); font-weight: 600; font-size: 0.95rem;
  text-wrap: balance;
}
.toast.bad { color: var(--danger); }
.toast.good { color: var(--good); }

.toolbar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tool {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  min-height: 62px; padding: 8px 4px;
  border: 0; border-radius: 18px; background: var(--surface);
  box-shadow: 0 4px 0 var(--btn-edge);
  font-weight: 700; font-size: 0.9rem; cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.tool:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-edge); }
.tool:disabled { opacity: 0.45; cursor: default; }
.tool .paw { fill: currentColor; stroke: none; color: var(--accent); }
.badge {
  position: absolute; top: -6px; right: -4px;
  min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 2px 0 var(--accent-edge);
  font-size: 0.8rem; font-variant-numeric: tabular-nums;
}
.hint-timer { font-size: 0.72rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.1; }
.hint-timer:empty { display: none; }
.tool-hint.resting { color: var(--muted); }
.tool-hint.resting .paw { color: var(--muted); }
.tool-hint.resting .badge { background: var(--line); color: var(--muted); box-shadow: none; }

/* ---------- Diálogos ---------- */
.sheet {
  width: min(440px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 22px 20px 18px;
  border: 0; border-radius: 26px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 6px 0 var(--btn-edge), var(--shadow);
}
.sheet::backdrop { background: var(--backdrop); backdrop-filter: blur(2px); }
.sheet[open] { animation: sheet-in 0.3s cubic-bezier(0.2, 1.2, 0.4, 1); }
@keyframes sheet-in { from { transform: translateY(18px) scale(0.96); opacity: 0; } }
.sheet-title { margin: 0 0 10px; font-family: var(--font-display); font-weight: 400; font-size: 1.7rem; line-height: 1.05; text-wrap: balance; }
.sheet-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.rules { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 8px; }
.rules li::marker { color: var(--accent); font-weight: 800; }
.help-demo { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: center; margin-top: 16px; color: var(--muted); font-weight: 600; }
.help-demo p { margin: 0; }
.demo-board {
  position: relative; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr);
  aspect-ratio: 1; max-width: 100%;
  border-radius: 12px; background: var(--backing);
  box-shadow: 0 0 0 6px var(--rim), 0 4px 0 6px var(--rim-lo);
  margin: 6px;
}
.demo-board .cell { cursor: default; }
.kbd-hint { margin: 14px 0 0; font-size: 0.85rem; color: var(--muted); }
kbd { font: inherit; font-weight: 700; padding: 0 5px; border-radius: 6px; background: var(--bg); box-shadow: 0 2px 0 var(--btn-edge); }

.settings { display: flex; flex-direction: column; gap: 4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch-row span { display: flex; flex-direction: column; min-width: 0; }
.switch-row small { color: var(--muted); font-size: 0.85rem; line-height: 1.3; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.theme-zone { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 12px; border-bottom: 1px solid var(--line); }
.theme-label { display: flex; flex-direction: column; }
.theme-label small { color: var(--muted); font-size: 0.85rem; line-height: 1.3; }
.theme-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 16px; background: var(--line); }
.theme-opt {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; border: 0; border-radius: 12px; background: transparent;
  color: var(--muted); font-weight: 700; cursor: pointer;
}
.theme-opt[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 2px 0 var(--btn-edge); }
.theme-face { width: 30px; height: 30px; flex: none; background: var(--dog-face) center / contain no-repeat; }
.code-zone { display: flex; flex-direction: column; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.code-zone label { display: flex; flex-direction: column; }
.code-zone small { color: var(--muted); font-size: 0.85rem; line-height: 1.3; }
.code-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.code-row input {
  min-width: 0; min-height: 46px; padding: 8px 14px;
  border: 0; border-radius: 14px; background: var(--bg); color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--line);
  font: inherit; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
}
.code-row input::placeholder { color: var(--muted); font-weight: 600; letter-spacing: 0; text-transform: none; }
.code-row input:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
.btn-small { min-height: 46px; padding: 6px 18px; font-size: 1rem; }
.code-msg { margin: 0; min-height: 1.3em; font-weight: 700; font-size: 0.92rem; }
.code-msg.good { color: var(--good); }
.code-msg.bad { color: var(--danger); }
.danger-zone { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.reset-confirm p { margin: 0 0 8px; font-weight: 600; }

.result { text-align: center; }
.result.sheet { overflow: visible; margin-top: auto; margin-bottom: auto; padding-top: 18px; }
.result-draco { display: block; width: 150px; height: auto; margin: -66px auto 4px; transform: rotate(-5deg); filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.3)); }
.result[open] .result-draco { animation: hero-in 0.6s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
.result-text { margin: 0; color: var(--muted); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0 0; }
.stats div { padding: 8px 4px; border-radius: 16px; background: var(--bg); }
.stats dt { color: var(--muted); font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.stats dd { margin: 0; font-weight: 800; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.lost-bones { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.lost-bones .bone { width: 48px; height: 25px; fill: var(--line); filter: none; }

/* Confeti de huellas al ganar */
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

@media (min-width: 720px) {
  .app { padding-block: 28px 32px; }
  .board-wrap { width: min(100%, calc(100dvh - 250px), 540px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
