:root {
    --bg: #0f172a;
    --card: #1e293b;
    --letra: #f59e0b;
    --cifra: #38bdf8;
    --ok: #22c55e;
    --error: #ef4444;
    --texto: #e2e8f0;
    --suave: #94a3b8;
}
* { box-sizing: border-box; }
html { height: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: radial-gradient(circle at top, #1e293b, var(--bg));
    color: var(--texto);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem 3rem;
}

/* Pantalla de inicio: intenta ocupar el alto; con los 3 rankings permite scroll. */
body.pantalla-inicio {
    min-height: 100dvh;
    justify-content: flex-start;
    gap: 1rem;
    padding: clamp(1rem, 4vh, 2rem) 1rem;
}
body.pantalla-inicio .inicio-top {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    flex: 0 0 auto;
}
body.pantalla-inicio h1 { margin: 0; font-size: clamp(1.4rem, 5vw, 2rem); }
.titulo-app {
    font-size: clamp(2.6rem, 11vw, 4rem) !important;
    font-weight: 800; letter-spacing: 1px;
    background: linear-gradient(90deg, var(--letra), var(--cifra));
    -webkit-background-clip: text; background-clip: text; color: transparent;
}
.botones-sec { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }
body.pantalla-inicio .fecha { margin: 0; }
body.pantalla-inicio .mi-punt { margin: 0.2rem 0 0; }
body.pantalla-inicio .rankings { margin: 0; width: 100%; max-width: 480px; }

.form-nombre { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.form-nombre input {
    padding: 0.7rem 1rem; border-radius: 10px; border: 1px solid #334155;
    background: #0b1220; color: var(--texto); font-size: 1.05rem; text-align: center; min-width: 200px;
}
.bloque-jugador { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.saludo { margin: 0; font-size: 1.2rem; }
.saludo b { color: var(--letra); }
.cambiar { color: var(--suave); font-size: 0.8rem; text-decoration: none; }
.cambiar:hover { color: var(--cifra); }

/* Desglose de puntos de hoy (compacto) */
.desglose {
    width: 100%; max-width: 320px; margin: 0.3rem auto 0;
    background: #0b1220; border: 1px solid #334155; border-radius: 12px; padding: 0.5rem 0.8rem;
}
.desglose .d-cab {
    display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
    border-bottom: 1px solid #334155; padding-bottom: 0.3rem; margin-bottom: 0.3rem;
}
.desglose .d-cab span { color: var(--suave); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; }
.desglose .d-cab b { color: var(--ok); font-size: 1.4rem; }
.desglose .d-line { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.92rem; padding: 0.12rem 0; }
.desglose .d-line .d-et { color: var(--letra); font-weight: 600; }
.desglose .d-line .d-pt { color: var(--cifra); font-weight: 600; }
.desglose .d-line .d-pt i { color: var(--suave); font-style: normal; }
.vuelve { margin: 0; color: var(--ok); font-weight: 600; }

/* Rankings */
.rankings .rank-bloque + .rank-bloque { margin-top: 1.1rem; }
.rank-cab { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.4rem; }
.rank-cab h2 { margin: 0; }
.cal-form { position: relative; display: inline-flex; }
.cal-btn {
    background: var(--cifra); color: #0b1220; border: none; border-radius: 8px;
    padding: 0.35rem 0.7rem; font-size: 0.85rem; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.cal-btn:hover { filter: brightness(1.08); }
/* El input de fecha queda invisible bajo el botón; el selector nativo se ancla aquí. */
.cal-input { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; }
.rankings h2 { margin: 0 0 0.4rem; font-size: 0.95rem; text-transform: none; letter-spacing: 0; color: var(--texto); }
.rankings .tabla td { padding: 0.28rem 0.4rem; font-size: 0.92rem; }
.rank-vacio { color: var(--suave); font-size: 0.85rem; margin: 0.2rem 0 0; font-style: italic; }
.rank-row { cursor: pointer; }
.rank-row:hover td { background: rgba(56,189,248,0.10); }

/* Modal resumen de puntuacion */
.modal-overlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay[hidden] { display: none; }
.modal {
    position: relative; width: 100%; max-width: 360px;
    background: var(--card); border: 1px solid #334155; border-radius: 16px;
    padding: 1.4rem 1.6rem; box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modal h3 { margin: 0 0 0.2rem; color: var(--letra); font-size: 1.3rem; }
.modal .m-fecha { color: var(--suave); font-size: 0.85rem; margin-bottom: 0.8rem; }
.modal .m-total { font-size: 1.6rem; font-weight: 800; color: var(--ok); margin-bottom: 0.8rem; }
.modal .m-line { display: flex; justify-content: space-between; gap: 1rem; padding: 0.4rem 0; border-top: 1px solid #334155; }
.modal .m-line span { color: var(--suave); }
.modal .m-line b { color: var(--cifra); }
.modal-x {
    position: absolute; top: 0.5rem; right: 0.7rem;
    background: none; border: none; color: var(--suave); font-size: 1.7rem; line-height: 1; cursor: pointer;
}
.modal-x:hover { color: var(--texto); }

/* Compartir */
.share-box {
    width: 100%; max-width: 320px; margin: 0.4rem auto 0;
    background: var(--card); border: 1px solid #334155; border-radius: 12px; padding: 0.8rem;
}
.share-cab {
    color: var(--suave); font-size: 0.75rem; text-transform: uppercase;
    letter-spacing: 1px; text-align: center; margin-bottom: 0.7rem;
}
.share-redes { display: flex; justify-content: center; gap: 0.7rem; flex-wrap: wrap; }
.share-btn {
    width: 46px; height: 46px; border-radius: 50%; padding: 0; border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: #fff; transition: transform .08s, filter .1s;
}
.share-btn svg { width: 22px; height: 22px; fill: currentColor; }
.share-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.share-btn.wa { background: #25d366; }
.share-btn.tw { background: #000; }
.share-btn.tg { background: #229ed9; }
.share-btn.fb { background: #1877f2; }
.share-btn.bs { background: #1185fe; }
.share-btn.rd { background: #ff4500; }
.share-btn.em { background: #475569; }
.share-btn.copy { background: #334155; }
.share-btn.copy.ok { background: var(--ok); }
.share-btn.native { background: var(--letra); color: #0b1220; }

/* Selector de idioma: botón con icono + modal con banderas */
.lang-btn {
    display: inline-flex; align-items: center; justify-content: center;
    margin-top: 0.6rem; width: 46px; height: 46px; border-radius: 50%;
    background: var(--card); border: 1px solid #334155; color: var(--texto); cursor: pointer;
    transition: filter .1s, transform .08s;
}
.lang-btn svg { width: 24px; height: 24px; }
.lang-btn:hover { transform: translateY(-2px); filter: brightness(1.12); }

.lang-modal h3 { margin: 0 0 1rem; color: var(--letra); font-size: 1.2rem; text-align: center; }
.lang-grid { display: flex; justify-content: center; gap: 0.8rem; flex-wrap: wrap; }
.lang-card {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.5rem; border-radius: 10px; border: 1px solid #334155;
    background: #0b1220; text-decoration: none; transition: background .1s, transform .08s;
}
.lang-card:hover { background: rgba(56,189,248,0.10); transform: translateY(-2px); }
.lang-card.activo { border-color: var(--letra); background: rgba(245,158,11,0.12); }
.lang-flag { flex: 0 0 auto; display: inline-flex; }
.lang-flag svg { width: 52px; height: 35px; border-radius: 4px; display: block; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }

@media (max-height: 560px) {
    body.pantalla-inicio { gap: 0.5rem; padding: 0.7rem 1rem; }
    body.pantalla-inicio .fecha { font-size: 0.8rem; }
    body.pantalla-inicio .card { padding: 0.8rem 1rem; }
    body.pantalla-inicio .card h2 { margin-bottom: 0.5rem; }
    body.pantalla-inicio .tabla td { padding: 0.3rem 0.4rem; }
    body.pantalla-inicio .boton { padding: 0.7rem 1.8rem; font-size: 1rem; }
}
h1 { font-size: 2rem; margin: 0.2rem 0; letter-spacing: 0.5px; }
.fecha { color: var(--suave); margin-bottom: 1.5rem; }
.card {
    background: var(--card);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 640px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.card h2 { margin: 0 0 1rem; font-size: 1.1rem; text-transform: uppercase; letter-spacing: 1px; color: var(--suave); }

.fichas { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; }
.ficha {
    width: 56px; height: 64px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.8rem; font-weight: 700;
    background: #0b1220;
    border: 2px solid transparent;
    user-select: none;
}
.ficha.letra { color: var(--letra); border-color: var(--letra); cursor: pointer; transition: transform .08s; position: relative; }
.ficha.letra:hover { transform: translateY(-3px); }
.ficha.letra .val { position: absolute; bottom: 3px; right: 5px; font-size: 0.7rem; font-weight: 600; opacity: 0.75; }
.ficha.letra.usada { opacity: 0.25; pointer-events: none; }
.ficha.cifra { color: var(--cifra); border-color: var(--cifra); }

.objetivo { text-align: center; font-size: 3rem; font-weight: 800; color: var(--cifra); margin-top: 1rem; }
.objetivo small { display: block; font-size: 0.9rem; color: var(--suave); font-weight: 400; letter-spacing: 1px; }

.boton {
    display: inline-block;
    background: var(--letra);
    color: #0b1220;
    border: none;
    border-radius: 10px;
    padding: 0.9rem 2.2rem;
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: transform .08s, filter .1s;
}
.boton:hover { transform: translateY(-2px); filter: brightness(1.05); }
.boton.azul { background: var(--cifra); }
.boton.secundario {
    background: transparent; color: var(--cifra); border: 1px solid var(--cifra);
    padding: 0.6rem 1.4rem; font-size: 1rem;
}
.boton:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.tabla { width: 100%; border-collapse: collapse; }
.tabla td { padding: 0.55rem 0.4rem; border-bottom: 1px solid #334155; }
.tabla .pos { color: var(--letra); font-weight: 700; width: 2rem; }
.tabla .pts { text-align: right; color: var(--cifra); font-weight: 700; }

.mi-punt { text-align: center; margin: 1rem 0 0; color: var(--ok); font-weight: 600; }

.palabra-actual {
    min-height: 64px;
    margin: 1.2rem 0;
    display: flex; gap: 0.4rem; justify-content: center; flex-wrap: wrap;
    align-items: center;
}
.palabra-actual .hueco { color: var(--suave); font-style: italic; }
.sel {
    width: 46px; height: 54px; border-radius: 8px;
    background: var(--letra); color: #0b1220;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 700; cursor: pointer;
}
.controles { display: flex; gap: 0.8rem; justify-content: center; flex-wrap: wrap; margin-top: 0.5rem; }
.mensaje { text-align: center; min-height: 1.6rem; margin-top: 1rem; font-weight: 600; }
.mensaje.ok { color: var(--ok); }
.mensaje.err { color: var(--error); }
.cronometro { font-size: 2.2rem; font-weight: 800; text-align: center; color: var(--texto); }
.cronometro.poco { color: var(--error); }
.mejor { text-align: center; color: var(--suave); margin-top: 0.6rem; }
.mejor b { color: var(--letra); }
/* Cifras interactivas */
.ficha.cifra { cursor: pointer; transition: transform .08s; }
.ficha.cifra:hover { transform: translateY(-3px); }
.ficha.cifra.elegido { box-shadow: 0 0 0 3px var(--cifra); transform: translateY(-3px); }
.ficha.cifra.resultado { border-style: dashed; background: #10203a; }
.operadores { display: flex; gap: 0.6rem; justify-content: center; margin: 1.2rem 0 0.4rem; }
.op {
    width: 56px; height: 56px; border-radius: 10px;
    border: 2px solid var(--cifra); background: #0b1220; color: var(--cifra);
    font-size: 1.6rem; font-weight: 700; cursor: pointer; transition: transform .08s, background .1s;
}
.op:hover { transform: translateY(-2px); }
.op.activo { background: var(--cifra); color: #0b1220; }
.cifras-puntos { text-align: center; font-size: 1.3rem; font-weight: 700; color: var(--ok); margin-top: 0.8rem; }

/* Visor de base de datos */
.db-wrap { width: 100%; max-width: 1000px; }
.db-tablas { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.db-tablas a {
    display: inline-block; padding: 0.4rem 0.8rem; border-radius: 8px;
    background: #0b1220; border: 1px solid #334155; color: var(--cifra); text-decoration: none;
}
.db-tablas a.activa { background: var(--cifra); color: #0b1220; border-color: var(--cifra); }
.db-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.db-form input[type=text] {
    flex: 1; padding: 0.6rem 0.8rem; border-radius: 8px; border: 1px solid #334155;
    background: #0b1220; color: var(--texto); font-family: monospace;
}
.db-scroll { overflow-x: auto; border: 1px solid #334155; border-radius: 8px; }
table.datos { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
table.datos th, table.datos td { padding: 0.45rem 0.7rem; border-bottom: 1px solid #334155; text-align: left; white-space: nowrap; }
table.datos th { background: #0b1220; color: var(--letra); position: sticky; top: 0; }
table.datos tr:hover td { background: rgba(56,189,248,0.06); }
.db-error { color: var(--error); margin-bottom: 1rem; font-family: monospace; }
.db-info { color: var(--suave); margin-bottom: 1rem; }

/* Vista de ayuda / como se juega */
.card.ayuda { max-width: 560px; }
.ayuda-bloque + .ayuda-bloque { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px solid #334155; }
.ayuda-bloque h2 { display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.5rem; font-size: 1.1rem; text-transform: none; letter-spacing: 0; color: var(--texto); }
.ayuda-bloque h2 .tiempo { margin-left: auto; font-size: 0.75rem; color: #0b1220; background: var(--letra); padding: 0.1rem 0.5rem; border-radius: 999px; font-weight: 700; }
.ayuda-bloque p { margin: 0.3rem 0; color: var(--texto); line-height: 1.45; font-size: 0.95rem; }
.ayuda-bloque p b { color: var(--letra); }

footer { color: var(--suave); font-size: 0.85rem; margin-top: 1rem; text-align: center; }
footer a { color: var(--cifra); }
