/* ========================================================
   TINY TEMPLE TOOLBOX - THEME
   Variabili, font e componenti condivisi da tutte le pagine
   della Toolbox. Stessa identita' visiva della vetrina
   (tinytemplestudio.it), ricreata qui perche' su Cloudflare
   Pages con root "toolbox/" non si puo' condividere lo
   style.css della vetrina (origin diverso). Font self-hosted,
   copie 1:1 in assets/fonts/ (licenze OFL-*.txt e
   LICENSE-Charter.txt). Nessuna richiesta verso Google.
   ======================================================== */

@font-face {
    font-family: 'Archivo';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/assets/fonts/archivo-400-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Archivo';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/assets/fonts/archivo-400-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Archivo';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('/assets/fonts/archivo-600-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Archivo';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('/assets/fonts/archivo-600-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Archivo';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('/assets/fonts/archivo-700-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Archivo';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('/assets/fonts/archivo-700-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/assets/fonts/inter-400-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('/assets/fonts/inter-400-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('/assets/fonts/inter-500-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('/assets/fonts/inter-500-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* La & disegnata a mano (vedi style.css della vetrina): un solo
   glifo, usato solo per quel carattere via unicode-range. */
@font-face {
    font-family: 'TT Ampersand';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('/assets/fonts/tiny-ampersand.woff') format('woff');
    unicode-range: U+0026;
    size-adjust: 102%;
}

/* --- VARIABILI (identiche alla vetrina) --- */
:root {
    --bg-color: #080808;
    --text-primary: #e6e6e6;
    --text-muted: #a09085;
    --accent-brown: #4a3b32;
    --accent-orange: #cf5c36;

    --font-title: 'TT Ampersand', 'Archivo', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-text: 'TT Ampersand', 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;

    --ease-cinematic: cubic-bezier(0.65, 0, 0.35, 1);

    /* Safe-area: standalone su iPhone (notch, home indicator). */
    --tb-safe-t: env(safe-area-inset-top, 0px);
    --tb-safe-r: env(safe-area-inset-right, 0px);
    --tb-safe-b: env(safe-area-inset-bottom, 0px);
    --tb-safe-l: env(safe-area-inset-left, 0px);
}

/* --- RESET MINIMO --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

img {
    height: auto;
    max-width: 100%;
    display: block;
}

html, body {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

html {
    height: 100%;
}

body {
    min-height: 100dvh;
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-text);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(74, 59, 50, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(207, 92, 54, 0.08) 0%, transparent 60%);
    padding-top: var(--tb-safe-t);
    padding-right: var(--tb-safe-r);
    padding-bottom: var(--tb-safe-b);
    padding-left: var(--tb-safe-l);
}

a {
    color: inherit;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

/* --- LAYOUT DI PAGINA --- */
/* Safe-area contata UNA sola volta, sul body: qui sotto solo px fissi. */
.tb-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: clamp(28px, 6vh, 56px) 5% 120px;
    min-height: 100dvh;
}

.tb-page-header {
    text-align: center;
    padding: clamp(40px, 10vh, 96px) 0 30px;
}

.tb-eyebrow {
    display: block;
    font-family: var(--font-text);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--accent-orange);
    margin-bottom: 18px;
}

.tb-page-header h1 {
    font-family: var(--font-title);
    font-size: clamp(2.1rem, 4vw, 2.7rem);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    line-height: 1.1;
}

.tb-page-intro {
    max-width: 640px;
    margin: 16px auto 0;
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-muted);
    font-weight: 300;
}

/* --- INTESTAZIONE STRUMENTO (ui.js: mountHeader) --- */
.tb-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    /* la safe-area in alto la riserva gia' il body: qui solo px fissi */
    padding: 14px 5%;
    background: linear-gradient(180deg, rgba(8, 8, 8, 0.92) 0%, rgba(8, 8, 8, 0.75) 80%, transparent 100%);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.tb-header-back {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 4px;
    font-family: var(--font-text);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-muted);
    transition: color 0.3s ease;
}

.tb-header-title {
    flex: 1;
    font-family: var(--font-title);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-primary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tb-header-lang {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--text-muted);
    transition: color 0.3s ease, background 0.3s ease;
}

.tb-header-lang svg {
    width: 20px;
    height: 20px;
}

@media (hover: hover) and (pointer: fine) {
    .tb-header-back:hover,
    .tb-header-lang:hover {
        color: var(--accent-orange);
    }
}

/* --- GRIGLIA STRUMENTI --- */
.tb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 20px;
    margin-top: 12px;
}

.tb-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 30px 26px;
    border-radius: 22px;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.05) 0%, rgba(18, 16, 14, 0.55) 100%);
    backdrop-filter: blur(25px) saturate(160%);
    -webkit-backdrop-filter: blur(25px) saturate(160%);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.tb-card h2 {
    font-family: var(--font-title);
    font-size: 1.15rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    line-height: 1.2;
    color: var(--text-primary);
}

