/* ═══ Sol Atlas design tokens ═════════════════════════════════════════
   Semantic palette as RGB triplets so alpha stays per-use:
   rgba(var(--sa-accent), 0.15). Naming follows the mycelix ecosystem's
   semantic-token contract where concepts match. Chrome uses the calm
   aurora accent; saturated color is reserved for DATA on the globe;
   gold is reserved for vitals (Φ, year); red for emergencies only.  */
:root {
    /* chrome palette */
    --sa-accent: 109, 227, 168;   /* aurora green — chrome accent */
    --sa-cool: 0, 221, 255;       /* secondary cyan */
    --sa-vital: 255, 215, 0;      /* gold — Φ and the year, nothing else */
    --sa-alarm: 255, 60, 60;      /* red — emergencies ONLY */
    --sa-panel: 20, 20, 30;       /* glass panel base */
    --sa-muted: 160, 200, 240;    /* headings/labels */
    --sa-dim: 180, 200, 220;      /* secondary text */
    --sa-line: 100, 160, 220;     /* hairlines/borders */
    --sa-scenario: 251, 191, 36;  /* amber — the fiction halo */
    --sa-confluence: 235, 240, 255; /* near-white — converged real signal, distinct from any single layer */
    --sa-fg: #e0e0e0;
    --sa-bg: #000;

    /* shape + rhythm */
    --sa-radius: 12px;
    --sa-radius-sm: 8px;
    --duration-breath: 8s;

    /* vitality — written from Rust (src/vitality) at runtime; these are
       the first-paint defaults for browsers where an API is unavailable */
    --device-energy: 1;
    --torpor-level: 0;
    --homeostasis: 0;
    --circadian-warmth: 1;
    --circadian-brightness: 1;

    /* derived: chrome breathes away in stillness, dims in torpor and at
       night — the globe itself stays the protagonist */
    --chrome-opacity: calc(
        (1 - var(--homeostasis) * 0.55)
        * (1 - var(--torpor-level) * 0.4)
        * var(--circadian-brightness)
    );
}

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

html {
    height: 100%;
}

/* min-height, not height: a hard `height: 100%` here reliably produced a
   permanently blank page on /labs/reactor-twin (found live, 2026-07-11;
   root-caused via CSS bisection in headless Chromium — html/body height:100%
   collapsed to 0 for reasons not fully understood, silently clipping all
   normal-flow content via overflow:hidden while the body background still
   painted the full viewport, which is what made it look like a stuck loading
   screen rather than a layout bug). The globe route is unaffected either
   way since #globe-canvas is position:absolute and resolves its own
   height:100% against the viewport directly, not against body's box. */
body {
    width: 100%;
    min-height: 100%;
    overflow: hidden;
    background: var(--sa-bg);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--sa-fg);
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
}

canvas#globe-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    z-index: 0;
}

canvas#globe-canvas:active {
    cursor: grabbing;
}

canvas#globe-canvas.has-hover {
    cursor: pointer;
}

.globe-unavailable {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 320px;
    text-align: center;
    font-size: 13px;
    line-height: 1.5;
    color: rgba(248, 113, 113, 0.9);
    z-index: 5;
}

/* ─── Title ─────────────────────────────────────────────────────── */

.globe-title {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 10;
    pointer-events: none;
}

.globe-title h1 {
    font-size: 18px;
    font-weight: 200;
    letter-spacing: 6px;
    text-transform: uppercase;
    color: rgba(var(--sa-accent), 0.7);
    text-shadow: 0 0 20px rgba(var(--sa-accent), 0.2);
    margin: 0;
}

.globe-title .subtitle {
    font-size: 10px;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: rgba(var(--sa-cool), 0.4);
    margin-top: 4px;
}

.labs-link {
    display: inline-block;
    margin-top: 8px;
    color: rgb(var(--sa-accent));
    font-size: 12px;
    text-decoration: none;
    opacity: 0.8;
    /* parent .globe-title is pointer-events:none so it doesn't block globe
       dragging — the link must opt back in or it's unclickable */
    pointer-events: auto;
}

