/* ============================================================
   GRANDEZZE PROPORZIONALI — stile locale
   Stessa famiglia del Calcolatore Retta (scheda dei dati, grafico con
   la tabella accanto, svolgimento): colori e font di math-base.css,
   niente palette propria (guida, cap. 3).
   ============================================================ */

.app-container {
    max-width: 1000px;
    width: 100%;
    margin: 32px auto;
    padding: 0 20px;
    flex: 1;
}

.calculator-card {
    background: var(--card);
    padding: 28px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
    margin-bottom: 28px;
}

.app-title {
    text-align: center;
    margin: 0 0 8px;
    font-weight: 800;
    color: var(--brand);
}

.sommario {
    text-align: center;
    color: var(--ink-2);
    max-width: 680px;
    margin: 0 auto 24px;
}

.calculator-card h2 { color: var(--brand); font-size: 1.25rem; margin: 0 0 14px; }
.calculator-card h3 { color: var(--ink); font-size: 1.05rem; margin: 22px 0 6px; }

/* ---------- I tre modi ---------- */
.mode-selector {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 24px;
}

.modo-btn {
    min-height: 44px;
    padding: 8px 20px;
    border: 2px solid var(--line);
    background: var(--card);
    color: var(--ink);
    border-radius: 999px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: background .2s, border-color .2s, color .2s;
}

.modo-btn:hover { border-color: var(--brand); }
.modo-btn.attivo { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- I campi ---------- */
.campi { max-width: 560px; margin: 0 auto; }

.etichetta { display: block; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }

/* 16px almeno: sotto, iOS ingrandisce la pagina al tocco (guida, cap. 4) */
.campo {
    width: 100%;
    min-height: 48px;
    padding: 10px 14px;
    border: 2px solid var(--line);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--ink);
    background: #fff;
    box-sizing: border-box;
}

.campo:focus { border-color: var(--brand); outline: 3px solid var(--ring); outline-offset: 1px; }
.campo-eq { font-size: 1.25rem; text-align: center; }

.aiuto { color: var(--ink-2); font-size: .92rem; margin: 8px 0 0; }

.esempi { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; justify-content: center; }

.esempio {
    min-height: 44px;
    padding: 6px 14px;
    border: 1px solid var(--line);
    background: var(--brand-light);
    color: var(--brand-deep);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: .95rem;
    cursor: pointer;
}

.esempio:hover { border-color: var(--brand); }





.calculate-btn {
    display: block;
    width: 100%;
    max-width: 320px;
    min-height: 48px;
    margin: 22px auto 0;
    padding: 12px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s, transform .2s;
}

.calculate-btn:hover { background: var(--brand-2); transform: translateY(-1px); }

.errore {
    max-width: 560px;
    margin: 16px auto 0;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: #fef2f2;
    border-left: 4px solid #dc2626;
    color: #7f1d1d;
}

.errore::before { content: "⚠️ "; }

/* ---------- I risultati ---------- */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-top: 26px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    padding: 14px 10px;
    border-radius: var(--radius-sm);
    min-width: 0;
}

.res-label { font-size: .88rem; color: var(--ink-2); text-align: center; }

/* Scorre in orizzontale se la formula è lunga, ma mai in verticale: una
   frazione è più alta della riga, e con overflow-y lasciato ad «auto»
   accanto a ogni frazione compariva una barra di scorrimento sottile. */
.res-value {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--brand);
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 2px;
    text-align: center;
}

/* ---------- Grafico e tabella ---------- */
.visual-section {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 24px;
    align-items: start;
    margin-bottom: 28px;
}

.canvas-wrapper {
    position: relative;
    background: var(--card);
    padding: 14px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}

#grafico {
    width: 100%;
    aspect-ratio: 1 / 1;
    display: block;
    border: 1px solid var(--line);
    border-radius: 8px;
    /* di norma il dito sul grafico fa scorrere la pagina */
    touch-action: pan-y pinch-zoom;
}


/* Sotto il grafico, non sopra: qui le curve partono dall'origine, in
   basso a sinistra, proprio dove i pulsanti appoggiati sul disegno
   coprivano la retta e i numeri dell'asse x. */
