/* ── Temi: chiaro (Essenziale) e scuro (Notte) ──
   Tutti i colori vengono da queste variabili. Il tema scuro si attiva con
   data-theme="dark" su <html> (pulsante sole/luna, vedi tema.js); le
   varianti -rgb servono per le trasparenze. Verde e rosso del pannello
   dell'accordatore (--tune-ok, --tune-off) sono uguali nei due temi: sono
   gli stessi colori calcolati in accordatore.js. */
:root {
    color-scheme: light;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bg: #f2f3f7;
    --panel: #ffffff;
    --panel-rgb: 255, 255, 255;
    --panel-line: rgba(17, 24, 39, 0.06);
    --panel-shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 12px 32px rgba(17, 24, 39, 0.06);
    --surface: #ffffff;
    --surface-rgb: 255, 255, 255;
    --surface-2: #f4f5f9;
    --sheet: #f2f3f7;
    --track: #e5e7ef;
    --text: #111827;
    --text-rgb: 17, 24, 39;
    --muted: #6b7280;
    --muted-rgb: 107, 114, 128;
    --border: #d9dce5;
    --accent: #4f46e5;
    --accent-rgb: 79, 70, 229;
    --accent-2: #4f46e5;
    --accent-2-rgb: 79, 70, 229;
    --on-accent: #ffffff;
    --beat: #111827;
    --beat-on: #4f46e5;
    --red: #e11d48;
    --red-rgb: 225, 29, 72;
    --red-text: #9f1239;
    --red-soft: #ffe4e6;
    --green: #16a34a;
    --green-rgb: 22, 163, 74;
    --live: #4ade80;
    --live-rgb: 74, 222, 128;
    --green-soft: #e7f6ed;
    --green-text: #14532d;
    --drone: #4f46e5;
    --drone-rgb: 79, 70, 229;
    --amber: #f59e0b;
    --amber-rgb: 245, 158, 11;
    --amber-text: #2b1a00;
    --flash-beat-rgb: 129, 140, 248;
    --flash-tempo-rgb: 165, 180, 252;
    --note: #111827;
    --shadow-rgb: 31, 41, 55;
    --tab-bar: rgba(255, 255, 255, 0.85);
    --tab-selected: #111827;
    --on-tab-selected: #ffffff;
    --glow: none;
    --beat-glow: none;
    --power-bg: #f4f5f9;
    --power-border: #e5e7ef;
    --power-text: #111827;
    --tune-ok: #1e9e3a;
    --tune-off: #d32f2f;
    --on-tone: #ffffff;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1220;
    --panel: #111a2b;
    --panel-rgb: 17, 26, 43;
    --panel-line: rgba(148, 163, 184, 0.14);
    --panel-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    --surface: #16213a;
    --surface-rgb: 22, 33, 58;
    --surface-2: #1a2642;
    --sheet: #111a2b;
    --track: #24324f;
    --text: #e8eefc;
    --text-rgb: 232, 238, 252;
    --muted: #8fa0bf;
    --muted-rgb: 143, 160, 191;
    --border: #2c3c60;
    --accent: #38bdf8;
    --accent-rgb: 56, 189, 248;
    --accent-2: #38bdf8;
    --accent-2-rgb: 56, 189, 248;
    --on-accent: #04121f;
    --beat: #38bdf8;
    --beat-on: #7dd3fc;
    --red: #fb7185;
    --red-rgb: 251, 113, 133;
    --red-text: #ffe4e6;
    --red-soft: #4a1d2a;
    --green: #34d399;
    --green-rgb: 52, 211, 153;
    --live: #34d399;
    --live-rgb: 52, 211, 153;
    --green-soft: #103b33;
    --green-text: #6ee7b7;
    --drone: #38bdf8;
    --drone-rgb: 56, 189, 248;
    --amber: #fbbf24;
    --amber-rgb: 251, 191, 36;
    --amber-text: #1f1400;
    --flash-beat-rgb: 2, 132, 199;
    --flash-tempo-rgb: 29, 78, 216;
    --note: #f8fafc;
    --shadow-rgb: 0, 0, 0;
    --tab-bar: rgba(17, 26, 43, 0.8);
    --tab-selected: #38bdf8;
    --on-tab-selected: #04121f;
    --glow: 0 0 30px rgba(56, 189, 248, 0.45);
    --beat-glow: 0 0 40px rgba(56, 189, 248, 0.5);
    --power-bg: #16213a;
    --power-border: #38bdf8;
    --power-text: #38bdf8;
}

/* ── Base ── */
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    font-family: var(--font);
    color: var(--text);
    -webkit-text-size-adjust: 100%;
}

:root[data-theme="dark"] body {
    background: radial-gradient(1200px 600px at 50% -10%, #17305a 0%, transparent 60%), linear-gradient(180deg, #0b1220, #05080f);
    background-attachment: fixed;
}

.site-header {
    position: relative;
    padding: 6px 24px 0;
}

/* Titolo da solo sulla prima riga, il La sotto. */
.site-heading-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    max-width: 900px;
    margin: 0 auto;
}

.site-title {
    margin: 0;
    font-size: clamp(1.4rem, 3.5vw, 2.35rem);
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: 0.02em;
}

.app-layout {
    display: grid;
    grid-template-columns: repeat(3, minmax(300px, 1fr));
    justify-content: center;
    gap: 24px;
    padding: 10px 24px 24px;
    box-sizing: border-box;
    max-width: 1480px;
    margin: 0 auto;
}

.metronomo,
.accordatore,
.drone {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: 100%;
    padding: 18px 28px;
    border-radius: 28px;
    background: rgba(var(--panel-rgb), 0.92);
    box-shadow: 0 0 0 1px var(--panel-line), var(--panel-shadow);
    text-align: center;
    box-sizing: border-box;
    display: grid;
    align-content: start;
    --panel-gap: 14px;
    gap: var(--panel-gap);
}

