/* Mathematical Design System CSS */
/* A clean, modular stylesheet for the design system interface */

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Core Foundation */
    --ds-base-unit: 16px;
    --ds-scale-ratio: 1.25;
    --ds-baseline-unit: 4px;
    --ds-roundness-factor: 0.25;
    --ds-shadow-intensity: 0.1;

    /* Primary color */
    --ds-primary-h: 220;
    --ds-primary-s: 91%;
    --ds-primary-l: 60%;
    
    /* Mathematical constants */
    --phi: 1.618;
    --sqrt2: 1.414;
    
    /* Typography scale - calculated dynamically */
    --text-xs: 10.24px;
    --text-sm: 12.80px;
    --text-base: 16.00px;
    --text-lg: 20.00px;
    --text-xl: 25.00px;
    --text-2xl: 31.25px;
    --text-3xl: 39.06px;
    --text-4xl: 48.83px;
    --text-5xl: 61.04px;
    --text-6xl: 76.29px;
    
    /* Harmonic spacing system */
    --space-0: 0px;
    --space-1: 16px;
    --space-2: 18px;
    --space-3: 20px;
    --space-4: 21px;
    --space-6: 24px;
    --space-8: 26px;
    --space-12: 32px;
    --space-16: 38px;
    --space-20: 48px;
    --space-24: 58px;
    --space-32: 64px;
    --space-48: 96px;
    --space-64: 128px;
    
    /* Neutral color system */
    --white: #ffffff;
    --black: #000000;
    --gray-50: #fafafa;
    --gray-100: #f5f5f5;
    --gray-200: #e5e5e5;
    --gray-300: #d4d4d4;
    --gray-400: #a3a3a3;
    --gray-500: #737373;
    --gray-600: #525252;
    --gray-700: #404040;
    --gray-800: #262626;
    --gray-900: #171717;
    
    /* Primary color scale (HSL) */
    --primary-50: hsl(var(--ds-primary-h), var(--ds-primary-s), 97%);
    --primary-100: hsl(var(--ds-primary-h), var(--ds-primary-s), 93%);
    --primary-200: hsl(var(--ds-primary-h), var(--ds-primary-s), 86%);
    --primary-300: hsl(var(--ds-primary-h), var(--ds-primary-s), 76%);
    --primary-400: hsl(var(--ds-primary-h), var(--ds-primary-s), 64%);
    --primary-500: hsl(var(--ds-primary-h), var(--ds-primary-s), var(--ds-primary-l));
    --primary-600: hsl(var(--ds-primary-h), var(--ds-primary-s), 55%);
    --primary-700: hsl(var(--ds-primary-h), var(--ds-primary-s), 45%);
    --primary-800: hsl(var(--ds-primary-h), var(--ds-primary-s), 35%);
    --primary-900: hsl(var(--ds-primary-h), var(--ds-primary-s), 25%);

    /* Grid system defaults */
    --ds-grid-columns: 12;
    --ds-grid-gutter: 16px;
    --ds-container-padding: 24px;
    
    /* Physics-based shadow system */
    --shadow-xs: 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-sm: 0 2px 4px -2px rgba(0, 0, 0, 0.07);
    --shadow-md: 0 4px 8px -4px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 8px 16px -8px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 12px 24px -12px rgba(0, 0, 0, 0.03);
    
    /* Mathematical border radius scale */
    --radius-none: 0px;
    --radius-xs: 2px;
    --radius-sm: 4px;
    --radius-base: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 24px;
    --radius-full: 9999px;
    
    /* Natural animation timing */
    --duration-fast: 150ms;
    --duration-base: 200ms;
    --duration-slow: 300ms;
    --ease-natural: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* Additional dynamic tokens */
    --overlay-bg: color-mix(in srgb, var(--gray-900) 40%, transparent);
    --toast-bg: var(--gray-900);
    --toast-color: var(--white);
}

/* Base Typography */
body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: var(--text-base);
    line-height: calc(1.5 + var(--ds-baseline-unit) / 100);
    color: var(--gray-900);
    background: linear-gradient(180deg, var(--white), var(--gray-50));
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    scroll-behavior: smooth;
}

