/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.85);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #38bdf8;
    --accent-cyan: #22d3ee;
    --accent-gold: #fbbf24;
    --accent-orange: #fb923c;
    --accent-green: #4ade80;
    --accent-red: #f87171;
    --accent-purple: #a78bfa;
    --earth-blue: #4a9eff;
    --moon-gray: #b0b0b0;
    --trajectory-future: rgba(100, 116, 139, 0.5);
    --trajectory-past: #38bdf8;
    --border-color: rgba(148, 163, 184, 0.15);
    --glow-blue: 0 0 20px rgba(56, 189, 248, 0.3);
    --glow-gold: 0 0 20px rgba(251, 191, 36, 0.3);
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

/* ===== Header ===== */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1.5rem;
    background: linear-gradient(180deg, rgba(17, 24, 39, 0.95) 0%, rgba(10, 14, 26, 0.9) 100%);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}

.mission-badge {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.badge-icon {
    font-size: 1.8rem;
    color: var(--accent-gold);
    text-shadow: var(--glow-gold);
    line-height: 1;
}

header h1 {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-orange));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 400;
    letter-spacing: 0.03em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--accent-green);
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1px solid rgba(74, 222, 128, 0.3);
    background: rgba(74, 222, 128, 0.08);
}

.live-indicator.inactive {
    color: var(--text-muted);
    border-color: var(--border-color);
    background: rgba(100, 116, 139, 0.08);
}

.live-indicator.inactive .live-dot {
    background: var(--text-muted);
    animation: none;
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-green);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
    50% { opacity: 0.6; box-shadow: 0 0 0 4px rgba(74, 222, 128, 0); }
}

.data-source {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ===== Main canvas area ===== */
main {
    position: relative;
    flex: 1;
    overflow: hidden;
    background: radial-gradient(ellipse at center, #0f172a 0%, #0a0e1a 70%);
}

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

#trajectoryCanvas:active {
    cursor: grabbing;
}

/* ===== Info Panel ===== */
.info-panel {
    position: absolute;
    top: 0.75rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    width: max-content;
    max-width: 98%;
}

.info-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.info-row-mobile {
    display: none;
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.45rem 0.8rem;
    backdrop-filter: blur(16px);
    min-width: 130px;
    text-align: center;
    pointer-events: auto;
    transition: background 0.2s;
}

.info-card:hover {
    background: var(--bg-card-hover);
}

.info-label {
    display: block;
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
    margin-bottom: 0.15rem;
}

.info-value {
    display: block;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    letter-spacing: 0.02em;
}

.phase-value {
    font-size: 0.8rem;
    font-family: var(--font-sans);
    color: var(--accent-gold);
}

.progress-bar {
    margin-top: 0.25rem;
    height: 3px;
    background: rgba(100, 116, 139, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
    border-radius: 2px;
    width: 0%;
    transition: width 0.5s ease;
}

/* ===== Controls ===== */
.controls {
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    z-index: 10;
}

.ctrl-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px);
    transition: all 0.15s;
    font-family: var(--font-sans);
}

.ctrl-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}

.ctrl-btn.text-btn {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.ctrl-btn.active-toggle {
    background: rgba(251, 191, 36, 0.15);
    border-color: rgba(251, 191, 36, 0.5);
    color: var(--accent-gold);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.2);
}

.ctrl-separator {
    height: 1px;
    background: var(--border-color);
    margin: 0.15rem 0;
}

/* ===== Scale Indicator ===== */
.scale-indicator {
    position: absolute;
    bottom: 4rem;
    left: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 10;
    opacity: 0.7;
}

.scale-bar {
    width: 80px;
    height: 2px;
    background: var(--text-secondary);
    position: relative;
}

.scale-bar::before,
.scale-bar::after {
    content: '';
    position: absolute;
    width: 2px;
    height: 8px;
    background: var(--text-secondary);
    top: -3px;
}

.scale-bar::before { left: 0; }
.scale-bar::after { right: 0; }

#scaleLabel {
    font-size: 0.65rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