.labs-link:hover {
    opacity: 1;
    text-decoration: underline;
}

/* ─── Layer dock ────────────────────────────────────────────────────
   A vertical arc of glyph-dots on the left edge. Real data above the
   divider, scenario fiction (amber halo) below. Hover/focus a dot to
   read its name + provenance in a flyout.                            */

.layer-dock {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    z-index: 10;
    /* 20 real+scenario layers now live here — cap height and scroll
       rather than overflow past the viewport on shorter screens. */
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    overflow-x: visible; /* flyouts must still escape to the right */
    scrollbar-width: thin;
}

.layer-dock::-webkit-scrollbar {
    width: 3px;
}
.layer-dock::-webkit-scrollbar-thumb {
    background: rgba(var(--sa-accent), 0.2);
    border-radius: 2px;
}

.dock-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dock-divider {
    height: 1px;
    width: 22px;
    margin: 6px 4px;
    background: linear-gradient(90deg, rgba(var(--sa-line), 0.35), transparent);
}

.dock-dot {
    position: relative;
    display: flex;
    align-items: center;
    background: none;
    border: none;
    padding: 5px;
    cursor: pointer;
}

.dock-dot-core {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(var(--sa-dim), 0.18);
    border: 1px solid rgba(var(--sa-line), 0.25);
    transition: transform 0.25s ease, box-shadow 0.4s ease, background 0.3s ease;
    flex-shrink: 0;
}

.dock-dot:hover .dock-dot-core,
.dock-dot:focus-visible .dock-dot-core {
    transform: scale(1.35);
}

.dock-dot.active .dock-dot-core {
    border-color: transparent;
    box-shadow: 0 0 8px currentColor;
    animation: dot-breathe var(--duration-breath) ease-in-out infinite;
}

/* scenario layers wear the amber halo — visible fiction */
.dock-dot.scenario .dock-dot-core {
    border-color: rgba(var(--sa-scenario), 0.45);
}

.dock-dot.scenario.active .dock-dot-core {
    box-shadow: 0 0 8px rgba(var(--sa-scenario), 0.8);
}

/* confluence: a derived signal, not a data layer — thin ringed border
   distinguishes it from both real-data dots and the scenario amber halo */
.dock-dot.confluence .dock-dot-core {
    border-color: rgba(var(--sa-confluence), 0.4);
    border-style: dashed;
}

.dock-dot.confluence.active .dock-dot-core {
    box-shadow: 0 0 8px rgba(var(--sa-confluence), 0.85);
}

.dock-dot.confluence .dock-flyout-prov {
    color: rgba(var(--sa-confluence), 0.8);
}

@keyframes dot-breathe {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.55; }
}

/* flyout: name + provenance, revealed on hover/focus */
.dock-flyout {
    position: absolute;
    left: 26px;
    top: 50%;
    transform: translateY(-50%) translateX(-6px);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    white-space: nowrap;
    padding: 6px 10px;
    border-radius: var(--sa-radius-sm);
    background: rgba(var(--sa-panel), 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(var(--sa-line), 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 11;
}

.dock-dot:hover .dock-flyout,
.dock-dot:focus-visible .dock-flyout {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

.dock-flyout-name {
    font-size: 11px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--sa-fg);
}

.dock-flyout-prov {
    font-size: 10px;
    color: rgba(var(--sa-dim), 0.65);
    font-style: italic;
}

.dock-dot.scenario .dock-flyout-prov {
    color: rgba(var(--sa-scenario), 0.75);
}

/* EROI micro-legend, present only while fossil deposits are lit */
.dock-eroi {
    display: flex;
    align-items: center;
    gap: 3px;
    margin: 8px 0 0 5px;
}

.eroi-step {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(var(--c), 0.9);
}

.eroi-label {
    font-size: 8px;
    letter-spacing: 1.5px;
    color: rgba(var(--sa-muted), 0.5);
    margin-left: 4px;
}

/* ─── Tooltip ───────────────────────────────────────────────────── */

.tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(10, 15, 30, 0.92);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(var(--sa-line), 0.3);
    border-radius: var(--sa-radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    z-index: 20;
    max-width: 280px;
    transform: translate(12px, -50%);
    transition: opacity 0.15s;
}

.tooltip-name {
    font-weight: 600;
    color: #fff;
    margin-bottom: 4px;
}

.tooltip-detail {
    color: rgba(var(--sa-dim), 0.8);
    font-size: 12px;
}

/* ─── Info panel (the dossier) ──────────────────────────────────── */

.info-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 320px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    background: rgba(var(--sa-panel), 0.8);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(var(--sa-accent), 0.2);
    border-radius: var(--sa-radius);
    padding: 20px;
    z-index: 10;
    box-shadow: 0 0 30px rgba(var(--sa-accent), 0.05), inset 0 0 20px rgba(var(--sa-cool), 0.02);
    transform-origin: 80% 20%;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.25s ease;
}

.info-panel.hidden {
    transform: scale(0.9);
    opacity: 0;
    pointer-events: none;
}

.info-panel h2 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
}

