/* IAM - Style */

/* Un solo colore e un solo spessore per tutti i contorni a riposo:
   gli elementi attivi mantengono i loro colori di stato (viola acceso, ciano, ambra). */
:root {
    --line: #5b4e96;
    --line-w: 1.5px;
}

/* Carattere del titolo IAM: Nunito 800 (licenza SIL OFL, vedi fonts/OFL.txt).
   Incluso nel progetto, così funziona anche senza rete. */
@font-face {
    font-family: 'Nunito IAM';
    src: url('fonts/nunito-800.woff2') format('woff2');
    font-weight: 800;
    font-style: normal;
    font-display: swap;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    touch-action: manipulation;
}

body {
    background-color: #0a0a0f; /* Antracite scuro */
    color: #a78bfa;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem 0;
    /* Se lo schermo è più basso dell'app si può scorrere, senza "rimbalzo" */
    overflow-y: auto;
    overscroll-behavior: none;
}

/* Container look rack hardware */
.container {
    width: 95vw;
    max-width: 500px;
    padding: 2rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    background: #12121a;
    border: 2px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 0 18px rgba(167, 139, 250, 0.12), 0 20px 50px rgba(0,0,0,0.8), inset 0 1px 1px rgba(255,255,255,0.05);
    /* margin:auto centra quando c'è spazio, ma non taglia la parte alta quando non c'è */
    margin: auto;
}

/* Targa del titolo IAM */
header {
    margin-bottom: 0.5rem;
    padding: 0.9rem 1rem;
    border: var(--line-w) solid var(--line);
    border-radius: 6px;
    background: linear-gradient(180deg, #17142c 0%, #12121a 100%);
    box-shadow: inset 0 1px 0 rgba(167, 139, 250, 0.08);
}

h1 {
    font-family: 'Nunito IAM', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 2.2rem;
    font-weight: 800;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    /* Lettere bianche con contorno viola; paint-order disegna il contorno
       sotto il riempimento, così le lettere non si assottigliano */
    color: #ffffff;
    -webkit-text-stroke: 1.5px #a78bfa;
    paint-order: stroke fill;
}

.frequency-section {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.freq-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

/* Display Hz (Intonatore e Accordatore) — prima puntava a un id non più esistente */
#hz-intonatore, #hz-accordatore {
    min-width: 120px;
    padding: 0.5rem;
    background: #080808;
    color: #00f2ff; /* Ciano Elettrico */
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 1.8rem;
    border: var(--line-w) solid var(--line);
    border-radius: 6px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.9);
}

/* Pulsanti +/− del diapason */
.ref-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #1a1a2e;
    border: var(--line-w) solid var(--line);
    color: #a78bfa;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s;
}

.ref-btn:hover {
    border-color: #a78bfa;
}

.ref-btn:active {
    background: #1e1a3a;
    box-shadow: 0 0 10px rgba(167, 139, 250, 0.3);
}

.audio-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.mic-btn, .btn-start {
    flex: 1;
    background: #2a2a2a;
    border: var(--line-w) solid var(--line);
    color: #aaa;
    padding: 0.8rem;
    border-radius: 4px;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.2s;
}

.mic-btn.active, .btn-start.active {
    color: #6c63ff;
    border-color: #00f2ff;
    background: #222;
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.2);
}

.octave-switcher {
    padding: 0.5rem 0;
}

.octave-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.octave-btn {
    background: #252525;
    border: var(--line-w) solid var(--line);
    color: #666;
    padding: 0.6rem 1.2rem;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
}

.octave-btn.active {
    color: #a78bfa;
    border-color: #a78bfa;
    background: #333;
}

.grid-container {
    padding: 0.5rem 0;
}

