:root {
    /* Marca XRS (mismos tokens que las propuestas): tinta, dorado, grises y Mulish. */
    --ink: #191d20;
    --gold: #ab8869;
    --bg: var(--ink);
    --fg: #f4f4f4;
    --muted: #bdbdbd;
    --secondary: #46494b;
    --line: rgba(244, 244, 244, 0.16);
    --panel: rgba(25, 29, 32, 0.62);
    --accent: var(--gold);
    --font: 'Mulish', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
}

body.viewer {
    overflow: hidden;
    overscroll-behavior: none;
    /* iOS ignora user-scalable=no: sin esto, un pellizco sobre la barra hace zoom de página. */
    touch-action: none;
}

#stage {
    position: fixed;
    inset: 0;
}

#stage canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

#stage canvas:active {
    cursor: grabbing;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.32em;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--gold);
}

/* Marca XRS: logotipo recortado a las letras (SVG), en blanco sobre la interfaz oscura. */
.logo {
    display: block;
    height: 15px;
    width: auto;
    align-self: flex-start; /* dentro de un flex en columna, si no se estira a todo el ancho */
}

.logo-lg {
    height: 36px;
    margin-bottom: 4px;
}

.logo-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-full {
    display: block;
    width: 164px;
    height: auto;
}

.logo-loading {
    width: 150px;
    margin-bottom: 6px;
}

.bar,
.views,
.views-toggle,
.hint,
.stick {
    opacity: 0;
    transition: opacity 0.4s ease;
}

body.ready .bar,
body.ready .views,
body.ready .views-toggle,
body.ready .hint,
body.ready .stick {
    opacity: 1;
}

.bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 28px
        calc(12px + env(safe-area-inset-left));
    background: linear-gradient(to bottom, rgba(25, 29, 32, 0.72), transparent);
    pointer-events: none;
}

.bar > * {
    pointer-events: auto;
}

.title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.title h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.actions {
    display: flex;
    gap: 8px;
}

.icon-btn,
.text-btn,
.views button,
.view-menu button {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--fg);
    font: inherit;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    transition:
        background 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        transform 0.12s ease;
}

.icon-btn[hidden],
.text-btn[hidden] {
    display: none;
}

.icon-btn[aria-pressed='true'] {
    background: var(--fg);
    border-color: var(--fg);
    color: var(--bg);
}

.icon-btn:active,
.text-btn:active,
.views button:active,
.view-menu button:active {
    transform: scale(0.96);
}

.icon-btn svg,
.views-toggle svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.text-btn {
    padding: 0 16px;
    letter-spacing: 0.08em;
}

.text-btn[aria-pressed='true'],
.text-btn.solid,
.text-btn[aria-expanded='true'],
.views button.on,
.view-menu button.on {
    background: var(--fg);
    border-color: var(--fg);
    color: var(--bg);
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.views {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    gap: 8px;
    padding: 28px calc(12px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom))
        calc(12px + env(safe-area-inset-left));
    overflow-x: auto;
    touch-action: pan-x;
    scrollbar-width: none;
    background: linear-gradient(to top, rgba(25, 29, 32, 0.72), transparent);
}

.views::-webkit-scrollbar {
    display: none;
}

.views button,
.view-menu button {
    flex: none;
    padding: 0 18px;
    white-space: nowrap;
}

/* Visor: las vistas se abren desde un botón, en un menú que crece hacia arriba. */
.views-toggle {
    position: fixed;
    left: calc(12px + env(safe-area-inset-left));
    bottom: calc(14px + env(safe-area-inset-bottom));
    gap: 8px;
}

.views-toggle svg {
    width: 18px;
    height: 18px;
}