.graph-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.ctrl-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    color: var(--ink);
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.ctrl-btn:hover { background: var(--brand-light); }
.ctrl-btn.attivo { background: var(--brand); color: #fff; border-color: var(--brand); }

.table-wrapper {
    background: var(--card);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.table-header h2 { margin: 0; font-size: 1.05rem; }

.ctrl-btn.text-btn {
    width: auto;
    min-height: 44px;
    height: auto;
    padding: 6px 12px;
    font-size: .88rem;
}

#tabella { width: 100%; border-collapse: collapse; font-family: var(--font-mono); }
#tabella th, #tabella td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: center; }
#tabella th { background: var(--bg); color: var(--ink-2); }



.legenda { font-size: .85rem; color: var(--ink-2); margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; }

/* ---------- Lo svolgimento ---------- */
.steps-title {
    text-align: center;
    margin: 0 auto 20px;
    padding-bottom: 8px;
    border-bottom: 3px solid var(--accent);
    width: fit-content;
}

.passo {
    border-left: 5px solid var(--brand);
    background: var(--bg);
    padding: 14px 16px;
    border-radius: 4px var(--radius-sm) var(--radius-sm) 4px;
    margin-bottom: 14px;
}

.passo:nth-child(3n+2) { border-left-color: var(--accent); }
.passo:nth-child(3n+3) { border-left-color: var(--brand-2); }

.passo h3 { margin: 0 0 6px; font-size: 1rem; color: var(--ink); }

/* Una formula lunga scorre da sola, la pagina no (guida, cap. 4) */
.passo-formula {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0;
    font-family: var(--font-mono);
}

.passo-perche { margin: 6px 0 0; color: var(--ink-2); font-size: .95rem; }

/* ---------- Le formule e la teoria ---------- */
.formula-list { display: flex; flex-wrap: wrap; gap: 12px; }

.formula-item {
    background: var(--bg);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.formula-item strong { color: var(--ink-2); margin-right: 6px; font-weight: 600; }

.teoria p, .teoria li { color: var(--ink); line-height: 1.65; }
.teoria ul { padding-left: 1.2rem; }
.teoria li { margin-bottom: 6px; }

.lessico dt { font-weight: 700; color: var(--brand); margin-top: 10px; }
.lessico dd { margin: 2px 0 0; color: var(--ink); }

.mono { font-family: var(--font-mono); }

/* ============================================================
   LE PARTI DI QUESTA APP
   ============================================================ */

/* I nomi delle due grandezze: compaiono nelle intestazioni, sul
   grafico e nelle frasi dello svolgimento */
.nomi {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 560px;
    margin: 0 auto 18px;
}
.nomi label { font-weight: 600; color: var(--ink-2); font-size: .9rem; display: grid; gap: 4px; }
.campo-nome { font-family: var(--font-body); font-size: 1rem; min-height: 44px; }

.mode-selector.piccolo { margin-bottom: 16px; }
.tipo-btn {
    min-height: 44px;
    padding: 6px 18px;
    border: 2px solid var(--line);
    background: var(--card);
    color: var(--ink);
    border-radius: 999px;
    font-weight: 700;
    cursor: pointer;
}
.tipo-btn.attivo { background: var(--brand-light); border-color: var(--brand); color: var(--brand-deep); }

/* La tabella da compilare: x, y e il pulsante per togliere la riga */
.righe-testa, .riga {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px;
    gap: 8px;
    align-items: center;
}
.righe-testa { font-weight: 700; color: var(--brand); margin-bottom: 6px; text-align: center; }
.righe-testa span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.righe-input { display: grid; gap: 8px; }
.riga .campo { text-align: center; }

.togli {
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: var(--radius-sm);
    color: var(--ink-2);
    font-size: 1rem;
    cursor: pointer;
}
.togli:hover { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }

.aggiungi {
    display: block;
    width: 100%;
    min-height: 44px;
    margin-top: 10px;
    border: 2px dashed var(--line);
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--brand);
    font-weight: 700;
    cursor: pointer;
}
.aggiungi:hover { border-color: var(--brand); background: var(--brand-light); }

/* Il problema del valore mancante: una griglia 3×3 come sul quaderno */
.griglia-mancante {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px 10px;
    align-items: center;
}
.griglia-mancante .testa { font-weight: 700; color: var(--brand); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.griglia-mancante .campo { text-align: center; }
.griglia-mancante .campo:placeholder-shown { border-style: dashed; border-color: var(--accent); background: var(--accent-soft); }

.campo-k { max-width: 220px; display: block; margin: 0 auto; text-align: center; font-size: 1.25rem; }
.campi[data-modo="esplora"] .etichetta { text-align: center; }

/* L'esito: che tipo di legame, la formula, una frase. Colore e icona
   insieme, mai solo il colore (guida, cap. 7) */
.esito {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-top: 24px;
    padding: 16px 18px;
    border-radius: var(--radius);
    border: 2px solid var(--line);
    background: var(--bg);
}
.esito p { margin: 0; }
.esito-icona {
    flex: 0 0 48px;
    height: 48px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: #fff;
    background: var(--brand);
}
.esito-tipo { font-weight: 800; font-size: 1.1rem; color: var(--ink); }
.esito-formula { font-size: 1.15rem; margin: 4px 0 !important; overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
/* la formula non va a capo a metà («= 1,5» sulla riga sotto): se non sta, scorre */
.esito-formula .katex { white-space: nowrap; }
.esito-frase { color: var(--ink-2); }
.esito.diretta { border-color: var(--brand); background: var(--brand-light); }
.esito.inversa { border-color: #7c3aed; background: #f5f3ff; }
.esito.inversa .esito-icona { background: #7c3aed; }
.esito.lineare { border-color: var(--accent); background: var(--accent-soft); }
.esito.lineare .esito-icona { background: #b45309; }
.esito.nessuna { border-color: #cbd5e1; }
.esito.nessuna .esito-icona { background: #64748b; }

/* La tabella controllata: le colonne y/x e x·y dicono che cosa resta costante */
.table-wrapper h2 { margin: 0 0 8px; font-size: 1.05rem; }
.tabella-scorre { overflow-x: auto; }
#tabella td.ok { background: #ecfdf5; }
#tabella td.ok::after { content: " ✓"; color: #047857; font-weight: 700; }
#tabella td { white-space: nowrap; }   /* il ✓ resta accanto al numero */
#tabella th.col-ok::after { content: " ✓"; color: #047857; }
#tabella th.col-no::after { content: " ≠"; color: #b91c1c; }
#tabella tr.trovato td:nth-child(-n+2) { background: var(--accent-soft); font-weight: 700; }
.legenda .segno { font-weight: 800; }
.legenda .segno.ok { color: #047857; }
.legenda .segno.no { color: #b91c1c; }

/* ---------- Telefono e tablet ---------- */
@media (max-width: 860px) {
    .visual-section { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 600px) {
    .app-container { margin: 18px auto; padding: 0 12px; }
    .calculator-card { padding: 18px 14px; }

    .modo-btn { flex: 1 1 100%; }
    .nomi { grid-template-columns: 1fr; }
    .esito { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
