/* studio.css — lo stile comune dei client di ai-studio (audio, immagini, e il portale ne tiene
   una copia ridotta inline: vive su un altro repo e su un altro server).

   MOBILE FIRST: le regole senza media query sono quelle del telefono; da 900px in su si
   aggiunge, non si toglie. Scuro e marcato: fondo quasi nero a tre livelli di superficie,
   testo ad alto contrasto, un solo colore d'accento per verticale (data-vert sul <body>) usato
   per l'azione principale e per "dove sono", non per decorare.

   Compatibilita': i nomi delle classi sono quelli che il JavaScript dei client gia' genera
   (.btn, .btn-mini, .btn-generate, .ed-input, .hint, .card, #toast, .spinner...), e le vecchie
   variabili (--bg-dark, --bg-panel, --border, --text-dim, --success) restano come alias, cosi'
   i fogli propri di ogni pagina non si rompono mentre li si riscrive. */

:root {
    color-scheme: dark;

    /* superfici: fondo, pannello, controllo, controllo attivo */
    --bg: #09090c;
    --surface: #131318;
    --surface-2: #1b1b22;
    --surface-3: #25252e;
    --line: #2a2a34;
    --line-strong: #3a3a46;

    --text: #f5f5f7;
    --text-dim: #a4a4b2;
    --text-faint: #6c6c7a;

    /* accento del portale; ogni verticale lo sostituisce */
    --accent: #c8f03c;
    --accent-ink: #0a0c02;              /* testo sopra l'accento */
    --accent-soft: rgb(200 240 60 / 0.12);
    --accent-line: rgb(200 240 60 / 0.45);

    --ok: #3ddc84;
    --warn-c: #ffb224;
    --danger: #ff5a5f;

    --radius-s: 10px;
    --radius: 14px;
    --radius-l: 20px;
    --tap: 48px;                        /* bersaglio minimo al tocco */
    --gutter: 16px;
    --bar-h: 64px;                      /* barra di navigazione in basso, sul telefono */
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto,
            "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;

    /* alias dei fogli precedenti */
    --bg-dark: var(--bg);
    --bg-panel: var(--surface);
    --border: var(--line);
    --success: var(--ok);
}

