/* Il telefono in aula: una sola schermata sopra tutto (anche sopra la barra dell'applicazione),
   dentro le aree sicure, senza scorrimento né rimbalzo. Due disposizioni della stessa struttura:
   orizzontale (slider | mappa | numeri e tasti) e verticale (mappa, numeri, slider e tasti). */

html:has(.phone), html:has(.phone) body {
    overflow: hidden;
    overscroll-behavior: none;
}

.phone {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    gap: 0.35rem;
    padding: max(0.3rem, env(safe-area-inset-top)) max(0.35rem, env(safe-area-inset-right))
             max(0.35rem, env(safe-area-inset-bottom)) max(0.35rem, env(safe-area-inset-left));
    background: var(--ground);
    overflow: hidden;
    overscroll-behavior: none;
    /* Niente zoom col doppio tocco né selezione del testo: si pilota, non si legge un documento. */
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.phone--landscape {
    grid-template-columns: auto minmax(0, 1fr) minmax(8.5rem, 11.5rem);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "bar bar bar"
        "slider map numbers"
        "slider map controls";
}

.phone--portrait {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 3fr) auto minmax(0, 2fr);
    grid-template-areas:
        "bar bar"
        "map map"
        "numbers numbers"
        "slider controls";
}

/* --- barra in alto: una riga sola ---------------------------------------- */

.phone__bar {
    grid-area: bar;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    white-space: nowrap;
}
.phone__who { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 0.85rem; }
.phone .chip { flex: 0 0 auto; font-size: 0.72rem; }
.phone__field {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}
.phone__icon {
    flex: 0 0 auto;
    width: 2.9rem;
    height: 2.8rem;
    border: 1px solid var(--edge);
    border-radius: 6px;
    background: var(--panel);
    color: var(--ink);
    font: inherit;
    font-size: 1.15rem;
    line-height: 1;
}

