/* css/app.css */

/* --- Temas --- */
body[data-tema="oscuro"] {
    --fondo: #0f1117;
    --superficie: #1a1d27;
    --superficie-2: #232733;
    --borde: #2e3340;
    --borde-fuerte: #4a5163;
    --texto: #e6e8ee;
    --texto-suave: #a0a6b4;
    --texto-tenue: #6b7280;
    --primario: #5b8def;
    --primario-hover: #4a7ce0;
    --match: #30a46c;
    --elim: #e5484d;
}
body[data-tema="claro"] {
    --fondo: #f4f5f8;
    --superficie: #ffffff;
    --superficie-2: #eef0f4;
    --borde: #dde0e7;
    --borde-fuerte: #a8adba;
    --texto: #1a1d27;
    --texto-suave: #545a6b;
    --texto-tenue: #8b90a0;
    --primario: #3b6fd4;
    --primario-hover: #2f5cbb;
    --match: #1a9d5f;
    --elim: #d13438;
}
body[data-tema="oceano"] {
    --fondo: #0a1929;
    --superficie: #0f2338;
    --superficie-2: #163150;
    --borde: #1e3f5f;
    --borde-fuerte: #396a94;
    --texto: #dbeafe;
    --texto-suave: #93b4d4;
    --texto-tenue: #5e82a3;
    --primario: #38bdf8;
    --primario-hover: #0ea5e9;
    --match: #2dd4bf;
    --elim: #f43f5e;
}
body[data-tema="bosque"] {
    --fondo: #313f35;
    --superficie: #3b4c40;
    --superficie-2: #475b4d;
    --borde: #536b5a;
    --borde-fuerte: #7d9d85;
    --texto: #eff5f0;
    --texto-suave: #c3d6c8;
    --texto-tenue: #93a998;
    --primario: #4f9a68;
    --primario-hover: #418355;
    --match: #8ce99a;
    --elim: #ff8a80;
}
body[data-tema="tierra"] {
    --fondo: #453a30;
    --superficie: #52453a;
    --superficie-2: #615244;
    --borde: #70604f;
    --borde-fuerte: #a08a6d;
    --texto: #f6efe5;
    --texto-suave: #dbcab4;
    --texto-tenue: #a89578;
    --primario: #bd7f42;
    --primario-hover: #a26a33;
    --match: #b7d47a;
    --elim: #e5806a;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--fondo);
    color: var(--texto);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

#app { max-width: 640px; margin: 0 auto; min-height: 100%; position: relative; }

/* --- Pantallas --- */
.pantalla { display: none; flex-direction: column; min-height: 100vh; padding: 1rem; }
.pantalla.activa { display: flex; }

/* --- Menú --- */
.menu-hero { text-align: center; margin-top: 22vh; margin-bottom: 3rem; }
.menu-logo { font-size: 3rem; font-weight: 700; letter-spacing: -0.02em; }
.menu-tagline { color: var(--texto-suave); font-size: 1.05rem; margin-top: 0.25rem; }
.menu-acciones { display: flex; flex-direction: column; gap: 0.9rem; max-width: 320px; margin: 0 auto; width: 100%; }
.menu-pie { text-align: center; color: var(--texto-tenue); font-size: 0.82rem; margin-top: auto; padding: 1.5rem 0; }

/* --- Botones --- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: none; border-radius: 12px; font-family: inherit;
    font-size: 0.95rem; font-weight: 600; padding: 0.8rem 1.2rem;
    cursor: pointer; transition: background 0.15s, opacity 0.15s, transform 0.1s;
    text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-grande { padding: 1rem 1.5rem; font-size: 1.05rem; }
.btn-pequeno { padding: 0.5rem 0.85rem; font-size: 0.82rem; border-radius: 9px; }
.btn-bloque { width: 100%; }
.btn-primario { background: var(--primario); color: #fff; }
.btn-primario:active { background: var(--primario-hover); }
.btn-secundario { background: var(--superficie-2); color: var(--texto); border: 1px solid var(--borde); }

.btn-icono {
    background: none; border: none; color: var(--texto);
    font-size: 1.8rem; line-height: 1; cursor: pointer;
    width: 2.5rem; height: 2.5rem; display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
}
.btn-icono:active { background: var(--superficie-2); }

/* --- Barra superior --- */
.barra-superior {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem; margin-bottom: 1rem; min-height: 2.5rem;
}
.barra-titulo { font-weight: 600; font-size: 1.05rem; flex: 1; text-align: center; }
.barra-espacio, .btn-icono { width: 2.5rem; flex-shrink: 0; }
.juego-crono { font-variant-numeric: tabular-nums; color: var(--texto-suave); font-size: 0.95rem; min-width: 3rem; text-align: right; }

/* --- Filtros --- */
.filtros { display: flex; gap: 0.75rem; margin-bottom: 1rem; }
.filtro { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.filtro > span { font-size: 0.78rem; color: var(--texto-suave); font-weight: 500; }
.filtro select, .ajuste-fila select {
    background: var(--superficie-2); border: 1px solid var(--borde);
    color: var(--texto); border-radius: 9px; padding: 0.6rem 0.7rem;
    font-size: 0.9rem; font-family: inherit; width: 100%;
}

/* --- Lista de puzzles --- */
.lista-puzzles { display: flex; flex-direction: column; gap: 0.7rem; }
.puzzle-card {
    background: var(--superficie); border: 1px solid var(--borde);
    border-radius: 12px; padding: 1rem; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between;
    font-family: inherit; color: var(--texto); text-align: left;
    transition: border-color 0.15s, transform 0.1s;
}
.puzzle-card:active { transform: scale(0.99); border-color: var(--borde-fuerte); }
.puzzle-card-resuelto { opacity: 0.7; }
.puzzle-card-info { display: flex; flex-direction: column; gap: 0.25rem; }
.puzzle-card-tema { font-weight: 600; font-size: 1rem; }
.puzzle-card-tam { color: var(--texto-tenue); font-size: 0.8rem; }
.puzzle-card-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 0.35rem; }
.puzzle-card-check { color: var(--match); font-size: 0.78rem; font-weight: 600; }

.badge { padding: 0.2rem 0.5rem; border-radius: 7px; font-size: 0.75rem; font-weight: 600; }
.badge-dif-1 { background: rgba(48,164,108,0.18); color: #4ade80; }
.badge-dif-2 { background: rgba(96,165,250,0.18); color: #60a5fa; }
.badge-dif-3 { background: rgba(251,191,36,0.18); color: #fbbf24; }
.badge-dif-4 { background: rgba(251,146,60,0.18); color: #fb923c; }
.badge-dif-5 { background: rgba(248,113,113,0.18); color: #f87171; }

/* --- Controles del juego --- */
.juego-controles { display: flex; gap: 0.5rem; margin-bottom: 0.9rem; flex-wrap: wrap; }

/* --- Panel de pistas --- */
.panel-pistas {
    background: var(--superficie); border: 1px solid var(--borde);
    border-radius: 12px; padding: 0.9rem 1rem; margin-bottom: 1rem;
    max-height: 28vh; overflow-y: auto;
}
.panel-pistas-oculto { display: none; }
.pistas-titulo { font-size: 0.85rem; color: var(--texto-suave); margin-bottom: 0.5rem; font-weight: 600; }
.lista-pistas { list-style: none; display: flex; flex-direction: column; gap: 0.4rem; }
.pista {
    font-size: 0.9rem; padding: 0.5rem 0.65rem; background: var(--superficie-2);
    border-radius: 8px; cursor: pointer; border-left: 3px solid transparent;
}
.pista-usada { opacity: 0.45; text-decoration: line-through; border-left-color: var(--match); }

/* ===================================================== */
/* --- TABLERO (rejilla en L, escala adaptativa) --- */
/* ===================================================== */

.tablero-scroll {
    width: 100vw;
    margin-left: 50%;
    transform: translateX(-50%);
    padding: 0 0.5rem 1rem;
    overflow-x: auto;
    text-align: center;
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
    .tablero-scroll { width: 88vw; max-width: 1250px; padding: 0 1rem 1rem; }
}

.tablero {
    display: block;
    width: 100%;
    --celda: 2.4rem;
    --lat: 5rem;
    --lat-cat: 22px;
    --head-h: 5.5rem;
    --fuente-item: 0.72rem;
}

.grid-wrap {
    display: inline-block;
    background: var(--superficie);
    border: 2px solid var(--borde-fuerte);
    border-radius: 14px;
    overflow: hidden;
    padding: 2px;
    max-width: 100%;
}

.grid { border-collapse: collapse; }

.g-corner { background: var(--superficie); }

.g-cathead {
    background: var(--superficie-2);
    color: var(--texto);
    font-weight: 700;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.4rem 0.2rem;
    text-align: center;
    border: 1px solid var(--borde);
}

.g-itemhead {
    background: var(--superficie);
    border: 1px solid var(--borde);
    height: var(--head-h);
    vertical-align: bottom;
    padding: 0.3rem 0;
}
.g-itemhead span {
    display: inline-block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    white-space: nowrap;
    max-height: calc(var(--head-h) - 0.6rem);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--fuente-item);
    color: var(--texto-suave);
}

.g-catlateral {
    background: var(--superficie-2);
    border: 1px solid var(--borde);
    width: var(--lat-cat);
    min-width: var(--lat-cat);
    vertical-align: middle;
    text-align: center;
    padding: 0;
}
.g-catlateral span {
    display: inline-block;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-weight: 700;
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--texto);
    white-space: nowrap;
}

.g-itemlateral {
    background: var(--superficie);
    border: 1px solid var(--borde);
    width: var(--lat);
    max-width: var(--lat);
    text-align: right;
    padding: 0 0.4rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: var(--fuente-item);
    color: var(--texto-suave);
}

.g-empty { background: transparent; border: none; }

.celda {
    width: var(--celda);
    height: var(--celda);
    min-width: var(--celda);
    border: 1px solid var(--borde);
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    background: var(--fondo);
    padding: 0;
    transition: filter 0.1s;
}
.celda:active { filter: brightness(1.25); }

.blk-left   { border-left: 2px solid var(--borde-fuerte) !important; }
.blk-right  { border-right: 2px solid var(--borde-fuerte) !important; }
.blk-top    { border-top: 2px solid var(--borde-fuerte) !important; }
.blk-bot    { border-bottom: 2px solid var(--borde-fuerte) !important; }

.marca {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%; line-height: 1;
}

body[data-marca="tic"] .celda-match .marca::before { content: "✓"; color: var(--match); font-size: calc(var(--celda) * 0.55); font-weight: 700; }
body[data-marca="tic"] .celda-elim .marca::before  { content: "✕"; color: var(--elim); font-size: calc(var(--celda) * 0.46); }

body[data-marca="punto"] .celda-match .marca::before { content: "●"; color: var(--match); font-size: calc(var(--celda) * 0.5); }
body[data-marca="punto"] .celda-elim .marca::before  { content: "✕"; color: var(--elim); font-size: calc(var(--celda) * 0.46); }

body[data-marca="relleno"] .celda-match { background: var(--match); }
body[data-marca="relleno"] .celda-elim  { background: var(--elim); }
body[data-marca="relleno"] .celda-match .marca::before { content: "✓"; color: rgba(0,0,0,0.62); font-size: calc(var(--celda) * 0.44); font-weight: 700; }
body[data-marca="relleno"] .celda-elim .marca::before  { content: "✕"; color: rgba(0,0,0,0.55); font-size: calc(var(--celda) * 0.4); }

body[data-tema="oscuro"][data-marca="relleno"] .celda-match .marca::before,
body[data-tema="oceano"][data-marca="relleno"] .celda-match .marca::before,
body[data-tema="claro"][data-marca="relleno"] .celda-match .marca::before,
body[data-tema="oscuro"][data-marca="relleno"] .celda-elim .marca::before,
body[data-tema="oceano"][data-marca="relleno"] .celda-elim .marca::before,
body[data-tema="claro"][data-marca="relleno"] .celda-elim .marca::before { color: rgba(255,255,255,0.92); }

/* Celda rellenada por Ayuda */
.celda-hint::after {
    content: "";
    position: absolute;
    top: 0; left: 0;
    border-style: solid;
    border-width: 7px 7px 0 0;
    border-color: var(--primario) transparent transparent transparent;
    opacity: 0.85;
    pointer-events: none;
}
body[data-marca="relleno"] .celda-hint::after { border-top-color: #fff; opacity: 0.95; }

/* --- Ajustes --- */
.ajustes-contenido { display: flex; flex-direction: column; gap: 1.1rem; }
.ajuste-fila {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    background: var(--superficie); border: 1px solid var(--borde);
    border-radius: 12px; padding: 0.9rem 1rem;
}
.ajuste-fila > span:first-child { font-weight: 500; }
.ajuste-fila select { max-width: 55%; }
.ajuste-valor { color: var(--texto-suave); }

/* --- Modal --- */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,0.6); align-items: center; justify-content: center; padding: 1.5rem;
}
.modal-overlay.activo { display: flex; }
.modal {
    background: var(--superficie); border: 1px solid var(--borde);
    border-radius: 16px; padding: 2rem 1.75rem; max-width: 340px; width: 100%; text-align: center;
}
.modal-titulo { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.modal-texto { color: var(--texto-suave); margin-bottom: 1.5rem; }
.modal-acciones { display: flex; flex-direction: column; gap: 0.6rem; }

/* --- Toast --- */
.toast {
    position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(1rem);
    background: var(--superficie-2); color: var(--texto); border: 1px solid var(--borde-fuerte);
    padding: 0.7rem 1.2rem; border-radius: 10px; font-size: 0.88rem;
    opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 200;
    max-width: 90%; text-align: center;
}
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.cargando, .vacio { color: var(--texto-tenue); text-align: center; padding: 2rem 0; font-size: 0.9rem; }

/* --- Selector de marca (● / ✕) sobre la celda --- */
.celda-selector-activo { z-index: 50; }

.selector-marca {
    position: absolute;
    bottom: calc(100% + 5px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 3px;
    background: var(--superficie-2);
    border: 1px solid var(--borde-fuerte);
    border-radius: 11px;
    padding: 3px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.4);
    z-index: 60;
}
.selector-marca::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--borde-fuerte);
}

.selector-marca.selector-abajo {
    bottom: auto;
    top: calc(100% + 5px);
}
.selector-marca.selector-abajo::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--borde-fuerte);
}

