:root {
    --bg-color: #e8ede4;
    --ui-accent: #2d3b2d;
    --panel-bg: rgba(232, 237, 228, 0.94);

    /* Bordi sicuri (notch, Dynamic Island, home indicator). Richiedono viewport-fit=cover */
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
}

[hidden] { display: none !important; }

html {
    margin: 0; padding: 0; width: 100%; height: 100%;
    overflow: hidden; background: var(--bg-color);
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}

body {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0;
    margin: 0; padding: 0; overflow: hidden; background: var(--bg-color);
    font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: var(--ui-accent);
    user-select: none; -webkit-user-select: none;
    -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

#canvas-visualizer { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }

#header-title {
    position: absolute; bottom: calc(20px + var(--sab)); left: calc(20px + var(--sal)); right: calc(20px + var(--sar));
    font-size: clamp(0.45rem, 2.5vw, 0.65rem); letter-spacing: 0.35em;
    color: var(--ui-accent); text-transform: uppercase; z-index: 50;
    pointer-events: none; text-align: center; line-height: 1.8;
    text-shadow: 0 0 12px var(--bg-color);
}

@media (min-width: 768px) {
    #header-title { bottom: calc(40px + var(--sab)); right: calc(40px + var(--sar)); left: auto; text-align: right; max-width: 50vw; }
}

/* Mixer */
#mixer-tab {
    position: fixed; left: 0; top: 50%; transform: translateY(-50%); width: calc(35px + var(--sal)); height: 110px;
    padding-left: var(--sal); box-sizing: border-box;
    background: var(--panel-bg); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-radius: 0 6px 6px 0;
    display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 1001;
    opacity: 0; pointer-events: none; transition: opacity 1.5s ease; border: 1px solid rgba(0, 0, 0, 0.05);
}
#mixer-tab.ready { opacity: 1; pointer-events: auto; }
#mixer-tab span { transform: rotate(-90deg); font-size: 0.4rem; letter-spacing: 0.4em; text-transform: uppercase; color: var(--ui-accent); white-space: nowrap; font-weight: 400; }

#ui-container {
    position: fixed; top: 0; left: -340px; width: calc(280px + var(--sal)); height: 100%; box-sizing: border-box;
    background: var(--panel-bg); -webkit-backdrop-filter: blur(25px); backdrop-filter: blur(25px);
    display: flex; flex-direction: column; align-items: center;
    padding: calc(24px + var(--sat)) 0 calc(24px + var(--sab)) var(--sal); gap: clamp(8px, 2vh, 20px); justify-content: center; z-index: 1002;
    transition: left 0.8s cubic-bezier(0.19, 1, 0.22, 1), visibility 0s linear 0.8s;
    overflow-y: auto; overflow-x: hidden; visibility: hidden;
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y;
}
#ui-container.open { left: 0; visibility: visible; transition: left 0.8s cubic-bezier(0.19, 1, 0.22, 1), visibility 0s; }

#drone-controls-container { width: 100%; display: flex; flex-direction: column; gap: clamp(4px, 1.2vh, 12px); }

.slider-group { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 14px; width: 100%; box-sizing: border-box; padding: 0 22px; }
.slider-group label { flex: 0 0 92px; font-size: 0.45rem; letter-spacing: 0.25em; text-transform: uppercase; color: var(--ui-accent); opacity: 0.8; font-weight: 400; }
.v-slider { -webkit-appearance: none; appearance: none; flex: 1 1 auto; min-width: 0; width: 100%; height: 1px; background: var(--ui-accent); opacity: 0.3; outline: none; touch-action: none; margin: 12px 0; }
.v-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 25px; height: 6px; background: var(--ui-accent); cursor: pointer; border-radius: 2px; }
.v-slider::-moz-range-thumb { width: 25px; height: 6px; background: var(--ui-accent); cursor: pointer; border-radius: 2px; border: 0; }

.ui-btn {
    background: transparent; border: 1px solid var(--ui-accent); color: var(--ui-accent); font-family: inherit;
    font-size: 0.5rem; padding: 10px 25px; cursor: pointer; text-transform: uppercase; letter-spacing: 0.2em; min-width: 120px;
    font-weight: 400; touch-action: manipulation;
}
.ui-btn-quiet { border: none; opacity: 0.5; margin-top: -6px; }

hr { width: 40px; border: 0; border-top: 1px solid var(--ui-accent); opacity: 0.2; margin: 0; }

.top-btn {
    position: fixed; top: calc(16px + var(--sat)); right: calc(16px + var(--sar)); z-index: 1003;
    background: rgba(232, 237, 228, 0.35); border: 1px solid rgba(45, 59, 45, 0.3);
    color: var(--ui-accent); padding: 8px 12px; font-family: inherit;
    font-size: 0.5rem; letter-spacing: 0.25em; text-transform: uppercase; font-weight: 400;
    cursor: pointer; transition: opacity 0.3s ease; touch-action: manipulation; opacity: 0.6;
}
.top-btn:hover { opacity: 1; }

/* Schermata d'ingresso */
#overlay {
    position: fixed; inset: 0; background: #e8ede4; color: #2d3b2d;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 10000; cursor: pointer; text-align: center; font-weight: 400;
    pointer-events: auto; touch-action: manipulation; transition: opacity 0.8s ease; box-sizing: border-box;
    padding: calc(20px + var(--sat)) calc(20px + var(--sar)) calc(20px + var(--sab)) calc(20px + var(--sal));
}
#overlay.fading { pointer-events: none; }
.ov-title { letter-spacing: 1.2em; margin-right: -1.2em; font-size: 0.8rem; line-height: 2; margin-bottom: 36px; }
.overlay-actions { display: flex; flex-direction: column; gap: 15px; align-items: center; }
.start-btn { font-size: 0.55rem; letter-spacing: 0.35em; opacity: 0.55; transition: opacity 0.3s ease; }
.start-btn:hover { opacity: 1; }

