/* Mate Arcade: hoja de cuaderno cuadriculado + figuritas con borde grueso. */
:root {
  --ink: #1d1a39; --paper: #fff8e7; --card: #fffdf6; --muted: #5b5777; --grid: #d9e6f5;
  --accent: #ffc21a; --good: #22a845; --bad: #ff4757;
  --shadow: 5px 5px 0 var(--ink); --shadow-sm: 3px 3px 0 var(--ink);
  font-family: 'Nunito', system-ui, sans-serif; color: var(--ink); font-size: 17px;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-width: 320px; min-height: 100vh;
  background-color: var(--paper);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
}
h1, h2, h3, p { margin: 0; }
h1, h2, .btn, .logo, .count, .clock, .tile, .op, .screen, .fighter, .recta-target, .target b, .cell b, .mface, .code-tiles span, .answer input, .pad button, .countdown strong, .eq-btn, .lane-score, .step b { font-family: 'Fredoka', 'Nunito', sans-serif; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 4px solid #3d8bff; outline-offset: 3px; }
[hidden] { display: none !important; }
sup { font-size: .55em; vertical-align: .9em; line-height: 0; }

/* Barra superior */
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px clamp(12px, 3vw, 32px); background: var(--ink); color: #fff; position: sticky; top: 0; z-index: 10; }
.logo { display: flex; align-items: baseline; gap: 6px; font-weight: 700; font-size: 26px; letter-spacing: .5px; }
.logo-a { background: var(--accent); color: var(--ink); padding: 0 8px; border-radius: 8px; transform: rotate(-3deg); display: inline-block; transition: background .3s; }
.logo-b { color: #fff; }
.grade { font-weight: 800; font-size: 14px; color: #c9c5ef; }
.topbar-space { flex: 1; }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; font-weight: 800; font-size: 15px; background: #fff; color: var(--ink); border: 2.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); }
.topbar .chip-btn { border-color: #fff; box-shadow: none; background: transparent; color: #fff; }
.topbar .chip-btn:hover { background: #ffffff1f; }
.chip-btn:disabled { opacity: .4; }
.chip-btn.round { width: 38px; height: 38px; padding: 0; justify-content: center; font-size: 19px; }

/* Botones */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: 14px; border: 3px solid var(--ink); box-shadow: var(--shadow-sm); font-weight: 600; font-size: 19px; background: #fff; transition: transform .08s, box-shadow .08s; }
.btn:not(:disabled):hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:not(:disabled):active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; }
.btn.go { background: var(--accent); }
.btn.big { font-size: 22px; padding: 15px 22px; width: 100%; }
.btn.small { font-size: 16px; padding: 8px 12px; border-radius: 11px; }

main { width: min(1180px, calc(100% - 28px)); margin: 0 auto; padding: 22px 0 40px; }
.back { font-weight: 800; color: var(--muted); padding: 6px 0; font-size: 16px; }
.back:hover { color: var(--ink); }
.form-error { color: #c4142b; font-weight: 800; min-height: 1.2em; margin-top: 8px; }
.mini-title { font-weight: 800; font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* Portada */
.home-head { display: flex; gap: 24px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 22px; }
.home-head h1 { font-size: clamp(36px, 5vw, 56px); line-height: 1; }
.lead { margin-top: 10px; max-width: 620px; font-size: 18px; color: var(--muted); font-weight: 700; }
.lead b { color: var(--ink); }
.join-card { background: var(--ink); color: #fff; border-radius: 18px; padding: 14px 16px; box-shadow: 5px 5px 0 var(--accent); transform: rotate(1deg); }
.join-card label { font-weight: 800; font-size: 15px; display: block; margin-bottom: 8px; }
.join-row { display: flex; gap: 8px; }
.code-input { width: 150px; padding: 8px 10px; border-radius: 12px; border: 3px solid #fff; background: #fff; color: var(--ink); font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: 26px; letter-spacing: .2em; text-transform: uppercase; text-align: center; }
.code-input::placeholder { color: #c9c5df; }
.join-card .btn { box-shadow: none; border-color: #fff; }
.join-card .form-error { color: #ffb3bd; min-height: 0; }

.games { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.game { position: relative; background: var(--card); border: 3px solid var(--ink); border-radius: 20px; box-shadow: var(--shadow); padding: 0 0 14px; display: flex; flex-direction: column; overflow: hidden; transition: transform .15s; }
.game:nth-child(odd) { transform: rotate(-.6deg); }
.game:nth-child(even) { transform: rotate(.6deg); }
.game:hover { transform: rotate(0) translateY(-3px); }
.game-art { height: 118px; background: var(--c); border-bottom: 3px solid var(--ink); display: grid; place-items: center; position: relative; overflow: hidden;
  background-image: radial-gradient(#ffffff55 2px, transparent 2.5px); background-size: 16px 16px; }
.game-art span { font-size: 64px; filter: drop-shadow(3px 3px 0 #1d1a3955); transition: transform .2s; }
.game:hover .game-art span { transform: scale(1.12) rotate(-6deg); }
.game h2 { font-size: 22px; line-height: 1.1; margin: 14px 16px 6px; }
.game p { font-size: 15px; color: var(--muted); font-weight: 700; margin: 0 16px 14px; flex: 1; }
.game-actions { display: flex; gap: 8px; padding: 0 14px; }
.game-actions .btn { flex: 1; padding-inline: 6px; }
.game-actions .btn.go { background: var(--c); }
.record { position: absolute; top: 8px; right: 8px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 9px; font-weight: 800; font-size: 13px; }
.teacher { margin-top: 30px; background: var(--card); border: 2.5px dashed var(--muted); border-radius: 14px; padding: 12px 16px; color: var(--muted); font-weight: 700; font-size: 15px; }
.teacher summary { cursor: pointer; font-weight: 800; color: var(--ink); }
.teacher p { margin-top: 10px; max-width: 900px; }

/* Preparar */
.setup-card { margin-top: 12px; display: grid; grid-template-columns: 300px 1fr; background: var(--card); border: 3px solid var(--ink); border-radius: 24px; box-shadow: var(--shadow); overflow: hidden; }
.setup-art { background: var(--accent); border-right: 3px solid var(--ink); display: grid; place-items: center; background-image: radial-gradient(#ffffff55 2px, transparent 2.5px); background-size: 18px 18px; }
.setup-art span { font-size: 130px; filter: drop-shadow(5px 5px 0 #1d1a3955); animation: bob 2.4s ease-in-out infinite; }
.setup-body { padding: 26px 28px; }
.setup-body h1 { font-size: 40px; }
.rule { font-size: 18px; font-weight: 700; color: var(--muted); margin: 8px 0 20px; max-width: 640px; }
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 8px 0 20px; }
.levels button { text-align: left; border: 3px solid var(--ink); border-radius: 14px; padding: 10px 12px; background: #fff; display: grid; gap: 3px; }
.levels button b { font-family: 'Fredoka', sans-serif; font-size: 20px; }
.levels button small { font-weight: 700; color: var(--muted); font-size: 13px; line-height: 1.25; }
.levels button[aria-pressed="true"] { background: var(--accent); box-shadow: var(--shadow-sm); transform: translate(-2px, -2px); }
.levels button[aria-pressed="true"] small { color: var(--ink); }
.setup-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.btn.plain { background: #fff; }

/* Sala de espera */
.lobby { margin-top: 12px; display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: start; }
.lobby-code-card { background: var(--card); border: 3px solid var(--ink); border-radius: 24px; box-shadow: var(--shadow); padding: 30px; text-align: center; display: grid; gap: 18px; justify-items: center; }
.code-tiles { display: flex; gap: 12px; }
.code-tiles span { width: clamp(60px, 9vw, 104px); aspect-ratio: 1; display: grid; place-items: center; font-size: clamp(42px, 7vw, 76px); font-weight: 700; background: var(--accent); border: 3.5px solid var(--ink); border-radius: 16px; box-shadow: var(--shadow); transform: rotate(calc((var(--i) - 1.5) * 3deg)); }
.lobby-side { display: grid; gap: 14px; }
.lobby-game { display: flex; gap: 14px; align-items: center; background: var(--card); border: 3px solid var(--ink); border-radius: 18px; padding: 14px 16px; }
.lobby-emoji { font-size: 46px; }
.lobby-game b { font-family: 'Fredoka', sans-serif; font-size: 24px; display: block; }
.lobby-game small { font-weight: 700; color: var(--muted); }
.seats { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.seats.many { max-height: 300px; overflow-y: auto; gap: 6px; padding: 2px; }
.seats.many .seat { padding: 6px 4px; }
.seats.many .seat-emoji { font-size: 28px; }
.seats.many .seat b { font-size: 15px; }
.seat { border: 3px dashed #aaa6c4; border-radius: 16px; padding: 12px 6px; text-align: center; display: grid; gap: 2px; background: #ffffff99; color: var(--muted); }
.seat-emoji { font-size: 42px; }
.seat.here { border: 3px solid var(--ink); background: var(--c); color: #fff; box-shadow: var(--shadow-sm); }
.seat.here .seat-emoji { animation: bob 1.6s ease-in-out infinite; }
.seat b { font-family: 'Fredoka', sans-serif; font-size: 18px; }
.seat small { font-weight: 800; }
.lobby-hint { font-weight: 800; color: var(--muted); text-align: center; }

/* Partida */
.play-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.play-bar h1 { font-size: 26px; }
.tag { font-weight: 800; font-size: 14px; background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 3px 10px; }
.clock { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 22px; background: var(--ink); color: #fff; padding: 2px 12px; border-radius: 10px; font-variant-numeric: tabular-nums; }

.race { display: grid; gap: 6px; background: var(--ink); border-radius: 18px; padding: 10px 14px; margin-bottom: 14px; box-shadow: 5px 5px 0 var(--accent); }
.lane { display: grid; grid-template-columns: 110px 1fr 60px; align-items: center; gap: 10px; color: #fff; }
.lane-name { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lane.mine .lane-name { color: var(--c); }
.track { position: relative; height: 38px; border-radius: 10px; background: repeating-linear-gradient(90deg, #ffffff22 0 14px, transparent 14px 28px) center / 100% 3px no-repeat, #2d2a50; font-size: 26px; }
.lane.mine .track { background: repeating-linear-gradient(90deg, #ffffff44 0 14px, transparent 14px 28px) center / 100% 3px no-repeat, color-mix(in srgb, var(--c) 35%, #2d2a50); outline: 2px solid var(--c); }
.runner { position: absolute; top: 50%; left: 0; margin-left: 4px; transform: translateY(-50%); transition: left .6s cubic-bezier(.3, 1.4, .5, 1); line-height: 1; padding: 0 .1em; }
.finish { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 22px; }
.lane-score { font-size: 20px; text-align: right; font-variant-numeric: tabular-nums; }
.lane.offline { opacity: .5; }
/* Con más de 6 en la sala: carriles finos y tablero con scroll. */
.race.compact { gap: 3px; max-height: 34vh; overflow-y: auto; padding: 8px 12px; }
.race.compact .track { height: 24px; font-size: 17px; }
.race.compact .finish { font-size: 15px; }
.race.compact .lane-name { font-size: 13px; }
.race.compact .lane-score { font-size: 15px; }

.stage-card { position: relative; background: var(--card); border: 3px solid var(--ink); border-radius: 24px; box-shadow: var(--shadow); padding: 16px 22px 18px; min-height: 420px; transition: box-shadow .3s; }
.stage-card.on-fire { box-shadow: 5px 5px 0 var(--ink), 0 0 0 5px #ff9f1c, 0 0 30px #ff9f1c88; }
.stage-card.shake { animation: shake .35s; }
.stage-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; min-height: 30px; }
.count { font-weight: 600; font-size: 18px; background: var(--accent); border: 2.5px solid var(--ink); border-radius: 999px; padding: 1px 14px; }
.streak { font-weight: 800; color: #e2620a; font-size: 18px; }
#stage.enter > * { animation: enter .3s ease-out; }
.feedback { min-height: 30px; text-align: center; font-weight: 800; font-size: 19px; margin-top: 8px; }
.feedback.good { color: var(--good); }
.feedback.bad { color: #d21f3c; }
.hint-row { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.hint-text { background: #fff4c2; border: 2px solid var(--ink); border-radius: 12px; padding: 6px 12px; font-weight: 700; max-width: 680px; }
.connection { text-align: center; font-weight: 800; color: #c4142b; margin-top: 10px; }
.waiting { text-align: center; padding: 70px 0; font-size: 70px; }
.waiting p { font-size: 22px; font-weight: 800; margin-top: 10px; }

.freeze { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 3; display: flex; align-items: center; gap: 10px; background: #d7f1ff; border: 3px solid var(--ink); border-radius: 999px; padding: 6px 18px 6px 10px; box-shadow: var(--shadow-sm); overflow: hidden; animation: drop .25s ease-out; }
.freeze span { font-size: 28px; }
.freeze b { font-family: 'Fredoka', sans-serif; font-size: 20px; }
.freeze i { position: absolute; left: 0; bottom: 0; height: 5px; width: 100%; background: #3d8bff; transform-origin: left; animation: drain linear forwards; }

/* Fracciones apiladas y número escondido */
.fr { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; line-height: 1; margin: 0 .08em; font-size: .78em; }
.fr b { font-weight: inherit; padding: 0 .12em; }
.fr b:first-child { border-bottom: .09em solid currentColor; padding-bottom: .06em; }
.fr b:last-child { padding-top: .06em; }
.hole { display: inline-grid; place-items: center; min-width: 1.15em; height: 1.15em; border: .08em dashed currentColor; border-radius: .2em; color: #e2620a; background: #fff1d6; vertical-align: middle; }

/* Respuesta con número */
.answer { display: grid; grid-template-columns: auto auto; gap: 10px 14px; align-items: start; justify-content: center; }
.answer-line { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 10px; }
.answer input { width: 210px; font-size: 40px; font-weight: 700; text-align: center; padding: 4px 10px; border: 3.5px solid var(--ink); border-radius: 14px; background: #fff; box-shadow: inset 0 3px 0 #0000000d; }
.answer input:focus { outline: none; border-color: #3d8bff; box-shadow: 0 0 0 4px #3d8bff44; }
.answer input::placeholder { color: #c9c5df; }
.answer-unit { font-weight: 800; font-size: 20px; color: var(--muted); }
.pad { display: grid; grid-template-columns: repeat(3, 52px); gap: 6px; }
.pad button { height: 44px; border: 2.5px solid var(--ink); border-radius: 10px; background: #fff; font-size: 22px; font-weight: 600; box-shadow: 2px 2px 0 var(--ink); }
.pad button:active { transform: translate(2px, 2px); box-shadow: none; }
.answer .ok { align-self: stretch; font-size: 22px; padding-inline: 18px; }

/* ⚡ */
.turbo { display: grid; grid-template-columns: 1.3fr 1fr; gap: 26px; align-items: center; padding: 8px 0; }
.screen { position: relative; background: #24304a; color: #b8ff6a; border: 4px solid var(--ink); border-radius: 22px; padding: 46px 22px; text-align: center; box-shadow: inset 0 0 0 6px #33405e, var(--shadow); min-height: 240px; display: grid; place-items: center; }
.screen::after { content: ''; position: absolute; inset: 6px; border-radius: 16px; background: repeating-linear-gradient(#ffffff08 0 2px, transparent 2px 5px); pointer-events: none; }
.screen-n { position: absolute; top: 12px; left: 16px; color: #8fa3c7; font-size: 16px; }
.expr { font-size: clamp(36px, 5.2vw, 64px); font-weight: 600; line-height: 1.2; text-shadow: 0 0 18px #b8ff6a66; }
.expr .hole { background: #b8ff6a22; color: #fff; }
.eq-sign { color: #8fa3c7; }
.turbo .answer { grid-template-columns: auto auto; }

/* 🥊 */
.duel { text-align: center; padding: 10px 0; }
.duel-q { font-family: 'Fredoka', sans-serif; font-size: 26px; font-weight: 600; margin-bottom: 18px; }
.duel-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: center; max-width: 900px; margin: 0 auto; }
.fighter { min-height: 200px; border: 4px solid var(--ink); border-radius: 24px; background: #fff; box-shadow: var(--shadow); font-size: clamp(36px, 5vw, 58px); font-weight: 600; padding: 16px; transition: transform .1s; }
.fighter:first-child { background: #ffe1e2; transform: rotate(-1.5deg); }
.fighter:last-child { background: #dbe9ff; transform: rotate(1.5deg); }
.fighter:hover { transform: scale(1.03); }
.fighter.right { background: #c9f7d1 !important; }
.fighter.wrong { background: #ffc4c9 !important; }
.eq-btn { width: 78px; height: 78px; border-radius: 50%; border: 4px solid var(--ink); background: var(--accent); font-size: 40px; font-weight: 700; box-shadow: var(--shadow-sm); }
.keys { margin-top: 18px; color: var(--muted); font-weight: 800; }
kbd { display: inline-block; min-width: 1.8em; padding: 1px 6px; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 7px; background: #fff; font-family: 'Fredoka', sans-serif; color: var(--ink); margin: 0 2px; }

/* 🔎 */
.detective { display: grid; grid-template-columns: 1.45fr 1fr; gap: 22px; align-items: center; }
.chart-card { background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 12px 12px 6px; }
.chart-title { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 19px; margin: 0 4px 4px; }
.chart-title small { font-family: 'Nunito', sans-serif; color: var(--muted); font-size: 14px; }
.chart { width: 100%; display: block; }
.chart .grid { stroke: #d6dcea; stroke-width: 1.5; }
.chart .tickmark, .chart .axis { stroke: var(--ink); stroke-width: 2.5; }
.chart .tick { font: 700 15px 'Nunito', sans-serif; fill: var(--muted); }
.chart .cat { font: 800 15px 'Nunito', sans-serif; fill: var(--ink); }
.chart .bar { stroke: var(--ink); stroke-width: 2.5; }
.chart .col-hit, .chart .pt-hit { fill: transparent; }
.chart .seg-hit { stroke: transparent; stroke-width: 26; stroke-linecap: round; }
.chart .seg-line { stroke: #3d8bff; stroke-width: 5; stroke-linecap: round; }
.chart .dot { fill: #fff; stroke: var(--ink); stroke-width: 3.5; }
.chart[data-mode="cat"] .col, .chart[data-mode="point"] .pt, .chart[data-mode="segment"] .seg { cursor: pointer; }
.chart[data-mode="cat"] .col:hover .col-hit { fill: #ffc21a33; }
.chart[data-mode="point"] .pt:hover .dot { fill: var(--accent); }
.chart[data-mode="segment"] .pt { pointer-events: none; }
.chart[data-mode="segment"] .seg:hover .seg-line { stroke: #ff8a3d; stroke-width: 8; }
.chart .tap.right .col-hit, .chart .tap.right .seg-line { fill: #22a84533; stroke: var(--good); }
.chart .tap.right .dot { fill: var(--good); }
.chart .tap.wrong .col-hit { fill: #ff475733; }
.chart .tap.wrong .seg-line { stroke: var(--bad); }
.chart .tap.wrong .dot { fill: var(--bad); }
.legend { list-style: none; display: flex; gap: 16px; padding: 0; margin: 2px 6px 4px; font-weight: 800; font-size: 15px; }
.legend i { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--ink); border-radius: 4px; margin-right: 6px; vertical-align: -2px; }
.legend.col { flex-direction: column; gap: 10px; font-size: 17px; }
.pie-wrap { display: flex; align-items: center; gap: 22px; justify-content: center; padding: 8px 0; }
.pie-wrap .chart { width: min(280px, 55%); }
.case { display: grid; gap: 14px; }
.case-n { font-weight: 800; color: var(--muted); }
.case-q { font-size: 25px; line-height: 1.25; }
.tap-note { font-weight: 800; font-size: 20px; background: #fff4c2; border: 2.5px solid var(--ink); border-radius: 14px; padding: 8px 14px; justify-self: start; }
.case .answer { justify-content: start; }
.case .answer-line { justify-content: start; }

/* 🎯 */
.recta { text-align: center; padding: 6px 0; }
.recta-ask { font-weight: 800; font-size: 20px; color: var(--muted); }
.recta-target { display: inline-block; margin: 8px 0 24px; font-size: 62px; font-weight: 700; background: var(--accent); border: 4px solid var(--ink); border-radius: 20px; padding: 2px 28px; box-shadow: var(--shadow); transform: rotate(-2deg); min-width: 150px; }
.numline { position: relative; height: 150px; cursor: crosshair; margin: 0 auto; max-width: 1000px; }
.scale { position: absolute; left: 5%; right: 5%; top: 0; bottom: 0; }
.axis-line { position: absolute; left: -3%; right: -3%; top: 70px; height: 6px; background: var(--ink); border-radius: 3px; }
.axis-line::after { content: ''; position: absolute; right: -10px; top: -8px; border: 11px solid transparent; border-left: 14px solid var(--ink); }
.tk { position: absolute; top: 50px; width: 0; }
.tk::before { content: ''; position: absolute; left: -3px; width: 6px; height: 46px; background: var(--ink); border-radius: 3px; }
.tk.minor::before { top: 12px; height: 22px; width: 4px; left: -2px; }
.tk b { position: absolute; top: 56px; left: 50%; transform: translateX(-50%); font-family: 'Fredoka', sans-serif; font-size: 32px; font-weight: 600; }
.shot { position: absolute; top: 18px; transform: translateX(-50%); font-size: 46px; line-height: 1; animation: drop .25s ease-out; pointer-events: none; }
.truth { position: absolute; top: 96px; transform: translateX(-4px); font-size: 22px; pointer-events: none; animation: enter .3s ease-out; }
.truth::before { content: '🚩'; font-size: 34px; position: absolute; left: -4px; top: -20px; }
.truth i { position: absolute; left: 30px; top: 6px; font-style: normal; font-weight: 800; background: #fff; border: 2px solid var(--ink); border-radius: 8px; padding: 0 6px; white-space: nowrap; font-size: 18px; }
.recta-note { color: var(--muted); font-weight: 800; margin-top: 6px; }

/* 🧩 */
.cifras { display: grid; justify-items: center; gap: 14px; padding: 4px 0; }
.target { display: flex; align-items: center; gap: 14px; background: var(--ink); color: #fff; border-radius: 18px; padding: 6px 22px; box-shadow: 5px 5px 0 var(--accent); }
.target small { font-weight: 800; text-transform: uppercase; letter-spacing: .08em; font-size: 14px; color: #c9c5ef; }
.target b { font-size: 56px; font-weight: 700; color: var(--accent); }
.tiles { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; min-height: 100px; }
.tile { min-width: 96px; height: 96px; padding: 0 12px; font-size: 42px; font-weight: 700; border: 4px solid var(--ink); border-radius: 18px; background: #fff; box-shadow: var(--shadow); transition: transform .1s; }
.tile:hover { transform: translateY(-3px); }
.tile.made { background: #e7dcff; }
.tile.sel { background: var(--accent); transform: translateY(-8px) rotate(-3deg); }
.ops { display: flex; gap: 10px; }
.op { width: 64px; height: 64px; border-radius: 50%; border: 3.5px solid var(--ink); background: #fff; font-size: 34px; font-weight: 700; box-shadow: var(--shadow-sm); }
.op.sel { background: var(--ink); color: var(--accent); }
.cifras-help { font-weight: 800; color: var(--muted); }
.log { list-style: none; padding: 0; margin: 0; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: 32px; }
.log li { background: #f0ebff; border: 2px solid var(--ink); border-radius: 10px; padding: 2px 10px; font-weight: 800; }
.row { display: flex; gap: 10px; }

/* 🐭 */
.maze-wrap { display: grid; grid-template-columns: auto auto; gap: 8px 28px; justify-content: center; align-items: center; }
.maze-rule { background: var(--ink); color: #fff; border-radius: 18px; padding: 14px 18px; box-shadow: 5px 5px 0 var(--accent); max-width: 240px; }
.maze-rule small { display: block; font-weight: 800; color: #c9c5ef; text-transform: uppercase; font-size: 13px; letter-spacing: .08em; }
.maze-rule b { font-family: 'Fredoka', sans-serif; font-size: 28px; line-height: 1.1; }
.maze { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 6px; width: min(430px, 80vw); background: #6b4f2a; padding: 8px; border-radius: 16px; border: 3px solid var(--ink); }
.cell { position: relative; aspect-ratio: 1; border-radius: 10px; background: #f6e7c4; border: 2.5px solid #4a3519; font-size: clamp(16px, 2.6vw, 24px); display: grid; place-items: center; }
.cell b { font-weight: 600; }
.cell.next:not(.bad):hover { background: #fff; }
.cell.trail { background: #b8f0c4; }
.cell.here { background: var(--accent); }
.cell.goal { background: #ffe68a; }
.cell.bad { background: #ff9aa5; }
.cell.bad::after { content: '✕'; position: absolute; top: 0; right: 4px; font-size: 14px; color: #a1001a; font-weight: 900; }
.mouse { position: absolute; top: -16px; left: -12px; font-size: 26px; animation: bob 1s ease-in-out infinite; }
.cheese { position: absolute; top: -12px; right: -8px; font-size: 28px; }
.maze-wrap .keys { grid-column: 1 / -1; text-align: center; margin: 0; }

/* 🃏 */
.memory-wrap { display: grid; justify-items: center; gap: 10px; }
.memory { display: grid; grid-template-columns: repeat(var(--cols), 118px); gap: 10px; perspective: 900px; }
.mcard { position: relative; height: 82px; transform-style: preserve-3d; transition: transform .35s; }
.mcard.open { transform: rotateY(180deg); }
.mback, .mface { position: absolute; inset: 0; display: grid; place-items: center; border: 3px solid var(--ink); border-radius: 14px; backface-visibility: hidden; box-shadow: var(--shadow-sm); }
.mback { background: #ff4fa3; color: #fff; font-family: 'Fredoka', sans-serif; font-size: 40px; font-weight: 700; background-image: radial-gradient(#ffffff44 2px, transparent 2.5px); background-size: 12px 12px; }
.mface { background: #fff; transform: rotateY(180deg); font-size: 30px; font-weight: 600; }
.mcard.done .mface { background: #c9f7d1; }
.memory-info { font-weight: 800; color: var(--muted); }

/* ⚖️ */
.balanzas { display: grid; grid-template-columns: 1.3fr 1fr; gap: 22px; align-items: center; }
.scales { display: grid; gap: 4px; }
.scales.two .balance { max-height: 200px; }
.balance { width: 100%; max-height: 300px; }
.balance .bq { font: 700 22px 'Fredoka', sans-serif; fill: var(--ink); }
.balance .bw { font: 700 17px 'Fredoka', sans-serif; fill: #fff; }
.legend-line { font-weight: 800; color: var(--muted); }

/* Cuenta regresiva, diálogos y efectos */
.countdown { position: fixed; inset: 0; z-index: 40; display: grid; place-content: center; text-align: center; background: #1d1a39e6; color: #fff; }
.countdown strong { font-size: min(40vw, 260px); line-height: 1; color: var(--accent); text-shadow: 8px 8px 0 #000; }
.countdown strong.pop { animation: pop .5s ease-out; }
.countdown p { font-weight: 800; font-size: 24px; }
dialog { border: 3.5px solid var(--ink); border-radius: 24px; box-shadow: 8px 8px 0 var(--ink); padding: 26px 30px; max-width: min(560px, calc(100% - 24px)); background: var(--card); color: var(--ink); text-align: center; }
dialog::backdrop { background: #1d1a39aa; }
dialog h2 { font-size: 36px; margin: 6px 0; }
dialog p { font-weight: 700; color: var(--muted); font-size: 18px; }
#rules-dialog p { margin: 10px 0 18px; color: var(--ink); }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 18px 0 8px; }
.step { width: 110px; background: var(--c); color: #fff; border: 3px solid var(--ink); border-radius: 14px 14px 4px 4px; display: grid; justify-items: center; align-content: start; padding: 8px 4px; gap: 1px; }
.step.p1 { min-height: 170px; } .step.p2 { min-height: 130px; } .step.p3 { min-height: 100px; }
.step-emoji { font-size: 40px; margin-top: -34px; filter: drop-shadow(2px 2px 0 #1d1a3966); }
.step.p1 .step-emoji { animation: bob 1s ease-in-out infinite; }
.step b { font-size: 26px; }
.step small { font-weight: 800; }
.step em { font-style: normal; font-weight: 800; opacity: .9; }
#result-status { margin: 8px 0 16px; color: var(--ink); }
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.spark { position: fixed; font-size: 22px; font-weight: 900; }
.confetti { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall linear forwards; }

@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -14px); } }
@keyframes drain { to { transform: scaleX(0); } }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } }
@keyframes fall { to { transform: translate(var(--x), 105vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* Notebook baja: todo entra sin scroll en 1366×768 */
@media (max-height: 800px) and (min-width: 900px) {
  main { padding-top: 12px; }
  .race { padding: 6px 12px; gap: 3px; margin-bottom: 10px; }
  .track { height: 30px; font-size: 22px; }
  .stage-card { padding: 10px 18px 12px; min-height: 0; }
  .screen { min-height: 200px; padding: 34px 18px; }
  .fighter { min-height: 160px; }
  .numline { height: 140px; }
  .recta-target { margin-bottom: 14px; font-size: 52px; }
  .chart-card .chart:not(.pie) { max-height: 290px; }
  .memory .mcard { height: 70px; }
  .tile { height: 84px; min-width: 84px; font-size: 38px; }
  .cifras { gap: 10px; }
  .maze { width: min(380px, 80vw); }
  .feedback { margin-top: 4px; min-height: 26px; }
  .scales.two .balance { max-height: 170px; }
}
@media (max-width: 1000px) {
  .games { grid-template-columns: repeat(2, 1fr); }
  .detective, .balanzas, .turbo { grid-template-columns: 1fr; }
  .lobby { grid-template-columns: 1fr; }
  .setup-card { grid-template-columns: 1fr; }
  .setup-art { border-right: 0; border-bottom: 3px solid var(--ink); height: 170px; }
  .setup-art span { font-size: 96px; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .games { grid-template-columns: 1fr; }
  .topbar .grade, #sound-label { display: none; }
  .topbar { gap: 8px; padding-inline: 10px; }
  .topbar .chip-btn { padding: 6px 10px; font-size: 14px; }
  .logo { font-size: 21px; }
  .levels, .setup-actions { grid-template-columns: 1fr; }
  .seats { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .lane { grid-template-columns: 70px 1fr 46px; }
  .duel-row { grid-template-columns: 1fr; }
  .eq-btn { justify-self: center; }
  .memory { grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); width: 100%; }
  .maze-wrap { grid-template-columns: 1fr; justify-items: center; }
  .stage-card { padding: 12px; }
  .answer { grid-template-columns: 1fr; justify-items: center; }
  .answer input { width: 170px; }
  .code-tiles { gap: 6px; }
  .join-card { transform: none; width: 100%; }
}
@media (max-width: 400px) {
  .logo { font-size: 18px; }
  .logo-a { padding: 0 5px; }
}

.lobby-picker { display: grid; gap: 8px; background: var(--card); border: 3px solid var(--ink); border-radius: 18px; padding: 12px 14px; }
.room-games { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.room-games button, .room-levels button { border: 3px solid var(--ink); border-radius: 12px; background: #fff; padding: 6px 8px; display: flex; gap: 6px; align-items: center; text-align: left; }
.room-games button b { font-family: 'Fredoka', sans-serif; font-size: 15px; line-height: 1.1; }
.room-games button span { font-size: 24px; }
.room-levels { display: flex; flex-wrap: wrap; gap: 8px; }
.room-levels button b { font-family: 'Fredoka', sans-serif; font-size: 15px; }
.room-games button[aria-pressed="true"], .room-levels button[aria-pressed="true"] { background: var(--c, var(--accent)); box-shadow: var(--shadow-sm); transform: translate(-1px, -1px); }
