/*
============================================================================
FITXER: css/escala-nombres.css
ROL: Estils propis de «L'escala de nombres»: les fileres, els cercles amb els
     nombres, el que augmenta a cada tram i el teclat de xifres.
     Les mides del tauler són relatives a la seva amplada (--amplada, en
     unitats de tauler.js), perquè s'encongeixi sencer en una pantalla estreta.
DEPENDÈNCIES: css/comu.css (s'ha de carregar abans).
============================================================================
*/
:root {
    --primary: #0e7490;
    --primary-light: #ecfeff;
    --primary-hover: #155e75;
    --primary-dark: #164e63;
    --tinta: #1e293b; /* les línies i les vores dels cercles, com al paper */
}

/* ══════════════════════════════════════════════
   EL TAULER: fileres (SVG) + cercles (HTML)
══════════════════════════════════════════════ */
#tauler-wrap {
    padding-top: 10px;
}
.tauler-escala {
    position: relative;
    max-width: 100%;
    container-type: inline-size;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
}
.dibuix {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}
.filera {
    fill: none;
    stroke: var(--tinta);
    stroke-width: 4.5;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.2s;
}
.filera.be {
    stroke: var(--success);
}
.filera.malament {
    stroke: var(--danger);
    stroke-width: 5.5;
}
.salt {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 10px;
    font-weight: 800;
    fill: var(--success);
    stroke: white;
    stroke-width: 3;
    stroke-linejoin: round;
    paint-order: stroke;
}

/* ---- Un cercle ---- */
.cercle {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: white;
    border: calc(100cqw * 2.2 / var(--amplada)) solid var(--tinta);
    color: var(--text-main);
    font-size: calc(100cqw * 14 / var(--amplada));
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.03em;
    cursor: pointer;
    transition:
        background 0.15s,
        border-color 0.15s,
        box-shadow 0.15s,
        transform 0.15s;
}
.cercle.llarg {
    font-size: calc(100cqw * 10.5 / var(--amplada));
}
/* Els números que ja hi són: negres i sense cursor */
.cercle.fix {
    cursor: default;
    color: var(--tinta);
}
/* Els que escriu qui juga: del color del tema */
.cercle:not(.fix) {
    color: var(--primary-dark);
}
.cercle.buit {
    border-style: dashed;
    border-color: var(--primary);
    background: #f8fafc;
}
.cercle.triat {
    background: var(--primary-light);
    border-color: var(--primary);
    border-style: solid;
    box-shadow: 0 0 0 calc(100cqw * 4 / var(--amplada)) rgba(14, 116, 144, 0.3);
}
/* El cercle on s'escriu: un cursor que parpelleja després del nombre (s'hi poden afegir xifres)… */
.cercle.triat:not(.substitueix)::after {
    content: '';
    width: calc(100cqw * 1.6 / var(--amplada));
    height: 0.95em;
    margin-left: 0.04em;
    background: currentColor;
    animation: parpelleja 1s steps(1) infinite;
}
/* …o, si s'acaba de triar i ja tenia nombre, el nombre ressaltat: la xifra següent el substitueix */
.cercle.triat.substitueix {
    background: var(--primary);
    color: white;
}
@keyframes parpelleja {
    50% {
        opacity: 0;
    }
}
.cercle:focus {
    outline: none;
}
.amb-seleccio .cercle:not(.fix) {
    border-color: var(--primary);
}
.cercle.sobre {
    transform: scale(1.15);
    background: var(--primary-light);
}
@media (hover: hover) {
    .tauler-escala:not(.resolt):not(.estatic) .cercle:not(.fix):not(.triat):hover {
        background: var(--primary-light);
    }
}
.tauler-escala.resolt .cercle,
.tauler-escala.estatic .cercle {
    cursor: default;
}
.tauler-escala.resolt .cercle:not(.fix) {
    color: #065f46;
}
.cercle.acaba-de-posar {
    animation: posa 0.25s ease-out;
}
.cercle.sacseja {
    animation: sacseja 0.3s;
}
@keyframes posa {
    from {
        transform: scale(1.2);
    }
}

/* ══════════════════════════════════════════════
   EL TECLAT (com el d'un telèfon), LA PANTALLA I EL FANTASMA D'ARROSSEGAR
   En una pantalla prou ampla, el teclat va a la dreta del tauler; si no, a sota.
══════════════════════════════════════════════ */
.zona-joc {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
.teclat {
    gap: 6px;
}
.pantalla {
    min-width: 132px;
    height: 52px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2.5px solid var(--primary);
    border-radius: 10px;
    background: white;
    color: var(--primary-dark);
    font-size: 1.9em;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}
.pantalla .cursor {
    width: 3px;
    height: 0.95em;
    margin-left: 2px;
    background: currentColor;
    animation: parpelleja 1s steps(1) infinite;
}
.pantalla.substitueix .valor {
    padding: 0 4px;
    border-radius: 4px;
    background: var(--primary);
    color: white;
}
.pantalla.substitueix .cursor {
    display: none;
}
.pantalla.buida {
    border-style: dashed;
    border-color: var(--border-strong);
    color: var(--text-muted);
    font-size: 1em;
    font-weight: 600;
}
.pantalla:empty {
    visibility: hidden;
}
.pila.xifres {
    display: grid;
    grid-template-columns: repeat(6, auto);
    gap: 8px;
}
.pista-teclat {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9em;
    text-align: center;
    text-wrap: balance;
}
@media (min-width: 700px) {
    .zona-joc {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 0 16px;
    }
    .zona-joc #tauler-wrap {
        flex: 0 1 auto;
        min-width: 0;
        padding: 10px 0 6px 0;
    }
    .pila.xifres {
        grid-template-columns: repeat(3, auto);
    }
    .pista-teclat {
        max-width: 190px;
    }
}
.xifra {
    min-width: 46px;
    height: 54px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 2.5px solid var(--tinta);
    border-radius: 10px;
    font-size: 1.7em;
    font-weight: 800;
    color: var(--text-main);
    box-shadow: 0 2px 0 rgba(15, 23, 42, 0.12);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition:
        transform 0.15s,
        background 0.15s,
        opacity 0.15s;
}
.xifra.esborra,
.xifra.fet {
    font-size: 1.4em;
    cursor: pointer;
}
.xifra.esborra {
    color: var(--danger);
}
.xifra.fet {
    color: var(--success);
}
.xifra:active {
    transform: translateY(1px);
}
.xifra.arrossegant {
    opacity: 0.4;
}
@media (hover: hover) {
    .pila .xifra:hover {
        border-color: var(--primary);
        background: var(--primary-light);
    }
}
.xifra.fantasma {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    transform: translate(-50%, -50%) rotate(-4deg) scale(1.08);
    border-color: var(--primary);
    color: var(--primary-dark);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.3);
    transition: none;
}

/* ---- Instruccions ---- */
.instr-salts {
    margin: 0;
    padding-left: 1.3em;
    font-weight: 600;
}

/* ---- Pantalles estretes ---- */
@media (max-width: 480px) {
    .pila.xifres {
        gap: 6px;
        padding: 6px 4px;
    }
    .xifra {
        min-width: 40px;
        height: 48px;
        padding: 0 4px;
        font-size: 1.5em;
    }
}
