/* =========================================================
   KEOTEACH — KEO GAME: PLATAFORMAS
   Escenario 16:9 que se adapta a la pantalla; en móvil
   vertical los mandos y el panel van debajo, en horizontal
   y en pantalla completa los mandos flotan sobre el juego.
========================================================= */

.kp {
    --kp-font: "Space Grotesk", "Inter", system-ui, sans-serif;
    position: relative; width: 100%; max-width: 1180px; margin: 0 auto; outline: none;
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}

.kp-stage {
    position: relative; width: min(100%, calc((100vh - var(--topbar-height) - 120px) * 16 / 9)); margin: 0 auto;
    aspect-ratio: 16 / 9; overflow: hidden; border-radius: 18px;
    border: 3px solid #10131c; background: #10131c;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 255, 255, .06), inset 0 0 0 2px rgba(255, 255, 255, .05);
    touch-action: none;
}

.kp-canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; display: block; }

/* ---------- Marcador ---------- */

.kp-hud {
    position: absolute; left: 0; right: 0; top: 0; z-index: 3;
    display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px;
    background: linear-gradient(rgba(5, 8, 16, .55), transparent); pointer-events: none;
    font-family: var(--kp-font); color: #fff; font-weight: 800; text-shadow: 0 2px 0 rgba(0, 0, 0, .5);
}
.kp-hud > * { pointer-events: auto; }
.kp-hud-left, .kp-hud-right { display: flex; align-items: center; gap: 8px; }
.kp-hearts { display: inline-flex; gap: 2px; font-size: clamp(11px, 1.7vw, 17px); }
.kp-hearts i { color: rgba(255, 255, 255, .25); }
.kp-hearts i.on { color: #ff4d6d; filter: drop-shadow(0 0 4px rgba(255, 77, 109, .6)); animation: kpBeat 1.6s ease-in-out infinite; }
.kp-stat { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; background: rgba(0, 0, 0, .35); font-size: clamp(11px, 1.5vw, 14px); }
.kp-stat .fa-lightbulb { color: #f7c95d; }
.kp-stat .fa-coins { color: #f7c95d; }
.kp-prog { padding: 4px 10px; border-radius: 20px; background: rgba(0, 0, 0, .35); font-size: clamp(11px, 1.5vw, 14px); }
.kp-hud-right button { width: clamp(28px, 4vw, 36px); height: clamp(28px, 4vw, 36px); display: grid; place-items: center; border-radius: 10px; background: rgba(0, 0, 0, .4); color: #fff; font-size: clamp(11px, 1.4vw, 14px); border: 1px solid rgba(255, 255, 255, .15); }
.kp-hud-right button:hover { background: rgba(255, 255, 255, .15); }

.kp-bossbar { display: flex; align-items: center; gap: 8px; min-width: min(46vw, 320px); }
.kp-bossbar span { color: #ff8fa3; font-size: clamp(11px, 1.5vw, 14px); letter-spacing: .1em; }
.kp-bossbar div { flex: 1; height: 12px; border-radius: 8px; background: rgba(0, 0, 0, .5); border: 2px solid #10131c; overflow: hidden; }
.kp-bossbar b { display: block; height: 100%; background: linear-gradient(90deg, #ff3b5c, #ff9d5c); transition: width .5s cubic-bezier(.2, .7, .2, 1); }

/* ---------- Avisos grandes y tarjetas ---------- */

.kp-banner {
    position: absolute; left: 50%; top: 22%; z-index: 4; transform: translateX(-50%);
    padding: 8px 18px; border-radius: 14px; border: 3px solid #10131c; background: #f7c95d; color: #10131c;
    font-family: var(--kp-font); font-weight: 900; font-size: clamp(14px, 3vw, 28px); letter-spacing: .04em; white-space: nowrap;
    box-shadow: 0 8px 0 #10131c; animation: kpBanner .5s cubic-bezier(.34, 1.56, .64, 1); pointer-events: none;
}
.kp-banner.good { background: #42d392; }
.kp-banner.bad { background: #ff6b83; }
.kp-banner.boss { background: #ff3b5c; color: #fff; }

.kp-overlay { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; padding: 12px; background: rgba(5, 8, 16, .62); }
.kp-card {
    width: min(520px, 100%); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 18px;
    border: 3px solid #10131c; border-radius: 18px; background: var(--surface); box-shadow: 0 10px 0 #10131c, 0 30px 60px rgba(0, 0, 0, .5);
    animation: kpBanner .45s cubic-bezier(.34, 1.56, .64, 1); text-align: center;
}
.kp-card h3 { margin: 0; font-family: var(--kp-font); font-size: clamp(18px, 3vw, 26px); }
.kp-tutorial ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; text-align: left; }
.kp-tutorial li { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-soft); }
.kp-key { min-width: 108px; display: inline-flex; justify-content: center; gap: 4px; padding: 5px 8px; border-radius: 8px; border: 2px solid var(--border-strong); border-bottom-width: 4px; background: var(--surface-2); color: var(--text); font-family: var(--font-mono); font-size: 12px; font-weight: 700; }
.kp.is-touch .kp-key { min-width: 44px; }
.kp-tip { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); color: var(--text-soft); font-size: 13px; text-align: left; }
.kp-tip i { margin-top: 3px; color: var(--yellow); }
.kp-go { margin-top: 4px; font-size: 16px; padding: 12px; }

/* ---------- Panel de la pregunta ---------- */

.kp-panel {
    position: absolute; left: 50%; top: 12%; z-index: 5; transform: translateX(-50%);
    width: min(720px, 92%); padding: 12px 14px; border: 3px solid #10131c; border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 94%, transparent); box-shadow: 0 8px 0 #10131c, 0 20px 40px rgba(0, 0, 0, .45);
    animation: kpPanel .4s cubic-bezier(.34, 1.4, .64, 1);
}
.kp-q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.kp-q-tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px; background: #f7c95d; color: #10131c; font-weight: 900; font-size: 12px; }
.kp-q-head small { color: var(--text-muted); font-size: 12px; }
.kp-q-text { margin: 8px 0 10px; font-size: clamp(14px, 1.9vw, 17px); font-weight: 700; line-height: 1.4; }
.kp-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.kp-opt {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; text-align: left;
    border: 2px solid color-mix(in srgb, var(--oc) 60%, #10131c); border-radius: 11px; background: color-mix(in srgb, var(--oc) 12%, var(--surface-2));
    color: var(--text); font-size: 13.5px; line-height: 1.35; transition: transform .2s ease, background .2s ease;
}
.kp-opt b { width: 24px; height: 24px; flex-shrink: 0; display: grid; place-items: center; border-radius: 6px; background: var(--oc); color: #10131c; font-weight: 900; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .25); }
.kp-opt:hover:not(:disabled) { transform: translateY(-2px); background: color-mix(in srgb, var(--oc) 22%, var(--surface-2)); }
.kp-opt:disabled { cursor: default; }
.kp-opt.right { --oc: #42d392; animation: kpRight .5s ease; }
.kp-opt.wrong { --oc: #ff6b83; animation: shake .35s ease; }
.kp-opt.off { opacity: .5; }
.kp-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 0; color: var(--text-muted); font-size: 12.5px; font-weight: 700; }
.kp-link:hover:not(:disabled) { color: var(--text); }
.kp-hint-btn i, .kp-hint i { color: #f7c95d; }
.kp-hint { display: flex; gap: 8px; margin: 8px 0 0; padding: 8px 10px; border-radius: 10px; background: rgba(247, 201, 93, .12); border: 1px solid rgba(247, 201, 93, .35); font-size: 13px; }
.kp-feedback { margin-top: 10px; padding: 10px 12px; border-radius: 12px; border: 2px solid; animation: kpPanel .35s ease; }
.kp-feedback.good { border-color: #42d392; background: rgba(66, 211, 146, .1); }
.kp-feedback.bad { border-color: #ff6b83; background: rgba(255, 107, 131, .1); }
.kp-feedback strong { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.kp-feedback.good strong { color: #42d392; }
.kp-feedback.bad strong { color: #ff8fa3; }
.kp-feedback p { margin: 4px 0 0; color: var(--text-soft); font-size: 13px; }
.kp-feedback-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.kp-feedback-foot .kp-link { margin: 0; }
.kp-report-out { color: var(--text-muted); font-size: 12px; }

/* ---------- Mandos táctiles ---------- */

.kp-pad { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 12px 6px 4px; pointer-events: none; }
.kp-pad > div { display: flex; gap: 12px; pointer-events: auto; }
.kp-pad button {
    width: 64px; height: 64px; display: grid; place-items: center; border-radius: 50%;
    border: 3px solid #10131c; background: rgba(255, 255, 255, .92); color: #10131c; font-size: 26px;
    box-shadow: 0 5px 0 #10131c; touch-action: none; transition: transform .08s ease, box-shadow .08s ease;
}
.kp-pad button.on { transform: translateY(4px); box-shadow: 0 1px 0 #10131c; background: #f7c95d; }
.kp-pad .kp-jump { width: 78px; height: 78px; background: #ff6b83; color: #fff; }
.kp-pad .kp-jump.on { background: #ff8fa3; }

/* Horizontal / pantalla completa en táctil: el JS mete los mandos dentro del escenario y flotan sobre el juego */
.kp-stage > .kp-pad { position: absolute; left: 0; right: 0; bottom: 0; z-index: 4; padding: 0 14px 10px; }
.kp-stage > .kp-pad button { opacity: .78; width: clamp(44px, 11vh, 64px); height: clamp(44px, 11vh, 64px); font-size: clamp(18px, 5vh, 26px); }
.kp-stage > .kp-pad .kp-jump { width: clamp(54px, 14vh, 78px); height: clamp(54px, 14vh, 78px); }

.kp.is-full { display: flex; flex-direction: column; justify-content: center; height: 100vh; max-width: none; background: #05070d; }
.kp.is-full .kp-stage { width: min(100vw, 100vh * 16 / 9); border-radius: 0; border: 0; }
.kp.is-full .kp-panel { top: 12%; z-index: 8; }
.kp.is-full .kp-stage > .kp-pad { padding: 0 22px 18px; }

/* Pantallas estrechas: el panel va debajo del juego para no taparlo */
.kp.is-narrow:not(.is-full) .kp-panel { position: static; transform: none; width: 100%; margin-top: 10px; box-shadow: 0 6px 0 #10131c; }
.kp.is-narrow .kp-opts { grid-template-columns: 1fr; }
.kp.is-narrow .kp-stage { border-radius: 12px; border-width: 2px; }

.kp-rotate { display: none; }

@media (orientation: portrait) and (pointer: coarse) {
    .kp-rotate { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 8px 0 0; color: var(--text-muted); font-size: 12px; }
    .kp-rotate i { animation: kpRotate 2.4s ease-in-out infinite; }
}

@media (max-width: 420px) {
    .kp-pad button { width: 58px; height: 58px; font-size: 22px; }
    .kp-pad .kp-jump { width: 70px; height: 70px; }
    .kp-hud { padding: 5px 6px; gap: 4px; }
    .kp-hud-left { gap: 4px; }
}

/* =========================================================
   MI KEO (armario)
========================================================= */

.kp-keobar {
    display: flex; align-items: center; gap: 14px; margin: 4px 0 18px; padding: 12px 16px;
    border: 1px solid rgba(247, 201, 93, .35); border-radius: 18px;
    background: radial-gradient(circle at 0% 50%, rgba(247, 201, 93, .14), transparent 50%), linear-gradient(145deg, var(--surface), var(--surface-2));
}
.kp-keobar canvas { width: 64px; height: 72px; flex-shrink: 0; image-rendering: pixelated; }
.kp-keobar div { flex: 1; min-width: 0; }
.kp-keobar strong { display: block; font-family: var(--font-display); font-size: 17px; }
.kp-keobar small { color: var(--text-muted); font-size: 12.5px; }
.kp-coins { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 20px; background: rgba(247, 201, 93, .15); color: var(--yellow); font-weight: 800; }

.kp-wardrobe { position: fixed; inset: 0; z-index: 500; display: grid; place-items: center; padding: 14px; background: rgba(2, 5, 11, .72); animation: kxFade .25s ease; }
.kp-wardrobe-card { width: min(860px, 100%); max-height: calc(100vh - 28px); overflow-y: auto; padding: 18px; border-radius: 22px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-lg); animation: modalIn .4s cubic-bezier(.34, 1.56, .64, 1); }
.kp-wardrobe-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.kp-wardrobe-head h3 { margin: 2px 0 4px; font-family: var(--font-display); font-size: 24px; }
.kp-wardrobe-head p { margin: 0; color: var(--text-soft); font-size: 13px; }
.kp-wardrobe-body { display: grid; grid-template-columns: 240px 1fr; gap: 16px; margin-top: 14px; }
.kp-stagebox { display: grid; place-items: center; padding: 12px; border-radius: 18px; background: linear-gradient(#5fa8ff, #b9dcff 75%, #42d392 75%, #2a9c66); border: 3px solid #10131c; min-height: 250px; }
.kp-stagebox canvas { width: 180px; height: 220px; image-rendering: pixelated; }
.kp-wtabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.kp-wtab { padding: 7px 12px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-soft); font-weight: 700; font-size: 13px; }
.kp-wtab.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.kp-wgrid h4 { margin: 4px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.kp-swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.kp-swatch { width: 36px; height: 36px; border-radius: 10px; background: var(--sw); border: 3px solid #10131c; transition: transform .25s cubic-bezier(.34, 1.56, .64, 1); }
.kp-swatch:hover { transform: scale(1.12); }
.kp-swatch.on { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--sw); }
.kp-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.kp-item { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px; border-radius: 14px; border: 2px solid var(--border); background: var(--surface-2); transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), border-color .2s ease; }
.kp-item:hover { transform: translateY(-3px); border-color: var(--border-strong); }
.kp-item.worn { border-color: var(--green); background: rgba(66, 211, 146, .08); }
.kp-item.poor { opacity: .6; }
.kp-item-canvas { width: 64px; height: 72px; image-rendering: pixelated; }
.kp-item strong { font-size: 12.5px; }
.kp-item small { color: var(--text-muted); font-size: 11.5px; }
.kp-item small .fa-coins { color: var(--yellow); }
.kp-item.worn small { color: var(--green); }
.kp-wardrobe-foot { display: flex; justify-content: flex-end; margin-top: 14px; }

@media (max-width: 640px) {
    .kp-wardrobe-body { grid-template-columns: 1fr; }
    .kp-stagebox { min-height: 180px; }
    .kp-stagebox canvas { width: 130px; height: 160px; }
    .kp-keobar { flex-wrap: wrap; }
}

/* ---------- Animaciones ---------- */

@keyframes kpBeat { 0%, 100% { transform: scale(1); } 12% { transform: scale(1.18); } 24% { transform: scale(1); } }
@keyframes kpBanner { from { opacity: 0; transform: translateX(-50%) scale(.6); } to { opacity: 1; transform: translateX(-50%) scale(1); } }
.kp-card { --x: 0; }
.kp-overlay .kp-card { animation-name: kpCard; }
@keyframes kpCard { from { opacity: 0; transform: scale(.85) translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes kpPanel { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%); } }
.kp.is-narrow:not(.is-full) .kp-panel { animation-name: kpPanelStatic; }
@keyframes kpPanelStatic { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes kpRight { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.04); } }
@keyframes kpRotate { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }

@media (prefers-reduced-motion: reduce) {
    .kp-hearts i.on, .kp-banner, .kp-card, .kp-panel, .kp-opt.right, .kp-rotate i, .kp-wardrobe-card { animation: none !important; }
}