.view-menu {
    position: fixed;
    left: calc(12px + env(safe-area-inset-left));
    bottom: calc(68px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    max-height: calc(100vh - 170px);
    overflow-y: auto;
    scrollbar-width: none;
    touch-action: pan-y;
}

.view-menu::-webkit-scrollbar {
    display: none;
}

.view-menu[hidden] {
    display: none;
}

@media (min-width: 900px) {
    .views {
        justify-content: center;
    }
}

.hint {
    position: fixed;
    left: 50%;
    bottom: calc(22px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    margin: 0;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--panel);
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
}

body.ready .hint.gone {
    opacity: 0;
}

body.has-stick .hint {
    bottom: calc(132px + env(safe-area-inset-bottom));
}

.stick {
    position: fixed;
    left: 50%;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: 72px;
    height: 72px;
    margin-left: -36px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    transition:
        opacity 0.4s ease,
        transform 0.16s ease;
}

/* Al apretarlo crece y sube un poco para no salirse por el borde inferior. */
.stick.active {
    transform: translateY(-18px) scale(var(--grow, 1.45));
}

.stick[hidden] {
    display: none;
}

.stick i {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border-radius: 50%;
    background: rgba(244, 244, 244, 0.82);
    transition: transform 0.12s ease;
    pointer-events: none;
}

.stick.active i {
    background: var(--fg);
    transition: none;
}

.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    background: var(--bg);
    text-align: center;
    transition:
        opacity 0.6s ease,
        visibility 0.6s;
}

.overlay[hidden] {
    display: none;
}

.overlay.gone {
    opacity: 0;
    visibility: hidden;
}

.overlay p {
    margin: 0;
    max-width: 32ch;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.progress {
    width: min(220px, 60vw);
    height: 2px;
    margin-top: 10px;
    background: var(--line);
    overflow: hidden;
}

.progress i {
    display: block;
    height: 100%;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
}

.pct {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

#error img {
    width: min(320px, 70vw);
    aspect-ratio: 16 / 10;
    object-fit: cover;
    border-radius: 12px;
    opacity: 0.5;
}

.row {
    display: flex;
    gap: 10px;
    margin-top: 6px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.01ms !important;
    }
}

body.home {
    background: #fff;
    color: var(--ink);
}

body.home main {
    max-width: 1040px;
    margin: 0 auto;
    padding: calc(48px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right))
        calc(48px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}

.home-head h1 {
    margin: 28px 0 10px;
    font-size: clamp(34px, 7vw, 60px);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.05;
}

.home-head p {
    margin: 0;
    max-width: 44ch;
    color: var(--secondary);
    font-size: 16px;
    line-height: 1.55;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 20px;
    margin-top: 40px;
}

.card {
    position: relative;
    display: block;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(25, 29, 32, 0.12);
    color: var(--ink);
    text-decoration: none;
    background: #f4f4f4;
}

.card img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.2, 0.7, 0.2, 1);
}

@media (hover: hover) {
    .card:hover img {
        transform: scale(1.04);
    }
}

.card-body {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 18px;
}

.card-body strong {
    font-size: 18px;
    font-weight: 700;
}

.card-body em {
    font-style: normal;
    font-size: 13px;
    color: var(--gold);
}

/* Página de realidad aumentada: el canvas lo maneja el motor AR y queda detrás de la UI. */
body.ar .bar,
body.ar .views,
body.ar .credit,
body.ar .overlay {
    z-index: 20;
}

body.ar .overlay {
    background: rgba(25, 29, 32, 0.92);
}