.info-panel .subtitle {
    font-size: 11px;
    color: rgba(var(--sa-muted), 0.6);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

/* the one number you'd say out loud first */
.hero-stat {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 4px 0 14px;
}

.hero-value {
    font-size: 34px;
    font-weight: 200;
    font-variant-numeric: tabular-nums;
    color: rgba(var(--sa-accent), 0.95);
    text-shadow: 0 0 18px rgba(var(--sa-accent), 0.25);
    line-height: 1;
}

.hero-unit {
    font-size: 11px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: rgba(var(--sa-dim), 0.6);
}

.info-panel .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 7px 0;
    border-bottom: 1px solid rgba(var(--sa-line), 0.1);
    font-size: 13px;
}

.info-panel .stat-label {
    color: rgba(var(--sa-dim), 0.6);
}

.info-panel .stat-value {
    color: #fff;
    font-weight: 500;
}

.info-panel .close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: rgba(var(--sa-dim), 0.5);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
}

.info-panel .close-btn:hover {
    color: #fff;
}

/* ─── The vital sign (HUD) ──────────────────────────────────────── */

.vital {
    position: absolute;
    top: 84px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
    pointer-events: none;
}

.vital-bloom {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: radial-gradient(
        circle,
        rgba(var(--sa-vital), 0.85) 0%,
        rgba(var(--sa-accent), 0.35) 55%,
        transparent 75%
    );
    animation: vital-breathe var(--vital-period, 6s) ease-in-out infinite;
}

@keyframes vital-breathe {
    0%, 100% { transform: scale(1); opacity: 0.75; }
    50% { transform: scale(1.45); opacity: 1; }
}

.vital-phi {
    font-size: 15px;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    color: rgba(var(--sa-vital), 0.9);
    text-shadow: 0 0 12px rgba(var(--sa-vital), 0.35);
}

/* parent .vital is pointer-events:none so it doesn't block globe
   dragging — this control must opt back in, same as .labs-link */
.aesthetic-cycle {
    pointer-events: auto;
    background: none;
    border: none;
    color: rgba(var(--sa-dim), 0.4);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 4px;
    margin-left: 2px;
    transition: color 0.2s, transform 0.4s ease;
}

.aesthetic-cycle:hover {
    color: rgba(var(--sa-accent), 0.85);
    transform: rotate(45deg);
}

/* ─── Epoch band (timeline) ─────────────────────────────────────── */

.epoch-band {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    width: min(560px, calc(100vw - 130px));
    z-index: 10;
}

.epoch-band-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 4px;
    justify-content: center;
}

.epoch-band-year {
    font-size: 24px;
    font-weight: 200;
    font-variant-numeric: tabular-nums;
    color: rgba(var(--sa-vital), 0.9);
    text-shadow: 0 0 12px rgba(var(--sa-vital), 0.3);
    line-height: 1;
}