::selection {
    background: var(--primary-200);
    color: var(--gray-900);
}

@media (min-width: 768px) {
    body {
        line-height: calc(1.6 + var(--ds-baseline-unit) / 100);
    }
}

h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: calc(1 + var(--ds-baseline-unit) / var(--ds-base-unit));
    letter-spacing: calc(-0.02em / var(--scale-ratio));
}

/* Layout System */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    background: var(--gray-50);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: var(--space-6) var(--space-6);
    border-bottom: 1px solid var(--gray-200);
    background: var(--white);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--gray-900);
}

.tagline {
    font-size: var(--text-sm);
    color: var(--gray-500);
    margin-top: 4px;
    font-weight: 400;
}

/* Interactive Elements */
@property --interactive-scale {
    syntax: '<number>';
    initial-value: 1;
    inherits: false;
}

button,
.nav-item,
.personality-btn,
.btn-icon,
.property-item,
.example-button {
    --interactive-scale: 1;
    transform: scale(var(--interactive-scale));
    transition: background-color var(--duration-fast) var(--ease-natural),
                color var(--duration-fast) var(--ease-natural),
                box-shadow var(--duration-fast) var(--ease-natural),
                --interactive-scale var(--duration-fast) var(--ease-spring);
    will-change: transform, box-shadow;
}

button:hover,
.nav-item:hover,
.personality-btn:hover,
.btn-icon:hover,
.property-item:hover,
.example-button:hover {
    --interactive-scale: 1.02;
    box-shadow: var(--shadow-sm);
}

button:active,
.nav-item:active,
.personality-btn:active,
.btn-icon:active,
.property-item:active,
.example-button:active {
    --interactive-scale: 0.98;
    box-shadow: var(--shadow-xs);
}

button:focus-visible,
.nav-item:focus-visible,
.personality-btn:focus-visible,
.btn-icon:focus-visible,
.property-item:focus-visible,
.example-button:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: var(--space-1);
}

/* Navigation System */
.nav {
    padding: var(--space-4) 0;
}

.nav-section {
    margin-bottom: var(--space-1);
}

.nav-section-title {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2) var(--space-6);
    user-select: none;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px var(--space-6);
    font-size: 14px;
    color: var(--gray-700);
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.nav-item:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

.nav-item.active {
    background: var(--white);
    color: var(--gray-900);
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}

/* Main Content Area */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    height: 60px;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 var(--space-8);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--white);
    position: sticky;
    top: 0;
    z-index: 5;
}

.header-title {
    font-size: var(--text-xl);
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--gray-900);
}

.header-actions {
    display: flex;
    gap: var(--space-3);
}

.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--white);
    color: var(--gray-600);
    cursor: pointer;
}

.btn-icon:hover {
    border-color: var(--gray-300);
    color: var(--gray-900);
    transform: translateY(-1px) scale(var(--interactive-scale));
    box-shadow: var(--shadow-sm);
}

.btn-icon:active {
    transform: translateY(0) scale(var(--interactive-scale));
}

/* Content and Grid System */
.content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-12);
    background: var(--gray-50);
}

.content-grid {
    max-width: 1400px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr));
    gap: var(--space-12);
}

/* Preview Section */
.preview-section {
    contain: layout style;
    isolation: isolate;
    background: linear-gradient(180deg, var(--white), var(--gray-50));
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm), var(--shadow-xs);
}

.preview-title {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--space-6);
    color: var(--gray-900);
    letter-spacing: -0.01em;
}

/* Properties Panel */
.properties-panel {
    background: linear-gradient(180deg, var(--gray-50), var(--white));
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    height: fit-content;
    position: sticky;
    top: var(--space-12);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm), var(--shadow-xs);
}

.property-group {
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-6);
    border-bottom: 1px solid var(--gray-200);
}

.property-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.property-group-title {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: var(--space-3);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.property-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin: 0 -12px;
    border-radius: var(--radius-md);
    cursor: pointer;
}

.property-item:hover {
    background: var(--white);
    box-shadow: var(--shadow-xs);
    transform: translateY(-1px) scale(var(--interactive-scale));
}

