:root {
  --azul: #2b6cb0; --azul-osc: #1e4e8c; --fondo: #f3f7fc; --texto: #1d2733; --suave: #5b6b7d;
  --tarjeta: #ffffff; --borde: #d7e1ee; --verde: #2f9e57; --amarillo: #f6c343;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--fondo); color: var(--texto);
  font-family: "Nunito", "Segoe UI", system-ui, sans-serif; overscroll-behavior: none; user-select: none; }
#barra { position: fixed; top: 0; left: 0; right: 0; height: 56px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; color: #fff; z-index: 10;
  background: linear-gradient(90deg, #f29a1a 0%, #e5243b 30%, #8a1c7c 55%, #3a33a8 78%, #0b8fd8 100%); }
#barra h1 { text-shadow: 0 1px 3px rgba(0,0,0,.35); }
img.logo { width: min(300px, 70vw); border-radius: 28px; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
img.logo.chico { width: min(150px, 36vw); border-radius: 20px; }
#barra h1 { flex: 1; font-size: 20px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#barraDerecha { display: flex; gap: 8px; align-items: center; font-weight: 700; }
button { font: inherit; cursor: pointer; border: 0; border-radius: 14px; }
button.icono { width: 44px; height: 44px; font-size: 30px; line-height: 1; background: rgba(255,255,255,.15); color: #fff; }
button.chico { padding: 8px 14px; background: rgba(255,255,255,.18); color: #fff; font-weight: 700; }
button.grande { padding: 16px 28px; font-size: 22px; font-weight: 800; background: var(--azul); color: #fff; }
button.grande:active { background: var(--azul-osc); }
#vista { position: fixed; top: 56px; left: 0; right: 0; bottom: 0; overflow: auto; padding: 16px; }
.oculto { display: none !important; }
.centro { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; min-height: 100%; text-align: center; }
.rejilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.tarjeta { background: var(--tarjeta); border: 2px solid var(--borde); border-radius: 20px; padding: 16px; text-align: center; }
.tarjeta.boton { cursor: pointer; }
.tarjeta.boton:active { transform: scale(.97); }
.avatar { font-size: 56px; line-height: 1.1; }
.nombre { font-size: 20px; font-weight: 800; margin-top: 6px; }
.grupo-btn { width: min(520px, 90vw); padding: 26px; font-size: 26px; font-weight: 800; border-radius: 24px; color: #fff; }
.grupo-btn small { display: block; font-size: 16px; font-weight: 600; opacity: .9; }
.miniatura { width: 100%; aspect-ratio: 3/4; object-fit: contain; background: #fff; border-radius: 12px; }
.sellos { margin-top: 6px; font-size: 22px; min-height: 28px; }
input.texto { font: inherit; font-size: 24px; padding: 12px 16px; border-radius: 14px; border: 2px solid var(--borde); width: min(420px, 90vw); text-align: center; }
.avatares { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 560px; }
.avatares button { font-size: 40px; width: 64px; height: 64px; background: #fff; border: 3px solid transparent; }
.avatares button.sel { border-color: var(--azul); background: #e6f0fb; }
h2 { margin: 6px 0 12px; }
.seccion { color: var(--suave); font-weight: 800; margin: 18px 4px 8px; font-size: 18px; }

/* Pintar */
#pintar { position: absolute; inset: 0; display: flex; }
#lienzoCaja { flex: 1; position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #e9eef5; }
#lienzoCaja canvas { position: absolute; touch-action: none; }
#capaLineas { mix-blend-mode: multiply; pointer-events: none; }
#paleta { width: 120px; background: #fff; border-left: 2px solid var(--borde); display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 6px; overflow-y: auto; }
#paleta .color { width: 46px; height: 46px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--borde); flex: none; }
#paleta .color.sel { box-shadow: 0 0 0 4px var(--azul); transform: scale(1.12); }
#paleta .colores { display: grid; grid-template-columns: 46px 46px; gap: 8px; }
#paleta button.accion { width: 100px; padding: 8px 0; background: #eef3f9; color: var(--texto); font-weight: 800; }
#progreso { width: 100px; text-align: center; font-weight: 800; }
#progreso .barra { height: 12px; border-radius: 6px; background: #e3e9f1; overflow: hidden; margin-top: 4px; }
#progreso .barra div { height: 100%; background: var(--verde); width: 0; transition: width .3s; }
@media (orientation: portrait) {
  #pintar { flex-direction: column; }
  #paleta { width: auto; height: 132px; border-left: 0; border-top: 2px solid var(--borde); flex-direction: row; padding: 6px 8px; overflow-x: auto; overflow-y: hidden; }
  #paleta .colores { grid-template-columns: repeat(9, 46px); }
}

/* Rompecabezas */
#rompe { position: absolute; inset: 0; display: flex; flex-direction: column; }
#rompeInfo { display: flex; gap: 16px; align-items: center; justify-content: center; padding: 8px; font-weight: 800; background: #fff; border-bottom: 2px solid var(--borde); flex-wrap: wrap; }
#rompeCaja { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #e9eef5; }
#rompeCaja canvas { touch-action: none; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
#modelo { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(233,238,245,.96); }
#modelo img { max-width: 92%; max-height: 92%; box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* Ranking */
table.ranking { width: min(640px, 100%); margin: 0 auto; border-collapse: collapse; background: #fff; border-radius: 16px; overflow: hidden; }
table.ranking td { padding: 10px 14px; border-bottom: 1px solid var(--borde); font-size: 20px; }
table.ranking td.pos { width: 60px; text-align: center; font-weight: 800; color: var(--suave); }
table.ranking td.pts { text-align: right; font-weight: 800; color: var(--azul); }
.pestanas { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; flex-wrap: wrap; }
.pestanas button { padding: 10px 18px; background: #fff; border: 2px solid var(--borde); font-weight: 800; }
.pestanas button.sel { background: var(--azul); color: #fff; border-color: var(--azul); }

#celebra { position: fixed; inset: 0; background: rgba(20,30,45,.55); display: flex; align-items: center; justify-content: center; z-index: 30; }
#celebra .tarjeta { width: min(460px, 90vw); padding: 28px; }
#celebraEmoji { font-size: 80px; }
#aviso { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1d2733; color: #fff; padding: 12px 20px; border-radius: 14px; z-index: 40; font-weight: 700; max-width: 90vw; text-align: center; }

/* Panel del maestro */
body.panel { user-select: auto; }

.panel .caja { background: #fff; border: 2px solid var(--borde); border-radius: 16px; padding: 14px; margin-bottom: 14px; }
.panel .fila { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.panel .fila > * { flex: none; }
.panel .fila .crece { flex: 1; min-width: 160px; }
.panel input, .panel select { font: inherit; font-size: 16px; padding: 9px 12px; border: 2px solid var(--borde); border-radius: 10px; background: #fff; color: var(--texto); }
button.primario, button.secundario, button.peligro { padding: 9px 16px; font-weight: 800; font-size: 16px; }
button.primario { background: var(--azul); color: #fff; }
button.secundario { background: #eef3f9; color: var(--texto); }
button.peligro { background: #fdecec; color: #b42318; }
button.mini { padding: 6px 10px; font-size: 14px; font-weight: 700; background: #eef3f9; color: var(--texto); border-radius: 10px; }
.panel h3 { margin: 0 0 10px; }
.panel .nota { color: var(--suave); font-size: 14px; }
.panel .dibujos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.panel .dibujo { border: 2px solid var(--borde); border-radius: 12px; padding: 8px; text-align: center; font-size: 14px; }
.panel .dibujo img { width: 100%; aspect-ratio: 3/4; object-fit: contain; background: #fff; }
.panel .ok { color: var(--verde); font-weight: 700; }
.panel .alerta { color: #b45309; font-weight: 700; }
.panel table { width: 100%; border-collapse: collapse; font-size: 15px; }
.panel th, .panel td { padding: 8px 6px; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: middle; }
.panel th { color: var(--suave); font-size: 13px; }
.panel td.num, .panel th.num { text-align: right; }
.panel tr.inactivo td { opacity: .5; }
.panel .acciones { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.panel .tabla { overflow-x: auto; }
dialog { border: 0; border-radius: 16px; padding: 18px; width: min(440px, 92vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,30,45,.45); }
dialog label { display: block; font-weight: 700; margin: 10px 0 4px; }
dialog input, dialog select { width: 100%; }
.dlg-botones { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
