/* ================= Modo cámara (body.on) ================= */
#cam {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    background: #000;
    display: none;
    transform-origin: center center;
}

#mira {
    display: none;
    position: fixed;
    left: 50%;
    top: 50%;
    width: 70px;
    height: 70px;
    margin: -35px 0 0 -35px;
    border: 2px solid #00f5d4;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 0 18px #00f5d4;
    z-index: 1;
    pointer-events: none;
    transition: top .2s;
}

#mira::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    margin: -5px 0 0 -5px;
    background: #ff2d95;
    border-radius: 50%;
    box-shadow: 0 0 10px #ff2d95;
}

#sil {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    display: none;
}

/* Etiquetas sobre la imagen */
#etq {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}

#etq > i,
#etq > div {
    left: 0;
    top: 0;
    will-change: transform;
}

.et {
    position: absolute;
    transform: translate(-50%, -100%);
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .82);
    border: 1px solid rgba(255, 255, 255, .35);
    border-width: 2px;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
}

.et small {
    font-weight: 500;
    opacity: .95;
}

.et.sel {
    font-size: 18px;
    color: #111;
}

.et.sel small {
    opacity: .9;
}

body.on #cam,
body.on #mira {
    display: block;
}

.pt {
    position: absolute;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .7), 0 0 6px rgba(0, 0, 0, .8);
}

.pt.sel {
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border-width: 3px;
    animation: lat 1.2s infinite;
}

@keyframes lat {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 255, 255, .85);
    }
    100% {
        box-shadow: 0 0 0 16px rgba(255, 255, 255, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .pt.sel {
        animation: none;
    }
}

.ln {
    position: absolute;
    width: 2px;
    margin-left: -1px;
    opacity: .85;
}

.pk {
    position: absolute;
    width: 0;
    height: 0;
    margin-left: -8px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 15px solid #80ed99;
    filter: drop-shadow(0 0 2px #000);
}

/* Leyenda lateral: solo los tipos que hay en pantalla */
#leyenda {
    display: none;
}

body.on #leyenda {
    display: block;
    position: fixed;
    z-index: 1;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    padding: 6px 10px;
    border-radius: 10px;
    background: rgba(0, 0, 0, .75);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.6;
    pointer-events: none;
}

#leyenda i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: -1px;
    border: 1px solid #fff;
}

#leyenda div {
    display: none;
}

#leyenda div.v {
    display: block;
}

body.on #leyenda.vacia {
    display: none;
}

/* Panel compacto: deja más cámara a la vista para los pueblos */
body.on main {
    max-width: none;
    background: linear-gradient(135deg, rgba(106, 17, 203, .8), rgba(37, 117, 252, .72));
    border-radius: 0 0 16px 16px;
    padding: calc(env(safe-area-inset-top, 0px) + 6px) 12px 8px;
}

body.on #rumbo {
    font-size: 14px;
    margin: 4px 0 2px;
    padding: 3px 10px;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: top;
}

body.on .ch {
    min-height: 34px;
    padding: 2px 4px;
    border-radius: 12px;
    font-size: 13px;
}

body.on #mejor {
    min-height: 36px;
    margin: 2px 0;
    line-height: 1.15;
}

body.on .it {
    padding: 5px 10px;
    margin: 3px 0;
    font-size: 14px;
}

body.on #msg {
    margin-top: 4px;
    font-size: 13px;
    line-height: 1.25;
}

body.on #msg.aviso {
    font-size: 14px;
    padding: 6px 10px;
}

body.on #brj {
    margin-top: 3px;
    font-size: 12px;
    line-height: 1.25;
}

body.on #info {
    display: none;
}

/* Pestaña para plegar el panel: solo quedan el rumbo y el nombre */
#plegar {
    display: none;
}

body.on #plegar {
    display: block;
    position: absolute;
    left: 50%;
    bottom: -26px;
    transform: translateX(-50%);
    width: 68px;
    min-height: 0;
    height: 26px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .4);
    border-top: 0;
    border-radius: 0 0 14px 14px;
    background: rgba(37, 40, 120, .88);
    box-shadow: none;
    font-size: 13px;
    line-height: 1;
    z-index: 3;
}

body.on main.plegado #estado,
body.on main.plegado #lista,
body.on main.plegado #msg,
body.on main.plegado #brj,
body.on main.plegado #rumbo {
    display: none;
}

body:not(.on) #rumbo,
body:not(.on) #mejor,
body:not(.on) #lista {
    display: none;
}

body.on #hero,
body.on #extras {
    display: none;
}

/* Con la cámara activa el pellizco controla el zoom de la cámara */
body.on,
body.on * {
    touch-action: pan-x pan-y;
}

#bar,
#zoom {
    display: none;
}

/* Barra inferior: 5 botones (Calibrar, Aldeas, Picos, Más lejos, Relieve) */
body.on #bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    position: fixed;
    z-index: 5;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 7px 6px calc(env(safe-area-inset-bottom, 0px) + 7px);
    background: rgba(8, 10, 28, .94);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, .2);
}

#bar button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    width: auto;
    min-width: 0;
    min-height: 66px;
    padding: 5px 2px;
    border: 2px solid rgba(255, 255, 255, .55);
    border-radius: 14px;
    background: rgba(255, 255, 255, .14);
    box-shadow: none;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
}

#bar .ic {
    font-size: 22px;
    line-height: 1;
}

#bar #calbtn {
    background: #1d4ed8;
    border-color: #bfdbfe;
}

#calbtn.pista {
    animation: pista 1s ease-in-out 6;
}

@keyframes pista {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 226, 89, .9);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(255, 226, 89, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    #calbtn.pista {
        animation: none;
        outline: 3px solid #ffe259;
    }
}

