/* ============================================
   GLOWING POLYHEDRONS - Retro Cyber Aesthetic
   ============================================ */

:root {
    /* Color Palette */
    --bg-deep: #0a0a12;
    --bg-panel: rgba(10, 15, 30, 0.85);
    --cyan-glow: #00ffff;
    --cyan-dim: #005f6f;
    --orange-glow: #ff8800;
    --orange-dim: #8f4400;
    --green-phosphor: #39ff14;
    --amber: #ffaa00;
    --text-primary: #e0e0e0;
    --text-dim: #707080;
    --border-glow: rgba(0, 255, 255, 0.3);

    /* Fonts */
    --font-display: 'Orbitron', sans-serif;
    --font-mono: 'Share Tech Mono', monospace;
}

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

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background: var(--bg-deep);
    background-image:
        radial-gradient(ellipse at center, #0f1525 0%, var(--bg-deep) 70%),
        repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 255, 255, 0.015) 2px,
            rgba(0, 255, 255, 0.015) 4px);
    font-family: var(--font-mono);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* Scanline overlay */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(0deg,
            rgba(0, 0, 0, 0.1) 0px,
            rgba(0, 0, 0, 0.1) 1px,
            transparent 1px,
            transparent 2px);
    opacity: 0.4;
}

/* Header */
.header {
    text-align: center;
    padding: 15px 20px 10px;
    background: linear-gradient(180deg, rgba(0, 20, 40, 0.8) 0%, transparent 100%);
    border-bottom: 1px solid var(--border-glow);
    position: relative;
    z-index: 10;
}

.title {
    font-family: var(--font-display);
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: 0.3em;
    margin-bottom: 5px;
}

.glow-text {
    color: var(--cyan-glow);
    text-shadow:
        0 0 10px var(--cyan-glow),
        0 0 20px var(--cyan-glow),
        0 0 40px var(--cyan-dim);
    animation: pulse-glow 3s ease-in-out infinite;
}

.glow-text.secondary {
    color: var(--orange-glow);
    text-shadow:
        0 0 10px var(--orange-glow),
        0 0 20px var(--orange-glow),
        0 0 40px var(--orange-dim);
    animation-delay: 1.5s;
}

@keyframes pulse-glow {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: absolute;
    top: 15px;
    left: 20px;
    z-index: 20;
}

.icon-button {
    background: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 2px;
}

.icon-button svg {
    width: 16px;
    height: 16px;
}

.icon-button:hover {
    background: rgba(0, 255, 255, 0.1);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
    transform: scale(1.05);
}

/* GitHub Link (updated to match alignment) */
.github-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary-color);
    text-decoration: none;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    opacity: 0.8;
}

/* Help Modal Overlay - Override generic modal-overlay which is sidebar-specific */
#help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    border-right: none;
    box-shadow: none;
    transform: none;
    /* Reset sidebar transform */
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

#help-modal.active {
    opacity: 1;
    visibility: visible;
}

/* Help Modal Inner Content container override */
#help-modal .modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--cyan-glow);
    border-radius: 8px;
    box-shadow: 0 0 40px rgba(0, 255, 255, 0.15);
    height: auto;
}

/* Help Modal Styling */
.help-modal-content {
    max-width: 1200px !important;
    /* Increased from 800px */
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.help-sections {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    /* Reduced min-width slightly to prevent overflow on small screens */
    gap: 1.5rem;
    overflow-y: auto;
    /*  overflow-x: hidden;  Not needed if width is controlled */
    padding-right: 0.5rem;
    margin-top: 1rem;
    padding-bottom: 1rem;
}

.help-section {
    background: rgba(0, 20, 40, 0.5);
    border: 1px solid rgba(0, 255, 255, 0.2);
    border-radius: 8px;
    padding: 1rem;
}

.help-section h3 {
    color: var(--secondary-color);
    margin-top: 0;
    margin-bottom: 0.8rem;
    border-bottom: 1px solid rgba(255, 0, 255, 0.3);
    padding-bottom: 0.5rem;
    font-size: 1.1rem;
}

.help-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-section li {
    margin-bottom: 0.5rem;
    color: #ccc;
    font-size: 0.95rem;
    line-height: 1.4;
}

.help-section strong {
    color: var(--primary-color);
}

.help-section p {
    color: #ccc;
    font-size: 0.95rem;
    line-height: 1.5;
    margin: 0;
}

/* Scrollbar for modal content */
.help-sections::-webkit-scrollbar {
    width: 6px;
}

.help-sections::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

.help-sections::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
}

