/* ============================================
   Dynamics Simulator — Shared Design System
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* --- Design Tokens --- */
:root {
    --bg-deep: #0a0c14;
    --bg-surface: rgba(16, 20, 32, 0.65);
    --bg-surface-hover: rgba(22, 28, 44, 0.8);
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.18);

    --text-primary: #f1f5f9;
    --text-secondary: rgba(255, 255, 255, 0.55);
    --text-muted: rgba(255, 255, 255, 0.35);

    --accent-orange: #f97316;
    --accent-red: #ef4444;
    --accent-violet: #8b5cf6;
    --accent-indigo: #6366f1;
    --accent-cyan: #06b6d4;
    --accent-emerald: #10b981;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 24px;

    --shadow-glow: 0 0 30px rgba(0, 0, 0, 0.5);
    --shadow-card: 0 10px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);

    --transition-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);

    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* --- Reset --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: -webkit-fill-available;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-deep);
    color: var(--text-primary);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Glass Panel --- */
.glass-panel {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}

/* --- Simulator Layout --- */
.sim-page {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.sim-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1.5rem;
    background: rgba(10, 12, 20, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-glass);
    z-index: 100;
    flex-shrink: 0;
}

.sim-topbar .back-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.25s ease;
}

.sim-topbar .back-link:hover {
    color: var(--text-primary);
}

.sim-topbar .back-link svg {
    width: 18px;
    height: 18px;
    transition: transform 0.25s ease;
}

.sim-topbar .back-link:hover svg {
    transform: translateX(-3px);
}

.sim-topbar .page-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.3px;
}

.sim-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.pendulum-top-wrap {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sim-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-deep);
}

.sim-canvas-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --- Controls Sidebar --- */
.controls-sidebar {
    width: 360px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: rgba(10, 14, 24, 0.92);
    backdrop-filter: blur(16px);
    border-left: 1px solid var(--border-glass);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 50;
}

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

.controls-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.controls-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.controls-section {
    padding: 1.2rem 1.4rem;
    border-bottom: 1px solid var(--border-glass);
}

.controls-section:last-child {
    border-bottom: none;
}

.section-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* --- Control Row --- */
.control-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

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

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.control-value {
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 0.85rem;
}

/* --- Slider --- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    outline: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    cursor: grab;
    transition: transform 0.2s var(--transition-spring);
}

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

input[type="range"]::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    border: none;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    cursor: grab;
}

/* --- Select Dropdown --- */
select {
    width: 100%;
    padding: 0.55rem 0.8rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.4)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
}

select:hover,
select:focus {
    border-color: rgba(255, 255, 255, 0.25);
}

select option {
    background: #1a1e2e;
    color: var(--text-primary);
}

/* --- Buttons --- */
.btn {
    padding: 0.65rem 1.5rem;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s var(--transition-spring);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-orange), var(--accent-red));
    color: white;
    box-shadow: 0 4px 15px rgba(249, 115, 22, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(249, 115, 22, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary.violet {
    background: linear-gradient(135deg, var(--accent-violet), var(--accent-indigo));
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.btn-primary.violet:hover {
    box-shadow: 0 6px 25px rgba(139, 92, 246, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-group {
    display: flex;
    gap: 0.6rem;
}

.btn-group .btn {
    flex: 1;
}

/* --- Toggle --- */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.8rem;
}

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

.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    cursor: pointer;
}

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

.toggle-track {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 11px;
    transition: background 0.3s ease;
}

.toggle-switch input:checked + .toggle-track {
    background: var(--accent-orange);
}

.toggle-track::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 3px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s var(--transition-spring);
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(18px);
}

/* --- Equations Panel --- */
.eq-panel {
    padding: 1.2rem 1.4rem;
}

.eq-panel .section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.eq-grid {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.eq-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.65rem;
    background: rgba(255, 255, 255, 0.025);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.03);
    transition: background 0.2s ease, border-color 0.2s ease;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.eq-row:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
}

.eq-row.highlight {
    border-color: rgba(249, 115, 22, 0.3);
    background: rgba(249, 115, 22, 0.05);
}

.eq-row.highlight.violet {
    border-color: rgba(139, 92, 246, 0.3);
    background: rgba(139, 92, 246, 0.05);
}

.eq-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 400;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.eq-label .formula {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-style: italic;
}

.eq-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    letter-spacing: 0.02em;
    text-align: right;
    min-width: 80px;
    word-break: break-all;
}

.eq-value .unit {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 0.25rem;
}

/* --- Mode Tabs --- */
.mode-tabs {
    display: flex;
    gap: 0;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-md);
    padding: 3px;
    margin-bottom: 1rem;
}

.mode-tab {
    flex: 1;
    padding: 0.55rem 1rem;
    border: none;
    border-radius: calc(var(--radius-md) - 2px);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.mode-tab.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

/* --- Footer --- */
.footer-text {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    padding: 1.5rem 0;
    position: relative;
    z-index: 10;
}

/* --- Mini Chart Panels --- */
.mini-charts {
    display: flex;
    gap: 1px;
    background: var(--border-glass);
    flex-shrink: 0;
}

.mini-chart {
    flex: 1;
    padding: 0.8rem;
    background: rgba(10, 14, 24, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mini-chart-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.mini-chart canvas {
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

/* --- Keyframe Animations --- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(40px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(249, 115, 22, 0.3);
    }
    50% {
        box-shadow: 0 4px 30px rgba(249, 115, 22, 0.6);
    }
}

@keyframes pulseViolet {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
    }
    50% {
        box-shadow: 0 4px 30px rgba(139, 92, 246, 0.6);
    }
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .sim-body {
        flex-direction: column;
        overflow: auto;
    }

    .pendulum-top-wrap {
        flex-direction: column;
        overflow: visible;
        flex: none;
    }

    .sim-canvas-wrap {
        height: 50vh;
        min-height: 300px;
        flex: none;
    }

    .controls-sidebar {
        width: 100%;
        flex: none;
        border-left: none;
        border-top: 1px solid var(--border-glass);
        overflow: visible;
    }

    .mini-charts {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .sim-topbar {
        padding: 0.6rem 1rem;
    }

    .sim-topbar .page-title {
        font-size: 1.05rem;
    }

    .controls-section {
        padding: 1.2rem 1rem;
    }

    .btn {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
    }

    .eq-label {
        font-size: 0.9rem !important;
    }

    .eq-label .formula {
        font-size: 0.8rem !important;
    }

    .eq-value {
        font-size: 1rem !important;
    }

    .eq-value .unit {
        font-size: 0.8rem !important;
    }

    .control-label {
        font-size: 0.95rem !important;
    }

    .control-value {
        font-size: 0.95rem !important;
    }

    .section-title {
        font-size: 0.8rem !important;
    }

    .toggle-label {
        font-size: 0.95rem !important;
    }

    .eq-ref-line {
        font-size: 0.85rem !important;
        line-height: 1.8 !important;
    }

    .eq-ref-card .ref-title {
        font-size: 0.75rem !important;
    }

    .sim-canvas-wrap {
        height: 40vh;
        min-height: 250px;
    }

    .eq-row {
        padding: 0.6rem 0.8rem;
    }
}
