/* ============================================================
   ORBIT — Jérémy GUSTAVE
   Minimaliste spatial · NASA / Voyager
   ============================================================ */

/* ---------- 1. Reset + variables ---------- */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg:        #050507;
    --ink:       #f0eee6;
    --ink-soft:  rgba(240, 238, 230, 0.55);
    --ink-mute:  rgba(240, 238, 230, 0.30);
    --ink-fade:  rgba(240, 238, 230, 0.12);
    --orange:    #ff7a3d;
    --orange-d:  #c45a26;

    --font-sans: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
}

/* ---------- 2. Base ---------- */

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    position: relative;
    cursor: none;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

/* ---------- Cursor (custom) ---------- */

.cursor {
    position: fixed;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 10000;
    transform: translate3d(-100px, -100px, 0);
    will-change: transform;
}

.cursor--core {
    width: 6px;
    height: 6px;
    margin: -3px 0 0 -3px;
    border-radius: 999px;
    background: var(--ink);
    box-shadow:
        0 0 10px rgba(240,238,230,0.35),
        0 0 18px rgba(255,122,61,0.20);
}

.cursor--ring {
    width: 36px;
    height: 36px;
    margin: -18px 0 0 -18px;
    border-radius: 999px;
    border: 1px solid rgba(255,122,61,0.55);
    box-shadow:
        inset 0 0 16px rgba(255,122,61,0.14),
        0 0 22px rgba(255,122,61,0.12);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0.9;
}

/* Hide custom cursor on touch devices */
@media (hover: none) {
    body { cursor: auto; }
    .cursor { display: none; }
}

/* ---------- 3. BOOT LOADER ---------- */

.boot {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg);
    display: grid;
    place-items: center;
    transition: opacity 600ms ease;
}

.boot.is-done {
    opacity: 0;
    pointer-events: none;
}

.boot__panel {
    width: 240px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
}

.boot__counter {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 22px;
    letter-spacing: 0.06em;
    color: var(--ink);
    text-align: left;
    line-height: 1;
}

.boot__pct {
    opacity: 0.4;
    margin-left: 2px;
}

.boot__bar {
    width: 100%;
    height: 1px;
    background: var(--ink-fade);
    overflow: hidden;
}

.boot__bar-fill {
    display: block;
    height: 100%;
    background: var(--orange);
    transform-origin: left center;
    transform: scaleX(var(--p, 0));
    transition: transform 80ms linear;
}

.boot__log {
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 10.5px;
    line-height: 1.65;
    color: var(--ink-mute);
    text-align: left;
    width: 100%;
    min-height: 5em;
    white-space: pre;
    overflow: hidden;
    margin-top: 4px;
}

.boot__log-line {
    display: block;
    opacity: 0;
    animation: bootLineIn 220ms ease-out forwards;
}

.boot__log-line.is-ok {
    color: var(--ink-soft);
}

@keyframes bootLineIn {
    from { opacity: 0; transform: translateY(2px); }
    to   { opacity: 1; transform: translateY(0);   }
}

/* ---------- 4. Starfield canvas ---------- */

#bg-canvas {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    display: block;
    opacity: 0;
    transition: opacity 800ms ease 100ms;
}

.is-revealed #bg-canvas {
    opacity: 1;
}

/* ---------- 4b. Nebula layer (ultra subtle) ---------- */

.nebula {
    position: fixed;
    inset: -10%;
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    /* Delay heavy layer until after name reveal to avoid jank */
    transition: opacity 900ms ease 2400ms;
    filter: blur(60px) saturate(130%);
    opacity: 0;
}

.is-revealed .nebula {
    opacity: 0.50;
}

.nebula__blob {
    position: absolute;
    width: 62vmax;
    height: 62vmax;
    border-radius: 999px;
    will-change: transform;
    opacity: 0.55;
}

.nebula__blob--a {
    top: -20%;
    left: -15%;
    background: radial-gradient(circle at 30% 30%, rgba(93, 160, 255, 0.22) 0%, rgba(93, 160, 255, 0) 60%);
    animation: nebulaDriftA 32s ease-in-out infinite alternate;
    animation-delay: 2.4s;
}

.nebula__blob--b {
    bottom: -25%;
    right: -20%;
    background: radial-gradient(circle at 60% 60%, rgba(255, 122, 61, 0.18) 0%, rgba(255, 122, 61, 0) 62%);
    animation: nebulaDriftB 38s ease-in-out infinite alternate;
    animation-delay: 2.4s;
}

