:root {
    --bg: #000;
    --glass: rgba(10, 14, 24, 0.55);
    --glass-strong: rgba(8, 11, 20, 0.78);
    --line: rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.18);
    --text: #eef1f7;
    --muted: #8f98ad;
    --accent: #ffc56b;
    --accent-2: #7cc4ff;
    --radius: 16px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --display: 'Space Grotesk', var(--font);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    touch-action: none;
    user-select: none;
}

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }

/* ---------- Etiquetas 3D ---------- */
.labels-layer { pointer-events: none; }

.label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px 3px 4px;
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: rgba(255, 255, 255, 0.82);
    border-radius: 999px;
    cursor: pointer;
    pointer-events: auto;
    white-space: nowrap;
    transition: opacity 0.4s, color 0.2s, background 0.2s;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
.label::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--dot, #fff);
    box-shadow: 0 0 8px var(--dot, #fff);
}
.label:hover, .label.active { color: #fff; background: rgba(255, 255, 255, 0.1); }
.label--moon { font-size: 10.5px; opacity: 0.85; }
.label--small { font-size: 10.5px; }
.label.is-hidden { opacity: 0; pointer-events: none; }

/* ---------- Inicio ---------- */
/* Deja ver la escena real detrás, con una viñeta que centra la mirada. */
.loader {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    background: radial-gradient(ellipse at 50% 50%, rgba(0, 0, 0, 0.15) 0%, rgba(0, 0, 0, 0.55) 60%, rgba(0, 0, 0, 0.9) 100%);
    transition: opacity 1.2s ease;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader__content {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 16vh 24px 14vh;
    text-align: center;
}
.loader__title {
    font-family: var(--display);
    font-weight: 300;
    font-size: clamp(30px, 6vw, 56px);
    letter-spacing: 0.32em;
    margin-right: -0.32em; /* compensa el espaciado de la última letra */
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.92);
    animation: appear 1.6s ease both;
}
.loader__error { max-width: 420px; color: #ff9a8a; font-size: 13px; line-height: 1.6; }

.start {
    position: relative;
    display: grid;
    place-items: center;
    width: 92px;
    height: 92px;
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.03);
    transition: color 0.6s, background 0.3s, transform 0.3s;
    animation: appear 1.6s 0.3s ease both;
}
.start__ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.start__track { fill: none; stroke: rgba(255, 255, 255, 0.1); stroke-width: 1.5; }
.start__progress {
    fill: none;
    stroke: #ffd08a;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 0.4s ease;
    filter: drop-shadow(0 0 4px rgba(255, 190, 110, 0.8));
}
.start__icon { width: 26px; height: 26px; margin-left: 4px; fill: currentColor; stroke: none; }
.loader.ready .start { color: #ffe2b0; cursor: pointer; animation: appear 1.6s 0.3s ease both, glow 2.8s 1s ease-in-out infinite; }
.loader.ready .start:hover { background: rgba(255, 200, 120, 0.1); transform: scale(1.06); }
.start:disabled { cursor: default; }

@keyframes appear { from { opacity: 0; transform: translateY(10px); } }
@keyframes glow {
    0%, 100% { box-shadow: 0 0 0 rgba(255, 190, 100, 0); }
    50% { box-shadow: 0 0 36px rgba(255, 190, 100, 0.35); }
}

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; transition: opacity 1.2s ease; }
.hud.hidden { opacity: 0; }
.hud > * { pointer-events: auto; }
.hud .scale-note { pointer-events: none; }

.glass, .toolbar, .timebar, .dock, .info {
    background: var(--glass);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    border: 1px solid var(--line);
}

/* Calidad baja: el desenfoque del fondo se recalcula en cada fotograma y es caro. */
.no-blur .toolbar, .no-blur .timebar, .no-blur .dock, .no-blur .info {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(8, 11, 20, 0.9);
}

.notice {
    position: absolute;
    top: 84px;
    left: 50%;
    transform: translateX(-50%);
    width: min(560px, calc(100% - 32px));
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 16px;
    border-radius: 12px;
    background: rgba(48, 28, 8, 0.92);
    border: 1px solid rgba(255, 180, 90, 0.4);
    font-size: 13px;
    line-height: 1.55;
    color: #ffe2b8;
    z-index: 2;
}
.notice button { font-size: 20px; line-height: 1; color: #ffcf8f; padding: 0 4px; }

.topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 24px;
    pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand h1 { font-family: var(--display); font-weight: 300; font-size: 22px; letter-spacing: 0.08em; text-transform: uppercase; }
.brand__date {
    margin-top: 4px;
    padding: 2px 0;
    font-size: 13px;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.03em;
    text-align: left;
    border-bottom: 1px dashed rgba(255, 197, 107, 0.4);
}
.brand__date:hover { color: #ffe0a8; border-bottom-color: #ffe0a8; }
.brand__date.is-approx::after { content: ' · aproximado'; color: var(--muted); }

.datepanel {
    position: absolute;
    top: 84px;
    left: 24px;
    width: 320px;
    max-height: calc(100% - 260px);
    overflow-y: auto;
    padding: 20px;
    border-radius: var(--radius);
    background: var(--glass-strong);
    border: 1px solid var(--line-strong);
    z-index: 3;
}
.datepanel h2 { font-family: var(--display); font-weight: 500; font-size: 18px; margin-bottom: 12px; }
.datepanel h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--accent); margin: 18px 0 8px; }
.datepanel__form { display: flex; gap: 8px; }
.datepanel__form input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    color-scheme: dark;
}
.datepanel__form button {
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(255, 197, 107, 0.16);
    color: var(--accent);
    font-weight: 500;
}
.datepanel__form button:hover { background: rgba(255, 197, 107, 0.28); }
.datepanel__hint { margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.datepanel__events { display: grid; gap: 4px; }
.event {
    display: grid;
    gap: 2px;
    padding: 9px 11px;
    border-radius: 10px;
    text-align: left;
    transition: background 0.2s;
}
.event:hover { background: rgba(255, 255, 255, 0.07); }
.event b { font-size: 13px; font-weight: 500; }
.event span { font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.event time { font-size: 11px; color: var(--accent-2); font-variant-numeric: tabular-nums; }

/* ---------- Barra de herramientas ---------- */
.toolbar { position: relative; display: flex; align-items: center; gap: 2px; padding: 4px; border-radius: 999px; }
.toolbar__more { display: contents; }
.tool {
    display: flex; align-items: center; gap: 7px;
    padding: 8px 13px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
}
.tool:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }
.tool.active { color: var(--text); }
.tool.active svg { color: var(--accent); }
/* Trayectorias: el interruptor principal, con su estado bien visible. */
.tool[data-toggle="orbits"] { border: 1px solid transparent; }
.tool[data-toggle="orbits"].active { background: rgba(255, 197, 107, 0.1); border-color: rgba(255, 197, 107, 0.28); }
.tool--menu { display: none; }

/* ---------- Panel de información ---------- */
.info {
    position: absolute;
    top: 86px;
    right: 24px;
    width: 340px;
    max-height: calc(100% - 270px);
    display: flex;
    flex-direction: column;
    border-radius: var(--radius);
    background: var(--glass-strong);
    transform: translateX(calc(100% + 40px));
    opacity: 0;
    overflow: hidden;
    transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.5s;
}
.info.open { transform: none; opacity: 1; }
.info__header { display: flex; align-items: flex-start; gap: 4px; padding: 18px 12px 0 22px; }
.info__summary {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: 1fr auto;
    text-align: left;
    column-gap: 8px;
    padding-bottom: 12px;
}
.info__grip { display: none; }
.info__type { grid-column: 1; font-size: 11px; text-transform: uppercase; letter-spacing: 0.2em; color: var(--accent); }
.info__name { grid-column: 1; font-family: var(--display); font-weight: 500; font-size: 32px; line-height: 1.15; margin-top: 4px; }
.info__peek { grid-column: 1; display: none; margin-top: 4px; font-size: 12.5px; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.info__chevron { grid-column: 2; grid-row: 1 / span 3; align-self: center; width: 20px; height: 20px; color: var(--muted); transition: transform 0.3s; }
.info__summary:hover .info__chevron { color: var(--text); }
.info.collapsed .info__chevron { transform: rotate(-90deg); }
.info.collapsed .info__peek { display: block; }
.info.collapsed .info__body { display: none; }
.info__close {
    flex-shrink: 0;
    width: 30px; height: 30px;
    border-radius: 50%;
    font-size: 20px; line-height: 1;
    color: var(--muted);
}
.info__close:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.info__body {
    min-height: 0;
    overflow-y: auto;
    padding: 0 22px 20px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.info__description { font-size: 13.5px; line-height: 1.65; color: #c9cfdc; }

.info__live, .info__stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 18px; border-radius: 12px; overflow: hidden; background: var(--line); }
.info__live { grid-template-columns: 1fr; }
.info__live div, .info__stats div { background: rgba(8, 11, 20, 0.92); padding: 10px 12px; }
.info__live div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
dd { font-size: 14px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.info__live dd { color: var(--accent-2); margin: 0; text-align: right; }

.info__fact { margin-top: 18px; padding: 14px 16px; border-left: 2px solid var(--accent); background: rgba(255, 197, 107, 0.06); border-radius: 0 10px 10px 0; }
.info__fact h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--accent); margin-bottom: 6px; font-weight: 600; }
.info__fact p { font-size: 13px; line-height: 1.6; color: #d6dae4; }

.info__moons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.info__moons:empty { display: none; }
.chip {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    color: #cfd6e4;
    transition: background 0.2s, border-color 0.2s;
}
.chip:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.3); }

/* ---------- Barra inferior ---------- */
.bottom {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 0 16px 18px;
    pointer-events: none;
}
.bottom > * { pointer-events: auto; }

.timebar { display: flex; align-items: center; gap: 4px; padding: 5px 6px; border-radius: 999px; }
.timebar__btn {
    display: grid; place-items: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    color: #cfd6e4;
    transition: background 0.2s;
}
.timebar__btn:hover { background: rgba(255,255,255,0.08); }
.timebar__btn--main { background: rgba(255, 197, 107, 0.14); color: var(--accent); }
.timebar__btn--main:hover { background: rgba(255, 197, 107, 0.24); }
.timebar__readout { display: flex; flex-direction: column; padding: 0 12px; min-width: 128px; text-align: center; }
.timebar__speed { font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.timebar__hint { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }
.timebar__now {
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--accent-2);
    border: 1px solid rgba(124, 196, 255, 0.3);
    transition: background 0.2s;
}
.timebar__now:hover { background: rgba(124, 196, 255, 0.12); }

.dock {
    display: flex;
    gap: 2px;
    padding: 5px;
    border-radius: 999px;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}
.dock::-webkit-scrollbar { display: none; }
.dock__item {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 14px 8px 10px;
    border-radius: 999px;
    font-size: 12.5px;
    color: #c3cad8;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}
.dock__item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.dock__item.active { background: rgba(255,255,255,0.13); color: #fff; }
.dock__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dot); box-shadow: 0 0 10px var(--dot); }

.scale-note {
    position: absolute;
    left: 24px;
    bottom: 22px;
    max-width: 240px;
    font-size: 10.5px;
    line-height: 1.5;
    color: rgba(255,255,255,0.35);
}

/* ---------- Modal ---------- */
.modal {
    position: fixed; inset: 0; z-index: 30;
    display: grid; place-items: center;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    padding: 16px;
}
.modal__card {
    position: relative;
    width: min(620px, 100%);
    max-height: 100%;
    overflow-y: auto;
    padding: 30px;
    border-radius: 20px;
    background: rgba(10, 13, 22, 0.94);
    border: 1px solid var(--line-strong);
}
.modal__card h2 { font-family: var(--display); font-weight: 500; font-size: 24px; margin-bottom: 18px; }
.modal__card h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--accent); margin-bottom: 10px; }
.modal__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.modal__card ul { list-style: none; display: grid; gap: 8px; font-size: 13px; color: #cfd6e4; }
.modal__close { position: absolute; top: 14px; right: 16px; font-size: 24px; color: var(--muted); width: 32px; height: 32px; border-radius: 50%; }
.modal__close:hover { background: rgba(255,255,255,0.08); }
.modal__credits { margin-top: 22px; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.modal__credits a { color: var(--accent-2); }
kbd {
    display: inline-block;
    min-width: 20px;
    padding: 1px 6px;
    font: 11px/18px var(--font);
    text-align: center;
    border-radius: 5px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.14);
}

/* ---------- Modo sin interfaz ---------- */
.immersive .hud { opacity: 0 !important; pointer-events: none; }
.immersive .hud > * { pointer-events: none; }
.immersive .labels-layer { opacity: 0; }
.immersive .label { pointer-events: none; }
.labels-layer { transition: opacity 0.5s; }
.show-ui {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 12;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--text);
    background: rgba(8, 11, 20, 0.55);
    border: 1px solid var(--line);
    opacity: 0.6;
    transition: opacity 0.25s;
    animation: rise 0.5s ease both;
}
.show-ui:hover, .show-ui:focus-visible { opacity: 1; }