.property-label {
    font-size: 13px;
    color: var(--gray-600);
    font-weight: 500;
}

.property-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-900);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

/* Copy Toast Notification */
.copy-toast {
    position: fixed;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--gray-900);
    color: var(--white);
    padding: 12px 20px;
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: 500;
    opacity: 0;
    transition: all var(--duration-base) var(--ease-spring);
    pointer-events: none;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.copy-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Example Components */
.example-grid {
    display: grid;
    gap: var(--space-8);
}

.example-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    transition: all var(--duration-base) var(--ease-natural);
}

.example-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.example-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: var(--primary-500);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

.example-button:hover {
    background: var(--primary-600);
    transform: translateY(-1px) scale(var(--interactive-scale));
    box-shadow: var(--shadow-md);
}

.example-button:active {
    transform: translateY(0) scale(var(--interactive-scale));
    box-shadow: var(--shadow-sm);
}

.example-input {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    background: var(--white);
    transition: all var(--duration-fast) var(--ease-natural);
    font-family: inherit;
}

.example-input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px var(--primary-100);
}

.example-input::placeholder {
    color: var(--gray-400);
}

/* Formula Display System */
.formula-card {
    background: var(--gray-900);
    color: var(--gray-100);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-top: var(--space-4);
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    box-shadow: var(--shadow-sm);
}

.formula-line {
    display: flex;
    align-items: center;
    padding: 4px 0;
}

.formula-label {
    color: var(--gray-500);
    min-width: 120px;
    font-weight: 500;
}

.formula-value {
    color: #79c0ff;
    font-weight: 600;
}

.formula-operator {
    color: #ff7b72;
    margin: 0 8px;
    font-weight: 600;
}

.formula-number {
    color: #a5d6ff;
    font-weight: 500;
}

/* Controls Section */
.controls-section {
    contain: layout style paint;
    overflow-y: auto;
    height: 100vh;
    background: linear-gradient(180deg, var(--white), var(--gray-50));
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    border: 1px solid var(--gray-200);
    margin-bottom: var(--space-8);
    box-shadow: var(--shadow-sm), var(--shadow-xs);
}

/* Generic control section */
.control-section {
    background: linear-gradient(180deg, var(--white), var(--gray-50));
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    border: 1px solid var(--gray-200);
    margin-bottom: var(--space-8);
    box-shadow: var(--shadow-sm), var(--shadow-xs);
}

.control-group {
    margin-bottom: var(--space-6);
}

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

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: var(--space-2);
}

.control-slider {
    width: 100%;
    height: 32px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
}

.control-slider::-webkit-slider-track {
    width: 100%;
    height: 4px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-500);
    border-radius: 50%;
    cursor: pointer;
    margin-top: -6px;
    box-shadow: var(--shadow-md);
    transition: all var(--duration-fast) var(--ease-natural);
}

.control-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.control-slider::-moz-range-track {
    width: 100%;
    height: 4px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    border: none;
}

.control-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary-500);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow-md);
    transition: all var(--duration-fast) var(--ease-natural);
}

.control-value {
    display: inline-block;
    padding: 4px 8px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 600;
    font-family: 'SF Mono', Monaco, monospace;
    color: var(--gray-700);
}

/* Personality Selection Grid */
.personality-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-6);
}

.personality-btn {
    padding: 12px;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--white);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    color: var(--gray-700);
    font-family: inherit;
}

.personality-btn:hover {
    border-color: var(--primary-300);
    background: var(--primary-50);
    color: var(--primary-700);
    transform: translateY(-1px) scale(var(--interactive-scale));
    box-shadow: var(--shadow-sm);
}