@keyframes nebulaDriftA {
    0%   { transform: translate(0, 0) scale(1) rotate(0deg); }
    100% { transform: translate(18vw, 8vh) scale(1.15) rotate(28deg); }
}

@keyframes nebulaDriftB {
    0%   { transform: translate(0, 0) scale(1) rotate(0deg); }
    100% { transform: translate(-16vw, -10vh) scale(1.18) rotate(-22deg); }
}

/* ---------- 5. Hero / orbit system ---------- */

.hero {
    position: fixed;
    inset: 0;
    z-index: 6;
    display: grid;
    place-items: center;
    pointer-events: none;
    perspective: 1200px;
}

.hero[aria-hidden="false"] {
    pointer-events: auto;
}

/* (no extra hint; minimalist) */

/* ---------- 6. Hero name ---------- */

.hero-name {
    position: relative;
    z-index: 2;
    text-align: center;
    line-height: 0.98;
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
    user-select: none;
    /* Avoid heavy repaints when scanline animates */
    contain: paint;
    isolation: isolate;
}

.hero-name::after {
    content: '';
    position: absolute;
    left: -36px;
    right: -36px;
    top: -14px;
    height: 52px; /* small moving band (cheap) */
    pointer-events: none;
    background:
        repeating-linear-gradient(
            180deg,
            rgba(240,238,230,0.00) 0px,
            rgba(240,238,230,0.00) 3px,
            rgba(240,238,230,0.10) 4px
        );
    opacity: 0;
    transform: translate3d(0, -22px, 0);
    will-change: transform, opacity;
}

.is-revealed .hero-name::after {
    /* scanline disabled by default (typewriter handles intro) */
    opacity: 0;
    animation: none;
}

@keyframes scanSweep {
    0%   { transform: translate3d(0, -22px, 0); opacity: 0; }
    18%  { opacity: 0.38; }
    100% { transform: translate3d(0, 84px, 0); opacity: 0; }
}

.hero-name__first,
.hero-name__last {
    display: block;
    opacity: 1;
    transform: none;
    will-change: contents;
}

.hero-name__first {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: clamp(2.6rem, 8.5vw, 7rem);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink);
}