.panel-title {
    margin: 0;
    font-size: 2rem;
    letter-spacing: 0.04em;
}

/* ── Pulsante Accendi/Spegni (in cima a ogni pannello) ──
   Spento: solo contorno. Acceso: pieno, con un pallino verde che pulsa. */
.power-btn {
    justify-self: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: min(100%, 320px);
    min-height: 54px;
    padding: 10px 20px;
    border: 2px solid var(--power-border);
    border-radius: 999px;
    background: var(--power-bg);
    color: var(--power-text);
    font-family: inherit;
    font-size: 1.15rem;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, color 0.12s;
}

.power-btn::before {
    content: '';
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-radius: 50%;
    box-sizing: border-box;
}

.power-btn.is-on {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
    box-shadow: var(--glow);
}

.power-btn.is-on::before {
    border-color: var(--live);
    background: var(--live);
    box-shadow: 0 0 0 4px rgba(var(--live-rgb), 0.3);
    animation: power-pulse 1.6s ease-in-out infinite;
}

@keyframes power-pulse {
    50% {
        box-shadow: 0 0 0 7px rgba(var(--live-rgb), 0);
    }
}

.power-btn:active {
    transform: scale(0.98);
}

.power-btn[aria-disabled="true"] {
    opacity: 0.6;
    cursor: progress;
}

/* ── Controlli comuni ── */
.opzioni {
    display: grid;
    gap: 12px;
    text-align: left;
    width: 100%;
}

.opzione-riga {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.opzione-riga label {
    font-weight: bold;
}

.selettore-tempo {
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
    min-width: 140px;
    min-height: 44px;
}

.slider {
    width: 100%;
    accent-color: var(--accent-2);
    flex: 1;
    min-height: 32px;
}

/* Pulsanti tondi −/+ (BPM e ottava del drone). */
.step-btn,
.drone-octave-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    padding: 0;
    border: 1.5px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 1.6rem;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.step-btn:active,
.drone-octave-btn:active {
    background: var(--surface-2);
}

.step-btn[aria-disabled="true"],
.drone-octave-btn[aria-disabled="true"] {
    opacity: 0.35;
    cursor: default;
}

.drone-volume-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: min(100%, 280px);
}

.drone-volume-value {
    min-width: 44px;
    text-align: right;
    font-weight: bold;
    color: var(--text);
}

/* Volume di metronomo e drone: sempre in vista, per cambiarlo subito. */
.volume-riga {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
}

.volume-etichetta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: bold;
}

.volume-icona {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Pulsante «Impostazioni» (sotto il titolo) e foglio delle impostazioni ──
   Il foglio sale dal basso sul telefono e compare al centro su iPad e
   computer; dentro, un gruppo per strumento con controlli segmentati e
   interruttori. */
.impostazioni-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
    padding: 2px 10px 2px 8px;
    border: 1px solid rgba(var(--muted-rgb), 0.2);
    border-radius: 999px;
    background: rgba(var(--panel-rgb), 0.85);
    color: var(--muted);
    font-family: inherit;
    font-size: 0.74rem;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, transform 0.1s;
    /* Piccolo da vedere, ma l'area che si tocca resta comoda (::after). */
    position: relative;
}

.impostazioni-btn::after {
    content: '';
    position: absolute;
    inset: -10px -6px;
}

.impostazioni-btn:hover {
    background: var(--surface-2);
}

.impostazioni-btn:active {
    transform: scale(0.97);
}

.impostazioni-icona {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
}

html:has(.foglio[open]) {
    overflow: hidden;
}

.foglio {
    --drag: 0px;
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-width: 560px;
    max-height: min(90dvh, 780px);
    margin: 0 auto;
    padding: 0;
    border: 0;
    border-radius: 28px 28px 0 0;
    background: var(--sheet);
    color: var(--text);
    box-shadow: 0 -16px 48px rgba(var(--text-rgb), 0.28);
    font-family: inherit;
    text-align: left;
    transform: translateY(var(--drag));
    overflow: hidden;
}

.foglio[open] {
    display: flex;
    flex-direction: column;
    animation: foglio-su 0.34s cubic-bezier(0.2, 0.9, 0.25, 1);
}

.foglio.is-chiudendo {
    animation: foglio-giu 0.22s ease-in forwards;
}

.foglio.is-trascinato {
    transition: none;
}

.foglio:not(.is-trascinato) {
    transition: transform 0.2s ease;
}

.foglio::backdrop {
    background: rgba(var(--text-rgb), 0.38);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    animation: foglio-velo 0.3s ease;
}

.foglio.is-chiudendo::backdrop {
    animation: foglio-velo 0.22s ease reverse forwards;
}

@keyframes foglio-su {
    from { transform: translateY(100%); }
}

@keyframes foglio-giu {
    to { transform: translateY(100%); }
}

@keyframes foglio-velo {
    from { opacity: 0; }
}

.foglio-corpo {
    display: grid;
    gap: 8px;
    padding: 6px 18px calc(22px + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    min-height: 0;
}

.foglio-maniglia {
    justify-self: center;
    width: 40px;
    height: 5px;
    margin-top: 2px;
    border-radius: 999px;
    background: rgba(var(--muted-rgb), 0.3);
}

.foglio-testa {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0 6px;
    touch-action: none;
    cursor: grab;
}

.foglio-titolo {
    margin: 0;
    font-size: 1.45rem;
    letter-spacing: 0.02em;
}

.foglio-chiudi {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(var(--muted-rgb), 0.12);
    color: var(--muted);
    cursor: pointer;
}

.foglio-chiudi svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
}