/* ---------- Guía inicial y avisos breves ---------- */
.hint {
    position: fixed;
    left: 50%;
    bottom: 150px;
    z-index: 11;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 13px;
    text-align: center;
    color: #e6ebf5;
    background: rgba(8, 11, 20, 0.72);
    border: 1px solid var(--line-strong);
    pointer-events: none;
    animation: hint 7s ease both;
}
@keyframes hint {
    0% { opacity: 0; transform: translate(-50%, 8px); }
    8%, 85% { opacity: 1; transform: translate(-50%, 0); }
    100% { opacity: 0; transform: translate(-50%, 0); }
}

.toast {
    position: fixed;
    left: 50%;
    top: 84px;
    z-index: 20;
    transform: translate(-50%, -8px);
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 12.5px;
    color: var(--text);
    background: rgba(8, 11, 20, 0.85);
    border: 1px solid var(--line-strong);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Accesibilidad ---------- */
button:focus-visible, input:focus-visible, .label:focus-visible {
    outline: 2px solid var(--accent-2);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
    .hint { animation: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .tool span { display: none; }
    .tool { padding: 9px; }
    .scale-note { display: none; }
}

/* ---------- Móvil: el modelo manda, la interfaz se aparta ---------- */
@media (max-width: 760px) {
    .topbar { padding: 10px 10px 0 14px; align-items: center; }
    .brand h1 { display: none; }
    .brand__date { margin: 0; font-size: 12px; }

    .toolbar { gap: 0; padding: 3px; }
    .tool { padding: 9px; }
    .tool--menu { display: flex; }
    .toolbar__more {
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        display: none;
        flex-direction: column;
        align-items: stretch;
        min-width: 210px;
        padding: 6px;
        border-radius: 16px;
        background: rgba(8, 11, 20, 0.94);
        border: 1px solid var(--line-strong);
        animation: rise 0.2s ease both;
    }
    .toolbar.open .toolbar__more { display: flex; }
    .toolbar__more .tool { padding: 11px 12px; border-radius: 10px; font-size: 13.5px; }
    .toolbar__more .tool span { display: inline; }
    .tool--menu[aria-expanded="true"] { background: rgba(255, 255, 255, 0.1); color: var(--text); }

    /* Hoja inferior: plegada muestra solo el nombre; desplegada, la ficha completa. */
    .info {
        top: auto;
        right: 8px;
        left: 8px;
        bottom: 112px;
        width: auto;
        max-height: 55vh;
        border-radius: 18px;
        transform: translateY(calc(100% + 140px));
    }
    .info__header { padding: 6px 8px 0 18px; }
    .info__summary { padding-bottom: 10px; }
    .info__grip {
        display: block;
        grid-column: 1 / -1;
        justify-self: center;
        width: 36px;
        height: 4px;
        margin: 2px 0 8px;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.2);
        transform: translateX(14px);
    }
    .info__name { font-size: 22px; }
    /* En la hoja inferior, la flecha indica hacia dónde se abre. */
    .info.collapsed .info__chevron { transform: rotate(180deg); }
    .info__body { padding: 0 18px 16px; }
    .info__description { font-size: 13px; }

    .datepanel { left: 8px; right: 8px; top: 58px; width: auto; max-height: calc(100% - 190px); }
    .notice { top: 58px; }
    .toast { top: 60px; }

    .bottom { padding: 0 8px 10px; gap: 6px; }
    .timebar { gap: 2px; padding: 3px 4px; }
    .timebar__btn { width: 32px; height: 32px; }
    .timebar__btn svg { width: 16px; height: 16px; }
    .timebar__readout { min-width: 84px; padding: 0 4px; }
    .timebar__speed { font-size: 12px; }
    .timebar__hint { display: none; }
    .timebar__now { padding: 6px 10px; font-size: 11.5px; }
    .dock { border-radius: 14px; padding: 3px; }
    .dock__item { padding: 6px 10px 6px 8px; font-size: 11.5px; gap: 6px; }
    .dock__dot { width: 8px; height: 8px; }

    .label { font-size: 10.5px; padding: 2px 7px 2px 3px; }
    .label--moon, .label--small { font-size: 10px; }
    .hint { bottom: 120px; font-size: 12px; border-radius: 14px; }
    .modal__grid { grid-template-columns: 1fr; }
    .modal__card { padding: 24px 20px; }
}
