:root {
  --ink: #2f2853;
  --muted: #6f6888;
  --purple: #6f5bd3;
  --purple-dark: #5140b0;
  --lavender: #eee9ff;
  --cream: #fffaf1;
  --mint: #dff7e9;
  --gold: #ffd75e;
  --danger: #e65f72;
  --light-square: #f2e9d6;
  --dark-square: #a9a0c8;
  --card: rgba(255,255,255,.93);
  --shadow: 0 18px 45px rgba(66, 47, 125, .18);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next Rounded", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: #f7f1ff;
  font-synthesis: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body, #app { min-height: 100%; margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 15% 5%, rgba(255,255,255,.9) 0 7%, transparent 24%),
    radial-gradient(circle at 90% 20%, rgba(216,244,255,.9) 0 9%, transparent 28%),
    linear-gradient(155deg, #f5edff 0%, #e9f8ff 52%, #fff6d9 100%);
}
button, input { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 4px solid #ff8a3d; outline-offset: 4px; }

.app-shell { min-height: 100vh; min-height: 100dvh; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.welcome-screen { display: grid; place-items: center; }
.welcome-card {
  width: min(700px, 100%);
  min-height: min(820px, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: clamp(28px, 6vw, 64px);
  border-radius: 44px;
  background: var(--card);
  box-shadow: var(--shadow);
  border: 2px solid rgba(255,255,255,.8);
  position: relative;
  overflow: hidden;
}
.sky-decoration { position: absolute; inset: 20px 24px auto; display: flex; justify-content: space-between; font-size: clamp(28px, 6vw, 48px); opacity: .8; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; font-weight: 900; color: var(--purple); }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(2.1rem, 8vw, 4.8rem); line-height: .95; margin-bottom: 8px; }
h2 { font-size: clamp(1.5rem, 4vw, 2.3rem); }
.welcome-copy { font-size: clamp(1.12rem, 3vw, 1.5rem); color: var(--muted); max-width: 460px; }

.mascot {
  width: 92px; height: 92px; border-radius: 50% 50% 44% 56%;
  display: grid; place-items: center;
  background: radial-gradient(circle at 38% 32%, #fffbc5 0 8%, #ffd75e 9% 33%, #ffab5f 70%, #ef7e64 100%);
  box-shadow: 0 12px 25px rgba(229, 132, 85, .35), inset 0 0 0 7px rgba(255,255,255,.45);
  position: relative;
  flex: 0 0 auto;
  animation: float 3.2s ease-in-out infinite;
}
.mascot::before, .mascot::after { content: ''; position: absolute; width: 34px; height: 48px; border-radius: 60% 40%; background: rgba(194,231,255,.75); z-index: -1; }
.mascot::before { left: -20px; transform: rotate(-25deg); }
.mascot::after { right: -20px; transform: rotate(25deg); }
.mascot-face { font-size: 2.2rem; color: white; text-shadow: 0 2px 8px rgba(90,51,87,.35); }
.mascot.large { width: 150px; height: 150px; }
.mascot.large .mascot-face { font-size: 3.5rem; }
.mascot.small { width: 70px; height: 70px; }
.mascot.small .mascot-face { font-size: 1.8rem; }
@keyframes float { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-9px) rotate(2deg); } }

.primary-button, .secondary-button, .quiet-button, .danger-button, .icon-button {
  border: 0; cursor: pointer; border-radius: 20px; font-weight: 850;
}
.primary-button {
  min-height: 62px; padding: 15px 24px; color: white;
  background: linear-gradient(145deg, var(--purple), var(--purple-dark));
  box-shadow: 0 10px 0 #40328e, 0 15px 30px rgba(79,63,170,.25);
  transition: transform .15s, box-shadow .15s;
}
.primary-button:active { transform: translateY(6px); box-shadow: 0 4px 0 #40328e; }
.primary-button.giant { min-height: 82px; padding: 18px 34px; font-size: clamp(1.12rem, 3vw, 1.45rem); display: flex; gap: 12px; align-items: center; }
.button-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.18); }
.secondary-button { min-height: 56px; padding: 12px 18px; background: white; color: var(--ink); box-shadow: 0 6px 18px rgba(65,52,105,.12); border: 2px solid var(--lavender); }
.quiet-button { min-height: 44px; padding: 10px 16px; background: transparent; color: var(--muted); }
.parent-entry { font-size: .82rem; position: relative; overflow: hidden; }
.parent-entry::after { content:''; position:absolute; left:0; bottom:0; width:0; height:4px; background:var(--purple); transition:width 1.5s linear; }
.parent-entry.holding::after { width:100%; }
.icon-button { min-width: 56px; min-height: 56px; padding: 8px; background: rgba(255,255,255,.88); color: var(--ink); font-size: 1.45rem; box-shadow: 0 8px 20px rgba(69,52,116,.12); }
.mission-audio-button { min-width: 0; padding: 12px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--purple); color: white; font-size: clamp(.9rem, 2vw, 1.05rem); white-space: nowrap; box-shadow: 0 8px 0 var(--purple-dark), 0 12px 24px rgba(79,63,170,.22); }
.danger-button { min-height: 52px; padding: 12px 18px; background: #fff0f2; color: #a3253a; border: 2px solid #ffc3cc; }

.topbar { width: min(1050px, 100%); margin: 0 auto 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand-mini { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
.mini-castle { font-size: 2rem; color: var(--purple); }
.top-actions { display: flex; gap: 10px; }

.map-panel { width: min(900px, 100%); margin: 0 auto; background: var(--card); border-radius: 36px; padding: clamp(20px, 4vw, 42px); box-shadow: var(--shadow); }
.map-heading { display: flex; align-items: center; gap: 24px; }
.map-heading h1 { font-size: clamp(2rem, 6vw, 3.7rem); margin: 5px 0 8px; }
.map-heading p:last-child { margin: 0; color: var(--muted); font-size: 1.05rem; }
.progress-wrap { margin: 26px 0 18px; }
.progress-label { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-weight: 750; }
.progress-track { height: 18px; background: #e7e1f7; border-radius: 999px; overflow: hidden; box-shadow: inset 0 2px 6px rgba(54,40,98,.12); }
.progress-fill { height: 100%; background: linear-gradient(90deg, #7e65e3, #54cdb2, #ffd75e); border-radius: inherit; transition: width .45s ease; }
.mission-path { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; padding: 14px 0; position: relative; }
.mission-node { min-height: 145px; padding: 14px 10px; border: 0; border-radius: 28px; background: #fff; box-shadow: 0 8px 20px rgba(66,50,107,.12); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--ink); position: relative; cursor: pointer; transition: transform .15s; }
.mission-node:active:not(:disabled) { transform: scale(.96); }
.mission-node.complete { background: linear-gradient(145deg, #e9fff0, #fffbe5); outline: 3px solid #85dca4; }
.mission-node.locked { filter: grayscale(.55); opacity: .58; cursor: not-allowed; box-shadow: none; }
.node-number { position: absolute; top: 10px; left: 12px; width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; background: var(--lavender); font-weight: 900; font-size: .82rem; }
.complete .node-number { background: #4dbb74; color: white; }
.node-icon { font-size: 2.7rem; }
.node-title { font-weight: 900; font-size: .95rem; }
.castle-finish { text-align: center; font-size: 5.5rem; filter: grayscale(.5); opacity: .65; }
.castle-finish.awake { filter: none; opacity: 1; animation: celebrate 1s ease both; }
@keyframes celebrate { 0% { transform: scale(.6) rotate(-10deg); } 70% { transform: scale(1.15) rotate(5deg); } 100% { transform: scale(1); } }
.map-footer { text-align: center; margin-top: 8px; }

.mission-layout { width: min(900px, 100%); margin: 0 auto; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.mission-counter { padding: 10px 16px; border-radius: 999px; background: rgba(255,255,255,.84); font-weight: 850; }
.narrator-card { width: 100%; display: flex; align-items: center; gap: 16px; }
.speech-bubble { flex: 1; background: white; border-radius: 26px; padding: 16px 20px; box-shadow: 0 10px 24px rgba(66,49,111,.13); position: relative; }
.speech-bubble::before { content:''; position:absolute; left:-13px; top:34px; border-width:12px 14px 12px 0; border-style:solid; border-color:transparent white transparent transparent; }
.speech-bubble h1 { font-size: clamp(1.5rem,4vw,2.25rem); margin: 0 0 6px; line-height: 1.05; }
.speech-bubble p { margin: 0; color: var(--muted); font-size: clamp(1rem,2.5vw,1.2rem); line-height: 1.35; }
.board-wrap { width: min(72vh, 690px, 96vw); aspect-ratio: 1; padding: clamp(8px, 1.6vw, 15px); border-radius: 28px; background: linear-gradient(145deg, #4a3d7a, #2e2852); box-shadow: 0 18px 35px rgba(49,37,89,.26); }
.chessboard { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(8,1fr); grid-template-rows: repeat(8,1fr); border-radius: 16px; overflow: hidden; border: 3px solid rgba(255,255,255,.32); }
.square { border: 0; min-width: 0; min-height: 0; padding: 0; position: relative; display: grid; place-items: center; cursor: pointer; touch-action: none; }
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square:focus-visible { outline: 4px solid #ff8a3d; outline-offset: -4px; z-index: 5; }
.square.selected { box-shadow: inset 0 0 0 6px #2f2853, inset 0 0 0 10px #ffd75e; }
.square.legal-target::after { content:''; position:absolute; width:32%; aspect-ratio:1; border-radius:50%; background:#08783f; border:3px solid white; box-shadow:0 0 0 3px #08783f; }
.square.danger { box-shadow: inset 0 0 0 6px rgba(230,95,114,.75); }
.marker { position:absolute; font-size:clamp(1rem,4vw,2.5rem); opacity:.78; z-index:1; }
.danger-mark { position:absolute; z-index:3; right:3px; top:1px; font-size:clamp(.75rem,2.5vw,1.4rem); }
.piece { z-index:4; width:100%; height:100%; display:grid; place-items:center; position:relative; top:-.14em; font-family: "Arial Unicode MS", "Noto Sans Symbols 2", "DejaVu Sans", serif; font-size:clamp(2rem,7.2vmin,5.2rem); line-height:1; user-select:none; -webkit-user-select:none; filter:drop-shadow(0 4px 2px rgba(30,22,47,.22)); transition:transform .15s; pointer-events:auto; }
.white-piece { color:#fffdf6; -webkit-text-stroke: clamp(1px,.25vw,2.5px) #3d345d; text-shadow:0 1px 0 #3d345d; }
.black-piece { color:#3c345a; -webkit-text-stroke: clamp(.5px,.12vw,1.2px) #f7f0df; }
.piece.dragging { transition:none; filter:drop-shadow(0 15px 7px rgba(30,22,47,.32)); }
.mission-tools { display:flex; flex-wrap:wrap; justify-content:center; gap:10px; }
.hint-card { width:min(650px,100%); display:flex; gap:12px; align-items:center; background:#fff8cc; border:2px solid #f0d660; border-radius:22px; padding:13px 18px; box-shadow:0 8px 20px rgba(116,87,20,.11); }
.hint-card span { font-size:1.8rem; }
.hint-card p { margin:0; font-weight:750; }
.guidance-card { background:#e8f6ff; border-color:#3197c7; color:#174e68; min-height:64px; padding:15px 18px; box-shadow:0 8px 20px rgba(35,112,145,.16); }

.success-overlay { position:fixed; z-index:100; inset:0; display:grid; place-items:center; padding:20px; background:rgba(45,35,78,.58); backdrop-filter:blur(10px); }
.success-card { width:min(550px,100%); background:white; border-radius:38px; padding:clamp(28px,6vw,48px); text-align:center; box-shadow:0 28px 80px rgba(23,17,49,.4); animation:pop .4s cubic-bezier(.2,.9,.3,1.25); }
@keyframes pop { from { transform:scale(.65); opacity:0; } to { transform:scale(1); opacity:1; } }
.reward-icon { font-size:5rem; margin-bottom:10px; animation:celebrate .75s ease .25s both; }
.success-card h2 { margin:7px 0 10px; }
.success-card > p:not(.eyebrow) { color:var(--muted); font-size:1.1rem; line-height:1.45; }
.reward-pill { display:inline-block; margin:8px 0 22px; border-radius:999px; padding:10px 16px; background:var(--mint); font-weight:850; }
.success-actions { display:flex; flex-direction:column; gap:9px; }
.confetti { position:absolute; inset:4% 0 auto; text-align:center; font-size:clamp(1.8rem,7vw,4rem); letter-spacing:.18em; color:#ffd75e; animation:confetti 1.2s ease-in-out infinite alternate; }
@keyframes confetti { to { transform:translateY(15px) rotate(3deg); } }

.parent-panel { width:min(1000px,100%); margin:0 auto; display:grid; gap:16px; }
.parent-summary { display:grid; grid-template-columns:repeat(3,1fr); gap:12px; }
.parent-summary div { background:white; border-radius:24px; padding:20px; display:flex; flex-direction:column; gap:6px; box-shadow:0 8px 20px rgba(65,50,104,.1); }
.parent-summary span { color:var(--muted); font-size:.9rem; }
.parent-summary strong { font-size:2rem; }
.adult-card { background:rgba(255,255,255,.94); border-radius:26px; padding:22px; box-shadow:0 8px 22px rgba(65,50,104,.1); }
.adult-card h2 { margin-bottom:14px; }
.toggle-row { display:flex; justify-content:space-between; align-items:center; gap:20px; padding:14px 0; border-top:1px solid #eeeaf6; }
.toggle-row:first-of-type { border-top:0; }
.toggle-row span { display:flex; flex-direction:column; gap:3px; }
.toggle-row small { color:var(--muted); }
.toggle-row input { width:56px; height:32px; accent-color:var(--purple); }
.table-scroll { overflow:auto; }
table { width:100%; border-collapse:collapse; min-width:620px; }
th,td { padding:12px 10px; text-align:left; border-bottom:1px solid #ece8f3; }
th { color:var(--muted); font-size:.83rem; text-transform:uppercase; }
.muted, .privacy-note { color:var(--muted); }
.privacy-note { text-align:center; font-size:.86rem; padding:8px 20px 24px; }
.danger-zone { border:2px solid #ffd3da; }

@media (min-width: 850px) {
  .mission-path { grid-template-columns: repeat(5, 1fr); }
  .mission-node:nth-child(even) { transform: translateY(20px); }
  .mission-node:nth-child(even):active { transform: translateY(20px) scale(.96); }
}

@media (max-width: 560px) {
  .app-shell { padding: max(10px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom)); }
  .welcome-card { border-radius:30px; min-height:calc(100dvh - 20px); }
  .map-heading { align-items:flex-start; gap:14px; }
  .map-heading .mascot { width:68px; height:68px; }
  .map-heading h1 { font-size:2rem; }
  .mission-path { grid-template-columns: repeat(2, 1fr); gap:11px; }
  .mission-node { min-height:125px; border-radius:22px; }
  .narrator-card { gap:9px; }
  .narrator-card .mascot { width:55px; height:55px; }
  .narrator-card .mascot::before,.narrator-card .mascot::after { display:none; }
  .mission-topbar { flex-wrap: wrap; }
  .mission-topbar .mission-counter { order: 3; flex: 1 0 100%; text-align: center; }
  .speech-bubble { padding:12px 14px; border-radius:20px; }
  .speech-bubble::before { left:-9px; top:23px; border-width:9px 10px 9px 0; }
  .board-wrap { width:min(68vh,96vw); border-radius:20px; padding:7px; }
  .chessboard { border-radius:12px; border-width:2px; }
  .parent-summary { grid-template-columns:1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:.01ms !important; animation-iteration-count:1 !important; scroll-behavior:auto !important; }
}

/* Mundos y ruta de aprendizaje v0.2 */
.recommended-start { min-width: min(360px, 100%); }
.start-note { margin: -8px 0 0; color: var(--muted); font-size: .88rem; }
.worlds-panel { width: min(980px, 100%); margin: 0 auto; background: var(--card); border-radius: 36px; padding: clamp(20px, 4vw, 42px); box-shadow: var(--shadow); }
.worlds-heading { display: flex; align-items: center; gap: 24px; }
.worlds-heading h1 { font-size: clamp(2rem, 6vw, 3.7rem); margin: 5px 0 8px; }
.worlds-heading p:last-child { margin: 0; color: var(--muted); font-size: 1.05rem; }
.overall-progress { margin: 24px 0 16px; display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 13px 18px; border-radius: 18px; background: var(--lavender); font-weight: 800; }
.worlds-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.world-card { position: relative; min-height: 310px; border: 0; border-radius: 30px; padding: 22px 18px 18px; background: white; color: var(--ink); box-shadow: 0 10px 28px rgba(66,50,107,.13); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; cursor: pointer; overflow: hidden; }
.world-card:active:not(:disabled) { transform: scale(.98); }
.world-card.recommended { outline: 4px solid #7e65e3; background: linear-gradient(155deg, #ffffff 0%, #f1edff 100%); }
.world-card.optional { background: linear-gradient(155deg, #ffffff 0%, #f4fbff 100%); }
.world-card.locked { opacity: .58; filter: grayscale(.45); cursor: not-allowed; box-shadow: none; }
.world-number { align-self: flex-start; color: var(--purple); text-transform: uppercase; letter-spacing: .12em; font-size: .72rem; font-weight: 900; }
.recommended-badge, .optional-badge { position: absolute; top: 16px; right: 14px; border-radius: 999px; padding: 6px 9px; font-size: .68rem; font-weight: 900; }
.recommended-badge { color: white; background: var(--purple); }
.optional-badge { color: #2e6677; background: #dcf6ff; }
.world-icon { font-size: 4.5rem; line-height: 1; margin-top: 9px; }
.world-copy { display: flex; flex-direction: column; gap: 9px; flex: 1; }
.world-copy strong { font-size: 1.25rem; line-height: 1.15; }
.world-copy small { color: var(--muted); line-height: 1.4; }
.world-progress-label { font-size: .84rem; font-weight: 900; color: var(--muted); }
.world-progress-track { width: 100%; height: 11px; border-radius: 999px; background: #e8e3f3; overflow: hidden; }
.world-progress-track > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #7e65e3, #54cdb2); }
.square.attack-line { box-shadow: inset 0 0 0 5px rgba(255, 215, 94, .72); }
.square.attack-line::before { content: ''; position: absolute; width: 34%; aspect-ratio: 1; border-radius: 50%; background: rgba(255, 242, 160, .54); z-index: 0; }
.adult-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.route-card { border: 2px solid #d8cffc; }
.world-table-row th { padding-top: 20px; background: #f5f1ff; color: var(--purple-dark); font-size: .9rem; letter-spacing: 0; text-transform: none; }

@media (max-width: 800px) {
  .worlds-grid { grid-template-columns: 1fr; }
  .world-card { min-height: 230px; }
}

@media (max-width: 560px) {
  .worlds-heading { align-items: flex-start; gap: 14px; }
  .worlds-heading .mascot { width: 68px; height: 68px; }
  .worlds-heading h1 { font-size: 2rem; }
  .worlds-panel { border-radius: 28px; padding: 18px 14px; }
  .world-card { min-height: 215px; border-radius: 24px; }
  .world-icon { font-size: 3.5rem; }
  .adult-actions { flex-direction: column; }
}