.epoch-band-name {
    font-size: 10px;
    letter-spacing: 2.5px;
    text-transform: uppercase;
    color: rgba(var(--sa-muted), 0.6);
}

.epoch-band-track {
    position: relative;
    height: 18px;
    display: flex;
    align-items: center;
}

.epoch-band-segments {
    position: absolute;
    inset: 7px 0;
    display: flex;
    gap: 2px;
    pointer-events: none;
}

.epoch-band-segments span {
    height: 4px;
    border-radius: 2px;
    background: rgba(var(--sa-accent), 0.14);
}

.epoch-band-segments span:nth-child(odd) {
    background: rgba(var(--sa-accent), 0.22);
}

.epoch-band-slider {
    position: relative;
    width: 100%;
    height: 18px;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    outline: none;
    cursor: pointer;
    z-index: 1;
}

.epoch-band-slider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(var(--sa-vital), 0.9);
    box-shadow: 0 0 10px rgba(var(--sa-vital), 0.5);
    cursor: pointer;
}

.epoch-band-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(var(--sa-vital), 0.9);
    box-shadow: 0 0 10px rgba(var(--sa-vital), 0.5);
    border: none;
    cursor: pointer;
}

.epoch-band-slider::-moz-range-track {
    background: transparent;
}

/* ─── Whisper ───────────────────────────────────────────────────── */

.whisper {
    position: absolute;
    bottom: 64px;
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    max-width: min(520px, calc(100vw - 40px));
    text-align: center;
    font-size: 12px;
    font-style: italic;
    letter-spacing: 0.4px;
    color: rgba(var(--sa-dim), 0.75);
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
    opacity: 0;
    transition: opacity 1.2s ease, transform 1.2s ease;
    pointer-events: none;
    z-index: 10;
}

.whisper.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── Planet navigation ─────────────────────────────────────────── */

.planet-nav {
    position: absolute;
    bottom: 80px;
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 10;
}

.planet-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(var(--sa-panel), 0.6);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(var(--sa-accent), 0.1);
    border-radius: var(--sa-radius-sm);
    color: rgba(var(--sa-dim), 0.6);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.planet-btn:hover {
    background: rgba(var(--sa-panel), 0.8);
    border-color: rgba(var(--sa-accent), 0.3);
    color: rgba(var(--sa-accent), 0.8);
}

.planet-btn.active {
    background: rgba(var(--sa-accent), 0.1);
    border-color: rgba(var(--sa-accent), 0.5);
    color: rgba(var(--sa-accent), 0.9);
    box-shadow: 0 0 15px rgba(var(--sa-accent), 0.15);
}

.planet-icon {
    font-size: 16px;
}

.planet-label {
    letter-spacing: 1px;
    text-transform: uppercase;
    font-size: 9px;
}

/* ─── Mobile ────────────────────────────────────────────────────────
   The dock becomes a bottom arc; nothing takes the globe over.       */

@media (max-width: 768px) {
    .layer-dock {
        left: 50%;
        top: auto;
        bottom: 46px;
        transform: translateX(-50%);
        flex-direction: row;
        align-items: center;
        max-width: calc(100vw - 16px);
        /* 20 dots no longer fit one screen width — scroll horizontally
           as a filter strip instead of wrapping (wrapping would eat
           vertical space the mobile layout can't spare). */
        max-height: none;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
    }

    .dock-group {
        flex-direction: row;
        gap: 0;
    }

    .dock-divider {
        width: 1px;
        height: 18px;
        margin: 0 4px;
        background: linear-gradient(180deg, rgba(var(--sa-line), 0.35), transparent);
    }

    /* No hover on touch — the whisper narrates toggles instead, and a
       tap-stuck flyout would squat on the epoch band */
    .dock-flyout {
        display: none;
    }

    .dock-eroi {
        display: none;
    }

    .epoch-band {
        bottom: 88px;
        width: calc(100vw - 32px);
    }

    .whisper {
        bottom: 140px;
    }

    .vital {
        top: 64px;
    }

    .globe-title h1 {
        font-size: 15px;
        letter-spacing: 4px;
    }

    .globe-title .subtitle {
        display: none;
    }

    .info-panel {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 55vh;
        border-radius: var(--sa-radius) var(--sa-radius) 0 0;
        transform-origin: 50% 100%;
    }

    .info-panel.hidden {
        transform: translateY(30px) scale(0.98);
    }

    .tooltip {
        display: none; /* hover doesn't exist on touch; tap opens the dossier */
    }

    .planet-nav {
        bottom: auto;
        top: 110px;
        right: 8px;
    }

    .planet-icon {
        font-size: 12px;
    }

    .planet-label {
        display: none;
    }
}