.github-link:hover {
    color: var(--cyan-glow);
    opacity: 1;
}

.github-link svg {
    flex-shrink: 0;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.4em;
    text-transform: uppercase;
}

/* Main Container */
.main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Control Panel */
.control-panel {
    width: 280px;
    min-width: 280px;
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border-glow);
    padding: 15px;
    overflow-y: auto;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.panel-section {
    background: rgba(0, 30, 50, 0.4);
    border: 1px solid var(--border-glow);
    border-radius: 4px;
    padding: 12px;
}

.panel-label {
    display: block;
    font-family: var(--font-display);
    font-size: 0.7rem;
    color: var(--cyan-glow);
    letter-spacing: 0.2em;
    margin-bottom: 8px;
}

.panel-title {
    font-family: var(--font-display);
    font-size: 0.65rem;
    color: var(--orange-glow);
    letter-spacing: 0.15em;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--orange-dim);
}

/* Cyber Select */
.cyber-select {
    width: 100%;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--cyan-dim);
    border-radius: 3px;
    color: var(--cyan-glow);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cyber-select:hover,
.cyber-select:focus {
    border-color: var(--cyan-glow);
    box-shadow: 0 0 10px var(--cyan-dim), inset 0 0 10px rgba(0, 255, 255, 0.1);
    outline: none;
}

.cyber-select option {
    background: #0a1020;
    color: var(--text-primary);
}

/* Filter Group */
.filter-group {
    margin-top: 10px;
}

.filter-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.filter-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--cyan-dim);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.7rem;
    color: var(--text-dim);
    transition: all 0.2s ease;
}

.filter-checkbox:hover {
    border-color: var(--cyan-glow);
}

.filter-checkbox:has(input:checked) {
    background: var(--cyan-dim);
    color: var(--cyan-glow);
    border-color: var(--cyan-glow);
}

.filter-checkbox input {
    display: none;
}

/* Filter Buttons (new two-row layout) */
.filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.filter-btn {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--cyan-dim);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.7rem;
    color: var(--text-dim);
    transition: all 0.2s ease;
}

.filter-btn:hover {
    border-color: var(--cyan-glow);
}

.filter-btn:has(input:checked) {
    background: var(--cyan-dim);
    color: var(--cyan-glow);
    border-color: var(--cyan-glow);
}