.note-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.note-btn {
    background: linear-gradient(180deg, #1a1a2e 0%, #12121a 100%);
    border: var(--line-w) solid var(--line);
    padding: 1.2rem 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.note-btn .note-name {
    font-size: 1.2rem;
    color: #ffffff;
}

.note-btn .note-freq {
    font-size: 0.7rem;
    color: #7c7c9a;
}

.note-btn.playing, .note-btn.mic-detected {
    border-color: #a78bfa;
    background: #1e1e1e;
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.3);
}

.note-btn.playing .note-name, .note-btn.mic-detected .note-name {
    color: #a78bfa;
    text-shadow: 0 0 5px rgba(0, 242, 255, 0.5);
}

.extra-controls {
    margin-top: 0.5rem;
}

.btn-toggle {
    background: none;
    border: var(--line-w) solid var(--line);
    color: #555;
    padding: 0.4rem 0.8rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    cursor: pointer;
}

.btn-toggle.active {
    color: #a78bfa;
    border-color: #ffbf00;
}


/* ================================================================
   QUADRANTE ACCORDATORE (SVG)
   Colori di stato coerenti con i vecchi LED:
   ciano = intonato (±5 cent), viola = vicino (±15), ambra = lontano
   ================================================================ */
.tuner-gauge {
    display: block;
    width: min(100%, 320px);
    margin: 0.75rem auto 0;
    overflow: visible;
}

.g-ring {
    fill: #0d0d14;
    stroke: var(--line);
    stroke-width: 2;
    transition: stroke 0.3s;
}

.g-scale {
    fill: none;
    stroke: #3d3561;
    stroke-width: 1.5;
}

.g-tick {
    stroke: #4a4570;
    stroke-width: 1.5;
    stroke-linecap: round;
}

.g-tick.major {
    stroke: #7c7c9a;
    stroke-width: 2.5;
}

.g-zone {
    fill: none;
    stroke: #00f2ff;
    stroke-width: 6;
    stroke-linecap: round;
    opacity: 0.25;
    transition: opacity 0.25s;
}

.g-sign {
    fill: #7c7c9a;
    font-size: 20px;
    text-anchor: middle;
    dominant-baseline: middle;
}

.g-needle-line {
    stroke: #a78bfa;
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke 0.2s, opacity 0.3s;
}

.g-needle-hub {
    fill: #a78bfa;
    transition: fill 0.2s, opacity 0.3s;
}

.g-note {
    fill: #ffffff;
    text-anchor: middle;
    font-weight: 700;
    transition: fill 0.2s;
}

.g-letter { font-size: 72px; }
.g-letter-long { font-size: 58px; }
.g-acc    { font-size: 34px; }
.g-oct    { font-size: 24px; font-weight: 600; fill: #7c7c9a; }

.g-cents {
    fill: #a78bfa;
    font-family: 'Courier New', monospace;
    font-size: 18px;
    font-weight: bold;
    text-anchor: middle;
}

.g-hz {
    fill: #7c7c9a;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    text-anchor: middle;
}

.g-transp {
    fill: #6c63ff;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-anchor: middle;
}

/* Stato: a riposo (nessun suono / microfono spento) */
.tuner-gauge.is-idle .g-needle-line,
.tuner-gauge.is-idle .g-needle-hub { opacity: 0.3; }
.tuner-gauge.is-idle .g-note { fill: #3d3561; }
.tuner-gauge.is-idle .g-cents {
    fill: #7c7c9a;
    font-family: inherit;
    font-size: 13px;
    font-weight: normal;
    letter-spacing: 0.1em;
}

/* Stato: intonato */
.tuner-gauge.is-in .g-zone { opacity: 1; filter: url(#gGlow); }
.tuner-gauge.is-in .g-ring { stroke: #00f2ff; }
.tuner-gauge.is-in .g-needle-line { stroke: #00f2ff; filter: url(#gGlow); }
.tuner-gauge.is-in .g-needle-hub { fill: #00f2ff; }
.tuner-gauge.is-in .g-note { fill: #00f2ff; }
.tuner-gauge.is-in .g-cents { fill: #00f2ff; }

/* Stato: lontano */
.tuner-gauge.is-off .g-needle-line { stroke: #ffbf00; }
.tuner-gauge.is-off .g-needle-hub { fill: #ffbf00; }
.tuner-gauge.is-off .g-cents { fill: #ffbf00; }

/* Selettore strumento (trasposizione) */
.transp-section {
    margin: 0.5rem 0 1rem;
}

.transp-label {
    font-size: 0.65rem;
    color: #7c7c9a;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-bottom: 0.5rem;
}

.transp-switch {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
}

.transp-btn {
    min-width: 44px;
    background: #1a1a2e;
    border: var(--line-w) solid var(--line);
    color: #7c7c9a;
    padding: 0.45rem 0.6rem;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.transp-btn.active {
    color: #a78bfa;
    border-color: #a78bfa;
    background: #1e1a3a;
}


/* ================================================================
   METRONOMO
   ================================================================ */
.metro {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    padding-top: 1.5rem;
}

.bpm-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.bpm-display {
    min-width: 160px;
    padding: 0.5rem 1rem;
    background: #080808;
    border: var(--line-w) solid var(--line);
    border-radius: 6px;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.9);
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.4rem;
}

#bpmValue {
    color: #00f2ff;
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 2.8rem;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.bpm-unit {
    color: #7c7c9a;
    font-size: 0.7rem;
    letter-spacing: 0.15em;
}

.tempo-name {
    font-style: italic;
    font-size: 1.05rem;
    letter-spacing: 0.05em;
    color: #a78bfa;
    min-height: 1.3em;
}

.bpm-slider {
    width: 100%;
    max-width: 360px;
    accent-color: #a78bfa;
    cursor: pointer;
}

/* LED dei tempi: il primo (accento) è più grande e ciano */
.beat-leds {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.9rem;
    min-height: 56px;
    margin: 0.5rem 0;
}

.beat-led {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #1a1a1a;
    border: var(--line-w) solid var(--line);
}

.beat-led.accent {
    width: 32px;
    height: 32px;
    border-color: #2b6f7a;
}

.beat-led.on {
    animation: beatPulse var(--beat-ms, 600ms) ease-out forwards;
}

.beat-led.accent.on {
    animation-name: beatPulseAccent;
}

@keyframes beatPulse {
    0%   { background: #a78bfa; border-color: #a78bfa; box-shadow: 0 0 16px #a78bfa; }
    100% { background: #1a1a1a; border-color: var(--line); box-shadow: none; }
}

@keyframes beatPulseAccent {
    0%   { background: #00f2ff; border-color: #00f2ff; box-shadow: 0 0 24px #00f2ff, 0 0 6px #00f2ff; }
    100% { background: #1a1a1a; border-color: #2b6f7a; box-shadow: none; }
}

.meter-section {
    margin-top: 0.3rem;
}

.meter-switch {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.meter-btn {
    min-width: 48px;
    background: #1a1a2e;
    border: var(--line-w) solid var(--line);
    color: #7c7c9a;
    padding: 0.45rem 0.6rem;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.meter-btn.active {
    color: #a78bfa;
    border-color: #a78bfa;
    background: #1e1a3a;
}

.metro-actions {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
}

.metro-aux {
    background: none;
    border: var(--line-w) solid var(--line);
    color: #7c7c9a;
    padding: 0.5rem 1rem;
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

.metro-aux:active {
    border-color: #a78bfa;
    color: #a78bfa;
}

.metro-aux.active {
    color: #ffbf00;
    border-color: #ffbf00;
}

.metro-start {
    width: 100%;
    max-width: 360px;
    margin-top: 0.4rem;
    padding: 1rem;
    background: #1a1a2e;
    border: 1px solid #6c63ff;
    color: #a78bfa;
    font-size: 0.9rem;
    font-weight: bold;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.metro-start.running {
    color: #00f2ff;
    border-color: #00f2ff;
    box-shadow: 0 0 14px rgba(0, 242, 255, 0.25);
}

@media (max-width: 499px) {
    #bpmValue { font-size: 2.2rem; }
    .bpm-display { min-width: 130px; }
    .beat-leds { gap: 0.6rem; }
    .meter-btn { min-width: 40px; padding: 0.35rem 0.4rem; font-size: 0.8rem; }
}


footer {
    margin-top: 1rem;
    padding-top: 0.8rem;
    border-top: var(--line-w) solid var(--line);
}

.info {
    font-size: 0.7rem;
    color: #444;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* Diapason e ottava non riguardano il Metronomo: la riga sparisce,
   ma lo spazio resta, così l'altezza del riquadro non cambia */
body[data-tab="metronomo"] footer > * {
    visibility: hidden;
}

/* Selettore notazione nel piè di pagina */
.notation-switch {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.7rem;
}

.notation-label {
    font-size: 0.65rem;
    color: #7c7c9a;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-right: 0.3rem;
}

.notation-btn {
    background: #1a1a2e;
    border: var(--line-w) solid var(--line);
    color: #7c7c9a;
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.notation-btn.active {
    color: #a78bfa;
    border-color: #a78bfa;
    background: #1e1a3a;
}

/* Respiro fra il riquadro Hz e "Avvia Audio" */
#tab-intonatore .audio-controls {
    margin-top: 1rem;
}


/* Controlli ottava */
.octave-controls {
    display: flex;
    justify-content: center;
    gap: 0.8rem;
    margin-bottom: 1.2rem;
}

.octave-btn {
    background: #2a2a2a;
    border: var(--line-w) solid var(--line);
    color: #666;
    padding: 0.5rem 1rem;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 50px;
    border-radius: 4px;
}

.octave-btn:hover {
    background: #333;
    border-color: #a78bfa;
}

.octave-btn.active {
    background: #333;
    color: #a78bfa;
    border-color: #a78bfa;
    box-shadow: 0 0 10px rgba(255, 191, 0, 0.2);
}


/* Ottimizzato per mobile */
@media (max-width: 499px) {
    .container {
        padding: 1rem;
        gap: 0.8rem;
    }
    
    header {
        margin-bottom: 0.8rem;
    }
    
    h1 {
        font-size: 1rem;
    }
    
    .freq-controls {
        margin-top: 0.5rem;
        gap: 1.2rem;
    }

    #hz-intonatore, #hz-accordatore {
        padding: 0.3rem 0.6rem;
        font-size: 1.1rem;
        min-width: 90px;
    }

    .ref-btn {
        width: 34px;
        height: 34px;
        font-size: 1.2rem;
    }

    .tuner-gauge {
        width: min(100%, 280px);
    }

    .transp-btn {
        min-width: 38px;
        padding: 0.35rem 0.4rem;
        font-size: 0.8rem;
    }
    
    .controls {
        gap: 0.5rem;
        margin-bottom: 0.8rem;
    }
    
    .btn-start {
        padding: 0.4rem 0.8rem;
        font-size: 0.75rem;
        width: 80%;
        max-width: 300px;
        margin: 0 auto;
    }
    
    .notation-toggle label {
        font-size: 0.65rem;
    }
    
    .btn-toggle {
        padding: 0.3rem 0.5rem;
        font-size: 0.65rem;
    }
    
    .octave-controls {
        margin-bottom: 0.5rem;
    }
    
    .octave-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.8rem;
        min-width: 38px;
    }
    
    .grid-container {
        margin-bottom: 0.5rem;
    }
    
    .note-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.6rem;
    }
    
    .note-btn {
        padding: 1rem 0.2rem;
        min-height: 80px;
    }

    .note-btn .note-name {
        font-size: 0.8rem;
    }
    
    .note-btn .note-freq {
        font-size: 0.55rem;
    }
    
    footer {
        margin-top: 0.3rem;
    }
    
    .info {
        font-size: 0.55rem;
    }

    .mic-controls {
        margin-top: 0.6rem;
    }

    .mic-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.75rem;
    }
}

.tab-nav {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    background: #1a1a2e;
    border: var(--line-w) solid var(--line);
    color: #7c7c9a;
    padding: 0.6rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.tab-btn.active {
    color: #a78bfa;
    border-color: #a78bfa;
    background: #1e1a3a;
}

/* Le tre tab occupano la STESSA cella della griglia: il contenitore prende
   l'altezza della più alta e resta identico qualunque tab sia aperta. */
.tab-panels {
    display: grid;
}

.tab-content {
    grid-area: 1 / 1;
    visibility: hidden;
}

.tab-content.active {
    visibility: visible;
}

/* Le transizioni dei pulsanti ritarderebbero la scomparsa della tab lasciata:
   nelle tab nascoste le spegniamo, così il cambio è istantaneo e pulito. */
.tab-content:not(.active),
.tab-content:not(.active) * {
    transition: none !important;
}