.tb-card p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-muted);
    font-weight: 300;
}

.tb-badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.04);
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

/* Il prossimo strumento in arrivo: bordo e badge in evidenza. */
.tb-card--next {
    border-color: rgba(207, 92, 54, 0.5);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 0 32px rgba(207, 92, 54, 0.12);
}

.tb-badge--next {
    border-color: var(--accent-orange);
    background: rgba(207, 92, 54, 0.16);
    color: var(--accent-orange);
}

/* --- BOTTONI --- */
.tb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 44px;
    padding: 14px 32px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    font-family: var(--font-text);
    font-size: 0.82rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-primary);
    text-decoration: none;
    transition: all 0.4s var(--ease-cinematic);
}

.tb-btn:active {
    transform: scale(0.97);
    border-color: var(--accent-orange);
}

/* .tb-install: alias dello stile del pulsante primario (spec §3), da usare
   insieme a .tb-btn sul pulsante di installazione. */
.tb-btn--primary,
.tb-install {
    background: var(--accent-orange);
    border-color: var(--accent-orange);
    color: #ffffff;
}

.tb-btn--primary:active,
.tb-install:active {
    background: #b64d2c;
    border-color: #b64d2c;
}

@media (hover: hover) and (pointer: fine) {
    .tb-btn:hover {
        border-color: var(--accent-orange);
        background: rgba(207, 92, 54, 0.15);
    }
    .tb-btn--primary:hover,
    .tb-install:hover {
        background: #b64d2c;
        border-color: #b64d2c;
    }
}

.tb-btn[hidden] {
    display: none !important;
}

/* --- STATO (idle/busy/ok/error/denied) --- */
.tb-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    min-height: 24px;
}

.tb-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.tb-status--idle { color: var(--text-muted); }
.tb-status--busy { color: var(--text-primary); }
.tb-status--ok { color: #4dd97a; }
.tb-status--error { color: #e8604c; }
.tb-status--denied { color: #e8604c; }

@media (prefers-reduced-motion: no-preference) {
    .tb-status--busy::before {
        animation: tb-pulse 1.2s ease-in-out infinite;
    }
}

@keyframes tb-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* --- TOAST --- */
.tb-toast-region {
    position: fixed;
    left: 50%;
    bottom: calc(96px + var(--tb-safe-b));
    transform: translateX(-50%);
    z-index: 10020;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(92vw, 420px);
    pointer-events: none;
}

.tb-toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px;
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(16, 15, 14, 0.85) 100%);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    color: var(--text-primary);
    font-size: 0.85rem;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: auto;
}

.tb-toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.tb-toast-action {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 6px 16px;
    border-radius: 50px;
    border: 1px solid var(--accent-orange);
    color: var(--accent-orange);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* --- CONSENSO (microfono, mic.js) --- */
.tb-consent {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    padding: 18px 20px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.tb-consent p {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-muted);
}

.tb-consent__title {
    font-family: var(--font-title);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.01em;
    color: var(--text-primary);
}

.tb-consent__text {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-muted);
}

.tb-consent--denied .tb-consent__text,
.tb-consent--unavailable .tb-consent__text {
    color: #e8604c;
}

.tb-consent--compact {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.tb-consent[hidden] {
    display: none !important;
}

/* --- STATO VUOTO / ERRORE --- */
.tb-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- INSTALLAZIONE PWA --- */
.tb-install-section {
    margin-top: 56px;
    padding: 40px clamp(20px, 5vw, 48px);
    border-radius: 24px;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.05) 0%, rgba(18, 16, 14, 0.55) 100%);
    border: 1px solid rgba(255, 255, 255, 0.09);
    text-align: center;
}