.filter-btn input {
    display: none;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-item {
    background: rgba(0, 0, 0, 0.3);
    padding: 8px;
    border-radius: 3px;
    border-left: 2px solid var(--cyan-dim);
}

.stat-label {
    display: block;
    font-size: 0.6rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.stat-value {
    display: block;
    font-size: 1.1rem;
    color: var(--green-phosphor);
    font-weight: bold;
    text-shadow: 0 0 5px var(--green-phosphor);
}

/* Flow Stats */
.flow-stats {
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.75rem;
}

.flow-stats table {
    width: 100%;
    border-collapse: collapse;
}

.flow-stats th {
    text-align: left;
    color: var(--cyan-glow);
    font-size: 0.65rem;
    padding: 4px 6px;
    border-bottom: 1px solid var(--cyan-dim);
    position: sticky;
    top: 0;
    background: rgba(10, 15, 30, 0.95);
}

.flow-stats td {
    padding: 3px 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.flow-stats .edge-col {
    color: var(--text-dim);
}

.flow-stats .raw-col {
    color: var(--amber);
}

.flow-stats .opt-col {
    color: var(--green-phosphor);
}

/* Pair Weights */
.pair-weights {
    max-height: 180px;
    overflow-y: auto;
    font-size: 0.8rem;
}

.flow-minmax {
    margin-bottom: 4px;
}

.minmax-item {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    font-size: 0.75rem;
}

.minmax-item span:first-child {
    color: var(--text-dim);
}

.pair-weight-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.pair-label {
    color: var(--text-dim);
}

.pair-value {
    color: var(--orange-glow);
    font-weight: bold;
}

.no-data {
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.75rem;
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 5px 0;
}

.toggle-label input[type="checkbox"] {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 1px solid var(--cyan-dim);
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    position: relative;
    transition: all 0.2s ease;
}

.toggle-label input[type="checkbox"]:checked {
    background: var(--cyan-glow);
    border-color: var(--cyan-glow);
    box-shadow: 0 0 8px var(--cyan-glow);
}

.toggle-label input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--bg-deep);
    font-size: 12px;
    font-weight: bold;
}

.toggle-text {
    font-size: 0.8rem;
    color: var(--text-primary);
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#webgl-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-deep);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 100;
    transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader {
    width: 50px;
    height: 50px;
    border: 3px solid var(--cyan-dim);
    border-top-color: var(--cyan-glow);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    color: var(--cyan-glow);
    font-family: var(--font-display);
    letter-spacing: 0.2em;
    animation: blink 1s ease-in-out infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Legend */
.legend {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-glow);
    border-radius: 4px;
    padding: 10px 15px;
    z-index: 10;
    max-width: 200px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0;
    font-size: 0.75rem;
}

.legend-color {
    width: 20px;
    height: 3px;
    border-radius: 2px;
    box-shadow: 0 0 8px currentColor;
}

.legend-label {
    color: var(--text-dim);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
}

::-webkit-scrollbar-thumb {
    background: var(--cyan-dim);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--cyan-glow);
}

/* Cyber Button */
.cyber-button {
    width: 100%;
    padding: 10px 15px;
    background: linear-gradient(135deg, var(--cyan-dim) 0%, rgba(0, 100, 120, 0.5) 100%);
    border: 1px solid var(--cyan-glow);
    border-radius: 3px;
    color: var(--cyan-glow);
    font-family: var(--font-display);
    font-size: 0.75rem;
    letter-spacing: 0.15em;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.cyber-button:hover {
    background: linear-gradient(135deg, rgba(0, 150, 180, 0.6) 0%, var(--cyan-dim) 100%);
    box-shadow: 0 0 15px var(--cyan-dim), inset 0 0 10px rgba(0, 255, 255, 0.1);
}

.flow-summary {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--green-phosphor);
    text-align: center;
}

/* Flow Analysis Side Panel */
.modal-overlay {
    position: fixed;
    top: 60px;
    /* Below header */
    left: 280px;
    /* Next to control panel */
    width: 320px;
    height: calc(100vh - 60px);
    background: var(--bg-panel);
    border-right: 1px solid var(--cyan-glow);
    z-index: 1000;
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 5px 0 30px rgba(0, 0, 0, 0.5);
}

.modal-overlay.active {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

.modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: transparent;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-glow);
    flex-shrink: 0;
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 0.85rem;
    color: var(--cyan-glow);
    letter-spacing: 0.15em;
    margin: 0;
    text-shadow: 0 0 10px var(--cyan-dim);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    color: var(--orange-glow);
    text-shadow: 0 0 10px var(--orange-glow);
}

.modal-body {
    padding: 15px;
    overflow-y: auto;
    flex: 1;
}

.modal-body .flow-stats {
    max-height: none;
}

/* Responsive */
@media (max-width: 768px) {
    .control-panel {
        width: 100%;
        min-width: unset;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-glow);
    }

    .main-container {
        flex-direction: column;
    }

    .title {
        font-size: 1.2rem;
        letter-spacing: 0.15em;
    }

    .legend {
        bottom: 10px;
        right: 10px;
        font-size: 0.65rem;
    }

    .modal-content {
        width: 95%;
        max-height: 90vh;
    }
}