.foglio-sezione {
    margin: 10px 4px 0;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: bold;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.foglio-gruppo {
    border-radius: 18px;
    background: var(--surface-2);
    box-shadow: 0 0 0 1px rgba(var(--muted-rgb), 0.1), 0 2px 10px rgba(var(--shadow-rgb), 0.06);
}

.foglio-riga {
    display: grid;
    gap: 10px;
    padding: 14px 16px;
}

.foglio-riga + .foglio-riga {
    border-top: 1px solid rgba(var(--muted-rgb), 0.12);
}

.foglio-riga--in-linea {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
}

.foglio-etichetta {
    font-weight: bold;
}

.foglio .tuner-sensitivity,
.foglio .drone-volume-row {
    width: 100%;
}

.foglio .rec-apri-btn {
    min-height: 38px;
    padding: 6px 16px;
    border: 0;
    border-radius: 999px;
    background: rgba(var(--accent-2-rgb), 0.1);
    color: var(--accent-2);
}

/* Controllo segmentato: la "pillola" bianca scivola sull'opzione scelta. */
.segmenti {
    --pad: 3px;
    position: relative;
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    padding: var(--pad);
    border-radius: 14px;
    background: rgba(var(--muted-rgb), 0.11);
}

.segmenti-pill {
    position: absolute;
    top: var(--pad);
    bottom: var(--pad);
    left: var(--pad);
    width: calc((100% - 2 * var(--pad)) / var(--n, 1));
    border-radius: 11px;
    background: var(--surface-2);
    box-shadow: 0 1px 2px rgba(var(--text-rgb), 0.12), 0 3px 10px rgba(var(--text-rgb), 0.1);
    transform: translateX(calc(100% * var(--i, 0)));
    transition: transform 0.28s cubic-bezier(0.3, 0.9, 0.3, 1);
}

.segmento {
    position: relative;
    min-height: 40px;
    padding: 6px 4px;
    border: 0;
    background: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: bold;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s;
}

.segmento[aria-checked="true"] {
    color: var(--text);
}

.segmento-nota {
    display: block;
    font-size: 0.72rem;
    font-weight: normal;
    color: var(--muted);
}

.segmento:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: -2px;
    border-radius: 11px;
}

/* Interruttore (casella con role="switch"): il pallino è un gradiente, così
   funziona in tutti i browser senza ::before sull'input. */
