/* ==========================================================================
   Newton's Third Law Physics Simulator - Stylesheet
   Theme: Modern Dark Engineering Lab with Glassmorphism
   ========================================================================== */

:root {
    /* Color Palette */
    --bg-main: #090d16;
    --bg-card: rgba(15, 23, 42, 0.75);
    --bg-card-border: rgba(255, 255, 255, 0.08);
    --bg-sidebar: #0f172a;
    
    /* Cart Colors */
    --color-cart-a: #38bdf8;
    --color-cart-a-dark: #0284c7;
    --color-cart-a-bg: rgba(56, 189, 248, 0.12);
    
    --color-cart-b: #fb7185;
    --color-cart-b-dark: #e11d48;
    --color-cart-b-bg: rgba(251, 113, 133, 0.12);

    --color-success: #4ade80;
    --color-warning: #fbbf24;
    --color-danger: #ef4444;
    
    /* Text */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Outfit', sans-serif;
    --font-code: 'Fira Code', monospace;
    
    /* Layout */
    --header-height: 64px;
    --sidebar-width: 340px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

/* Helper hidden class */
.hidden {
    display: none !important;
}

/* ==========================================================================
   Header
   ========================================================================== */
.app-header {
    height: var(--header-height);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--bg-card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(251, 113, 133, 0.2));
    border: 1px solid rgba(56, 189, 248, 0.4);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-cart-a);
}

.header-brand h1 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(90deg, #f8fafc, #38bdf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-brand .subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.preset-selector-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.styled-select {
    background: #1e293b;
    color: var(--text-primary);
    border: 1px solid #334155;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.styled-select:hover {
    border-color: var(--color-cart-a);
}

.btn-icon {
    background: #1e293b;
    border: 1px solid #334155;
    color: var(--text-primary);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: #334155;
    border-color: var(--color-cart-a);
}

/* ==========================================================================
   Main Layout Grid
   ========================================================================== */
.main-container {
    display: flex;
    flex: 1;
    gap: 1.25rem;
    padding: 1.25rem;
    max-width: 1700px;
    margin: 0 auto;
    width: 100%;
}

/* ==========================================================================
   Sidebar Panel Controls
   ========================================================================== */
.sidebar-panel {
    width: var(--sidebar-width);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-section {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    backdrop-filter: blur(8px);
}

.section-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 8px;
}

.section-subtitle {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Controls & Sliders */
.control-group {
    margin-bottom: 1.15rem;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
}

.cart-a-dot { background-color: var(--color-cart-a); }
.cart-b-dot { background-color: var(--color-cart-b); }

.val-badge {
    background: #1e293b;
    border: 1px solid #334155;
    color: var(--text-primary);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-code);
    font-size: 0.8rem;
    font-weight: 600;
}

.highlighted-control {
    background: rgba(56, 189, 248, 0.05);
    border: 1px solid rgba(56, 189, 248, 0.2);
    padding: 10px;
    border-radius: var(--radius-md);
}

input[type="range"] {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #1e293b;
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-primary);
    border: 2px solid var(--color-cart-a);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.5);
    transition: transform 0.1s;
}

.cart-b-theme input[type="range"]::-webkit-slider-thumb {
    border-color: var(--color-cart-b);
    box-shadow: 0 0 10px rgba(251, 113, 133, 0.5);
}

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

.slider-marks {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Toggle Overlays Grid */
.toggle-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.toggle-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

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

.toggle-card.active {
    background: rgba(56, 189, 248, 0.12);
    border-color: var(--color-cart-a);
    color: var(--text-primary);
}

.toggle-icon {
    font-size: 0.9rem;
}

/* Action Buttons */
.action-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.button-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #0284c7, #0369a1);
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #38bdf8, #0284c7);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(56, 189, 248, 0.5);
}

.btn-secondary {
    background: #334155;
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: #475569;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.3);
    border-color: var(--color-danger);
    color: #ffffff;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.speed-control-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding-top: 4px;
}

.speed-buttons {
    display: flex;
    gap: 4px;
}

.speed-btn {
    background: #1e293b;
    border: 1px solid #334155;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

.speed-btn.active {
    background: var(--color-cart-a);
    color: #0f172a;
    font-weight: 700;
    border-color: var(--color-cart-a);
}

/* ==========================================================================
   Main Viewport & Physics Panel
   ========================================================================== */
.simulation-viewport-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-width: 0;
}

/* Key Law Banner */
.law-banner {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-lg);
    padding: 0.85rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    backdrop-filter: blur(8px);
}

.banner-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pulse-indicator {
    color: var(--color-success);
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.equality-formula {
    font-family: var(--font-code);
    font-size: 1.25rem;
    color: var(--text-primary);
}

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
}

.status-equal {
    background: rgba(74, 222, 128, 0.15);
    border: 1px solid rgba(74, 222, 128, 0.4);
    color: var(--color-success);
}

/* SVG Viewport */
.svg-container {
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-lg);
    height: 360px;
    width: 100%;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.6);
}

#simSvg {
    width: 100%;
    height: 100%;
    display: block;
}

/* SVG spoke animation */
.wheel .spoke {
    transform-origin: center;
}

/* ==========================================================================
   Telemetry Cards Grid
   ========================================================================== */
.telemetry-grid {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 1rem;
}

.telemetry-card {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    backdrop-filter: blur(8px);
}

.card-cart-a { border-top: 3px solid var(--color-cart-a); }
.card-cart-b { border-top: 3px solid var(--color-cart-b); }
.card-center-summary { border-top: 3px solid var(--color-warning); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.card-header h3 {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 700;
}

.badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 600;
}