.hero-name__last {
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: clamp(1rem, 2.4vw, 1.6rem);
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.hero-name__bar {
    display: block;
    width: 70%;
    height: 1px;
    background: var(--orange);
    transform-origin: center;
    transform: scaleX(0);
    margin-top: 10px;
    opacity: 0.9;
}

.is-revealed .hero-name__bar {
    animation: barIn 900ms cubic-bezier(.2,.7,.3,1) forwards;
    animation-delay: 1750ms;
}

@keyframes barIn {
    from { transform: scaleX(0); }
    to   { transform: scaleX(1); }
}

/* ---------- 7. Planet modal ---------- */

.planet-modal {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
        "header  header"
        "viewport specs"
        "footer  compass";
    padding: clamp(20px, 4vmin, 56px);
    pointer-events: auto;
    color: var(--ink);
    background: rgba(5, 5, 7, 0);
    transition: background 400ms ease;
    opacity: 0;
}

.planet-modal.is-open {
    opacity: 1;
    background: rgba(5, 5, 7, 0.92);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.planet-modal__backdrop {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.planet-modal__topo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    opacity: 0;
    transition: opacity 700ms ease;
    mix-blend-mode: screen;
}

.planet-modal.is-open .planet-modal__topo {
    opacity: 0.55;
    transition-delay: 200ms;
}

.planet-modal__close {
    position: absolute;
    top: clamp(16px, 3vmin, 36px);
    right: clamp(16px, 3vmin, 36px);
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.18em;
    color: var(--ink-soft);
    padding: 8px 12px;
    border: 1px solid var(--ink-fade);
    transition: color 200ms ease, border-color 200ms ease, background 200ms ease;
    opacity: 0;
}

.planet-modal.is-open .planet-modal__close {
    opacity: 1;
    transition: opacity 400ms ease 350ms, color 200ms ease, border-color 200ms ease, background 200ms ease;
}

.planet-modal__close:hover,
.planet-modal__close:focus-visible {
    color: var(--orange);
    border-color: var(--orange);
    background: rgba(255, 122, 61, 0.08);
    outline: none;
}

.planet-modal__close-kbd {
    color: var(--ink-mute);
    font-size: 10px;
}

.planet-modal__header {
    grid-area: header;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 500ms ease, transform 500ms ease;
}

.planet-modal.is-open .planet-modal__header {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 320ms;
}

.planet-modal__code {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: clamp(1.4rem, 3.2vw, 2.2rem);
    letter-spacing: 0.18em;
    color: var(--ink);
}

.planet-modal__sub {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.22em;
    color: var(--ink-mute);
    text-transform: uppercase;
}

.planet-modal__viewport {
    grid-area: viewport;
    z-index: 3;
    position: relative;
    display: grid;
    place-items: center;
    min-height: 0;
}

.planet-modal__planet {
    position: relative;
    width: clamp(180px, 38vmin, 380px);
    height: clamp(180px, 38vmin, 380px);
    border-radius: 50%;
    will-change: transform, width, height, top, left;
    transform-origin: center;
    transition:
        width 700ms cubic-bezier(.2,.7,.3,1),
        height 700ms cubic-bezier(.2,.7,.3,1);
}

/* On open we animate from the small clicked-planet rect to the centered viewport size.
   The JS sets explicit position:fixed + top/left/width/height for the FLIP animation. */
.planet-modal__planet.is-flying {
    position: fixed;
    transition:
        top 700ms cubic-bezier(.2,.7,.3,1),
        left 700ms cubic-bezier(.2,.7,.3,1),
        width 700ms cubic-bezier(.2,.7,.3,1),
        height 700ms cubic-bezier(.2,.7,.3,1),
        box-shadow 700ms ease,
        filter 700ms ease;
}

.planet-modal__specs {
    grid-area: specs;
    z-index: 3;
    align-self: center;
    justify-self: end;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 320px;
    width: 100%;
    opacity: 0;
    transform: translateX(8px);
    transition: opacity 500ms ease, transform 500ms ease;
}

.planet-modal.is-open .planet-modal__specs {
    opacity: 1;
    transform: translateX(0);
    transition-delay: 480ms;
}

.planet-modal__specs-title {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.22em;
    color: var(--ink-mute);
    text-transform: uppercase;
    border-bottom: 1px solid var(--ink-fade);
    padding-bottom: 8px;
}

.specs-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 24px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.specs-grid dt {
    color: var(--ink-mute);
    letter-spacing: 0.14em;
}

.specs-grid dd {
    color: var(--ink);
    text-align: right;
    letter-spacing: 0.06em;
}

.compass {
    grid-area: compass;
    z-index: 4;
    width: 96px;
    height: 96px;
    align-self: end;
    justify-self: end;
    color: var(--ink);
    opacity: 0;
    transform: scale(0.85);
    transition: opacity 500ms ease, transform 500ms ease;
    pointer-events: none;
}

.planet-modal.is-open .compass {
    opacity: 0.95;
    transform: scale(1);
    transition-delay: 600ms;
}

.compass__rotor {
    transform-origin: center;
    transition: transform 120ms cubic-bezier(.2,.7,.3,1);
}

/* ---------- 8. Reveal trigger ---------- */

.is-revealed #hero {
    opacity: 1;
}

#hero {
    opacity: 0;
    transition: opacity 600ms ease;
}

/* ---------- 9. Responsive ---------- */

@media (max-width: 720px) {
    .planet-modal {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "header"
            "viewport"
            "specs"
            "compass";
    }
    .planet-modal__specs {
        justify-self: stretch;
        max-width: none;
    }
    .compass {
        justify-self: end;
        width: 80px;
        height: 80px;
    }
}

@media (max-width: 420px) {
    .hero-name__first { font-size: 0.85rem; letter-spacing: 0.28em; }
    .hero-name__last  { font-size: 2.4rem;  letter-spacing: 0.12em; }

    .boot__panel { width: 200px; }
}

/* ---------- 10. Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
    .compass__rotor {
        animation: none !important;
        transition: none !important;
    }
    .is-revealed .hero-name__first,
    .is-revealed .hero-name__last,
    .is-revealed .hero-name__bar {
        animation: none !important;
        opacity: 1;
        transform: none;
    }
    .is-revealed .hero-name__bar {
        transform: scaleX(1);
    }
}
