:root {
  --verde: #2b6a4f; --verde2: #3f9b6f; --amarillo: #ffc93c; --crema: #fffdf6;
  --tinta: #2d2a32; --rojo: #e4572e; --azul: #3a86ff; --borde: #e2dcc8;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; color: var(--tinta); background: var(--crema); line-height: 1.4; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: .3em 0 .5em; }
.error { color: var(--rojo); font-weight: 700; min-height: 1.4em; margin: .4em 0; }
.mini { color: #6b6672; font-size: 14px; margin: .2em 0; }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 22px; border: 0; border-radius: 16px;
  background: var(--verde); color: #fff; font-weight: 800; font-size: 16px; text-decoration: none; box-shadow: 0 4px 0 rgba(0, 0, 0, .22); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .22); }
.btn.grande { width: 100%; font-size: 19px; margin-top: 10px; }
.btn.sec { background: #ebe5d2; color: var(--tinta); }
.btn.rojo { background: var(--rojo); }
.btn.chico { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: 12px; box-shadow: 0 3px 0 rgba(0, 0, 0, .2); }
.link { background: none; border: 0; color: var(--verde); font-weight: 700; padding: 12px; text-decoration: underline; }
.fila { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.fila .btn { flex: 1; }

/* ---------- Avatares y marcos ---------- */
.av { display: inline-flex; flex: none; width: 48px; height: 48px; padding: 4px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.av > span { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 50%; background: #fff7dc; font-size: 26px; }
.av.chico { width: 44px; height: 44px; }
.marco-plata { background: linear-gradient(135deg, #f5f5f5, #8f9aa3, #f5f5f5); }
.marco-oro { background: linear-gradient(135deg, #fff3a6, #e0a800, #fff3a6); box-shadow: 0 0 10px #ffd34e; }
.marco-fuego { background: linear-gradient(0deg, #ff3d00, #ffb300, #ff3d00); box-shadow: 0 0 12px #ff6a00; animation: fuego 1s infinite alternate; }
.marco-hielo { background: linear-gradient(135deg, #e1f5ff, #4db5ff, #e1f5ff); box-shadow: 0 0 10px #9fdcff; }
.marco-neon { background: linear-gradient(135deg, #00ffd5, #ff00e6); box-shadow: 0 0 12px #ff00e6, 0 0 6px #00ffd5; }
.marco-arcoiris { background: conic-gradient(#f33, #fa0, #ee0, #3d3, #0cf, #55f, #e3e, #f33); }
@keyframes fuego { to { box-shadow: 0 0 20px #ffb300; } }

/* ---------- Entrada del alumno ---------- */
body.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px;
  background: linear-gradient(#8fd3ff 0%, #d5f1ff 45%, #9be09a 45%, #5fb878 100%); }
.tarjeta { width: 100%; max-width: 420px; background: var(--crema); border-radius: 28px; padding: 24px 20px 14px; text-align: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .2); }
.tarjeta .logo { font-size: 56px; line-height: 1; }
.tarjeta h1 { color: var(--verde); font-size: 30px; }
.tarjeta input { width: 100%; height: 64px; font-size: 32px; text-align: center; letter-spacing: 6px; text-transform: uppercase; border: 3px solid var(--borde); border-radius: 18px; background: #fff; }
.tarjeta input:focus { outline: none; border-color: var(--azul); }
.rejilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 10px 0; }
.alumno { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; background: #fff; border: 3px solid var(--borde); border-radius: 18px; min-height: 108px; }
.alumno .av { width: 56px; height: 56px; } .alumno .av > span { font-size: 32px; }
.alumno:active { border-color: var(--azul); }
#quien { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 22px; margin-bottom: 4px; }
#puntos { font-size: 38px; letter-spacing: 12px; margin: 4px 0 8px; color: var(--verde); }
.teclado { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 300px; margin: 0 auto; }
.teclado button { height: 68px; font-size: 28px; font-weight: 800; background: #fff; border: 3px solid var(--borde); border-radius: 18px; }
.teclado button:active { background: var(--amarillo); }
.sacude { animation: sacude .4s; }
@keyframes sacude { 25% { transform: translateX(-10px); } 75% { transform: translateX(10px); } }
.solo-maestro { margin-top: 16px; color: #fff; font-size: 14px; opacity: .85; }

/* ---------- Mapa (mundo abierto en canvas) ---------- */
body.mapa { margin: 0; overflow: hidden; background: #234d3a; overscroll-behavior: none; }
#cv { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.hud { position: fixed; top: 0; left: 50%; transform: translateX(-50%); z-index: 20; width: 100%; max-width: 600px; padding: 8px 10px 8px; padding-top: max(8px, env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; gap: 8px; background: rgba(255, 253, 246, .95); backdrop-filter: blur(6px); box-shadow: 0 3px 12px rgba(0, 0, 0, .25); border-radius: 0 0 20px 20px; }
#hud-yo { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.yo-cara { position: relative; flex: none; }
.yo-cara .av { width: 54px; height: 54px; }
.nivel { position: absolute; right: -6px; bottom: -4px; min-width: 24px; height: 24px; padding: 0 4px; border-radius: 12px; background: #3a6ee8; border: 2px solid #fff; color: #fff; font-weight: 900; font-size: 13px; line-height: 20px; text-align: center; box-sizing: border-box; }
.yo-datos { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.yo-datos .fila { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.pts { display: inline-flex; align-items: center; gap: 3px; font-weight: 900; color: #a56a00; font-size: 15px; flex: none; }
.ico { width: 20px; height: 20px; object-fit: contain; flex: none; }
.xp { position: relative; height: 14px; border-radius: 7px; background: #ddd5bd; overflow: hidden; }
.xp i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(#5b9bff, #3a6ee8); border-radius: 7px; transition: width .4s; }
.xp em { position: absolute; inset: 0; text-align: center; font-style: normal; font-size: 10px; line-height: 14px; font-weight: 800; color: #1d2b52; text-shadow: 0 0 3px #fff, 0 0 3px #fff; }
.vidas { display: flex; align-items: center; gap: 1px; min-height: 20px; }
.vidas .corazon { width: 19px; height: 19px; }
.vidas small { margin-left: 6px; font-size: 11px; font-weight: 800; color: #6b6672; white-space: nowrap; }
.vidas.inf small { color: #7a3fd0; }
.vidas.inf .corazon { filter: drop-shadow(0 0 4px #b57bff); }
.hud-btns { display: flex; gap: 4px; flex: none; }
.hud-btns button { width: 50px; padding: 4px 0 3px; border: 0; border-radius: 12px; background: #f0ead6; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 10px; font-weight: 800; color: #4a4552; }
.hud-btns button img { width: 28px; height: 28px; object-fit: contain; }
.hud-btns button:active { background: #e0d8bd; transform: scale(.95); }
@media (max-width: 400px) { .hud-btns button { width: 42px; } .hud-btns button img { width: 24px; height: 24px; } .hud-btns button span { font-size: 9px; } }
#cartel { position: fixed; top: 96px; left: 50%; transform: translateX(-50%); z-index: 15; padding: 6px 16px; border-radius: 99px; background: rgba(0, 0, 0, .45); color: #fff; font-weight: 800; white-space: nowrap; opacity: 0; pointer-events: none; }
#cartel.ver { animation: cartel 3s ease-out; }
@keyframes cartel { 0% { opacity: 0; transform: translate(-50%, -10px); } 12%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
#brujula { position: fixed; top: 100px; right: 12px; z-index: 15; width: 66px; padding: 6px 4px; border-radius: 18px; background: rgba(255, 253, 246, .93); text-align: center; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
#flecha { display: block; font-size: 30px; line-height: 34px; color: #d6420a; transition: transform .2s; }
#dist { display: block; font-size: 11px; }
.toast { position: fixed; top: 104px; left: 50%; transform: translateX(-50%); z-index: 60; padding: 12px 18px; border-radius: 99px; background: #2d2a32; color: #fff; font-weight: 800; animation: entra .3s; max-width: 92vw; text-align: center; }
@keyframes entra { from { opacity: 0; transform: translate(-50%, -12px); } }
.confeti { position: fixed; z-index: 70; font-size: 22px; pointer-events: none; animation: vuela 1s ease-out forwards; }
@keyframes vuela { to { transform: translate(var(--dx), var(--dy)) rotate(280deg); opacity: 0; } }
.av > .cara { background-color: #fff7dc; background-repeat: no-repeat; background-size: 150% auto; background-position: 50% 24%; }
.pjs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
.pj { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px; background: #fff; border: 3px solid var(--borde); border-radius: 18px; }
.pj img { width: 84px; height: 112px; object-fit: contain; }
.pj:active { border-color: var(--azul); background: #e8f0ff; }
.npc { display: flex; align-items: flex-end; gap: 12px; padding-right: 44px; }
.npc .retrato { width: 60px; height: 80px; object-fit: contain; flex: none; }
.npc b { display: block; font-size: 20px; } .rol { color: #6b6672; font-size: 14px; }
.globo { position: relative; margin: 10px 0; padding: 12px 14px; background: #fff; border: 3px solid var(--borde); border-radius: 18px; font-size: 17px; }
.pregunta h3 { margin: 6px 0 10px; font-size: 21px; }
#mini { display: block; width: 100%; max-width: 360px; margin: 0 auto 8px; border-radius: 14px; background: #000; }

/* ---------- Hoja inferior ---------- */
#velo { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .25s; }
#velo.abierto { opacity: 1; pointer-events: auto; }
#hoja { position: fixed; bottom: 0; left: 50%; z-index: 50; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  background: var(--crema); border-radius: 26px 26px 0 0; transform: translate(-50%, 105%); transition: transform .3s cubic-bezier(.2, .8, .3, 1); box-shadow: 0 -6px 24px rgba(0, 0, 0, .25); }
#hoja.abierta { transform: translate(-50%, 0); }
.cerrar { position: absolute; top: 10px; right: 12px; width: 42px; height: 42px; border: 0; border-radius: 50%; background: #ece6d3; font-size: 18px; }
#hoja h2 { padding-right: 44px; }
.texto { font-size: 20px; line-height: 1.7; } .texto p { margin: .7em 0; }
.grande { font-size: 20px; font-weight: 800; }
.cuenta { font-size: 34px; text-align: center; margin: 16px 0; padding: 0; }
.acertijo { font-size: 21px; font-style: italic; background: #f1e9ff; padding: 14px; border-radius: 16px; }
.opcion { display: block; width: 100%; min-height: 56px; margin: 8px 0; padding: 12px 16px; text-align: left; font-size: 17px; background: #fff; border: 3px solid var(--borde); border-radius: 16px; }
.opcion.elegida { border-color: var(--azul); background: #e8f0ff; }
.opcion.bien { border-color: #35b86a; background: #dcf7e5; }
.opcion.mal { border-color: var(--rojo); background: #ffe2da; }
.opciones.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opciones.dos .opcion { text-align: center; font-size: 28px; font-weight: 800; margin: 0; min-height: 76px; }
#resp { width: 100%; height: 56px; padding: 0 14px; font-size: 20px; border: 3px solid var(--borde); border-radius: 16px; margin: 6px 0; }
.progreso { height: 12px; border-radius: 9px; background: #e8e2cf; overflow: hidden; margin: 4px 44px 6px 0; }
.progreso i { display: block; height: 100%; background: var(--amarillo); transition: width .3s; }
.estrellas { font-size: 44px; letter-spacing: 4px; }
.dato { margin: 10px 0; padding: 12px 14px; border-radius: 14px; background: #fff1bd; }
.dato.aviso { background: #ffe0d6; }
.repaso { padding-left: 18px; } .repaso li { margin: 10px 0; }
details summary { font-weight: 800; cursor: pointer; padding: 6px 0; }
.rejilla-items { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 2px; background: #fff; border: 3px solid var(--borde); border-radius: 16px; }
.item.sel { border-color: var(--azul); } .item.puesto { background: #e7f8e9; }
.item small { font-weight: 800; font-size: 12px; }
.accion { position: sticky; bottom: -12px; padding-top: 10px; background: var(--crema); min-height: 50px; text-align: center; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Panel del maestro ---------- */
body.maestro { background: #f4f1e6; }
.barra { background: var(--verde); color: #fff; display: flex; align-items: center; gap: 4px; padding: 0 12px; flex-wrap: wrap; }
.barra b { margin-right: 10px; padding: 12px 0; }
.barra a { color: #fff; text-decoration: none; padding: 14px 12px; font-weight: 700; opacity: .85; }
.barra a.act, .barra a:hover { opacity: 1; background: rgba(255, 255, 255, .16); border-radius: 8px; }
.barra .der { margin-left: auto; }
.cont { max-width: 1000px; margin: 0 auto; padding: 18px 14px 60px; }
.panel { background: #fff; border-radius: 16px; padding: 16px; margin: 14px 0; box-shadow: 0 2px 8px rgba(0, 0, 0, .07); }
.panel h2 { margin-top: 0; }
.aviso-ok { background: #dcf7e5; border: 2px solid #35b86a; border-radius: 12px; padding: 12px 14px; margin: 12px 0; }
.aviso-mal { background: #ffe2da; border: 2px solid var(--rojo); border-radius: 12px; padding: 12px 14px; margin: 12px 0; }
.codigo { display: inline-block; font-size: 26px; font-weight: 900; letter-spacing: 5px; background: #fff1bd; padding: 2px 12px; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid #eee; vertical-align: middle; }
th { font-size: 13px; color: #6b6672; }
.tabla-wrap { overflow-x: auto; }
body.maestro input[type=text], body.maestro input[type=email], body.maestro input[type=password], body.maestro input[type=number], body.maestro select, body.maestro textarea {
  width: 100%; padding: 10px 12px; border: 2px solid var(--borde); border-radius: 10px; background: #fff; }
body.maestro textarea { min-height: 90px; resize: vertical; }
label { display: block; font-weight: 700; margin: 12px 0 4px; font-size: 14px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.en-linea { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; } .en-linea > * { flex: 1; min-width: 150px; } .en-linea .btn { flex: none; }
.preg { border: 2px solid var(--borde); border-radius: 14px; padding: 12px; margin: 12px 0; background: #fdfcf7; }
.op { display: flex; gap: 8px; align-items: center; margin: 6px 0; } .op input[type=radio] { width: 22px; height: 22px; flex: none; }
.barras { display: flex; align-items: end; gap: 6px; height: 110px; padding: 6px 0; }
.barras div { flex: 1; background: var(--verde2); border-radius: 6px 6px 0 0; position: relative; min-height: 4px; }
.barras span { position: absolute; top: -18px; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 800; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 800; background: #ece6d3; }
.pill.ok { background: #dcf7e5; } .pill.mal { background: #ffe2da; }
.login-m { max-width: 380px; margin: 12vh auto; padding: 0 14px; }
/* selector de ubicación del tesoro */
.picker { position: relative; width: 100%; max-width: 360px; overflow: hidden; border-radius: 14px; border: 3px solid var(--borde); cursor: crosshair; touch-action: manipulation; }
.picker .poi { pointer-events: none; opacity: .7; } .picker .poi .ico { width: 44px; height: 44px; font-size: 24px; } .picker .poi .lbl { display: none; }
.marca { position: absolute; transform: translate(-50%, -50%); font-size: 30px; pointer-events: none; z-index: 5; }