.badge-a { background: var(--color-cart-a-bg); color: var(--color-cart-a); }
.badge-b { background: var(--color-cart-b-bg); color: var(--color-cart-b); }
.badge-system { background: rgba(251, 191, 36, 0.15); color: var(--color-warning); }

.metrics-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.82rem;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.m-value {
    font-family: var(--font-code);
    font-weight: 600;
    color: var(--text-primary);
}

.highlighted-a { color: var(--color-cart-a); font-size: 0.95rem; }
.highlighted-b { color: var(--color-cart-b); font-size: 0.95rem; }

/* Center Proof Comparison Box */
.comparison-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
    padding: 8px 12px;
    margin-bottom: 0.75rem;
}

.comp-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.comp-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.comp-val {
    font-family: var(--font-code);
    font-size: 1.05rem;
    font-weight: 700;
}

.val-a { color: var(--color-cart-a); }
.val-b { color: var(--color-cart-b); }
.val-total { color: var(--color-success); }

.comp-operator {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--color-warning);
}

/* Momentum Bar */
.momentum-conservation-box {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
    padding: 8px 12px;
}

.mom-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.mom-equation {
    font-family: var(--font-code);
    font-size: 0.85rem;
    margin-bottom: 6px;
    text-align: center;
}

.mom-bar-container {
    height: 8px;
    background: #1e293b;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    position: relative;
}

.mom-bar-fill-a {
    height: 100%;
    background: var(--color-cart-a);
    transition: width 0.1s;
}

.mom-bar-fill-b {
    height: 100%;
    background: var(--color-cart-b);
    transition: width 0.1s;
}

/* ==========================================================================
   Analytics & Tabs Section
   ========================================================================== */
.analytics-tabs-panel {
    background: var(--bg-card);
    border: 1px solid var(--bg-card-border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    backdrop-filter: blur(8px);
}

.tab-buttons {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding-bottom: 8px;
    margin-bottom: 1rem;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
    background: var(--color-cart-a-bg);
    color: var(--color-cart-a);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Chart Canvas */
.chart-container {
    position: relative;
    width: 100%;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.chart-header h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.chart-legend {
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 12px;
    height: 4px;
    border-radius: 2px;
}

.color-a { background: var(--color-cart-a); }
.color-b { background: var(--color-cart-b); }

canvas {
    width: 100%;
    display: block;
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
}

/* Theory Grid */
.theory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.theory-card {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
    padding: 1rem;
}

.theory-card h3 {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    color: var(--color-cart-a);
    margin-bottom: 8px;
}

.theory-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 10px;
}

.math-callout {
    background: #1e293b;
    padding: 8px;
    border-radius: var(--radius-sm);
    text-align: center;
    font-family: var(--font-code);
    color: var(--text-primary);
    font-size: 1.05rem;
    margin-bottom: 6px;
}

.card-subnote {
    font-size: 0.75rem !important;
    color: var(--text-muted) !important;
    font-style: italic;
}

/* Quiz Container */
.quiz-container {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.quiz-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid #1e293b;
    padding-bottom: 8px;
}

.quiz-header h3 {
    font-family: var(--font-heading);
    font-size: 1rem;
}

.quiz-score {
    background: var(--color-cart-a-bg);
    color: var(--color-cart-a);
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.85rem;
}

.quiz-questions-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.quiz-card h4 {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.quiz-opt {
    background: #1e293b;
    border: 1px solid #334155;
    color: var(--text-secondary);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    text-align: left;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.quiz-opt:hover:not(:disabled) {
    background: #334155;
    color: var(--text-primary);
}

.quiz-opt.correct {
    background: rgba(74, 222, 128, 0.2) !important;
    border-color: var(--color-success) !important;
    color: #ffffff !important;
}

.quiz-opt.incorrect {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: var(--color-danger) !important;
    color: #ffffff !important;
}

.quiz-feedback {
    margin-top: 6px;
    font-size: 0.8rem;
    padding: 6px 10px;
    border-radius: 4px;
}

.quiz-feedback.correct-fb {
    background: rgba(74, 222, 128, 0.15);
    color: var(--color-success);
}

.quiz-feedback.incorrect-fb {
    background: rgba(239, 68, 68, 0.15);
    color: var(--color-danger);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.app-footer {
    padding: 1rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--bg-card-border);
    margin-top: auto;
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 1200px) {
    .main-container {
        flex-direction: column;
    }
    .sidebar-panel {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
    }
    .telemetry-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar-panel {
        grid-template-columns: 1fr;
    }
    .app-header {
        flex-direction: column;
        height: auto;
        padding: 10px;
        gap: 8px;
    }
}

/* Mobile Portrait */
@media screen and (max-width: 767px) and (orientation: portrait) {
    .main-container {
        flex-direction: column;
        padding: 8px;
        gap: 10px;
    }
    .sidebar-panel {
        width: 100%;
        grid-template-columns: 1fr;
        order: 2;
    }
    .sim-area, .canvas-wrapper {
        order: 1;
    }
    .telemetry-grid {
        grid-template-columns: 1fr;
        order: 3;
    }
    canvas, svg {
        width: 100% !important;
        max-height: 45vh;
    }
    /* Touch-friendly targets */
    .btn, button, select, input[type="range"], .btn-icon {
        min-height: 44px;
        min-width: 44px;
        font-size: 16px !important;
    }
    .toggle-grid {
        grid-template-columns: 1fr;
    }
}

/* Mobile Landscape */
@media screen and (max-width: 950px) and (orientation: landscape) {
    .main-container {
        flex-direction: row;
        padding: 8px;
        gap: 10px;
    }
    .sidebar-panel {
        width: 240px;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        max-height: calc(100vh - 60px);
        overflow-y: auto;
    }
    .telemetry-grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}
