*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    overflow: hidden;
    font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, sans-serif;
    background: #050b1a;
    color: #f0f0f0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Top navigation ── */
.top-nav {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 24px;
    background: rgba(12, 14, 28, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(12px);
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #f0f0f0;
}

.brand-icon {
    color: #3b82f6;
    font-size: 0.9rem;
}

.nav-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 4px;
}

.nav-link {
    display: block;
    padding: 7px 16px;
    border-radius: 8px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.06);
}

.nav-link.active {
    color: #fff;
    background: rgba(59, 130, 246, 0.25);
}

/* ── 3D viewport ── */
.viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.viewport canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* ── Sidebar panels ── */
.sidebar {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 340px;
    max-height: calc(100% - 40px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    z-index: 10;
    pointer-events: none;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.panel {
    background: rgba(20, 20, 35, 0.88);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 18px 20px;
    color: #f0f0f0;
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    pointer-events: auto;
    font-size: 14px;
}

.panel h3 {
    margin: 0 0 14px 0;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.2px;
    border-left: 3px solid #3b82f6;
    padding-left: 10px;
}

.file-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.progress-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.progress-label {
    font-size: 0.78rem;
    color: #94a3b8;
}

.progress-bar {
    background: rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    height: 12px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.75rem;
    color: #64748b;
    text-align: right;
}

.upload-btn {
    background: #3b82f6;
    border: none;
    padding: 9px 18px;
    border-radius: 40px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.85rem;
    align-self: flex-start;
}

.upload-btn:hover { background: #2563eb; }

.file-name {
    font-size: 0.75rem;
    opacity: 0.65;
    word-break: break-all;
    line-height: 1.4;
}

.info-text {
    background: rgba(0, 0, 0, 0.45);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 0.78rem;
    font-family: 'Consolas', 'Courier New', monospace;
    word-break: break-word;
    line-height: 1.65;
}

.info-text .meta-row {
    display: block;
    padding: 2px 0;
}

.info-text .meta-label {
    color: #64748b;
    display: inline-block;
    min-width: 88px;
}

.event-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.event-nav label {
    font-weight: 500;
    font-size: 0.85rem;
}

.event-input {
    background: #0f0f1a;
    border: 1px solid #4b5563;
    color: white;
    padding: 7px 10px;
    border-radius: 10px;
    width: 76px;
    text-align: center;
    font-weight: 500;
    font-size: 0.9rem;
}

.nav-buttons { display: flex; gap: 6px; }

.nav-btn {
    background: #334155;
    border: none;
    color: white;
    font-size: 1.1rem;
    font-weight: bold;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    transition: 0.1s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover { background: #3b82f6; }

/* View mode buttons */
.view-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.view-btn {
    background: #1e293b;
    border: 1px solid #475569;
    color: #cbd5e1;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    flex: 1 1 auto;
    text-align: center;
}

.view-btn:hover {
    background: #334155;
    border-color: #64748b;
}

.view-btn.active {
    background: rgba(59, 130, 246, 0.25);
    border-color: #3b82f6;
    color: #60a5fa;
}

.display-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #cbd5e1;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #3b82f6;
    cursor: pointer;
}

.checkbox-label:hover {
    color: #e2e8f0;
}

.status {
    font-size: 0.75rem;
    margin-top: 12px;
    color: #94a3b8;
    line-height: 1.5;
}

.status.warning { color: #f97316; }
.status.error { color: #f87171; }

/* ── Samples panel ── */
.samples-panel {
    max-height: 300px;
    display: flex;
    flex-direction: column;
}

.samples-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.samples-list::-webkit-scrollbar { width: 4px; }
.samples-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 2px; }

.samples-loading {
    font-size: 0.75rem;
    color: #64748b;
    padding: 8px 4px;
    text-align: center;
}

.sample-item {
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.8rem;
    color: #e2e8f0;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    word-break: break-word;
}

.sample-item:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.5);
    color: #ffffff;
}

.sample-item.builtin {
    color: #7c3aed;
    border-color: rgba(124, 58, 237, 0.3);
}

.sample-item.builtin:hover {
    background: rgba(124, 58, 237, 0.15);
    border-color: rgba(124, 58, 237, 0.5);
}

.sample-item.user-loaded {
    color: #60a5fa;
    border-color: rgba(96, 165, 250, 0.3);
}

.sample-item.user-loaded:hover {
    background: rgba(96, 165, 250, 0.15);
    border-color: rgba(96, 165, 250, 0.5);
}

.sample-badge {
    font-size: 0.65rem;
    padding: 2px 5px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0.7;
    flex-shrink: 0;
}

.sample-item.builtin .sample-badge {
    background: rgba(124, 58, 237, 0.3);
}

.sample-item.user-loaded .sample-badge {
    background: rgba(96, 165, 250, 0.3);
}

/* ── Particle tooltip ── */
.tooltip-3d {
    position: absolute;
    background: rgba(8, 12, 24, 0.92);
    backdrop-filter: blur(10px);
    border-radius: 14px;
    padding: 12px 16px;
    pointer-events: none;
    z-index: 20;
    border: 1px solid rgba(59, 130, 246, 0.35);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    min-width: 210px;
}

.tooltip-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tooltip-name {
    font-size: 1.25rem;
    line-height: 1.2;
}

.tooltip-name .katex { font-size: 1.25rem; color: #f8fafc; }

.tooltip-pid {
    font-size: 0.7rem;
    color: #64748b;
    font-family: 'Consolas', monospace;
}

.tooltip-body {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 14px;
    font-size: 0.78rem;
}

.tooltip-body .t-label {
    color: #64748b;
    font-family: 'Consolas', monospace;
}

.tooltip-body .t-label .katex { font-size: 0.78rem; color: #64748b; }

.tooltip-body .t-value {
    color: #e2e8f0;
    font-family: 'Consolas', monospace;
    text-align: right;
}

.tooltip-body .t-value .katex { font-size: 0.78rem; color: #e2e8f0; }

/* ── Particle sphere labels (KaTeX) ── */
.particle-label-layer {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
}

.particle-label {
    pointer-events: none;
    user-select: none;
    line-height: 1;
    transform: translate(-50%, -50%);
}

.particle-label .katex {
    color: #ffffff;
    text-shadow: 0 0 3px rgba(0, 0, 0, 0.95), 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* ── Home overlay ── */
.home-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 20, 0.75);
    backdrop-filter: blur(6px);
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    padding: 72px 20px 40px;
}

.home-overlay[hidden] { display: none; }

.home-card {
    position: relative;
    background: rgba(18, 20, 38, 0.97);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 36px 40px;
    max-width: 680px;
    width: 100%;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.home-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

.home-close:hover { color: #fff; background: rgba(255,255,255,0.08); }

.home-header h1 {
    margin: 0 0 6px;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #f8fafc;
}

.home-tagline {
    margin: 0 0 28px;
    color: #64748b;
    font-size: 0.95rem;
}

.home-section {
    margin-bottom: 24px;
}

.home-section h2 {
    margin: 0 0 10px;
    font-size: 1rem;
    font-weight: 600;
    color: #93c5fd;
}

.home-section p {
    margin: 0 0 10px;
    line-height: 1.65;
    color: #cbd5e1;
    font-size: 0.9rem;
}

.home-steps {
    margin: 0 0 12px;
    padding-left: 1.4rem;
    color: #cbd5e1;
    font-size: 0.9rem;
    line-height: 1.75;
}

.home-steps li { margin-bottom: 4px; }

.home-section code {
    background: rgba(0,0,0,0.35);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    color: #93c5fd;
}

.home-footer {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.home-footer p {
    margin: 0 0 6px;
    font-size: 0.85rem;
    color: #94a3b8;
}

.home-footer a { color: #60a5fa; text-decoration: none; }
.home-footer a:hover { text-decoration: underline; }

.home-credit {
    font-size: 0.78rem !important;
    color: #475569 !important;
    font-style: italic;
}

@media (max-width: 600px) {
    .sidebar {
        width: calc(100% - 24px);
        left: 12px;
        top: 12px;
        max-height: calc(100% - 24px);
    }
    .panel { padding: 14px 16px; }
    .home-card { padding: 28px 22px; }
    .top-nav { padding: 0 14px; }
}