/* ─── Reactor Digital Twin demo page ────────────────────────────── */

.reactor-twin-page {
    position: relative;
    z-index: 10;
    width: 100%;
    min-height: 100%;
    overflow-y: auto;
    background: #05070d;
    padding: 32px 24px 64px;
    max-width: 720px;
    margin: 0 auto;
}

.reactor-twin-page > a {
    color: rgb(var(--sa-accent));
    text-decoration: none;
    font-size: 13px;
}

.reactor-twin-page h1 {
    margin: 12px 0 8px;
    font-size: 24px;
    color: #fff;
}

.reactor-twin-disclaimer {
    background: rgba(255, 200, 0, 0.08);
    border: 1px solid rgba(255, 200, 0, 0.35);
    border-radius: var(--sa-radius-sm);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--sa-fg);
    margin-bottom: 24px;
}

.reactor-twin-panel {
    background: rgba(var(--sa-panel), 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--sa-radius-sm);
    padding: 20px;
}

.reactor-twin-safety {
    display: inline-block;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 4px;
    margin-bottom: 12px;
}

.reactor-twin-safety.safety-green {
    background: rgba(var(--sa-accent), 0.15);
    color: rgb(var(--sa-accent));
}

.reactor-twin-safety.safety-yellow {
    background: rgba(255, 220, 0, 0.15);
    color: #ffdc00;
}

.reactor-twin-safety.safety-orange {
    background: rgba(255, 140, 0, 0.18);
    color: #ff8c00;
}

.reactor-twin-safety.safety-red {
    background: rgba(var(--sa-alarm), 0.18);
    color: rgb(var(--sa-alarm));
}

.reactor-twin-synthetic-tag {
    font-weight: 400;
    text-transform: none;
    font-size: 11px;
    opacity: 0.75;
    margin-left: 6px;
}

.reactor-twin-clock {
    font-size: 13px;
    opacity: 0.7;
    margin-bottom: 16px;
}

.reactor-twin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.reactor-twin-field {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 4px;
    padding: 8px 10px;
}

.reactor-twin-field-label {
    font-size: 11px;
    opacity: 0.6;
    margin-bottom: 4px;
}

.reactor-twin-field-value {
    font-size: 16px;
    font-variant-numeric: tabular-nums;
}

.reactor-twin-dispatch {
    border-top: 1px solid rgba(255, 140, 0, 0.3);
    padding-top: 14px;
    margin-top: 4px;
}

.reactor-twin-dispatch h3 {
    color: #ff8c00;
    font-size: 14px;
    margin-bottom: 6px;
}

.reactor-twin-dispatch p {
    font-size: 13px;
    line-height: 1.5;
    opacity: 0.85;
}

/* ─── Vitality coupling (living UI, not a dashboard) ────────────── */

/* Chrome breathes away in stillness (homeostasis), dims in torpor and at
   night. The info panel and whisper are excluded: content the human asked
   for manages its own presence. */
.layer-dock,
.vital,
.epoch-band,
.planet-nav,
.globe-title {
    opacity: var(--chrome-opacity);
    transition: opacity 2.5s ease;
}

/* ─── Reduced motion ────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .dock-dot.active .dock-dot-core,
    .vital-bloom {
        animation: none;
    }
    .info-panel,
    .whisper,
    .dock-flyout {
        transition: none;
    }
}