.phone__menu {
    position: absolute;
    z-index: 1200;
    top: calc(max(0.3rem, env(safe-area-inset-top)) + 3rem);
    right: max(0.35rem, env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: min(20rem, calc(100vw - 1rem));
    padding: 0.5rem;
    border: 1px solid var(--edge);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
.phone__menu > button, .phone__menu-row button, .phone__hint button, .phone__action, .phone__chip {
    min-height: 2.6rem;
    padding: 0.3rem 0.7rem;
    border: 1px solid var(--edge);
    border-radius: 6px;
    background: #0f141b;
    color: var(--ink);
    font: inherit;
    text-align: left;
}
.phone__menu-row { display: flex; align-items: center; gap: 0.35rem; color: var(--ink-dim); }
.phone__menu-row span { flex: 1 1 auto; }
.phone__menu-row button.is-on { background: #7fd4ff; color: #06121f; border-color: #7fd4ff; }
.phone__help { margin: 0; color: var(--ink-dim); font-size: 0.85rem; white-space: normal; }

.phone__hint {
    position: absolute;
    z-index: 1150;
    left: 50%;
    bottom: calc(max(0.35rem, env(safe-area-inset-bottom)) + 0.5rem);
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: calc(100vw - 1rem);
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: #0f2a47;
    font-size: 0.85rem;
}

/* --- mappa con quello che le sta sopra ------------------------------------ */

/* La mappa in un suo contesto: i livelli di Leaflet (400–1000) non coprono l'indice dello slider né il menu. */
.phone__map { grid-area: map; position: relative; z-index: 0; min-height: 0; min-width: 0; }
.phone__map > .map-frame { height: 100%; min-height: 0; }
.phone__over { position: absolute; z-index: 1100; display: flex; gap: 0.3rem; pointer-events: none; }
.phone__over > * { pointer-events: auto; }
.phone__over--top { top: 0.3rem; left: 3rem; right: 0.3rem; justify-content: center; }
.phone__over--bottom { left: 0.3rem; bottom: 4.8rem; max-width: 60%; } /* sopra la legenda della mappa */
.maneuvers--compact .maneuvers__button { min-height: 2.6rem; padding: 0.3rem 0.8rem; font-size: 1rem; }
.phone__over--corner { right: 0.3rem; bottom: 1.5rem; flex-direction: column; align-items: flex-end; }

.phone .atcbox--compact { flex: 0 1 auto; min-width: 0; }
.phone .atcbox--compact .atcbox__item { background-color: #2b2206; min-height: 2.6rem; padding: 0.2rem 0.3rem 0.2rem 0.6rem; }
.phone .atcbox--compact .atcbox__item.is-done { background-color: rgba(13, 17, 23, 0.85); }
.phone .atcbox--compact .atcbox__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.phone .atcbox--compact button { min-width: 3rem; min-height: 2.2rem; font-weight: 700; }

.phone__next {
    max-width: 16rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0.15rem 0.5rem;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 700;
}
.phone__chip { min-height: 2.4rem; background: rgba(13, 17, 23, 0.9); border-color: #7fd4ff; color: #9fdcff; font-weight: 700; }
.phone__chip.is-on { background: #7fd4ff; color: #06121f; }

.phone__sheet {
    position: absolute;
    z-index: 1150;
    left: 0.3rem;
    right: 7.5rem;          /* la colonna dei chip resta libera: "Frase" richiude */
    bottom: 0.3rem;
    max-height: 75%;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.phone__sheet .phrasebox { font-size: 0.85rem; padding: 0.4rem 0.6rem; }
/* Aperta a richiesta, la frase si vede tutta: scritta, pronunciata, risposta, collimazione. */
.phone__sheet .phrasebox__spoken, .phone__sheet .phrasebox__reply, .phone__sheet .phrasebox__note { display: block; }
.phone__sheet .phrasebox__step--reply, .phone__sheet .phrasebox__step--readback { display: grid; }
.phone__sheet .phrasebox__source { display: flex; }
.phone__sheet .phrasebox--compact .phrasebox__written { white-space: normal; }
.phone__sheet--circuit .circuit-tools { padding: 0.5rem; border: 1px solid var(--edge); border-radius: 8px; background: var(--panel); }
.phone__sheet--circuit button, .phone__sheet--circuit select { min-height: 2.4rem; }

/* --- tre numeri grandi ----------------------------------------------------- */

.phone__numbers {
    grid-area: numbers;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    gap: 0.2rem;
    min-height: 0;
}
.phone--portrait .phone__numbers { flex-direction: row; }
.phone__number {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.1rem 0.4rem;
    border: 1px solid var(--edge);
    border-radius: 6px;
    background: #070a0e;
    font-variant-numeric: tabular-nums;
}
.phone--portrait .phone__number { flex: 1 1 0; }
.phone__number strong { color: #7ff0a8; font-size: 1.9rem; line-height: 1.15; }
.phone__number small { color: var(--ink-dim); font-size: 0.8rem; }
.phone__trend { min-width: 0.9rem; color: #7ff0a8; font-size: 1.3rem; font-weight: 800; }

/* --- slider della quota ---------------------------------------------------- */

.phone__slider { grid-area: slider; position: relative; z-index: 1; display: flex; min-height: 0; }
.phone .altslider { flex: 1 1 auto; min-height: 0; padding: 0.25rem 0.3rem; }
.phone .altslider__track { min-height: 0; }
.phone .altslider input[type=range] { width: 3rem; touch-action: none; }
.phone__auto {
    position: absolute;
    left: 50%;
    bottom: 1.6rem;
    transform: translateX(-50%);
    padding: 0 0.3rem;
    border-radius: 3px;
    background: #d86bff;
    color: #1a0524;
    font-size: 0.65rem;
    font-weight: 800;
}

/* --- tasti di virata e riquadro a terra --------------------------------------- */

.phone__controls {
    grid-area: controls;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 0.35rem;
    min-height: 0;
    min-width: 0;
}
.phone__turns { display: flex; gap: 0.4rem; }
.phone__turn {
    flex: 1 1 0;
    min-width: 3.5rem;
    min-height: 4.5rem;
    border: 2px solid var(--warn);
    border-radius: 12px;
    background: #2b2206;
    color: #ffe9a6;
    font-size: 1.8rem;
    line-height: 1;
    /* Il dito resta sul tasto: niente scorrimento, zoom o menu del sistema. */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
.phone__turn.is-held { background: var(--warn); color: #1f1600; }
.phone--portrait .phone__turn { min-height: 5.5rem; }
.phone__reengage { border-color: #d86bff; background: #2a1433; color: #f3d1ff; text-align: center; }
.phone__ground { flex-direction: column; align-items: stretch; background: #0f141b; overflow-y: auto; }
.phone__ground .phone__action { text-align: center; font-weight: 700; border-color: var(--accent); background: #0f2a47; }

/* Verticale: barra stretta, il nome si accorcia prima di pista e vento; l'indice della quota
   assegnata, a destra dello slider, non va sopra il tasto di sinistra. */
.phone__who { flex-shrink: 3; }
.phone--portrait .phone__who, .phone--portrait .phone__field { font-size: 0.78rem; }
.phone--portrait .phone__icon { width: 2.75rem; }
.phone--portrait .phone__controls { padding-left: 3.2rem; }
