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

:root {
    --violet: #9b59e8;
    --violet-dim: #6b3aa0;
    --violet-glow: #c084fc;
    --cyan: #22d3ee;
    --cyan-dim: #0e7490;
    --orange: #f97316;
    --amber: #fbbf24;
    --bg-dark: #0a0a0f;
    --bg-panel: rgba(12, 12, 20, 0.92);
    --bg-panel-border: rgba(155, 89, 232, 0.15);
    --text-primary: #e2e8f0;
    --text-dim: #64748b;
    --text-bright: #f8fafc;
}

body {
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: 'IBM Plex Sans', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#scanline-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9998;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
}

#easter-egg-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    background: radial-gradient(ellipse at center, rgba(155, 89, 232, 0.3), transparent 70%);
    transition: opacity 2s ease;
}

#easter-egg-overlay.active {
    opacity: 1;
    animation: easterPulse 3s ease-in-out;
}

#easter-egg-overlay .greeting-msg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.4rem;
    color: var(--violet-glow);
    text-align: center;
    text-shadow: 0 0 30px var(--violet), 0 0 60px var(--violet-dim);
    letter-spacing: 0.15em;
    opacity: 0;
    animation: greetFadeIn 3s ease-in-out 0.5s forwards;
}

@keyframes easterPulse {
    0% { opacity: 0; }
    30% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes greetFadeIn {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    30% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    70% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.05); }
}

/* ---- HEADER ---- */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 24px;
    background: linear-gradient(180deg, rgba(15,15,25,0.98), rgba(10,10,15,0.95));
    border-bottom: 1px solid var(--bg-panel-border);
    z-index: 100;
    position: relative;
}

#header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--violet-dim), transparent);
}

.header-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    color: var(--text-bright);
    text-shadow: 0 0 12px rgba(155, 89, 232, 0.3);
}

.header-subtitle {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    font-weight: 300;
    color: var(--text-dim);
    letter-spacing: 0.1em;
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.stardate {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--cyan);
    letter-spacing: 0.1em;
}

.resonance-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--violet);
    box-shadow: 0 0 8px var(--violet), 0 0 20px var(--violet-dim);
    animation: pulseDot 1.15s ease-in-out infinite;
}

@keyframes pulseDot {
    0%, 100% { opacity: 0.5; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.3); }
}

.resonance-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: var(--violet-glow);
}

/* ---- APP CONTAINER ---- */
#app-container {
    display: flex;
    height: calc(100vh - 100px - 40px - 30px);
    position: relative;
}

/* ---- SIDEBAR ---- */
#sidebar {
    width: 80px;
    background: rgba(8, 8, 14, 0.95);
    border-right: 1px solid var(--bg-panel-border);
    display: flex;
    flex-direction: column;
    padding: 12px 0;
    gap: 4px;
    z-index: 50;
}

.nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    font-family: 'JetBrains Mono', monospace;
}

.nav-tab:hover {
    color: var(--text-primary);
    background: rgba(155, 89, 232, 0.05);
}

.nav-tab.active {
    color: var(--violet-glow);
    background: rgba(155, 89, 232, 0.1);
}

.nav-tab.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--violet);
    box-shadow: 0 0 8px var(--violet);
}

.tab-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.tab-label {
    font-size: 0.55rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* ---- VIEWPORT ---- */
#viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#scene-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
}

#scene-container canvas {
    display: block;
}

#hotspot-container {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

.hotspot {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: rgba(155, 89, 232, 0.6);
    border: 1px solid var(--violet-glow);
    box-shadow: 0 0 10px var(--violet), 0 0 20px rgba(155, 89, 232, 0.3);
    cursor: pointer;
    pointer-events: all;
    transform: translate(-50%, -50%);
    animation: hotspotPulse 2s ease-in-out infinite;
    transition: transform 0.2s;
}

.hotspot:hover {
    transform: translate(-50%, -50%) scale(1.5);
    background: var(--violet-glow);
}

.hotspot-label {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.55rem;
    color: var(--violet-glow);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s;
    text-shadow: 0 0 8px var(--violet);
    pointer-events: none;
}

.hotspot:hover .hotspot-label {
    opacity: 1;
}

