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

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #131827;
    --bg-tertiary: #1a2033;
    --text-primary: #e4e7eb;
    --text-secondary: #9ca3af;
    --accent-physics: #3b82f6;
    --accent-neural: #10b981;
    --border-color: #2d3748;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
}

header {
    text-align: center;
    flex-shrink: 0;
    margin-bottom: 0.5rem;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.125rem;
}

.subtitle {
    font-size: 0.625rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.375rem;
}

.header-nav {
    display: flex;
    justify-content: center;
    gap: 0.375rem;
}

.nav-link {
    padding: 0.25rem 0.75rem;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.625rem;
    font-weight: 500;
    border-radius: 3px;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-secondary);
}

.nav-link.active {
    color: var(--text-primary);
    border-color: var(--accent-physics);
    background: var(--bg-secondary);
}

.layout {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    min-height: 0;
}

.canvas-section {
    background: var(--bg-secondary);
    border-radius: 4px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#trajectoryCanvas {
    width: 100%;
    flex: 1;
    min-height: 0;
    border-radius: 3px;
    background: var(--bg-tertiary);
}

.canvas-info {
    margin-top: 0.375rem;
    flex-shrink: 0;
}

.legend {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.625rem;
}

.legend-color {
    width: 16px;
    height: 2px;
    border-radius: 1px;
}

.legend-color.physics { background: var(--accent-physics); }
.legend-color.neural { background: var(--accent-neural); }

.controls-section {
    background: var(--bg-secondary);
    border-radius: 4px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    overflow-y: auto;
    flex-shrink: 0;
    max-height: 45vh;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    transition: all 0.3s;
}

.status-dot.trained {
    background: var(--accent-neural);
    box-shadow: 0 0 8px var(--accent-neural);
}

.status-dot.training {
    background: var(--accent-physics);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.2); }
}

.status-text {
    font-size: 0.625rem;
    font-weight: 500;
}

.mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.toggle-label {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 16px;
    cursor: pointer;
}

.toggle-label input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-label input:disabled + .toggle-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-color);
    border-radius: 16px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    left: 2px;
    top: 2px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle-label input:checked + .toggle-slider {
    background: var(--accent-neural);
}

.toggle-label input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

.toggle-text {
    font-size: 0.625rem;
    font-weight: 500;
    min-width: 50px;
}

.control-group {
    margin-bottom: 0.5rem;
}

.control-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.control-label {
    font-size: 0.625rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.control-value {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--text-primary);
}

input[type="range"] {
    width: 100%;
    height: 3px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent-physics);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent-physics);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
}

.btn {
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: 3px;
    font-size: 0.625rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-primary {
    background: var(--accent-physics);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-primary:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    transform: translateY(-1px);
}

.btn-sm {
    padding: 0.375rem 0.625rem;
    font-size: 0.5625rem;
}

.training-section {
    background: var(--bg-tertiary);
    border-radius: 3px;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border-color);
    display: none;
}

.training-section.active {
    display: block;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.training-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.375rem;
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--accent-physics);
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-physics), var(--accent-neural));
    width: 0%;
    transition: width 0.3s;
}

.training-viz-wrapper {
    width: 100%;
    margin-bottom: 0.5rem;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
}

#neuralVizCanvas {
    width: 100%;
    height: 140px;
    display: block;
}

#lossCanvas {
    width: 100%;
    height: 90px;
    border-radius: 3px;
    display: block;
}

.info-panel {
    background: var(--bg-tertiary);
    border-radius: 3px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
}

.info-item {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
    font-size: 0.625rem;
}

.info-item:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.info-label {
    color: var(--text-secondary);
}

.info-value {
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

@media (min-width: 768px) {
    .container {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .layout {
        flex-direction: row;
        gap: 0.75rem;
    }

    .canvas-section {
        flex: 2;
    }

    .controls-section {
        flex: 1;
        max-width: 300px;
        max-height: none;
    }

    #neuralVizCanvas {
        height: 160px;
    }
    
    #lossCanvas {
        height: 110px;
    }
}

.controls-section::-webkit-scrollbar {
    width: 4px;
}

.controls-section::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

.controls-section::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}