.tb-install-section h2 {
    font-family: var(--font-title);
    font-size: 1.3rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-primary);
    margin-bottom: 14px;
}

.tb-install-section p {
    max-width: 520px;
    margin: 0 auto 20px;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-muted);
}

.tb-ios-help {
    max-width: 480px;
    margin: 20px auto 0;
    padding: 18px 20px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    text-align: left;
}

.tb-ios-help[hidden] {
    display: none !important;
}

.tb-ios-help ol {
    margin: 12px 0 0;
    padding-left: 22px;
    color: var(--text-primary);
}

.tb-ios-help li {
    margin-bottom: 6px;
    font-size: 0.88rem;
}

.tb-ios-help .tb-ios-note {
    margin-top: 14px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* --- PULSANTE LINGUA FLUTTUANTE (index.html) --- */
.tb-lang-btn {
    position: fixed;
    left: max(20px, var(--tb-safe-l));
    bottom: calc(24px + var(--tb-safe-b));
    width: 50px;
    height: 50px;
    z-index: 10015;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.12) 0%, rgba(18, 18, 18, 0.45) 100%);
    backdrop-filter: blur(25px) saturate(200%);
    -webkit-backdrop-filter: blur(25px) saturate(200%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6), inset 0 1px 2px rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
    transition: transform 0.3s var(--ease-cinematic), border-color 0.3s ease;
}

.tb-lang-btn svg {
    width: 22px;
    height: 22px;
}

.tb-lang-btn.is-pressed,
.tb-lang-btn:active {
    transform: scale(0.92);
    border-color: var(--accent-orange);
}

@media (hover: hover) and (pointer: fine) {
    .tb-lang-btn:hover {
        border-color: var(--accent-orange);
    }
}

/* --- FEEDBACK AL TOCCO --- */
.is-pressed {
    transition-duration: 0.09s !important;
}

/* --- FOOTER --- */
/* padding-bottom fisso: la safe-area in basso la riserva gia' il body */
.tb-footer {
    margin-top: 70px;
    padding-top: 30px;
    padding-bottom: 40px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    text-align: center;
    font-size: 0.78rem;
    line-height: 1.7;
    color: var(--text-muted);
}

.tb-footer p {
    margin-bottom: 4px;
}

.tb-footer-legal {
    max-width: 640px;
    margin: 14px auto;
}

.tb-footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 18px;
    margin-top: 14px;
}

.tb-footer-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
    .tb-footer-links a:hover {
        color: var(--accent-orange);
    }
}

.tb-footer-links a.is-pressed {
    color: var(--accent-orange);
}

/* --- BREAKPOINT MOBILE --- */
@media (max-width: 768px) {
    .tb-shell {
        padding: 20px 6% 110px;
    }

    .tb-grid {
        grid-template-columns: 1fr 1fr;
        gap: 14px;
    }

    .tb-card {
        padding: 22px 18px;
    }
}

@media (max-width: 480px) {
    .tb-grid {
        grid-template-columns: 1fr;
    }
}

/* --- ACCESSIBILITA': FOCUS DA TASTIERA --- */
:focus-visible {
    outline: 2px solid var(--accent-orange) !important;
    outline-offset: 3px !important;
}

.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* --- MOVIMENTO RIDOTTO --- */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto !important;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-delay: 0ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0ms !important;
    }
}