/* ===== Legend ===== */
.legend {
    position: absolute;
    bottom: 4rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    z-index: 10;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    backdrop-filter: blur(16px);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.legend-line {
    display: inline-block;
    width: 20px;
    height: 2px;
    border-radius: 1px;
}

.legend-line.future {
    background: var(--trajectory-future);
    border: 1px dashed var(--text-muted);
    height: 0;
}

.legend-line.completed {
    background: var(--trajectory-past);
    height: 3px;
    box-shadow: 0 0 6px rgba(56, 189, 248, 0.4);
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-dot.orion {
    background: var(--accent-gold);
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

.legend-dot.moon-legend {
    background: var(--moon-gray);
}

.legend-dot.earth-legend {
    background: var(--earth-blue);
}

/* ===== Toggle Switch ===== */
.legend-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    padding: 0.1rem 0;
}

.legend-toggle input[type="checkbox"] {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 30px;
    height: 16px;
    background: rgba(100, 116, 139, 0.3);
    border-radius: 999px;
    border: 1px solid rgba(100, 116, 139, 0.3);
    transition: all 0.25s ease;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all 0.25s ease;
}

.legend-toggle input:checked + .toggle-switch {
    background: rgba(167, 139, 250, 0.3);
    border-color: rgba(167, 139, 250, 0.5);
}

.legend-toggle input:checked + .toggle-switch::after {
    left: 16px;
    background: var(--accent-purple);
    box-shadow: 0 0 6px rgba(167, 139, 250, 0.5);
}

.toggle-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    font-weight: 500;
    transition: color 0.2s;
}

.legend-toggle input:checked ~ .toggle-label {
    color: var(--accent-purple);
}

/* Warm toggle variant for gravity field */
.legend-toggle input:checked + .toggle-switch-warm {
    background: rgba(251, 191, 36, 0.3);
    border-color: rgba(251, 191, 36, 0.5);
}

.legend-toggle input:checked + .toggle-switch-warm::after {
    left: 16px;
    background: var(--accent-gold);
    box-shadow: 0 0 6px rgba(251, 191, 36, 0.5);
}

#gravFieldToggle input:checked ~ .toggle-label {
    color: var(--accent-gold);
}

.legend-separator {
    height: 1px;
    background: var(--border-color);
    margin: 0.15rem 0;
}

/* ===== Time Control ===== */
.time-control {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.5rem;
    padding-bottom: calc(0.6rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(0deg, rgba(10, 14, 26, 0.95) 0%, rgba(10, 14, 26, 0.8) 100%);
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    z-index: 10;
}

/* ===== Play Button ===== */
.btn-play {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: all 0.2s;
    padding: 0;
}

.btn-play.playing {
    background: rgba(74, 222, 128, 0.15);
    border-color: rgba(74, 222, 128, 0.5);
    color: var(--accent-green);
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.2);
}

.time-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
    font-weight: 500;
}

#timeSlider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--accent-blue), var(--trajectory-future));
    outline: none;
    cursor: pointer;
}

#timeSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-primary);
    box-shadow: 0 0 8px rgba(34, 211, 238, 0.5);
    cursor: pointer;
    transition: transform 0.1s;
}

#timeSlider::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

#timeSlider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-primary);
    box-shadow: 0 0 8px rgba(34, 211, 238, 0.5);
    cursor: pointer;
}

.time-display {
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    white-space: nowrap;
    min-width: 140px;
}

.btn-live {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--accent-green);
    background: rgba(74, 222, 128, 0.1);
    border: 1px solid rgba(74, 222, 128, 0.3);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.btn-live:hover {
    background: rgba(74, 222, 128, 0.2);
    border-color: var(--accent-green);
}

.btn-live.active {
    color: var(--text-muted);
    border-color: var(--border-color);
    background: transparent;
}

/* ===== Stars background (drawn on canvas) ===== */

/* ===== Mobile Info Strip ===== */
.info-strip {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.35rem 0.6rem;
    backdrop-filter: blur(16px);
    pointer-events: auto;
}

.info-strip-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.05rem;
    min-width: 0;
}

.info-strip-label {
    font-size: 0.5rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 500;
    line-height: 1;
}

.info-strip-value {
    font-size: 0.65rem;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    letter-spacing: 0.01em;
    white-space: nowrap;
    line-height: 1.1;
}

.info-strip-sep {
    color: var(--border-color);
    font-size: 0.7rem;
    line-height: 1;
    flex-shrink: 0;
}

.info-strip-progress {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.3rem 0.6rem;
    backdrop-filter: blur(16px);
    pointer-events: auto;
}

.info-strip-progress .progress-bar {
    width: 50px;
    margin-top: 0;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    header {
        padding: 0.4rem 0.6rem;
    }
    
    header h1 {
        font-size: 0.85rem;
    }

    .subtitle {
        font-size: 0.6rem;
    }

    .badge-icon {
        font-size: 1.4rem;
    }

    .data-source {
        display: none;
    }

    .info-row-desktop {
        display: none;
    }

    .info-row-mobile {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.3rem;
    }

    .info-panel {
        top: 0.4rem;
    }
    
    .legend {
        display: none;
    }
    
    .scale-indicator {
        bottom: 3.5rem;
    }

    .time-control {
        padding: 0.45rem 0.6rem;
        padding-bottom: calc(0.45rem + env(safe-area-inset-bottom, 0px));
        gap: 0.4rem;
    }

    .time-label {
        display: none;
    }

    .time-display {
        font-size: 0.6rem;
        min-width: 100px;
    }

    .btn-live {
        font-size: 0.6rem;
        padding: 0.25rem 0.45rem;
    }

    .btn-play {
        width: 28px;
        height: 28px;
        font-size: 0.7rem;
    }

    .controls {
        right: 0.5rem;
    }

    .ctrl-btn {
        width: 32px;
        height: 32px;
    }
}