.selector-btn {
    width: 2.5rem; height: 2.5rem;
    border: none; border-radius: 8px;
    background: var(--superficie);
    cursor: pointer; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.1s, filter 0.1s;
}
.selector-btn:active { transform: scale(0.9); }
.selector-btn::before { font-size: 1.2rem; }
.selector-btn-elim::before { content: "✕"; color: var(--elim); }

body[data-marca="tic"] .selector-btn-match::before,
body[data-marca="relleno"] .selector-btn-match::before { content: "✓"; color: var(--match); font-weight: 700; }
body[data-marca="punto"] .selector-btn-match::before { content: "●"; color: var(--match); }

body[data-marca="relleno"] .selector-btn-match { background: var(--match); }
body[data-marca="relleno"] .selector-btn-match::before { color: rgba(0,0,0,0.65); }
body[data-marca="relleno"] .selector-btn-elim { background: var(--elim); }
body[data-marca="relleno"] .selector-btn-elim::before { color: rgba(0,0,0,0.6); }

body[data-tema="oscuro"][data-marca="relleno"] .selector-btn-match::before,
body[data-tema="oceano"][data-marca="relleno"] .selector-btn-match::before,
body[data-tema="claro"][data-marca="relleno"] .selector-btn-match::before,
body[data-tema="oscuro"][data-marca="relleno"] .selector-btn-elim::before,
body[data-tema="oceano"][data-marca="relleno"] .selector-btn-elim::before,
body[data-tema="claro"][data-marca="relleno"] .selector-btn-elim::before { color: #fff; }

/* --- Responsivo: pantallas muy pequeñas --- */
@media (max-width: 380px) {
    .menu-logo { font-size: 2.5rem; }
    .g-cathead { font-size: 0.62rem; }
}

/* --- Celda marcada como incorrecta tras comprobar --- */
.celda-error {
    box-shadow: inset 0 0 0 2px var(--elim);
    background: color-mix(in srgb, var(--elim) 22%, transparent);
    animation: parpadeo-error 0.5s ease-in-out 2;
}
body[data-marca="relleno"] .celda-error {
    box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px var(--elim);
}
@keyframes parpadeo-error {
    0%, 100% { filter: none; }
    50% { filter: brightness(1.5); }
}

/* --- Separadores de categoría (marco de cada subgrid) --- */
body[data-tema="oscuro"] { --separador: #8b9dc9; }
body[data-tema="claro"]  { --separador: #5a6b8c; }
body[data-tema="oceano"] { --separador: #62b6e8; }
body[data-tema="bosque"] { --separador: #d4b95e; }
body[data-tema="tierra"] { --separador: #8fb3a0; }

.blk-left   { border-left:   3px solid var(--separador) !important; }
.blk-right  { border-right:  3px solid var(--separador) !important; }
.blk-top    { border-top:    3px solid var(--separador) !important; }
.blk-bot    { border-bottom: 3px solid var(--separador) !important; }

.grid-wrap { border-color: var(--separador); }

/* --- Tutorial --- */
.tut-cabecera {
    background: var(--superficie);
    border: 1px solid var(--borde);
    border-radius: 12px;
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
}
.tut-progreso {
    font-size: 0.75rem; color: var(--texto-tenue);
    text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}
.tut-titulo { font-size: 1.1rem; margin: 0.25rem 0 0.4rem; }
.tut-texto { font-size: 0.92rem; color: var(--texto-suave); margin-bottom: 0.9rem; }

.tut-aviso {
    background: var(--superficie-2);
    border: 1px solid var(--primario);
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    font-size: 0.88rem;
    margin-bottom: 0.9rem;
    opacity: 0; max-height: 0; overflow: hidden;
    transition: opacity 0.2s, max-height 0.2s, margin 0.2s, padding 0.2s;
    padding-top: 0; padding-bottom: 0; border-width: 0;
}
.tut-aviso.visible {
    opacity: 1; max-height: 200px;
    padding-top: 0.7rem; padding-bottom: 0.7rem; border-width: 1px;
}

.tut-tablero-zona { text-align: center; overflow-x: auto; padding-bottom: 0.5rem; }
.tut-tablero { --celda: 2.7rem; --lat: 4.4rem; --head-h: 4.2rem; --fuente-item: 0.74rem; }

.celda-objetivo {
    box-shadow: inset 0 0 0 3px var(--primario);
    animation: pulso-objetivo 1.4s ease-in-out infinite;
}
@keyframes pulso-objetivo {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.45); }
}

.tut-pie { margin-top: auto; padding-top: 1rem; text-align: center; }

/* Punto indicador de "tutorial no visto" */
.con-punto { position: relative; }
.con-punto::after {
    content: "";
    position: absolute; top: 0.7rem; right: 0.9rem;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--primario);
}

/* --- Puzzle diario --- */
.btn-diario {
    background: linear-gradient(135deg, var(--primario), var(--primario-hover));
    color: #fff;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.85rem 1.2rem;
}
.btn-diario.diario-hecho { background: var(--superficie-2); color: var(--texto); border: 1px solid var(--match); }
.diario-titulo { font-size: 1.05rem; font-weight: 600; }
.diario-sub { font-size: 0.76rem; opacity: 0.85; font-weight: 400; }

.modal-racha {
    display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
    background: var(--superficie-2); border: 1px solid var(--borde);
    border-radius: 12px; padding: 0.9rem; margin-bottom: 1.25rem;
}
.racha-num { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.racha-lbl { font-size: 0.8rem; color: var(--texto-suave); }

/* --- Vincular pistas con el tablero --- */
.ajuste-check { width: 1.3rem; height: 1.3rem; cursor: pointer; accent-color: var(--primario); }

.pista { display: flex; align-items: flex-start; gap: 0.55rem; }
.pista-txt { flex: 1; }

.pista-check {
    display: none;
    flex: 0 0 auto;
    width: 1.05rem; height: 1.05rem; margin-top: 0.18rem;
    border: 2px solid var(--borde-fuerte); border-radius: 50%;
    background: transparent; cursor: pointer; padding: 0;
}
body[data-vincular="1"] .pista-check { display: block; }
.pista-usada .pista-check { background: var(--match); border-color: var(--match); }

.pista-activa {
    border-left-color: var(--primario);
    box-shadow: inset 0 0 0 1px var(--primario);
}

.celda-foco {
    box-shadow: inset 0 0 0 3px var(--primario);
    animation: pulso-foco 1.3s ease-in-out infinite;
}
.celda-linea { background: color-mix(in srgb, var(--primario) 16%, transparent); }
.cab-foco { background: color-mix(in srgb, var(--primario) 26%, var(--superficie)) !important; }

@keyframes pulso-foco {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.4); }
}