/* ============================================================ */
/*   STILE QUESTIONARIO DSA — MODELLO BASE                      */
/*   Compatibile con: Chrome, Safari, Firefox                   */
/*   Dispositivi: Desktop, iPhone (Chrome + Safari), Android    */
/* ============================================================ */

body {
    font-family: Arial, Verdana, sans-serif;
    background: #f5f7fa;
    margin: 0;
    padding: 20px;
    letter-spacing: 0.04em;
    line-height: 1.9;
}

.container {
    width: 95%;
    max-width: 1100px;
    margin: auto;
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* --- HEADER --- */
.header-box {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 15px !important;
    border: 2px dashed #28a745 !important;
    border-radius: 8px !important;
    background-color: white !important;
    margin-bottom: 25px !important;
    transition: background-color 0.3s;
}

.header-box:hover {
    background-color: #f0fdf4 !important;
    cursor: pointer;
}

/* --- TITOLO --- */
.header-title h1 {
    color: #2e7d32;
    font-size: 1.8em;
    margin-bottom: 8px;
}

.header-title .subtitle {
    color: #555;
    font-style: italic;
    font-size: 1.05em;
}

/* --- SEPARATORE --- */
.separator {
    border: 0;
    height: 2px;
    background: linear-gradient(to right, transparent, #28a745, transparent);
    margin: 20px 0;
}

/* --- QUESITI --- */
.question {
    background: #f0f4f8;
    padding: 20px;
    margin: 20px 0 0 0;
    border-left: 5px solid #2e7d32;
    border-radius: 8px;
}

.question h2 {
    color: #1b5e20;
    font-size: 1.3em;
    margin-top: 0;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

/* --- TESTO DEL PROBLEMA --- */
.problem-text {
    background: white;
    padding: 15px 20px;
    margin: 10px 0 0 0;
    border-left: 4px solid #2196f3;
    border-radius: 4px;
    font-size: 1.05em;
    line-height: 1.9;
}

/* --- BOTTONE SEZIONE (apri/chiudi soluzione) ---
     NOTA: usa <button> (non <a>), così funziona su tutti i dispositivi mobile.
     Il tag <button> è la chiave per la compatibilità iOS Safari/Chrome. */
.section-button {
    width: 100%;
    padding: 15px;
    font-size: 1.15em;
    background: #e0f2f1;
    border: 2px solid #80cbc4;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    font-weight: bold;
    color: #004d40;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,77,64,0.1);
    margin-top: 10px;
    font-family: Arial, Verdana, sans-serif;
    letter-spacing: 0.04em;
    /* Necessario per iOS: evita che il browser ridimensioni il testo automaticamente */
    -webkit-text-size-adjust: 100%;
    /* Evita l'effetto "tap highlight" grigio su mobile */
    -webkit-tap-highlight-color: transparent;
    /* Rimuove lo stile nativo dei bottoni su Safari iOS */
    -webkit-appearance: none;
    appearance: none;
}

.section-button:hover {
    background: #b2dfdb;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,77,64,0.2);
}

/* Stato APERTO (soluzione visibile) */
.section-button.active-open {
    background-color: #2196f3;
    color: white;
    border-color: #1976d2;
    box-shadow: 0 4px 10px rgba(33,150,243,0.3);
}

.section-button.active-open .arrow {
    color: white;
}

.section-button.active-open:hover {
    background-color: #1976d2;
}

.arrow {
    transition: transform 0.3s ease, color 0.3s ease;
    font-size: 0.85em;
    color: #00796b;
    /* Impedisce la selezione del testo della freccia su mobile */
    user-select: none;
    -webkit-user-select: none;
}

/* --- CONTENUTO SOLUZIONE (toggle con animazione) ---
     IMPORTANTE: usa display:block + max-height (NON display:none/block).
     Questo è il pattern che funziona su iOS Safari e Chrome mobile. */
.section-content {
    display: block;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0 20px;
    border: 2px solid #e8f5e9;
    border-top: none;
    border-radius: 0 0 8px 8px;
    background: #fafafa;
    transition: max-height 0.6s ease-in-out, opacity 0.5s ease, padding 0.5s ease;
    /* Forza il box model corretto su tutti i browser */
    box-sizing: border-box;
}

.section-content.is-visible {
  max-height: none;        /* ← era: padding gestito solo da JS */
  opacity: 1;
  padding-top: 20px;
  padding-bottom: 20px;
}

/* --- STEP DELLA SOLUZIONE --- */
.step {
    background: #f1f8e9;
    padding: 15px 20px;
    margin: 15px 0;
    border-radius: 8px;
    line-height: 1.9;
}

.step h3 {
    color: #2e7d32;
    margin-top: 0;
    font-size: 1.1em;
    border-bottom: 1px solid #c8e6c9;
    padding-bottom: 6px;
    margin-bottom: 12px;
}

/* --- FORMULA BOX --- */
.formula-box {
    background: white;
    padding: 15px 20px;
    margin: 12px 0;
    border-left: 4px solid #4caf50;
    border-radius: 4px;
    /* overflow-x: auto permette lo scroll orizzontale per formule larghe su mobile */
    overflow-x: visible;
    overflow-y: visible;
    width: 100%;
    box-sizing: border-box;
}

/* --- RESULT BOX --- */
.result-box {
    background: #e8f5e9;
    padding: 15px;
    border: 2px solid #2e7d32;
    border-radius: 8px;
    margin-top: 12px;
    line-height: 1.9;
}

/* --- GRAFICI --- */
.graph-container {
    background-color: white;
    border: 1px solid #c8e6c9;
    border-radius: 12px;
    padding: 20px;
    margin: 20px auto;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.graph-container img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.graph-container p {
    margin: 10px 0 0 0;
    font-size: 0.95em;
    color: #2c3e50;
    font-style: italic;
}

/* --- BOTTONE AUDIO ---
     Usa <button> anche qui, non <a> o <div>. */
.btn-ascolta-domanda {
    background-color: #ff9800;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 7px 14px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9em;
    font-family: Arial, Verdana, sans-serif;
    transition: all 0.3s ease;
    white-space: nowrap;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-ascolta-domanda:hover {
    background-color: #e65100;
    transform: translateY(-1px);
}

.btn-ascolta-domanda.speaking {
    background-color: #e53935;
}

/* --- BOTTONI NAVIGAZIONE --- */
.nav-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 30px;
    flex-wrap: wrap;
}

.btn-nav {
    padding: 12px 20px;
    background: white;
    color: #2e7d32;
    border: 2px solid #2e7d32;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    font-family: Arial, Verdana, sans-serif;
    cursor: pointer;
    transition: 0.3s;
    font-size: 0.95em;
    letter-spacing: 0.03em;
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.btn-nav:hover {
    background: #2e7d32;
    color: white;
}

/* X rossa del bottone chiusura */
.close-icon {
    color: #d32f2f;
    font-weight: bold;
    margin-right: 8px;
    font-size: 1.1em;
}

/* Bottone "Nascondi soluzione" dentro la soluzione */
.btn-nav.close-solution {
    background-color: #2196f3;
    color: white;
    border-color: #1976d2;
}

.btn-nav.close-solution:hover {
    background-color: #1976d2;
}

/* --- ACCESSIBILITÀ --- */
button:focus-visible,
a:focus-visible {
    outline: 3px solid #ff9800;
    outline-offset: 2px;
}

/* --- INSTRUCTION BOX --- */
.instruction-box {
    background: #fff3cd;
    padding: 15px;
    border-left: 4px solid #ffc107;
    border-radius: 4px;
    margin: 10px 0 25px 0;
    font-size: 1em;
    line-height: 1.7;
}

/* --- STAMPA --- */
@media print {
    body { background: white; padding: 0; }

    .container {
        width: 100%;
        max-width: 100%;
        box-shadow: none;
        border: none;
    }

    .section-content {
        display: block !important;
        max-height: none !important;
        opacity: 1 !important;
        overflow: visible !important;
        border: 1px solid #eee !important;
        padding: 20px !important;
        margin-bottom: 20px;
    }

    .section-button, .arrow, .nav-buttons,
    .btn-ascolta-domanda, .instruction-box {
        display: none !important;
    }

    .section { page-break-inside: avoid; margin-bottom: 30px; }
    .step, .formula-box { page-break-inside: avoid; }
}

/* --- RESPONSIVE TABLET --- */
@media (max-width: 768px) {
    body {
        padding: 10px;
        font-size: 17px;
        line-height: 1.8;
    }

    .container {
        padding: 15px;
    }

    .question h2 {
        font-size: 1.15em;
        flex-direction: column;
        align-items: flex-start;
    }

    .section-button {
        font-size: 1.05em;
        padding: 14px;
    }

    .nav-buttons {
        flex-direction: column;
        align-items: center;
    }

    .btn-nav {
        width: 100%;
        text-align: center;
    }

    .graph-container {
        max-width: 100%;
        padding: 10px;
    }
}

/* --- RESPONSIVE SMARTPHONE --- */
@media (max-width: 600px) {
    .header-box {
        flex-direction: column;
        gap: 15px;
    }

    /* Su schermi piccoli le formule possono scorrere orizzontalmente */
    .formula-box {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
/* Impedisce alle virgole o ai segni di punteggiatura di finire da soli a capo dopo una formula */
.no-wrap {
    white-space: nowrap;
}