.interruttore {
    -webkit-appearance: none;
    appearance: none;
    flex-shrink: 0;
    width: 52px;
    height: 32px;
    margin: 0;
    border-radius: 999px;
    background: radial-gradient(circle, #fff 0 12px, transparent 13px) 2px center / 28px 28px no-repeat, var(--track);
    cursor: pointer;
    transition: background-position 0.22s ease, background-color 0.22s ease;
}

.interruttore:checked {
    background-color: var(--accent-2);
    background-position: 22px center;
}

.interruttore:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

/* iPad e computer: il foglio è una scheda al centro. */
@media (min-width: 700px) and (min-height: 560px) {
    .foglio {
        inset: 0;
        margin: auto;
        max-height: min(86vh, 780px);
        border-radius: 28px;
        box-shadow: 0 24px 70px rgba(var(--text-rgb), 0.35);
    }

    .foglio[open] {
        animation-name: foglio-appare;
    }

    .foglio.is-chiudendo {
        animation-name: foglio-sparisce;
    }

    .foglio-maniglia {
        display: none;
    }

    .foglio-testa {
        cursor: default;
    }

    .foglio-corpo {
        padding: 18px 22px 24px;
    }
}

@keyframes foglio-appare {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
}

@keyframes foglio-sparisce {
    to {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
}

/* ── Metronomo ── */
.metronomo {
    transition: background-color 0.12s ease;
    will-change: background-color;
}

.metronomo.attivo-battere {
    background: rgba(var(--flash-beat-rgb), 0.97);
}

.metronomo.attivo-tempo {
    background: rgba(var(--flash-tempo-rgb), 0.97);
}

.contatore {
    margin: 0;
    font-size: clamp(7.4rem, 22vw, 13rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: -0.04em;
    color: var(--beat);
    text-shadow: var(--beat-glow);
    transition: transform 0.1s ease, color 0.1s ease;
    will-change: transform, color;
}

.contatore.attivo {
    transform: scale(1.05);
    color: var(--beat-on);
}

/* Durante il lampeggio il numero resta scuro, altrimenti sull'arancio sparisce. */
.metronomo:is(.attivo-battere, .attivo-tempo) .contatore {
    color: var(--text);
}

.bpm-box {
    display: grid;
    gap: 12px;
    justify-items: center;
}

.bpm-value {
    font-size: clamp(2.7rem, 11vw, 3.3rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: -0.01em;
}

.tempo-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
}

.tap-btn {
    width: min(100%, 240px);
    min-height: 60px;
    padding: 12px 18px;
    border: 1.5px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 1.4rem;
    font-weight: bold;
    letter-spacing: 0.08em;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.08s, color 0.08s, border-color 0.08s;
}

.tap-btn--hit {
    background: var(--accent-2);
    border-color: var(--accent-2);
    color: var(--on-accent);
}

.time-sig-selectors {
    display: flex;
    align-items: center;
    gap: 6px;
}

.time-sig-slash {
    font-size: 1.4rem;
    font-weight: bold;
}

.time-sig-selectors .selettore-tempo {
    min-width: 72px;
}

.beat-mute-block {
    display: grid;
    gap: 8px;
    margin: 8px 0;
}

.beat-mute-title {
    font-weight: bold;
    font-size: 0.95rem;
}

.beat-mute-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.beat-mute-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    background: var(--green-soft);
    color: var(--green-text);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

/* Più di 8 battiti: griglia di pulsanti piccoli, al massimo due righe. */
.beat-mute-grid.is-tanti {
    display: grid;
    grid-template-columns: repeat(var(--colonne, 12), minmax(0, 44px));
    justify-content: center;
    gap: 4px;
    width: 100%;
}

.beat-mute-grid.is-tanti .beat-mute-btn {
    min-width: 0;
    min-height: 0;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border-radius: 8px;
    font-size: 0.85rem;
}

.beat-mute-btn.beat-muted {
    background: var(--red-soft);
    color: var(--red-text);
    border-color: var(--red);
}

/* ── Accordatore ── */
.accordatore-display {
    display: grid;
    gap: 4px;
}

.accordatore-nota {
    /* Larga quanto il testo e centrata: il nome col bemolle (.nota-alt) le sta
       accanto senza spostarla. */
    position: relative;
    justify-self: center;
    font-size: clamp(4.8rem, 18vw, 7rem);
    font-weight: bold;
    line-height: 0.95;
    color: var(--note);
}

/* Stessa nota col bemolle, piccola, in alto a destra della nota grande. */
.nota-alt {
    position: absolute;
    left: 100%;
    top: 0.14em;
    margin-left: 0.14em;
    font-size: 0.32em;
    line-height: 1;
    white-space: nowrap;
}

/* Cosa fare: subito sotto la nota, grande. L'altezza della riga non
   dipende dal testo, così lancetta e grafico non saltano tra una nota e
   l'altra. */
.accordatore-stato {
    --stato-size: clamp(1.8rem, 6vw, 2.3rem);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(var(--stato-size) * 1.15);
    font-size: var(--stato-size);
    font-weight: bold;
    line-height: 1.15;
    color: var(--muted);
}

/* Istruzioni (microfono spento, silenzio): più piccole del verdetto. */
.accordatore-stato.is-hint {
    font-size: 1.2rem;
    font-weight: normal;
    line-height: 1.3;
}

.accordatore-dettagli {
    display: flex;
    justify-content: center;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 16px;
}

.accordatore-cents {
    font-size: 1.35rem;
    font-weight: bold;
    color: var(--muted);
}

.accordatore-freq {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 1rem;
    color: var(--muted);
}

/* Strumento traspositore scelto: i nomi delle note sono quelli scritti. */
.accordatore-traspos {
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: bold;
    color: var(--accent);
}

/* Colore di tutto il pannello secondo l'intonazione (come il metronomo):
   verde = intonato (±3 cent), sfumatura dal rosso verso il verde = quasi
   (colore calcolato in accordatore.js), rosso = stonato (oltre 10 cent).
   Sullo sfondo colorato i testi diventano chiari; lancetta e grafico hanno
   il loro fondo chiaro. */
.accordatore {
    transition: background-color 0.15s ease, color 0.15s ease;
}

.accordatore.tuner-ok {
    background: var(--tune-ok);
}

.accordatore.tuner-near {
    background: var(--tuner-near-color, var(--amber));
}

.accordatore.tuner-off {
    background: var(--tune-off);
}

.accordatore:is(.tuner-ok, .tuner-near, .tuner-off),
.accordatore:is(.tuner-ok, .tuner-near, .tuner-off) :is(.accordatore-nota, .accordatore-stato, .accordatore-cents, .accordatore-freq, .accordatore-traspos, .scale-labels) {
    color: var(--on-tone);
}

/* Testi piccoli sul colore: un fondo scuro trasparente li rende leggibili. */
.accordatore:is(.tuner-ok, .tuner-near, .tuner-off) :is(.accordatore-freq, .accordatore-traspos, .scale-labels span) {
    background: rgba(0, 0, 0, 0.3);
}

.accordatore:is(.tuner-ok, .tuner-near, .tuner-off) .power-btn {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}

/* Lancetta: le zone corrispondono ai colori del pannello
   (verde ±3 cent, ambra fino a ±10, rosso oltre). */
.needle-wrap {
    display: grid;
    gap: 6px;
}

.needle-scale {
    position: relative;
    height: 28px;
    border-radius: 999px;
    background: var(--track);
    border: 1px solid var(--border);
    overflow: hidden;
}

.needle-zones {
    position: absolute;
    inset: 0;
    z-index: 1;
    /* --zona-verde e --zona-quasi vengono dalla precisione (accordatore.js). */
    background: linear-gradient(to right,
        rgba(var(--red-rgb), 0.16) 0 calc(50% - var(--zona-quasi, 10%)),
        rgba(var(--amber-rgb), 0.24) calc(50% - var(--zona-quasi, 10%)) calc(50% - var(--zona-verde, 3%)),
        rgba(var(--green-rgb), 0.32) calc(50% - var(--zona-verde, 3%)) calc(50% + var(--zona-verde, 3%)),
        rgba(var(--amber-rgb), 0.24) calc(50% + var(--zona-verde, 3%)) calc(50% + var(--zona-quasi, 10%)),
        rgba(var(--red-rgb), 0.16) calc(50% + var(--zona-quasi, 10%)) 100%);
}

.needle-center {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    width: 2px;
    height: 100%;
    background: var(--text);
    opacity: 0.9;
    z-index: 3;
}

/* Grigia quando non c'è una nota (microfono spento o silenzio). */
.needle {
    position: absolute;
    left: 50%;
    top: 2px;
    width: 16px;
    height: 22px;
    border-radius: 999px;
    background: var(--muted);
    transform: translateX(-50%);
    z-index: 2;
    transition: left 0.08s linear;
}

.accordatore.tuner-ok .needle {
    background: var(--tune-ok);
}

.accordatore.tuner-near .needle {
    background: var(--tuner-near-color, var(--amber));
}

.accordatore.tuner-off .needle {
    background: var(--tune-off);
}

.scale-labels {
    display: flex;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.9rem;
    padding: 0 2px;
}

.scale-labels span {
    padding: 0 4px;
    border-radius: 6px;
}

.tuner-graph-wrap {
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    overflow: hidden;
}

.tuner-graph {
    display: block;
    width: 100%;
    height: 150px;
}

/* Riepilogo dell'ultima frase (Impostazioni › Riepilogo dei passaggi). */
.frase {
    padding: 10px 10px 12px;
    border-radius: 14px;
    background: var(--surface-2);
}

.frase-titolo {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin: 0 2px 8px;
    font-weight: bold;
    font-size: 1rem;
    color: var(--text);
}

.frase-titolo .frase-conto {
    font-size: 0.9rem;
    color: var(--muted);
}

.frase-note {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.frase-nota {
    min-width: 40px;
    padding: 5px 5px 4px;
    border: 3px solid transparent;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: bold;
    line-height: 1.05;
    text-align: center;
    color: #fff;
    cursor: pointer;
}

.frase-nota small {
    display: block;
    font-size: 0.9rem;
    line-height: 1;
    margin-top: 2px;
}

.frase-ok {
    background: var(--green);
}

.frase-near {
    background: var(--amber);
    color: var(--amber-text);
}

.frase-off {
    background: var(--red);
}

.frase-nota[aria-pressed="true"] {
    border-color: var(--text);
    box-shadow: 0 0 0 2px #fff inset;
}

.frase-nota[aria-disabled="true"] {
    cursor: default;
    opacity: 0.6;
}

.frase-prima {
    align-self: center;
    padding: 0 4px;
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--muted);
}

.frase-legenda {
    margin: 8px 2px 0;
    font-size: 0.8rem;
    color: var(--muted);
}

/* ── Registrazione e riascolto ── */
.registra {
    display: grid;
    justify-items: center;
}

.rec-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 6px 20px;
    border: 2px solid var(--red);
    border-radius: 999px;
    background: var(--surface);
    color: var(--red);
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.rec-btn::before {
    content: '';
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--red);
}

.rec-btn.is-rec {
    border-color: var(--red);
    background: var(--red);
    color: #fff;
}

.rec-btn.is-rec::before {
    width: 11px;
    height: 11px;
    border-radius: 2px;
    background: #fff;
}

/* Sul pannello colorato (anche rosso) «Stop» resta ben visibile. */
.accordatore:is(.tuner-ok, .tuner-near, .tuner-off) .rec-btn.is-rec {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.rec-btn[aria-disabled="true"] {
    opacity: 0.6;
    cursor: progress;
}

.rec-btn:active,
.player-play:active {
    transform: scale(0.97);
}

.rec-live {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.rec-time {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--surface);
    color: var(--red);
    font-weight: bold;
    font-variant-numeric: tabular-nums;
}

.rec-time::before {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--red);
    animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse {
    50% {
        opacity: 0.25;
    }
}

.player {
    display: grid;
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--surface-2);
    color: var(--text);
}

.rec-btn[hidden],
.rec-live[hidden],
.player[hidden] {
    display: none;
}

.player-titolo {
    margin: 0 2px;
    font-weight: bold;
    text-align: center;
}

/* Tutta la registrazione: un trattino per nota, il riquadro di quello che
   si vede nel grafico e il punto che si ascolta. */
.player-striscia {
    position: relative;
    height: 34px;
    border-radius: 8px;
    background: var(--track);
    overflow: hidden;
    cursor: pointer;
    touch-action: pan-y;
}

.player-note {
    position: absolute;
    inset: 7px 0;
}

.player-segno {
    position: absolute;
    top: 0;
    bottom: 0;
    min-width: 3px;
    border-radius: 2px;
}

.player-finestra {
    position: absolute;
    top: 0;
    bottom: 0;
    border: 2px solid var(--accent);
    border-radius: 6px;
    background: rgba(var(--accent-rgb), 0.1);
    box-sizing: border-box;
}

.player-punto {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 3px;
    margin-left: -1.5px;
    border-radius: 2px;
    background: var(--text);
}

.player-legenda {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    margin: -2px 2px 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.player-comandi {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-play {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: var(--on-accent);
    font-family: inherit;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.player-barra {
    min-width: 0;
}

.player-tempo {
    flex-shrink: 0;
    font-size: 0.9rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.player-azioni {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.player-azioni button {
    min-height: 44px;
    padding: 4px 2px;
    border: none;
    background: none;
    color: var(--accent);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: bold;
    text-decoration: underline;
    cursor: pointer;
}

.player-azioni .player-elimina {
    color: var(--red);
}

/* Impostazioni: riaprire una registrazione salvata. */
.rec-apri-btn {
    min-height: 44px;
    padding: 8px 14px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
}

.rec-apri-btn[aria-disabled="true"] {
    opacity: 0.6;
    cursor: progress;
}

.rec-apri-stato {
    flex-basis: 100%;
    margin: 0;
    font-size: 0.9rem;
    color: var(--muted);
}

.rec-apri-stato:empty {
    display: none;
}

/* Nel riascolto il grafico si trascina per andare avanti e indietro. */
.accordatore.is-review .tuner-graph {
    cursor: grab;
    touch-action: pan-y;
}

/* La nota che si sta ascoltando. */
.frase-nota.is-now {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* Avviso: il microfono sente il drone. */
/* Avvisi dell'accordatore: senza avvisi in vista il contenitore non deve
   lasciare uno spazio vuoto in più nel pannello. */
.tuner-hints {
    display: grid;
    gap: var(--panel-gap);
}

.tuner-hints:not(:has(.tuner-hint:not([hidden]))) {
    /* Fuori dalla griglia ma ancora nella pagina: gli screen reader
       continuano a sentire l'area di stato quando compare un avviso. */
    position: absolute;
}

.tuner-hint {
    margin: 0;
    padding: 8px 12px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: rgba(var(--surface-rgb), 0.92);
    color: var(--muted);
    font-size: 0.95rem;
    line-height: 1.35;
}

.tuner-sensitivity {
    display: grid;
    gap: 6px;
    width: min(100%, 250px);
}

.tuner-sensitivity .drone-volume-row {
    width: 100%;
}

.tuner-level {
    position: relative;
    height: 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--track);
    overflow: hidden;
}

.tuner-level-fill {
    width: 0;
    height: 100%;
    background: var(--border);
}

.tuner-level-fill--active {
    background: var(--green);
}

.tuner-level-gate {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--text);
    transform: translateX(-50%);
}

/* ── Drone ── */
.drone-octave-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.drone-octave-label {
    font-size: 1.1rem;
    min-width: 90px;
    text-align: center;
}

.drone-circle-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-width: 300px;
    margin: 0 auto;
    /* Le misure del Quadrante (punti, nomi, note al centro) seguono il cerchio. */
    container-type: inline-size;
}

/* Quadrante: anello sottile, linee tra le note accese (disegnate da drone.js). */
.drone-quadrante {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.drone-anello {
    fill: none;
    stroke: var(--border);
    stroke-width: 2px;
    vector-effect: non-scaling-stroke;
}

.drone-forma {
    fill: rgba(var(--drone-rgb), 0.10);
    stroke: none;
}

.drone-corda {
    fill: none;
    stroke: var(--drone);
    stroke-width: 3.5px;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.7;
    vector-effect: non-scaling-stroke;
}

/* Al centro le note accese, una riga per ottava. Il bordino del colore del
   pannello le stacca dalle linee che ci passano sotto. */
.drone-centro {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 56%;
    transform: translate(-50%, -50%);
    margin: 0;
    font-size: clamp(0.85rem, 6.6cqw, 1.7rem);
    font-weight: 800;
    line-height: 1.25;
    text-align: center;
    color: var(--text);
    pointer-events: none;
    -webkit-text-stroke: 0;
    text-shadow:
        0 0 3px var(--panel), 0 0 3px var(--panel), 0 0 6px var(--panel),
        2px 0 0 var(--panel), -2px 0 0 var(--panel), 0 2px 0 var(--panel), 0 -2px 0 var(--panel);
}

.drone-centro.is-piccolo {
    font-size: clamp(0.75rem, 5cqw, 1.3rem);
}

.drone-centro span {
    display: block;
}

.drone-circle {
    position: absolute;
    inset: 0;
    border-radius: 50%;
}

/* Breve richiamo quando si preme "Accendi" senza aver scelto una nota. */
.drone-circle--hint {
    animation: circle-hint 0.9s ease 2;
}

@keyframes circle-hint {
    50% {
        box-shadow: 0 0 0 6px rgba(var(--accent-rgb), 0.35);
    }
}

/* Ogni nota: un'area da toccare grande quanto un pulsante, con il punto
   sull'anello e il nome fuori (--ux, --uy: direzione verso l'esterno). */
.drone-circle-btn {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: bold;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    z-index: 1;
    padding: 0;
    line-height: 1.15;
    text-align: center;
}

.dcb-punto {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 3.6cqw;
    height: 3.6cqw;
    min-width: 10px;
    min-height: 10px;
    box-sizing: border-box;
    border: 2px solid var(--muted);
    border-radius: 50%;
    background: var(--panel);
    transform: translate(-50%, -50%) scale(var(--respiro, 1));
    transition: width 0.14s, height 0.14s, background 0.14s, border-color 0.14s;
    pointer-events: none;
}

.drone-circle-btn--active .dcb-punto {
    width: 8.6cqw;
    height: 8.6cqw;
    border-color: var(--drone);
    background: var(--drone);
    box-shadow: 0 0 4cqw rgba(var(--drone-rgb), var(--luce, 0.55));
}

/* Nota accesa in un'altra ottava: punto tratteggiato e numero dell'ottava. */
.drone-circle-btn--altrove .dcb-punto {
    width: 7.4cqw;
    height: 7.4cqw;
    border: 2.5px dashed var(--drone);
}

.drone-circle-btn--active.drone-circle-btn--altrove .dcb-punto {
    border-style: solid;
}

.drone-circle-btn:active .dcb-punto {
    transform: translate(-50%, -50%) scale(0.9);
}

.dcb-name {
    position: absolute;
    left: 50%;
    top: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.05;
    white-space: nowrap;
    transform: translate(-50%, -50%) translate(calc(var(--ux) * 12cqw), calc(var(--uy) * 11cqw));
    pointer-events: none;
}

.drone-circle-btn--active .dcb-name,
.drone-circle-btn--altrove .dcb-name {
    color: var(--drone);
}

.drone-circle-btn:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 0;
}

.dcb-ottave {
    position: absolute;
    left: 50%;
    top: 50%;
    /* Verso il centro, così non copre il nome della nota. */
    transform: translate(-50%, -50%) translate(calc(var(--ux) * -6.5cqw), calc(var(--uy) * -6.5cqw));
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    box-sizing: border-box;
    border: 2px solid var(--panel);
    border-radius: 10px;
    background: var(--drone);
    color: var(--on-accent);
    font-size: 0.7rem;
    font-weight: bold;
    line-height: 16px;
    text-align: center;
    pointer-events: none;
}

.dcb-alt {
    font-size: 0.78em;
    font-weight: normal;
    letter-spacing: -0.02em;
    color: var(--muted);
}

.drone-circle-btn--active .dcb-alt,
.drone-circle-btn--altrove .dcb-alt {
    color: inherit;
    opacity: 0.8;
}

.drone-active-row {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}

/* Secondario: piccolo, come un link. */
.drone-clear-btn {
    min-height: 44px;
    padding: 0 8px;
    border: none;
    background: none;
    color: var(--accent);
    font-family: inherit;
    font-size: 0.9rem;
    text-decoration: underline;
    cursor: pointer;
    touch-action: manipulation;
}

/* ── Schede (solo telefono e tablet) ── */
.tab-bar {
    display: none;
}

.tab {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 56px;
    padding: 6px 4px;
    border: 0;
    border-radius: 15px;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, color 0.15s;
}

.tab-name {
    font-size: 0.98rem;
    font-weight: bold;
}

.tab-status {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.82rem;
    color: var(--muted);
}

.tab[aria-selected="true"] {
    background: var(--tab-selected);
    color: var(--on-tab-selected);
}

.tab[aria-selected="true"] .tab-status,
.tab--on[aria-selected="true"] .tab-status {
    color: inherit;
    opacity: 0.85;
}

.tab--on .tab-status {
    color: var(--accent);
    font-weight: bold;
}

.tab--on .tab-status::before {
    content: '● ';
    content: '● ' / '';
    color: var(--green);
}

/* La scheda dell'accordatore prende il colore dell'intonazione sul bordo
   e sul pallino; il testo resta scuro su fondo chiaro, sempre leggibile. */
.tab[data-tool="accordatore"]:not([data-tone=""]) {
    box-shadow: inset 0 0 0 3px var(--tab-tone);
}

.tab[data-tool="accordatore"]:not([data-tone=""], [aria-selected="true"]) .tab-status {
    color: var(--text);
}

.tab[data-tool="accordatore"]:not([data-tone=""]) .tab-status::before {
    color: var(--tab-tone);
}

/* Avviso «Suono interrotto» (iPhone dopo una chiamata o una sveglia). */
.avviso-audio {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 50;
    max-width: 520px;
    margin: 0 auto;
    padding: 14px 18px;
    border-radius: 16px;
    background: var(--text);
    color: var(--surface);
    font-size: 1.1rem;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* Testo letto solo dagli screen reader. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ── Footer ── */
/* Installare l'app: pulsante in alto sotto il titolo (Android, computer) o
   istruzioni che si aprono dallo stesso pulsante (iPhone). */
.header-riga {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px 14px;
}

.install-btn {
    min-height: 44px;
    padding: 6px 16px;
    border: 2px solid var(--accent);
    border-radius: 999px;
    background: var(--surface);
    color: var(--accent);
    font-family: inherit;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    touch-action: manipulation;
}

.install-hint {
    max-width: 32em;
    margin: 8px auto 4px;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 4px 14px rgba(var(--shadow-rgb), 0.12);
    font-size: 0.95rem;
    line-height: 1.4;
    text-align: center;
    color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
    .power-btn.is-on::before,
    .drone-circle--hint {
        animation: none;
    }

    .contatore.attivo {
        transform: none;
    }

    .drone-circle-btn:active .dcb-punto {
        transform: translate(-50%, -50%);
    }

    .contatore,
    .dcb-punto,
    .segmenti-pill,
    .interruttore,
    .foglio {
        transition: none;
    }

    .foglio[open],
    .foglio::backdrop {
        animation: none;
    }
}

/* ── Computer ── */
@media (min-width: 1100px) {
    /* Si usa il mouse: i pulsanti sotto il titolo possono essere più bassi. */
    .install-btn {
        min-height: 34px;
        padding: 3px 14px;
        font-size: 0.95rem;
    }

    /* Tre colonne strette: il verdetto deve stare su una riga e il nome col
       bemolle accanto alla nota. */
    .accordatore-stato {
        --stato-size: clamp(1.75rem, 2.6vw, 2.3rem);
    }

    .accordatore-nota {
        font-size: clamp(4.6rem, 6vw, 7rem);
    }
}

/* ── Computer con schermo basso (es. portatile 1280×720): tre colonne compatte ── */
@media (min-width: 1100px) and (max-height: 900px) {
    .site-header {
        padding-top: 2px;
    }

    .site-title {
        font-size: 1.6rem;
    }

    .app-layout {
        padding: 6px 20px 16px;
        gap: 18px;
    }

    .metronomo,
    .accordatore,
    .drone {
        padding: 12px 22px;
        --panel-gap: 10px;
    }

    .panel-title {
        font-size: 1.5rem;
    }

    .power-btn {
        min-height: 46px;
        font-size: 1.05rem;
    }

    .contatore {
        font-size: 6.2rem;
    }

    .bpm-value {
        font-size: 2.4rem;
    }

    .tap-btn {
        min-height: 48px;
        font-size: 1.2rem;
    }

    .accordatore-nota {
        font-size: 4.6rem;
    }

    .accordatore-stato {
        --stato-size: 1.75rem;
    }

    .tuner-graph {
        height: 110px;
    }

    .drone-circle-wrap {
        max-width: 260px;
    }

    .drone-circle-btn {
        width: 50px;
        height: 50px;
    }
}

/* ── Telefono e tablet: un pannello alla volta, scelto con le schede ── */
@media (max-width: 1099px) {
    /* Il campo con il focus non deve finire sotto la barra delle schede. */
    html {
        scroll-padding-top: 96px;
    }

    .app-layout {
        grid-template-columns: minmax(0, 640px);
        align-items: start;
        padding: 10px 16px 20px;
    }

    .has-tabs .tab-bar {
        position: sticky;
        top: 0;
        z-index: 20;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 4px;
        max-width: 616px;
        margin: 6px auto 0;
        padding: 4px;
        /* In colonna flex la barra delle schede resta larga come la pagina. */
        width: calc(100% - 24px);
        box-sizing: border-box;
        border: 1px solid var(--panel-line);
        border-radius: 20px;
        background: var(--tab-bar);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
        box-shadow: 0 4px 14px rgba(var(--shadow-rgb), 0.08);
    }

    .has-tabs .app-layout > section:not(.tab-active) {
        display: none;
    }

    .drone-circle-wrap {
        max-width: 340px;
    }

    .drone-circle-btn {
        width: 62px;
        height: 62px;
        font-size: 0.92rem;
    }
}

@media (max-width: 640px) {
    .site-header {
        padding: 6px 16px 0;
    }

    .app-layout {
        padding: 8px 12px 16px;
    }


    .metronomo,
    .accordatore,
    .drone {
        padding: 16px;
        border-radius: 24px;
        --panel-gap: 12px;
    }

    .panel-title {
        font-size: 1.45rem;
    }

    .opzione-riga {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .selettore-tempo,
    .tuner-sensitivity {
        width: 100%;
        box-sizing: border-box;
    }

    .drone-volume-row {
        width: 100%;
    }

    .needle-scale {
        height: 24px;
    }

    .needle {
        height: 18px;
        top: 3px;
    }

    .contatore {
        font-size: clamp(5.4rem, 30vw, 9rem);
    }

    .accordatore-nota {
        font-size: clamp(4rem, 22vw, 5.8rem);
    }

    .drone-circle-btn {
        width: 58px;
        height: 58px;
        font-size: 0.88rem;
    }
}

@media (max-width: 380px) {
    .tab-name {
        font-size: 0.88rem;
    }

    .accordatore-stato {
        --stato-size: 1.6rem;
    }

    .drone-circle-btn {
        width: 52px;
        height: 52px;
        font-size: 0.8rem;
    }
}

/* ── Telefono in orizzontale: schermo basso, caratteri più piccoli ── */
@media (max-width: 1099px) and (max-height: 500px) {
    /* La barra delle schede non resta fissa: lo spazio serve al pannello. */
    .has-tabs .tab-bar {
        position: static;
        margin-top: 0;
        padding-top: 2px;
        padding-bottom: 2px;
    }

    .tab {
        min-height: 44px;
        padding: 2px 4px;
    }

    html {
        scroll-padding-top: 0;
    }

    .contatore {
        font-size: clamp(4.5rem, 28vh, 7rem);
    }

    .accordatore-nota {
        font-size: clamp(3.2rem, 18vh, 4.6rem);
    }

    .accordatore-stato {
        --stato-size: 1.6rem;
    }

    .tuner-graph {
        height: 100px;
    }
}

/* ── Telefono e tablet: ogni scheda sta tutta nello schermo ──
   La pagina è alta quanto lo schermo; nella scheda la parte "flessibile"
   (il numero del metronomo, il grafico dell'accordatore, il cerchio del
   drone) prende lo spazio che resta. Se un pannello ha più contenuto del
   solito (riepilogo, registrazione) la pagina torna a scorrere. */
@media (max-width: 1099px) {
    body.has-tabs {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .has-tabs .app-layout {
        flex: 1 0 auto;
        width: 100%;
        align-items: stretch;
    }

    .has-tabs .app-layout > section {
        display: flex;
        flex-direction: column;
    }

    .has-tabs .app-layout > section > * {
        flex-shrink: 0;
    }

    /* Il nome dello strumento è già sulla scheda in alto: il titolo resta
       solo per gli screen reader. */
    .has-tabs .panel-title {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    /* In colonna flex justify-self non vale: si centra con align-self. */
    .has-tabs .power-btn,
    .has-tabs .accordatore-nota {
        align-self: center;
    }

    .has-tabs .area-flessibile {
        flex: 1 1 0;
        min-height: 90px;
    }

    .has-tabs .contatore-area {
        container-type: size;
        display: grid;
        place-items: center;
        min-height: 70px;
    }

    .has-tabs .contatore {
        font-size: min(100cqh, 60cqw, 18rem);
    }

    .has-tabs .tuner-graph-wrap {
        position: relative;
        min-height: 100px;
    }

    .has-tabs .tuner-graph {
        position: absolute;
        inset: 0;
        height: 100%;
    }

    .has-tabs .drone-area {
        container-type: size;
        display: grid;
        place-items: center;
        min-height: 220px;
    }

    .has-tabs .drone-circle-wrap {
        container-type: inline-size;
        width: min(100cqw, 100cqh, 600px);
        max-width: none;
    }

    .has-tabs .drone-circle-btn {
        width: clamp(46px, 18cqw, 92px);
        height: clamp(46px, 18cqw, 92px);
        font-size: clamp(0.8rem, 4.2cqw, 1.3rem);
    }

    /* Tempo e pattern ritmico affiancati: una riga in meno. */
    .has-tabs .bpm-box > .opzioni {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
    }

    .has-tabs .bpm-box > .opzioni .opzione-riga {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .has-tabs .bpm-box > .opzioni .selettore-tempo {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    .has-tabs .time-sig-selectors {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .has-tabs .time-sig-selectors .selettore-tempo {
        flex: 1;
        padding-inline: 8px;
    }
}

/* Telefoni bassi (es. iPhone SE): tutto un po' più compatto. */
@media (max-width: 1099px) and (max-height: 760px) and (min-height: 501px) {
    .has-tabs .app-layout {
        padding-top: 6px;
        padding-bottom: 8px;
    }

    .has-tabs .app-layout > section {
        --panel-gap: 8px;
        padding-top: 10px;
        padding-bottom: 12px;
    }

    .has-tabs .power-btn {
        min-height: 46px;
    }

    .has-tabs .tap-btn {
        min-height: 46px;
        padding: 6px 18px;
    }

    .has-tabs .bpm-box {
        gap: 8px;
    }

    .has-tabs .beat-mute-block {
        margin: 0;
    }
}

.foglio-firma {
    margin: 14px 0 0;
    text-align: center;
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--accent);
}

/* Computer con schermo basso: niente margine sotto i pannelli, così la
   pagina non scorre. */
@media (min-width: 1100px) and (max-height: 760px) {
    .app-layout {
        padding-bottom: 4px;
    }

    /* Un po' di margine in più: i caratteri cambiano da browser a browser. */
    .metronomo,
    .accordatore,
    .drone {
        --panel-gap: 8px;
    }
}

/* ── Pulsante tema chiaro/scuro (in alto a destra) ── */
.tema-btn {
    position: absolute;
    top: 8px;
    right: 16px;
    z-index: 25;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--panel-line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(var(--shadow-rgb), 0.08);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Piccolo da vedere, ma l'area che si tocca resta comoda. */
.tema-btn::after {
    content: '';
    position: absolute;
    inset: -6px;
}

.tema-btn:active {
    transform: scale(0.94);
}

.tema-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tema-sole,
:root[data-theme="dark"] .tema-luna {
    display: none;
}

:root[data-theme="dark"] .tema-sole {
    display: block;
}
