:root {
  --bg: #fdf6e9;
  --panel: #ffffff;
  --ink: #3b2f2a;
  --muted: #8a7b72;
  --accent: #7c4dff;
  --accent-2: #ff8a3d;
  --good: #2eae6b;
  --bad: #e5484d;
  --light-sq: #f3e2c3;
  --dark-sq: #b58863;
  --radius: 18px;
  --shadow: 0 6px 18px rgba(80, 50, 20, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito", "Comic Neue", "Segoe UI", system-ui, sans-serif;
  font-size: 18px;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* Barra superior */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
}
.topbar h1 { flex: 1; margin: 0; font-size: 24px; }
.home-btn { font-size: 26px; background: none; border: 0; cursor: pointer; }
.stars-total { font-weight: 800; font-size: 20px; background: rgba(255,255,255,.2); padding: 4px 14px; border-radius: 99px; }

main { max-width: 1200px; margin: 0 auto; padding: 18px; }

.screen { display: none; }
.screen.active { display: block; animation: pop .25s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h2 { margin: 12px 0; }

/* Botones */
.btn {
  font: inherit;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 14px;
  border: 2px solid #e4d6c6;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
}
.btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.small { padding: 6px 12px; font-size: 15px; }
.btn.big { font-size: 22px; padding: 14px 30px; margin-top: 18px; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; text-decoration: underline; }

/* Buho */
.owl-box { display: flex; align-items: center; gap: 14px; margin: 10px 0; }
.owl { width: 90px; height: 90px; flex: none; }
.owl-box.big .owl { width: 140px; height: 140px; }
.owl svg { width: 100%; height: 100%; }
.owl.talking svg { animation: bob .5s ease 2; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.bubble {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  font-size: 20px;
  line-height: 1.35;
  min-height: 56px;
  flex: 1;
}
.bubble:empty { visibility: hidden; }
.bubble::before {
  content: "";
  position: absolute;
  left: -10px; top: 24px;
  border: 10px solid transparent;
  border-right-color: var(--panel);
  border-left: 0;
}
.bubble.good { outline: 3px solid var(--good); }
.bubble.bad { outline: 3px solid var(--bad); }
.bubble.warn { outline: 3px solid var(--accent-2); background: #fff4ea; }

/* Inicio */
.menu { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-top: 20px; }
.card {
  font: inherit;
  text-align: left;
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px;
  border-radius: var(--radius);
  border: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  color: var(--ink);
  transition: transform .15s;
}
.card:hover { transform: translateY(-4px) scale(1.02); }
.card .ic { font-size: 44px; }
.card b { font-size: 22px; }
.card small { color: var(--muted); font-size: 15px; }
.card.locked { opacity: .5; cursor: not-allowed; }
.card.done { outline: 3px solid var(--good); }
.parents-link { display: block; margin: 30px auto 0; }
.name-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 16px 0; font-size: 22px; }
.name-form input { font: inherit; padding: 8px 14px; border-radius: 12px; border: 2px solid #e4d6c6; }

/* Escuela */
.lesson-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.lesson-list .stars { font-size: 18px; letter-spacing: 2px; }

/* Layout de juego */
.play-layout { display: flex; gap: 24px; align-items: flex-start; }
.board-wrap { flex: none; }
.side { flex: 1; min-width: 280px; }
.lesson-head { display: flex; align-items: center; gap: 12px; }
.lesson-head h2 { margin: 0; }
.dots { display: flex; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
.dots span { width: 18px; height: 18px; border-radius: 50%; background: #e4d6c6; }
.dots span.done { background: var(--good); }
.dots span.cur { background: var(--accent); transform: scale(1.2); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.turn { font-weight: 700; color: var(--muted); margin-top: 6px; }
.warn { display: flex; gap: 10px; margin: 8px 0; }
.vs { font-size: 20px; font-weight: 700; }
.moves { margin-top: 14px; color: var(--muted); font-size: 15px; max-height: 140px; overflow: auto; }

/* Tablero */
.board {
  --size: min(78vh, 58vw, 640px);
  width: var(--size);
  height: var(--size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 6px solid #7a5230;
  user-select: none;
  touch-action: none;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.last { box-shadow: inset 0 0 0 100px rgba(255, 220, 60, .45); }
.sq.selected { box-shadow: inset 0 0 0 100px rgba(124, 77, 255, .45); }
.sq.hint { box-shadow: inset 0 0 0 100px rgba(46, 174, 107, .55); animation: pulse 1s infinite; }
.sq.danger { box-shadow: inset 0 0 0 100px rgba(229, 72, 77, .5); }
.sq.check { background: radial-gradient(circle, #ff5a5a 0%, #e5484d 40%, transparent 75%), var(--dark-sq); }
@keyframes pulse { 50% { box-shadow: inset 0 0 0 100px rgba(46, 174, 107, .25); } }
.sq.target::after {
  content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(60, 40, 20, .3);
}
.sq.target-capture::after {
  content: ""; position: absolute; inset: 6%; border-radius: 50%; border: 5px solid rgba(60, 40, 20, .35);
}
.piece {
  font-size: calc(var(--size) / 8 * 0.8);
  line-height: 1;
  cursor: grab;
  font-family: "DejaVu Sans", "Segoe UI Symbol", "Noto Sans Symbols2", "Arial Unicode MS", sans-serif;
  position: relative;
  z-index: 1;
}
.piece.white { color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 2px 3px rgba(0,0,0,.4); }
.piece.black { color: #222; text-shadow: 0 0 2px #fff8, 0 2px 3px rgba(0,0,0,.3); }
.piece.dragging { opacity: .3; }
.piece.ghost { position: fixed; pointer-events: none; z-index: 1000; display: flex; align-items: center; justify-content: center; cursor: grabbing; }
.coord { position: absolute; font-size: 12px; font-weight: 700; opacity: .7; pointer-events: none; }
.coord.rank { top: 3px; left: 4px; }
.coord.file { bottom: 2px; right: 5px; }
.sq.light .coord { color: var(--dark-sq); }
.sq.dark .coord { color: var(--light-sq); }

/* Partida: setup */
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.levels .card.sel, .chip.sel { outline: 4px solid var(--accent); }
.levels .record { font-size: 14px; color: var(--muted); }
.colors { display: flex; gap: 12px; flex-wrap: wrap; }
.chip { font: inherit; font-weight: 700; padding: 10px 18px; border-radius: 99px; border: 0; background: #fff; box-shadow: var(--shadow); cursor: pointer; }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 18px; font-weight: 700; cursor: pointer; }
.switch input { width: 22px; height: 22px; }

/* Medallas */
.medal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.medal { background: #fff; border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow); }
.medal .ic { font-size: 46px; }
.medal b { display: block; margin-top: 6px; }
.medal small { color: var(--muted); }
.medal.off { filter: grayscale(1); opacity: .4; }

/* Panel papa */
.parents { display: grid; gap: 16px; }
.parents .box { background: #fff; border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); }
.parents table { border-collapse: collapse; width: 100%; font-size: 16px; }
.parents th, .parents td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #f0e6da; }
.parents .row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.parents input[type=text] { font: inherit; padding: 6px 10px; border-radius: 10px; border: 2px solid #e4d6c6; }
.tip { background: #f2edff; border-radius: 12px; padding: 10px 14px; margin: 6px 0; }

/* Toast y confeti */
.toast {
  position: fixed; left: 50%; top: 80px; transform: translateX(-50%);
  background: var(--accent-2); color: #fff; font-weight: 800; font-size: 22px;
  padding: 14px 26px; border-radius: 99px; box-shadow: var(--shadow); z-index: 2000;
  animation: pop .3s ease;
}
.confetti { position: fixed; top: -20px; width: 12px; height: 16px; z-index: 1500; pointer-events: none; animation: fall 2.4s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 900px) {
  .play-layout { flex-direction: column; }
  .board { --size: min(92vw, 70vh); }
  .side { width: 100%; }
}

/* Fracciones */
.fx-play { max-width: 820px; margin: 0 auto; }
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1.05; margin: 0 4px; font-weight: 800; }
.frac > span:first-child { border-bottom: 3px solid currentColor; padding: 0 6px; }
.fx-question { font-size: 26px; font-weight: 700; margin: 10px 0; text-align: center; }
.fx-question .story { font-size: 21px; font-weight: 600; text-align: left; background: #fff; border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow); }
.fx-tpl { margin-top: 8px; }
.slot { display: inline-block; min-width: 46px; padding: 2px 8px; border: 3px dashed var(--accent); border-radius: 10px; color: var(--accent); background: #fff; }
.slot.ok { border-style: solid; border-color: var(--good); color: var(--good); }
.fx-visual { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 14px 0; }
.fx-svg.bar { width: min(640px, 100%); }
.fx-svg.pie { width: 220px; }
.fx-svg .part { stroke: #3b2f2a; stroke-width: 3; }
.fx-svg .part.tap { cursor: pointer; }
.fx-svg .part.tap:hover { opacity: .8; }
.fx-svg .lbl { font: 700 24px "Nunito", system-ui, sans-serif; text-anchor: middle; fill: #3b2f2a; }
.fx-svg .lbl.top { font-size: 22px; }
.fx-svg .brace { fill: none; stroke: #3b2f2a; stroke-width: 3; }
.fx-svg .cross { stroke: #e5484d; stroke-width: 5; stroke-linecap: round; }
.fx-row { display: flex; align-items: center; gap: 12px; width: min(720px, 100%); }
.fx-row .fx-tag { width: 60px; font-size: 22px; text-align: center; }
.fx-row .fx-svg.bar { flex: 1; }
.fx-items { font-size: 26px; letter-spacing: 2px; text-align: center; max-width: 640px; line-height: 1.3; }
.fx-input { display: flex; justify-content: center; margin: 10px 0; }
.fx-choices { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.fx-choice { font-size: 26px; min-width: 110px; padding: 14px 22px; }
.fx-choice.good { background: var(--good); border-color: var(--good); color: #fff; }
.fx-choice.bad { background: #ffe1e1; border-color: var(--bad); }
.fx-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 8px; }
.fx-pad .btn { font-size: 24px; padding: 12px 0; }
.fx-big { font-size: 64px; }
#fxActions, #pbActions { justify-content: center; }

/* Probabilidad */
.pb-svg.bag { width: 240px; }
.pb-svg.bag.mini { width: 150px; }
.pb-svg .sack { fill: #d9b98a; stroke: #3b2f2a; stroke-width: 3; }
.pb-svg .tie { fill: none; stroke: #8a5a2b; stroke-width: 6; stroke-linecap: round; }
.pb-svg .ball { stroke: #3b2f2a; stroke-width: 2.5; }
.pb-svg .ball.tap { cursor: pointer; }
.pb-svg .ball.tap:hover { opacity: .8; }
.pb-svg.spin { width: 220px; }
.pb-svg .sector { stroke: #3b2f2a; stroke-width: 3; }
.pb-svg .arrow { stroke: #3b2f2a; stroke-width: 6; stroke-linecap: round; }
.pb-svg .arrow-head, .pb-svg .hub { fill: #3b2f2a; }
.pb-dice { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pb-svg.die { width: 54px; }
.pb-svg.die rect { fill: #fff; stroke: #3b2f2a; stroke-width: 3; }
.pb-svg.die circle { fill: #3b2f2a; }
.pb-emoji { font-size: 72px; line-height: 1.1; }
.fx-choices.wide .fx-choice { padding: 8px; min-width: 0; }


/* Mochila de valentia */
.bv-view { text-align: center; }
.bv-view .lesson-list { text-align: left; }
.bv-view h2 { text-align: left; margin-top: 22px; }
.bv-pack { display: inline-flex; align-items: center; gap: 10px; background: #fff; border-radius: 99px; padding: 8px 18px; box-shadow: var(--shadow); }
.bv-bag { font-size: 40px; }
.bv-slot { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; background: #efe6da; color: var(--muted); font-weight: 800; }
.bv-slot.on { background: #e5f6ec; outline: 2px solid var(--good); }
.bv-stage { min-height: 170px; display: flex; align-items: center; justify-content: center; }
.bv-big { font-size: 110px; }
.bv-big.pop { animation: bvpop .6s ease; }
@keyframes bvpop { 50% { transform: scale(1.25); } }
.bv-q { font-size: 26px; font-weight: 700; margin: 14px auto; max-width: 720px; }
.bv-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; max-width: 900px; margin: 0 auto; }
.bv-opt { align-items: center; text-align: center; }
.bv-opt b { font-size: 19px; }
.bv-next { display: block; margin: 22px auto 0; }
.bv-thermo { display: flex; flex-direction: column; gap: 8px; max-width: 460px; margin: 0 auto; }
.bv-level { font: inherit; display: grid; grid-template-columns: 50px 1fr 110px; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 16px; border: 3px solid transparent; background: #fff; box-shadow: var(--shadow); cursor: pointer; text-align: left; }
.bv-level:hover, .bv-level.sel { border-color: var(--c); }
.bv-face { font-size: 34px; }
.bv-bar { height: 16px; border-radius: 99px; background: var(--c); }
.bv-breath { width: 90px; height: 90px; border-radius: 50%; background: radial-gradient(#b9a4ff, var(--accent)); transition: transform 5s ease-in-out; }
.bv-breath.grow { transform: scale(1.9); transition-duration: 4s; }
.bv-see { display: grid; grid-template-columns: repeat(3, 90px); gap: 12px; justify-content: center; }
.bv-thing { font-size: 48px; height: 90px; border-radius: 18px; border: 3px solid transparent; background: #fff; box-shadow: var(--shadow); cursor: pointer; }
.bv-thing.on { border-color: var(--good); background: #e5f6ec; }
.bv-result { display: flex; align-items: center; justify-content: center; gap: 26px; margin-top: 20px; }
.bv-result div { display: flex; flex-direction: column; align-items: center; background: #fff; border-radius: var(--radius); padding: 14px 24px; box-shadow: var(--shadow); }
.bv-result b { font-size: 64px; }
.bv-arrow { font-size: 40px; color: var(--muted); }
/* Pictogramas */
.pg { background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 12px 16px; max-width: 100%; }
.pg-title { font-weight: 800; font-size: 20px; text-align: center; margin-bottom: 8px; }
.pg-table { border-collapse: collapse; }
.pg-table td { border: 2px solid #3b2f2a; padding: 6px 10px; }
.pg-cat { font-size: 20px; white-space: nowrap; }
.pg-icons { min-width: 220px; }
.pg-ic { width: 34px; height: 34px; vertical-align: middle; }
.pg-ic circle, .pg-ic path { stroke: #3b2f2a; stroke-width: 2.5; }
.pg-ic .tap { cursor: pointer; stroke-dasharray: 4 3; }
.pg-ic .tap:hover { opacity: .8; }
.pg-q { font-size: 30px; }
.pg-key { display: flex; gap: 18px; justify-content: center; align-items: center; margin-top: 10px; font-size: 20px; font-weight: 700; }
.pb-svg.die.hl rect { fill: #ffe08a; }
/* Tablas de conteo y gráficos de barras */
.tl-svg { height: 34px; vertical-align: middle; }
.tl-svg line { stroke: #3b2f2a; stroke-width: 3.5; stroke-linecap: round; }
.fx-choices.wide .fx-choice .tl-svg { height: 40px; }
.bc-svg { width: 440px; max-width: 100%; display: block; }
.bc-svg .grid { stroke: #d8cfc7; stroke-width: 1.5; }
.bc-svg .axis { stroke: #3b2f2a; stroke-width: 2.5; }
.bc-svg .num { font: 700 14px "Nunito", system-ui, sans-serif; text-anchor: end; fill: #3b2f2a; }
.bc-svg .bar { stroke: #3b2f2a; stroke-width: 2.5; }
.bc-svg .part.tap { stroke: #3b2f2a; stroke-width: 1.5; stroke-dasharray: 4 3; cursor: pointer; }
.bc-svg .part.tap:hover { opacity: .8; }
.bc-svg .em { font-size: 22px; text-anchor: middle; }
.bc-svg .nm { font: 700 13px "Nunito", system-ui, sans-serif; text-anchor: middle; fill: #3b2f2a; }
.bc-svg .hid { font: 800 40px "Nunito", system-ui, sans-serif; text-anchor: middle; fill: #8a7a70; }
.lesson-list .lv-group { grid-column: 1 / -1; margin: 12px 0 0; font-size: 24px; border-bottom: 3px solid #e8ddd3; padding-bottom: 6px; }