body[data-vert="audio"]    { --accent: #ffb224; --accent-ink: #1a1000; --accent-soft: rgb(255 178 36 / 0.13); --accent-line: rgb(255 178 36 / 0.5); }
body[data-vert="immagini"] { --accent: #b794ff; --accent-ink: #12082a; --accent-soft: rgb(183 148 255 / 0.14); --accent-line: rgb(183 148 255 / 0.5); }

/* ---- base ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0; min-height: 100vh; min-height: 100dvh;
    background: var(--bg); color: var(--text);
    font: 16px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
[hidden] { display: none !important; }
img, video { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
::selection { background: var(--accent); color: var(--accent-ink); }

h1, h2, h3 { margin: 0 0 12px; line-height: 1.15; letter-spacing: -0.02em; }
h1 { font-size: 1.75rem; font-weight: 800; }
h2 { font-size: 1.25rem; font-weight: 750; color: var(--text); }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 12px; }
code { font-family: var(--mono); font-size: 0.9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.hint { color: var(--text-dim); font-size: 0.875rem; }
.warn { color: #ff9a9d; }
.eyebrow, label.eyebrow {
    display: block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-faint);
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---- barra in alto ---- */
.app-bar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 12px;
    min-height: 56px; padding: 8px var(--gutter);
    padding-top: max(8px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--line);
}
/* La sfocatura sta su uno pseudo-elemento, non sulla barra: un backdrop-filter sulla barra ne fa
   il "containing block" dei figli position:fixed, e la .tabbar (figlia della testata) finirebbe
   in cima allo schermo invece che in fondo. */
.app-bar::before {
    content: ""; position: absolute; inset: 0; z-index: -1;
    background: rgb(9 9 12 / 0.82);
    -webkit-backdrop-filter: saturate(160%) blur(14px); backdrop-filter: saturate(160%) blur(14px);
}
.app-brand {
    display: flex; align-items: center; gap: 10px; min-width: 0;
    color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: -0.02em;
}
/* Il marchio di ZStudio: l'omega blu su bianco, lo stesso disegno dell'icona dell'app
   (/icone/marchio-96.png, servita alla radice da tutte e due le facce; la genera
   _shared/pwa/genera.py). Non prende l'accento del verticale: e' il nome del sito, non "dove sono". */
.app-mark {
    width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
    display: block; object-fit: contain;
    background: #fff;
}
.app-title { font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-title small { display: block; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em;
    text-transform: uppercase; color: var(--text-faint); line-height: 1.1; }
.app-user { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.app-who {
    width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center; overflow: hidden;
    background: var(--surface-3); color: var(--text); font-size: 0.8rem; font-weight: 800;
    border: 1px solid var(--line-strong); text-transform: uppercase;
}
.app-who-name { display: none; color: var(--text-dim); font-size: 0.875rem; max-width: 16rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-exit {
    min-height: 36px; padding: 0 12px; border-radius: 999px; display: inline-flex; align-items: center;
    color: var(--text-dim); text-decoration: none; font-size: 0.85rem; font-weight: 600;
    border: 1px solid var(--line);
}
.app-exit:hover { color: var(--text); border-color: var(--line-strong); }

/* ---- controllo a segmenti (poche voci, sempre visibile: Anima | Libera) ---- */
.seg {
    display: inline-flex; padding: 4px; gap: 2px; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--line);
}
.seg > a, .seg > button {
    min-height: 36px; padding: 0 14px; border-radius: 999px; border: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: transparent; color: var(--text-dim); font: inherit; font-size: 0.9rem; font-weight: 650;
    text-decoration: none; cursor: pointer; white-space: nowrap;
}
.seg > [aria-current="page"], .seg > .active, .seg > [aria-selected="true"] {
    background: var(--accent); color: var(--accent-ink);
}

/* ---- barra di navigazione: in basso sul telefono, nella testata da 900px ---- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    display: flex; gap: 4px;
    padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom));
    background: rgb(15 15 19 / 0.94);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
}
.tabbar > button, .tabbar > a {
    flex: 1 1 0; min-width: 0; min-height: 52px; border: 0; border-radius: 12px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: transparent; color: var(--text-faint);
    font: inherit; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
    text-decoration: none; cursor: pointer;
}
/* icone SVG a tratto, colore dal testo del pulsante */
.tabbar .ico { width: 22px; height: 22px; flex: 0 0 auto; display: block; }
.tabbar .ico svg, .tabbar svg.ico { width: 22px; height: 22px; fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar > .active, .tabbar > [aria-current="page"], .tabbar > [aria-selected="true"] {
    color: var(--text); background: var(--accent-soft);
}
.tabbar > .active .ico, .tabbar > [aria-current="page"] .ico, .tabbar > [aria-selected="true"] .ico { color: var(--accent); }
.tabbar .lbl { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.has-tabbar { padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom)); }

/* ---- controlli ---- */
label { color: var(--text-dim); font-size: 0.875rem; font-weight: 600; }
.control-group { margin-bottom: 16px; }
.control-group > label { display: block; margin-bottom: 6px; }

.ed-input, select.ed-input, textarea.ed-input {
    width: 100%; min-height: var(--tap);
    padding: 11px 14px;
    background: var(--surface-2); color: var(--text);
    border: 1px solid var(--line); border-radius: var(--radius-s);
    font: inherit; font-size: 1rem;              /* 16px: sotto, iOS ingrandisce la pagina */
    transition: border-color .15s, background-color .15s;
}
.ed-input::placeholder { color: var(--text-faint); }
.ed-input:hover { border-color: var(--line-strong); }
.ed-input:focus { outline: none; border-color: var(--accent); background: var(--surface-3);
    box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.ed-input { resize: vertical; line-height: 1.5; }
select.ed-input {
    appearance: none; -webkit-appearance: none; padding-right: 40px;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                      linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
    background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
    background-size: 6px 6px; background-repeat: no-repeat;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 20px; height: 20px; }
input[type="range"] { accent-color: var(--accent); }

.btn, .btn-mini {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
    color: var(--text); background: var(--surface-2);
    border: 1px solid var(--line); border-radius: 12px;
    transition: background-color .15s, border-color .15s, transform .06s;
    -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.btn { min-height: var(--tap); padding: 0 20px; font-size: 1rem; }
.btn-mini { min-height: 44px; padding: 0 14px; font-size: 0.875rem; border-radius: 10px; }
.btn:hover, .btn-mini:hover { background: var(--surface-3); border-color: var(--line-strong); }
.btn:active, .btn-mini:active { transform: scale(0.98); }
.btn-generate, .btn-primary {
    background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 800;
    letter-spacing: -0.01em;
}
.btn-generate:hover, .btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.08); }
.btn-danger { color: #ff9a9d; border-color: rgb(255 90 95 / 0.4); }
.btn:disabled, .btn-mini:disabled { opacity: 0.4; cursor: not-allowed; transform: none; filter: none; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.btn-row > .btn { flex: 1 1 auto; }

/* ---- pannelli ---- */
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l);
    padding: 18px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.page { width: 100%; max-width: 72rem; margin: 0 auto; padding: 20px var(--gutter) 32px; }
.page-head { margin: 4px 0 18px; }
.page-head p { color: var(--text-dim); max-width: 42rem; }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details.fold > summary {
    min-height: var(--tap); display: flex; align-items: center; gap: 10px;
    font-weight: 650; color: var(--text);
}
details.fold > summary::after {
    content: ""; margin-left: auto; width: 8px; height: 8px; flex: 0 0 auto;
    border-right: 2px solid var(--text-dim); border-bottom: 2px solid var(--text-dim);
    transform: rotate(45deg); transition: transform .2s;
}
details.fold[open] > summary::after { transform: rotate(-135deg); }

.chip {
    display: inline-flex; align-items: center; gap: 6px; min-height: 26px; padding: 0 10px;
    border-radius: 999px; font-size: 0.75rem; font-weight: 700;
    background: var(--surface-3); color: var(--text-dim); border: 1px solid var(--line);
}
.chip.ok { color: var(--ok); border-color: rgb(61 220 132 / 0.35); background: rgb(61 220 132 / 0.08); }
.chip.run { color: var(--warn-c); border-color: rgb(255 178 36 / 0.35); background: rgb(255 178 36 / 0.08); }
.chip.err { color: #ff9a9d; border-color: rgb(255 90 95 / 0.35); background: rgb(255 90 95 / 0.08); }

.empty {
    padding: 28px 16px; text-align: center; color: var(--text-dim);
    border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
}

/* zona per scegliere un file: grande, da toccare */
.drop {
    position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 6px; min-height: 120px; padding: 18px; text-align: center; cursor: pointer;
    border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-2);
    color: var(--text-dim); overflow-wrap: anywhere; transition: border-color .15s, background-color .15s;
}
.drop:hover, .drop:focus-within { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.drop strong { color: var(--text); font-weight: 700; }

.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit;
    transition: width .3s; }

/* ---- avvisi ---- */
#toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 60;
    transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
    max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 14px;
    background: var(--surface-3); color: var(--text); border: 1px solid var(--line-strong);
    box-shadow: 0 12px 32px rgb(0 0 0 / 0.5); font-weight: 600;
    transition: opacity .2s, transform .2s;
}
body.has-tabbar #toast { bottom: calc(var(--bar-h) + 16px + env(safe-area-inset-bottom)); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { border-color: var(--danger); color: #ffb3b5; }

.spinner {
    width: 36px; height: 36px; border-radius: 50%;
    border: 3px solid var(--surface-3); border-top-color: var(--accent);
    animation: studio-gira 0.8s linear infinite;
}
@keyframes studio-gira { to { transform: rotate(360deg); } }

.boot { display: grid; place-items: center; min-height: 50vh; color: var(--text-dim); }

.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation-duration: 0.001ms !important; }
}

/* ---- da 900px: la navigazione sale nella testata ---- */
@media (min-width: 900px) {
    :root { --gutter: 24px; }
    h1 { font-size: 2.25rem; }
    .app-bar { min-height: 64px; gap: 20px; }
    .btn-mini { min-height: 40px; }
    .tabbar {
        position: static; padding: 4px; gap: 2px; border: 1px solid var(--line); border-radius: 999px;
        background: var(--surface-2); -webkit-backdrop-filter: none; backdrop-filter: none;
    }
    .tabbar > button, .tabbar > a {
        flex: 0 0 auto; flex-direction: row; gap: 8px; min-height: 40px; padding: 0 16px;
        border-radius: 999px; font-size: 0.9rem; color: var(--text-dim);
    }
    .tabbar .ico, .tabbar .ico svg, .tabbar svg.ico { width: 18px; height: 18px; }
    .tabbar > .active, .tabbar > [aria-current="page"], .tabbar > [aria-selected="true"] {
        background: var(--accent); color: var(--accent-ink);
    }
    .tabbar > .active .ico, .tabbar > [aria-current="page"] .ico, .tabbar > [aria-selected="true"] .ico { color: inherit; }
    body.has-tabbar { padding-bottom: 0; }
    body.has-tabbar #toast { bottom: 24px; }
    .card { padding: 22px; }
}

/* ---- da 1200px c'e' posto anche per il nome accanto alle iniziali ---- */
@media (min-width: 1200px) {
    .app-who-name { display: block; }
}