@keyframes hotspotPulse {
    0%, 100% { box-shadow: 0 0 10px var(--violet), 0 0 20px rgba(155,89,232,0.3); }
    50% { box-shadow: 0 0 15px var(--violet-glow), 0 0 35px rgba(155,89,232,0.5); }
}

/* ---- EMBRYONIC CONTROLS ---- */
#embryonic-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    background: var(--bg-panel);
    border: 1px solid var(--bg-panel-border);
    border-radius: 8px;
    padding: 16px 32px;
    backdrop-filter: blur(12px);
    width: min(500px, 90%);
}

.slider-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    color: var(--cyan);
    letter-spacing: 0.15em;
    display: block;
    margin-bottom: 8px;
}

#stage-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: linear-gradient(90deg, var(--violet-dim), var(--violet));
    border-radius: 2px;
    outline: none;
}

#stage-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--violet-glow);
    border: 2px solid var(--bg-dark);
    box-shadow: 0 0 10px var(--violet);
    cursor: pointer;
}

.stage-markers {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    color: var(--text-dim);
}

.stage-info-panel {
    margin-top: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    color: var(--text-primary);
    line-height: 1.6;
}

.stage-info-panel .stat-highlight {
    color: var(--cyan);
}

/* ---- COMM PANEL ---- */
#comm-panel {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--bg-panel);
    border-top: 1px solid var(--bg-panel-border);
    padding: 16px;
    backdrop-filter: blur(12px);
}

.comm-buttons {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.comm-btn {
    background: rgba(155, 89, 232, 0.1);
    border: 1px solid var(--bg-panel-border);
    border-radius: 6px;
    padding: 10px 16px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    min-width: 160px;
}

.comm-btn:hover {
    border-color: var(--violet);
    background: rgba(155, 89, 232, 0.2);
    box-shadow: 0 0 15px rgba(155, 89, 232, 0.2);
}

.comm-btn.active {
    border-color: var(--cyan);
    background: rgba(34, 211, 238, 0.1);
}

.comm-pulses {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--violet-glow);
    font-weight: 700;
}

.comm-freq {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    color: var(--cyan);
}

.comm-text {
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.65rem;
    color: var(--text-dim);
    font-style: italic;
}

#waveform-canvas {
    width: 100%;
    max-width: 600px;
    height: 120px;
    display: block;
    margin: 0 auto;
    border: 1px solid rgba(155, 89, 232, 0.1);
    border-radius: 4px;
}

/* ---- SOCIETY PANEL ---- */
#society-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 20;
    background: rgba(8, 8, 14, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}

#network-canvas {
    width: 100%;
    max-width: 800px;
    flex: 1;
    border: 1px solid rgba(155, 89, 232, 0.1);
    border-radius: 4px;
}

.society-facts {
    margin-top: 16px;
    max-width: 600px;
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.8rem;
    line-height: 1.8;
    color: var(--text-dim);
}

.society-facts p {
    margin-bottom: 4px;
}

/* ---- DISCOVERY PANEL ---- */
#discovery-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 20;
    background: rgba(8, 8, 14, 0.95);
    overflow-y: auto;
    padding: 40px 20px;
}

.timeline {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    padding-left: 40px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, var(--violet-dim), var(--cyan-dim), var(--violet-dim));
}

.timeline-event {
    position: relative;
    margin-bottom: 36px;
    opacity: 0;
    transform: translateX(20px);
    animation: timelineReveal 0.6s ease forwards;
}

.timeline-event:nth-child(1) { animation-delay: 0.1s; }
.timeline-event:nth-child(2) { animation-delay: 0.25s; }
.timeline-event:nth-child(3) { animation-delay: 0.4s; }
.timeline-event:nth-child(4) { animation-delay: 0.55s; }
.timeline-event:nth-child(5) { animation-delay: 0.7s; }
.timeline-event:nth-child(6) { animation-delay: 0.85s; }

@keyframes timelineReveal {
    to { opacity: 1; transform: translateX(0); }
}

.timeline-node {
    position: absolute;
    left: -34px;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--violet);
    border: 2px solid var(--bg-dark);
    box-shadow: 0 0 10px var(--violet);
}

.timeline-content h3 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--cyan);
    margin-bottom: 6px;
    font-weight: 500;
}

.timeline-content p {
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.8rem;
    color: var(--text-dim);
    line-height: 1.6;
}