.personality-btn.active {
    border-color: var(--primary-500);
    background: var(--primary-100);
    color: var(--primary-700);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* Toast Notification System */
.toast-container {
    position: fixed;
    top: var(--space-6);
    right: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    z-index: calc(var(--phi) * 1000);
}

.toast {
    background: var(--toast-bg);
    color: var(--toast-color);
    padding: var(--space-4) var(--space-6);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(calc(-1 * var(--space-2)));
    animation: toast-enter var(--duration-base) var(--ease-natural) forwards;
    will-change: transform, opacity;
}

.toast.hide {
    animation: toast-exit var(--duration-base) var(--ease-natural) forwards;
}

@keyframes toast-enter {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-exit {
    to {
        opacity: 0;
        transform: translateY(calc(-1 * var(--space-2)));
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg);
    backdrop-filter: blur(var(--space-1));
    z-index: calc(var(--phi) * 1000);
    will-change: opacity;
    opacity: 0;
    transition: opacity var(--duration-base) var(--ease-natural);
}

.loading-overlay.active {
    opacity: 1;
}

.loading-overlay[aria-hidden="true"] {
    display: none;
}

/* Modal System */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg);
    backdrop-filter: blur(var(--space-1));
    z-index: calc(var(--phi) * 1000);
    opacity: 0;
    animation: overlay-fade var(--duration-base) var(--ease-natural) forwards;
    will-change: opacity;
}
.modal-overlay[aria-hidden="true"] {
    display: none;
}

.modal {
    background: var(--white);
    color: var(--gray-900);
    border-radius: var(--radius-xl);
    padding: var(--space-8);
    max-width: min(90vw, 500px);
    width: 100%;
    box-shadow: var(--shadow-lg);
    transform: translateY(calc(var(--space-2) * -1)) scale(0.95);
    animation: modal-in var(--duration-base) var(--ease-spring) forwards;
    will-change: transform, opacity;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
}
.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: var(--space-2);
    line-height: 0;
    color: inherit;
}
.modal-close:hover,
.modal-close:focus {
    outline: 2px solid var(--primary-500, currentColor);
    outline-offset: 2px;
}

@media (max-width: 480px) {
    .modal {
        padding: var(--space-6);
    }
}

@keyframes overlay-fade {
    to {
        opacity: 1;
    }
}

@keyframes modal-in {
    to {
        transform: translateY(0) scale(1);
    }
}

/* Responsive Design */
@media (max-width: 1200px) {
    .content-grid {
        grid-template-columns: 1fr;
    }
    
    .properties-panel {
        position: static;
        max-width: 600px;
        margin: 0 auto;
    }
}

@media (max-width: 768px) {
    .sidebar {
        display: none;
    }
    
    .content {
        padding: var(--space-6);
    }
    
    .content-grid {
        gap: var(--space-6);
    }
    
    .header {
        padding: 0 var(--space-6);
    }
    
    .personality-grid {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    }
}

@media (max-width: 480px) {
    .content {
        padding: var(--space-4);
    }
    
    .preview-section,
    .controls-section {
        padding: var(--space-6);
    }
    
    .properties-panel {
        padding: var(--space-4);
    }
}

/* Focus and Accessibility */
.control-slider:focus-visible {
    outline: 2px solid var(--primary-500);
    outline-offset: var(--space-2);
}

/* Print Styles */
@media print {
    body {
        background: var(--white);
        color: var(--gray-900);
    }

    .sidebar {
        display: none;
    }

    .content {
        padding: var(--space-6);
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --white: #0a0a0a;
        --gray-50: #141414;
        --gray-100: #1a1a1a;
        --gray-200: #262626;
        --gray-300: #404040;
        --gray-400: #525252;
        --gray-500: #737373;
        --gray-600: #a3a3a3;
        --gray-700: #d4d4d4;
        --gray-800: #e5e5e5;
        --gray-900: #f5f5f5;
        --black: #ffffff;
        --overlay-bg: color-mix(in srgb, var(--black) 60%, transparent);
        --toast-bg: var(--gray-100);
        --toast-color: var(--gray-900);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

:root[data-theme='dark'] {
    --white: #0a0a0a;
    --gray-50: #141414;
    --gray-100: #1a1a1a;
    --gray-200: #262626;
    --gray-300: #404040;
    --gray-400: #525252;
    --gray-500: #737373;
    --gray-600: #a3a3a3;
    --gray-700: #d4d4d4;
    --gray-800: #e5e5e5;
    --gray-900: #f5f5f5;
    --black: #ffffff;
    --overlay-bg: color-mix(in srgb, var(--black) 60%, transparent);
    --toast-bg: var(--gray-100);
    --toast-color: var(--gray-900);
}