.credit {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(76px + env(safe-area-inset-bottom));
    margin: 0;
    text-align: center;
    font-size: 10px;
    color: rgba(244, 244, 244, 0.7);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.credit a {
    color: inherit;
    pointer-events: auto;
}

.size {
    position: fixed;
    right: calc(12px + env(safe-area-inset-right));
    top: calc(72px + env(safe-area-inset-top));
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.size[hidden],
.hud[hidden] {
    display: none;
}

.size .icon-btn {
    font-size: 22px;
    line-height: 1;
}

body.ar .hint {
    z-index: 20;
    bottom: calc(110px + env(safe-area-inset-bottom));
}

.hud {
    position: fixed;
    left: calc(12px + env(safe-area-inset-left));
    top: calc(72px + env(safe-area-inset-top));
    z-index: 20;
    margin: 0;
    padding: 6px 8px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace;
    pointer-events: none;
}

/* Teléfono o tablet en apaisado: se sostiene con las dos manos, así que el joystick va al
   costado izquierdo (pulgar izquierdo) y el derecho queda libre para arrastrar la mirada.
   El botón de vistas pasa a la derecha para no quedar debajo del pulgar. */
@media (orientation: landscape) {
    body.has-stick .stick {
        left: calc(36px + env(safe-area-inset-left));
        bottom: calc(28px + env(safe-area-inset-bottom));
        width: 84px;
        height: 84px;
        margin-left: 0;
    }

    body.has-stick .stick.active {
        transform: scale(var(--grow, 1.45));
    }

    body.has-stick .views-toggle {
        left: auto;
        right: calc(12px + env(safe-area-inset-right));
    }

    body.has-stick .view-menu {
        left: auto;
        right: calc(12px + env(safe-area-inset-right));
        align-items: flex-end;
        max-height: calc(100vh - 124px);
    }

    body.has-stick .hint {
        bottom: calc(18px + env(safe-area-inset-bottom));
    }
}

/* Panel de calibración del movimiento (?ajustes). */
.tuning {
    position: fixed;
    left: calc(12px + env(safe-area-inset-left));
    top: calc(72px + env(safe-area-inset-top));
    width: 216px;
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(25, 29, 32, 0.8);
    font-size: 12px;
}

.tuning label {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 8px;
}

.tuning output {
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

.tuning input {
    grid-column: 1 / -1;
    width: 100%;
    height: 28px;
    margin: 0;
    accent-color: var(--accent);
}

@media (orientation: landscape) and (max-height: 500px) {
    .tuning {
        top: calc(64px + env(safe-area-inset-top));
        left: auto;
        right: calc(130px + env(safe-area-inset-right));
        width: 380px;
        grid-template-columns: 1fr 1fr;
        padding: 8px 12px;
    }
}

/* Administrador de puntos de vista: el visor a la izquierda y un panel fijo a la derecha. */
body.admin #stage {
    right: 340px;
}

body.admin .overlay {
    z-index: 30;
}

.panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 340px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 20px 18px;
    overflow-y: auto;
    border-left: 1px solid var(--line);
    background: #15181b;
    font-size: 13px;
    touch-action: pan-y;
}

.panel h1 {
    margin: 6px 0 12px;
    font-size: 20px;
    font-weight: 500;
}

.panel h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
}

.panel p {
    margin: 0;
    color: var(--muted);
    line-height: 1.5;
}

.panel .text-btn,
.pt-actions button {
    min-height: 36px;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.panel .text-btn {
    padding: 0 14px;
    letter-spacing: 0;
}

.panel .text-btn[aria-current='page'] {
    background: var(--fg);
    border-color: var(--fg);
    color: var(--bg);
}

.panel button:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.panel-scenes,
.panel-auth,
.panel-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.panel-auth p {
    flex: 1 1 100%;
}

.panel-row {
    justify-content: space-between;
    color: var(--muted);
}

.panel-row h2 {
    color: var(--fg);
}

.panel-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.points {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pt {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(244, 244, 244, 0.03);
}

.pt.selected {
    border-color: var(--accent);
}

.pt-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.pt-order {
    flex: none;
    min-width: 22px;
    font-size: 11px;
    color: var(--accent);
}

.pt-go {
    flex: 1;
    min-height: 32px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--fg);
    font: inherit;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}

.pt-go:hover {
    color: var(--accent);
}

.pt-name-input {
    flex: 1;
    min-width: 0;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg);
    font: inherit;
    font-size: 15px;
}

.pt-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pt-actions button {
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: none;
    color: var(--fg);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
}

.pt-actions button:hover:not(:disabled) {
    border-color: var(--fg);
}

.pt-actions button.danger {
    border-color: #e5484d;
    background: #e5484d;
    color: #fff;
}

.wide {
    width: 100%;
}

.status {
    min-height: 1.5em;
}

.status[data-kind='ok'] {
    color: #7bd88f;
}

.status[data-kind='error'] {
    color: #ff8f8f;
}

.panel-foot {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    font-size: 12px;
}

/* En pantallas angostas el panel pasa abajo y el visor queda arriba. */
@media (max-width: 760px) {
    body.admin #stage {
        right: 0;
        bottom: 55vh;
    }

    .panel {
        top: 45vh;
        left: 0;
        width: auto;
        border-left: 0;
        border-top: 1px solid var(--line);
    }
}

/* Sin appKey de XGRIDS el SDK dibuja su logo sobre el borde inferior del canvas, en un lugar
   que depende del ratio de píxeles (ver watermark.js). Se tapa con una franja oscura a lo ancho,
   cuya altura fija el visor; con licencia la franja no se crea. */
.wm-cover {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    background: linear-gradient(to top, rgba(25, 29, 32, 0.97) 0 var(--wm-solid, 25px), rgba(25, 29, 32, 0) 100%);
}

body.ar .wm-cover {
    position: fixed;
    z-index: 15;
}