/* ---- DETAIL PANEL ---- */
#detail-panel {
    width: 340px;
    background: var(--bg-panel);
    border-left: 1px solid var(--bg-panel-border);
    padding: 24px;
    overflow-y: auto;
    z-index: 60;
    backdrop-filter: blur(16px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s;
    transform: translateX(0);
}

#detail-panel.hidden {
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
}

#detail-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: 1px solid rgba(155, 89, 232, 0.3);
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#detail-close:hover {
    color: var(--violet-glow);
    border-color: var(--violet);
}

#detail-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 700;
    color: var(--violet-glow);
    margin-bottom: 16px;
    padding-right: 36px;
    text-shadow: 0 0 12px rgba(155, 89, 232, 0.3);
}

#detail-body {
    font-family: 'IBM Plex Sans', sans-serif;
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.7;
}

#detail-body .detail-stat {
    font-family: 'JetBrains Mono', monospace;
    color: var(--cyan);
    font-size: 0.75rem;
    display: block;
    margin: 8px 0;
    padding: 6px 10px;
    background: rgba(34, 211, 238, 0.05);
    border-left: 2px solid var(--cyan-dim);
    border-radius: 2px;
}

/* ---- BOTTOM BAR ---- */
#bottom-bar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(180deg, rgba(10,10,15,0.95), rgba(8,8,12,0.98));
    border-top: 1px solid var(--bg-panel-border);
    height: 60px;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    cursor: default;
    transition: transform 0.2s;
    padding: 4px 8px;
}

.stat:hover {
    transform: translateY(-2px);
}

.stat:hover .stat-value {
    color: var(--violet-glow);
    text-shadow: 0 0 8px var(--violet);
}

.stat-icon {
    font-size: 0.9rem;
    color: var(--violet-dim);
}

.stat-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.5rem;
    color: var(--text-dim);
    letter-spacing: 0.1em;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--cyan);
    font-weight: 500;
    transition: all 0.3s;
}

/* ---- FOOTER ---- */
#footer {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 6px 16px;
    background: rgba(6, 6, 10, 0.98);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.55rem;
    color: var(--text-dim);
    height: 30px;
}

#footer a {
    color: var(--violet);
    text-decoration: none;
    transition: color 0.2s;
}

#footer a:hover {
    color: var(--violet-glow);
}

.disclaimer {
    font-size: 0.5rem;
    color: rgba(100, 116, 139, 0.5);
    font-style: italic;
}

.hidden {
    display: none !important;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar {
    width: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--violet-dim);
    border-radius: 2px;
}

/* ---- MOBILE ---- */
@media (max-width: 768px) {
    #header {
        flex-direction: column;
        gap: 4px;
        padding: 8px 12px;
    }
    .header-title {
        font-size: 0.8rem;
    }
    .header-subtitle {
        font-size: 0.5rem;
    }
    #app-container {
        flex-direction: column;
        height: calc(100vh - 80px - 55px - 30px);
    }
    #sidebar {
        width: 100%;
        flex-direction: row;
        order: 2;
        padding: 0;
        gap: 0;
        border-right: none;
        border-top: 1px solid var(--bg-panel-border);
        overflow-x: auto;
    }
    .nav-tab {
        padding: 8px 12px;
        min-width: 60px;
    }
    .nav-tab.active::before {
        left: 8px; right: 8px;
        top: 0; bottom: auto;
        width: auto; height: 2px;
    }
    .tab-label {
        font-size: 0.5rem;
    }
    #viewport {
        order: 1;
        flex: 1;
    }
    #detail-panel {
        width: 100%;
        position: absolute;
        bottom: 0;
        top: auto;
        height: 60%;
        transform: translateY(0);
        border-left: none;
        border-top: 1px solid var(--bg-panel-border);
    }
    #detail-panel.hidden {
        transform: translateY(100%);
    }
    #bottom-bar {
        height: auto;
        padding: 6px 8px;
    }
    .stat {
        padding: 2px 4px;
    }
    .stat-label { font-size: 0.45rem; }
    .stat-value { font-size: 0.6rem; }

    .comm-btn { min-width: 120px; padding: 8px 10px; }
    #embryonic-controls { padding: 12px 16px; }
}