/* Terminar: primera fila del panel, a la derecha del rumbo */
#fila1 {
    display: none;
}

body.on #fila1 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

body.on #salir {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: none;
    margin-left: auto;
    width: auto;
    min-width: 44px;
    min-height: 36px;
    padding: 4px 12px;
    border: 2px solid #fecaca;
    border-radius: 999px;
    background: #b91c1c;
    box-shadow: none;
    font-size: 14px;
    font-weight: 700;
}

/* Añadir un lugar desde la cámara */
#anadircam {
    display: none;
}

body.on #anadircam {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex: none;
    width: auto;
    min-width: 44px;
    min-height: 36px;
    padding: 4px 10px;
    border: 2px solid #86efac;
    border-radius: 999px;
    background: linear-gradient(90deg, #15803d, #0f766e);
    box-shadow: none;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
}

/* Interruptores: color + estado siempre visible */
#bar .tg[aria-pressed="true"] {
    background: #15803d;
    border-color: #86efac;
}

#bar .tg[aria-pressed="false"] {
    background: rgba(255, 255, 255, .1);
    border-color: rgba(255, 255, 255, .55);
}

.est {
    display: inline-block;
    min-width: 36px;
    padding: 1px 6px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 800;
    line-height: 1.3;
}

.tg[aria-pressed="true"] .est {
    background: #fff;
    color: #14532d;
}

.tg[aria-pressed="false"] .est {
    background: rgba(255, 255, 255, .22);
    color: #fff;
}

.tg[aria-pressed="true"] .est::after {
    content: "Sí";
}

.tg[aria-pressed="false"] .est::after {
    content: "No";
}

/* Aldeas: dice qué se ve en vez de Sí/No */
#aldeas .est {
    min-width: 0;
    padding: 1px 5px;
    font-size: 10px;
    line-height: 1.1;
    white-space: normal;
    text-align: center;
    border-radius: 9px;
}

#aldeas[aria-pressed="true"] .est::after {
    content: "Con aldeas";
}

#aldeas[aria-pressed="false"] .est::after {
    content: "Solo pueblos";
}

/* Más lejos: muestra el alcance real */
#lejosb[aria-pressed="false"] .est::after {
    content: "40 km";
}

#lejosb[aria-pressed="true"] .est::after {
    content: "80 km";
}

/* Relieve: Sí / No */
#relb[aria-pressed="true"] .est::after {
    content: "Sí";
}

#relb[aria-pressed="false"] .est::after {
    content: "No";
}

/* Zoom con nivel visible + botón de enfoque */
body.on #zoom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: fixed;
    z-index: 5;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    padding: 8px 6px;
    border-radius: 18px;
    background: rgba(0, 0, 0, .55);
}

#zoom button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 52px;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, .6);
    border-radius: 14px;
    font-size: 26px;
    line-height: 1;
    background: rgba(255, 255, 255, .2);
    box-shadow: none;
}

#zoom #enf {
    height: 58px;
    font-size: 12px;
    font-weight: 700;
    gap: 2px;
    margin-top: 4px;
}

#zoom #enf .ic {
    font-size: 22px;
    line-height: 1;
}

#toast {
    display: none;
    position: fixed;
    z-index: 6;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 176px);
    transform: translateX(-50%);
    width: max-content;
    max-width: 86vw;
    padding: 12px 20px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .9);
    border: 1px solid rgba(255, 255, 255, .6);
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
}

#toast.v {
    display: block;
    animation: tst 6s ease forwards;
}

@keyframes tst {
    0% { opacity: 0; }
    8% { opacity: 1; }
    85% { opacity: 1; }
    100% { opacity: 0; }
}

#foco {
    position: fixed;
    width: 74px;
    height: 74px;
    margin: -37px 0 0 -37px;
    border: 2px solid #ffe259;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
    z-index: 1;
    pointer-events: none;
    display: none;
}

#foco.v {
    display: block;
    animation: foc 1.2s ease-out forwards;
}

@keyframes foc {
    0% { transform: scale(1.6); opacity: .2; }
    25% { transform: scale(1); opacity: 1; }
    100% { transform: scale(1); opacity: 0; }
}

#giro {
    display: none;
}

@media (orientation: landscape) and (pointer: coarse) {
    body.on #giro {
        display: flex;
        position: fixed;
        inset: 0;
        z-index: 40;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 24px;
        box-sizing: border-box;
        background: rgba(5, 7, 20, .94);
        color: #fff;
        font-size: 20px;
        font-weight: 700;
        text-align: center;
    }
    body.on #giro small {
        font-size: 14px;
        font-weight: 500;
        opacity: .9;
    }
}

#toque {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 3;
    pointer-events: none;
    display: none;
    max-width: 80vw;
    box-sizing: border-box;
    padding: 8px 14px;
    border-radius: 14px;
    background: rgba(0, 0, 0, .88);
    border: 2px solid #ffe259;
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
}

#toque small {
    display: block;
    font-weight: 500;
    font-size: 13px;
    opacity: .9;
}

#fdw {
    display: none;
}

body.on #fdw.v {
    display: flex;
    align-items: center;
    gap: 10px;
    position: fixed;
    z-index: 5;
    left: 12%;
    right: 12%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 100px);
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(0, 0, 0, .7);
    font-size: 15px;
    font-weight: 600;
}

#fdw input {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 32px;
}

#fdw button {
    width: auto;
    min-height: 48px;
    padding: 8px 16px;
    font-size: 15px;
    box-shadow: none;
    background: rgba(255, 255, 255, .3);
}

#zval {
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 1px 3px #000;
    white-space: nowrap;
    padding: 2px 0;
}
