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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: relative;
}

.header {
    background: white;
    padding: 1.5rem 2rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    text-align: center;
    border-bottom: 3px solid #4A90E2;
}

.header h1 {
    font-size: 2.2rem;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
    background: linear-gradient(45deg, #2c3e50, #4A90E2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.1rem;
    color: #666;
    font-weight: 300;
    margin-bottom: 1rem;
}

.illusion-strength-meter {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.9rem;
    color: #555;
}

.meter-bar {
    width: 150px;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}

.meter-fill {
    height: 100%;
    transition: width 0.3s ease, background-color 0.3s ease;
    border-radius: 3px;
}

.meter-fill.low {
    background: linear-gradient(90deg, #27AE60, #2ECC71);
}

.meter-fill.medium {
    background: linear-gradient(90deg, #F39C12, #E67E22);
}

.meter-fill.high {
    background: linear-gradient(90deg, #E74C3C, #C0392B);
}

.main-content {
    display: flex;
    flex: 1;
    gap: 2rem;
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

.canvas-container {
    flex: 1;
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    overflow: hidden;
    transition: box-shadow 0.3s ease;
    min-height: 700px;
}

.canvas-container:hover {
    box-shadow: 0 12px 48px rgba(74, 144, 226, 0.15);
}

#canvas {
    width: 100%;
    height: 700px;
    display: block;
    cursor: crosshair;
    transition: transform 0.2s ease;
}

#canvas:active {
    transform: scale(0.99);
}

.performance-info {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    backdrop-filter: blur(10px);
}

.zoom-controls {
    position: absolute;
    top: 15px;
    left: 15px;
    display: flex;
    gap: 0.5rem;
    flex-direction: column;
}

.zoom-controls button {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(0,0,0,0.8);
    color: white;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.zoom-controls button:hover {
    background: rgba(74, 144, 226, 0.9);
    transform: scale(1.05);
}

.controls-panel {
    width: 400px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    padding: 1.5rem;
    max-height: 700px;
    overflow-y: auto;
    transition: box-shadow 0.3s ease;
}

.controls-panel:hover {
    box-shadow: 0 12px 48px rgba(74, 144, 226, 0.1);
}

.control-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #f0f0f0;
}

.control-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.control-section h3 {
    color: #2c3e50;
    margin-bottom: 1.2rem;
    font-size: 1.1rem;
    font-weight: 600;
    position: relative;
}

.control-section h3:after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 0;
    width: 30px;
    height: 2px;
    background: #4A90E2;
}

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

.control-group label {
    display: block;
    margin-bottom: 0.6rem;
    font-weight: 500;
    color: #555;
    font-size: 0.9rem;
}

.width-controls label {
    color: #4A90E2;
    font-weight: 600;
}

.height-controls label {
    color: #27AE60;
    font-weight: 600;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

input[type="range"] {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: #e8e8e8;
    outline: none;
    appearance: none;
    transition: background 0.2s ease;
}

input[type="range"]:hover {
    background: #ddd;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #4A90E2;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: #357abd;
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.width-controls input[type="range"]::-webkit-slider-thumb {
    background: #4A90E2;
}

.height-controls input[type="range"]::-webkit-slider-thumb {
    background: #27AE60;
}

input[type="range"]::-moz-range-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #4A90E2;
    cursor: pointer;
    border: none;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
}

.fine-tune-btn {
    width: 36px;
    height: 36px;
    border: 2px solid #4A90E2;
    background: white;
    color: #4A90E2;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
    font-size: 1.1rem;
}

.fine-tune-btn:hover {
    background: #4A90E2;
    color: white;
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

.value-display {
    text-align: center;
    margin-top: 0.5rem;
}

.value-display span {
    background: #f8f9fa;
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-weight: 600;
    border: 1px solid #e9ecef;
    font-size: 0.85rem;
    min-width: 60px;
    display: inline-block;
}

.width-indicator {
    color: #4A90E2 !important;
    border-color: #4A90E2 !important;
    background: rgba(74, 144, 226, 0.1) !important;
}

.height-indicator {
    color: #27AE60 !important;
    border-color: #27AE60 !important;
    background: rgba(39, 174, 96, 0.1) !important;
}

.aspect-controls {
    margin: 1rem 0;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #9B59B6;
}

.aspect-lock {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    color: #9B59B6;
}

.aspect-lock input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #9B59B6;
}

.preset-rectangles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
    margin-top: 1rem;
}

.preset-btn {
    padding: 0.7rem 0.5rem;
    border: 2px solid #e9ecef;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 0.85rem;
    text-align: center;
}

.preset-btn:hover {
    border-color: #4A90E2;
    background: #f0f8ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.pattern-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.pattern-btn {
    padding: 0.8rem 1rem;
    border: 2px solid #e9ecef;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    font-weight: 500;
    font-size: 0.9rem;
    position: relative;
}

.pattern-btn:hover {
    border-color: #4A90E2;
    background: #f0f8ff;
    transform: translateX(4px);
}

.pattern-btn.active {
    border-color: #4A90E2;
    background: #4A90E2;
    color: white;
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

.pattern-btn.active:before {
    content: '✓';
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
}

.animation-controls {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.animation-btn {
    padding: 0.75rem 1rem;
    background: #95a5a6;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.animation-btn:hover {
    background: #7f8c8d;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.animation-btn.active {
    background: #E67E22;
    box-shadow: 0 4px 12px rgba(230, 126, 34, 0.3);
}

.color-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.color-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.color-group label {
    margin-bottom: 0;
    min-width: 80px;
    font-weight: 500;
}

input[type="color"] {
    width: 50px;
    height: 40px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0,0,0,0.15);
    transition: transform 0.2s ease;
}

input[type="color"]:hover {
    transform: scale(1.05);
}

.preset-colors {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.6rem;
}

.color-preset {
    padding: 0.6rem 0.4rem;
    border: 2px solid #e9ecef;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    font-size: 0.85rem;
}

.color-preset:hover {
    border-color: #4A90E2;
    background: #f0f8ff;
    transform: scale(1.05);
}

.export-controls {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
}

.action-btn {
    padding: 0.8rem 0.6rem;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.action-btn:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.info-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    padding: 2rem;
    max-width: 600px;
    z-index: 1000;
    display: none;
    max-height: 80vh;
    overflow-y: auto;
}

.info-panel h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.3rem;
}

.info-panel p {
    line-height: 1.6;
    margin-bottom: 1rem;
    color: #555;
}

.info-panel ul {
    margin: 1rem 0;
    padding-left: 1.5rem;
}

.info-panel li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.info-toggle {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    border: none;
    background: #4A90E2;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.5rem;
    font-weight: bold;
    box-shadow: 0 4px 16px rgba(74, 144, 226, 0.3);
    transition: all 0.2s ease;
    z-index: 100;
}

.info-toggle:hover {
    background: #357abd;
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(74, 144, 226, 0.4);
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 32px;
    height: 32px;
    border: none;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: #c82333;
    transform: scale(1.1);
}

#dimension-display {
    color: #4A90E2;
    font-weight: bold;
}

#ratio-display {
    color: #27AE60;
    font-weight: bold;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }
    
    .controls-panel {
        width: 100%;
        max-height: none;
        order: 2;
    }
    
    .canvas-container {
        order: 1;
    }
    
    .preset-rectangles {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
        gap: 1rem;
    }
    
    .header {
        padding: 1rem;
    }
    
    .header h1 {
        font-size: 1.8rem;
    }
    
    .controls-panel {
        padding: 1rem;
    }
    
    .preset-rectangles {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .preset-colors {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .export-controls {
        grid-template-columns: 1fr;
    }
    
    #canvas {
        height: 400px;
    }
    
    .canvas-container {
        min-height: 400px;
    }
    
    .illusion-strength-meter {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .performance-info {
        flex-direction: column;
        gap: 0.5rem;
        font-size: 0.75rem;
        padding: 0.5rem;
    }
}

/* Custom scrollbar */
.controls-panel::-webkit-scrollbar {
    width: 8px;
}

.controls-panel::-webkit-scrollbar-track {
    background: #f8f9fa;
    border-radius: 4px;
}

.controls-panel::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.controls-panel::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Animations */
@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(20px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

.control-section {
    animation: fadeIn 0.3s ease;
}

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

.animation-btn.active {
    animation: pulse 2s ease-in-out infinite;
}

/* Focus styles for accessibility */
input:focus, button:focus {
    outline: 3px solid rgba(74, 144, 226, 0.3);
    outline-offset: 2px;
}

/* Loading animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading {
    animation: spin 1s linear infinite;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .controls-panel {
        border: 2px solid #000;
    }
    
    .preset-btn, .pattern-btn, .animation-btn, .action-btn, .color-preset {
        border-width: 3px;
    }
}

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