#btn-install-pwa {
    display: inline-block; touch-action: manipulation;
    background: transparent; border: 1px solid #2d3b2d; color: #2d3b2d;
    padding: 8px 16px; font-family: inherit; font-size: 0.6rem;
    letter-spacing: 0.2em; text-transform: uppercase; font-weight: 400;
    cursor: pointer; transition: all 0.3s ease;
}
#btn-install-pwa:hover { background: #2d3b2d; color: #e8ede4; }

#ios-install-instructions {
    font-size: 0.6rem; opacity: 0.75; letter-spacing: 0.1em; max-width: 280px;
    line-height: 1.6; text-align: center; cursor: default; font-weight: 400;
}
#ios-install-instructions .share-icon { width: 1.25em; height: 1.25em; vertical-align: -0.25em; margin: 0 0.15em; }

#overlay-msg { font-size: 0.6rem; letter-spacing: 0.15em; line-height: 1.6; max-width: 300px; opacity: 0.85; color: #8a3a2a; }

@media (max-width: 480px) {
    .ov-title { letter-spacing: 0.7em; margin-right: -0.7em; font-size: 0.72rem; }
}

@media (pointer: coarse) {
    .ui-btn { padding: 13px 28px; font-size: 0.55rem; }
    #btn-install-pwa { padding: 12px 18px; }
    #mixer-tab { width: calc(40px + var(--sal)); }
    #mixer-tab span { font-size: 0.45rem; }
}

/* Landscape su telefoni: poca altezza */
@media (orientation: landscape) and (max-height: 480px) {
    .ov-title { margin-bottom: 14px; }
    #ui-container { gap: 6px; padding-top: calc(10px + var(--sat)); padding-bottom: calc(10px + var(--sab)); }
    .v-slider { margin: 8px 0; }
    .ui-btn { padding: 8px 22px; }
}


/* Info: discreta, in alto a destra (fuori dal mixer) */
#info-btn {
    position: fixed; z-index: 1003; top: calc(16px + var(--sat)); left: calc(16px + var(--sal));
    background: rgba(232, 237, 228, 0.35); border: 1px solid rgba(45, 59, 45, 0.3);
    color: var(--ui-accent); padding: 8px 12px; font-family: inherit;
    font-size: 0.5rem; letter-spacing: 0.25em; text-transform: uppercase; font-weight: 400;
    cursor: pointer; transition: opacity 0.3s ease; touch-action: manipulation; opacity: 0.6;
    visibility: hidden;
}
body.mixer-open #info-btn { opacity: 0; pointer-events: none; }
#info-btn.ready { visibility: visible; }
#info-btn:hover { opacity: 1; }
#info-panel {
    position: fixed; inset: 0; z-index: 2000; display: flex; justify-content: flex-start; align-items: flex-start;
    background: var(--panel-bg); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    opacity: 0; visibility: hidden; transition: opacity 0.5s ease, visibility 0s linear 0.5s; box-sizing: border-box;
    padding: calc(28px + var(--sat)) calc(28px + var(--sar)) calc(28px + var(--sab)) calc(28px + var(--sal));
    overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain;
}
#info-panel.open { opacity: 1; visibility: visible; transition: opacity 0.5s ease, visibility 0s; background: rgba(232, 237, 228, 0.97); }
.info-box { max-width: 560px; width: 100%; color: var(--ui-accent); font-weight: 400; }
.info-title { font-size: clamp(1.2rem, 4.4vw, 1.9rem); line-height: 1.15; letter-spacing: -0.01em; text-transform: uppercase; margin-bottom: 30px; }
.info-box h2 { font-size: 0.55rem; letter-spacing: 0.3em; text-transform: uppercase; font-weight: 400; margin: 30px 0 10px; opacity: 0.7; }
.info-box p, .info-box li { font-size: 0.8rem; line-height: 1.6; letter-spacing: 0; margin: 0 0 12px; opacity: 0.9; }
.info-box ul { list-style: none; margin: 0; padding: 0; }
.info-box li { padding-left: 0; margin-bottom: 14px; }
.info-box b { font-weight: 500; }
.info-box .info-credits { font-size: 0.7rem; opacity: 0.55; margin-top: 28px; }
.info-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; padding-top: 24px; }
#info-close, .info-links a {
    background: none; border: 0; padding: 8px 0; font-family: inherit; font-size: 0.5rem; letter-spacing: 0.3em;
    text-transform: uppercase; font-weight: 400; color: var(--ui-accent); opacity: 0.5; cursor: pointer; text-decoration: none;
    border-bottom: 1px solid transparent; transition: opacity 0.3s;
}
.info-links a { cursor: pointer; }
#info-close:hover, .info-links a:hover { opacity: 1; }


/* Oscillatori: slider verticali affiancati (la colonna del mixer non scorre) */
#drone-controls-container { flex-direction: row; justify-content: space-between; align-items: flex-end; gap: 0; padding: 0 18px; box-sizing: border-box; }
.slider-group.osc-group { flex: 1 1 0; min-width: 0; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; padding: 0; }
.osc-track { position: relative; width: 28px; height: clamp(70px, 20vh, 130px); }
.osc-track .v-slider { position: absolute; left: 50%; top: 50%; width: clamp(70px, 20vh, 130px); margin: 0; transform: translate(-50%, -50%) rotate(-90deg); }
.slider-group.osc-group label { flex: none; letter-spacing: 0.05em; font-size: 0.42rem; }
.osc-hz { display: none; }
#osc-caption { font-size: 0.42rem; letter-spacing: 0.25em; text-transform: uppercase; opacity: 0.6; margin-bottom: -4px; }
