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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 15px;
}

/* Sticky Header */
.sticky-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid rgba(102, 126, 234, 0.3);
    z-index: 1000;
    padding: 15px 0;
}

.header-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
}

.sticky-header h1 {
    color: white;
    font-size: 1.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    margin: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.speed-control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.speed-control-group label {
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
}

.speed-control-group select {
    padding: 8px 12px;
    border: 2px solid #374151;
    border-radius: 6px;
    background: white;
    font-size: 0.9rem;
    min-width: 180px;
}

.custom-speed-controls {
    display: none;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 12px;
    border-radius: 6px;
}

.custom-speed-controls input[type="range"] {
    width: 120px;
    margin: 0;
}

.custom-speed-controls input[type="number"] {
    width: 80px;
    padding: 4px 8px;
    border: 1px solid #374151;
    border-radius: 4px;
    font-size: 0.9rem;
}

.unit-label {
    color: white;
    font-size: 0.8rem;
    opacity: 0.8;
}

.action-buttons {
    display: flex;
    gap: 8px;
}

.step-btn {
    background: #f59e0b;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.step-btn:hover:not(:disabled) {
    background: #d97706;
    transform: translateY(-1px);
}

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

.primary-btn, .secondary-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.primary-btn {
    background: #667eea;
    color: white;
}

.primary-btn:hover:not(:disabled) {
    background: #5a6fd8;
    transform: translateY(-1px);
}

.secondary-btn {
    background: #6b7280;
    color: white;
}

.secondary-btn:hover:not(:disabled) {
    background: #4b5563;
    transform: translateY(-1px);
}

.primary-btn:disabled, .secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Status Overlay */
.status-overlay {
    position: fixed;
    top: 120px;
    right: 20px;
    z-index: 999;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 15px;
    color: white;
    text-align: center;
    min-width: 200px;
}

.generation-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 8px;
}

.mode-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mode-badge.setup {
    background: rgba(147, 51, 234, 0.3);
    border: 1px solid rgba(147, 51, 234, 0.6);
}

.mode-badge.generating {
    background: rgba(22, 163, 74, 0.3);
    border: 1px solid rgba(22, 163, 74, 0.6);
    animation: pulse 2s infinite;
}

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

.point-counter {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 1.1rem;
    font-weight: bold;
}

/* Main Content */
.main-content {
    margin-top: 140px;
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 20px;
    margin-bottom: 20px;
}

.canvas-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.canvas-container {
    position: relative;
    background: rgba(255, 255, 255, 0.98);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

#sierpinski-canvas {
    border: 3px dashed #9333ea;
    border-radius: 12px;
    cursor: grab;
    touch-action: none;
    max-width: 100%;
    height: auto;
    transition: border-color 0.3s ease;
}

#sierpinski-canvas:active {
    cursor: grabbing;
}

.canvas-instructions {
    position: absolute;
    top: 25px;
    left: 25px;
    right: 25px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 15px;
    border-radius: 12px;
    pointer-events: none;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.instruction-step {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 6px 0;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.3s ease;
    opacity: 0.5;
    font-size: 0.9rem;
}

.instruction-step.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.instruction-step.completed {
    opacity: 0.7;
    text-decoration: line-through;
}

.step-number {
    background: #667eea;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.instruction-step.completed .step-number {
    background: #16a34a;
}

.step-text {
    flex: 1;
}

/* Step Analysis Panel */
.step-analysis-panel {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    min-height: 300px;
}

.step-analysis-panel h4 {
    color: #475569;
    margin-bottom: 15px;
    font-size: 1.1rem;
    font-weight: 700;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 8px;
}

.analysis-placeholder {
    color: #64748b;
    font-style: italic;
    text-align: center;
    padding: 40px 20px;
}

.analysis-section {
    margin-bottom: 20px;
}

.analysis-section h5 {
    color: #374151;
    font-size: 1rem;
    margin-bottom: 10px;
    font-weight: 600;
}

.step-details {
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 15px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    margin: 6px 0;
    font-size: 0.9rem;
}

.label {
    color: #64748b;
    font-weight: 500;
}

.value {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    color: #1e293b;
    font-weight: 600;
}

.stats-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 500;
}

.stat-value {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    color: #1e293b;
    font-weight: 600;
}

.stat-bar {
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.stat-fill {
    height: 100%;
    transition: width 0.3s ease;
    border-radius: 3px;
}

/* Settings Panel */
.settings-panel {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 16px;
    padding: 20px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    height: fit-content;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.panel-section {
    margin-bottom: 25px;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 20px;
}

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

.panel-section h3 {
    color: #475569;
    margin-bottom: 15px;
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.preset-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 15px;
}

.preset-btn {
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 40px;
}

.preset-btn:hover {
    border-color: #9333ea;
    color: #9333ea;
    transform: translateY(-1px);
}

.preset-btn.active {
    background: #9333ea;
    border-color: #9333ea;
    color: white;
}

.coordinates-display {
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px;
    margin: 10px 0;
    font-size: 0.85rem;
}

.coord-header {
    font-weight: 600;
    color: #475569;
    margin-bottom: 8px;
}

.vertex-coord,
.start-point-coord {
    display: flex;
    justify-content: space-between;
    margin: 6px 0;
    padding: 4px 8px;
    background: white;
    border-radius: 4px;
}

.vertex-label {
    color: #64748b;
    font-weight: 500;
}

.coord-values {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    color: #1e293b;
    font-weight: 600;
}

.start-point-coord {
    border-left: 3px solid #ef4444;
}

.control-group {
    margin-bottom: 18px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #475569;
    font-size: 0.9rem;
}

select {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: white;
    font-size: 1rem;
    cursor: pointer;
    min-height: 48px;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%23475569" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
}

select:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

input[type="range"] {
    width: 100%;
    margin: 12px 0 8px 0;
    -webkit-appearance: none;
    height: 8px;
    border-radius: 4px;
    background: #e2e8f0;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

input[type="checkbox"] {
    margin-right: 10px;
    transform: scale(1.4);
    cursor: pointer;
    accent-color: #667eea;
}

/* Offscreen Notice */
.offscreen-notice {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(239, 68, 68, 0.95);
    color: white;
    padding: 15px 20px;
    border-radius: 10px;
    z-index: 1000;
    text-align: center;
    backdrop-filter: blur(10px);
    border: 2px solid rgba(239, 68, 68, 0.5);
}

.notice-content {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.notice-content button {
    background: white;
    color: #ef4444;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.notice-content button:hover {
    background: #f3f4f6;
    transform: translateY(-1px);
}

/* Footer */
footer {
    text-align: center;
    color: white;
    opacity: 0.95;
    margin-top: 20px;
    font-size: 0.9rem;
}

footer a {
    color: #fbbf24;
    text-decoration: none;
    font-weight: 600;
}

footer a:hover {
    text-decoration: underline;
}

footer p {
    margin-bottom: 6px;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr 320px;
        gap: 15px;
    }
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .settings-panel {
        max-height: none;
    }
    
    .header-content {
        flex-direction: column;
        gap: 10px;
    }
    
    .header-controls {
        width: 100%;
        justify-content: center;
    }
    
    .status-overlay {
        position: relative;
        top: 0;
        right: 0;
        margin-bottom: 15px;
    }
    
    .main-content {
        margin-top: 20px;
    }
}

@media (max-width: 768px) {
    .sticky-header h1 {
        font-size: 1.2rem;
    }
    
    .header-controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .preset-buttons {
        grid-template-columns: 1fr;
    }
    
    .action-buttons {
        flex-direction: column;
        width: 100%;
    }
    
    .action-buttons button {
        width: 100%;
    }
    
    .canvas-instructions {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        margin-bottom: 15px;
    }
    
    input[type="range"]::-webkit-slider-thumb,
    input[type="range"]::-moz-range-thumb {
        width: 28px;
        height: 28px;
    }
}

/* Accessibility */
:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

button:focus,
select:focus,
input:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* Loading states */
.controls-panel {
    transition: all 0.3s ease;
}

.canvas-container {
    transition: all 0.3s ease;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .settings-panel,
    .canvas-container,
    .step-analysis-panel {
        background: rgba(255, 255, 255, 1);
        border: 3px solid #000;
    }
    
    #sierpinski-canvas {
        border: 3px solid #000;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .settings-panel,
    .canvas-container,
    .step-analysis-panel {
        background: rgba(31, 41, 55, 0.98);
        color: #f3f4f6;
        border-color: rgba(55, 65, 81, 0.8);
    }
    
    .panel-section h3,
    .step-analysis-panel h4 {
        color: #d1d5db;
    }
    
    .coordinates-display,
    .step-details {
        background: #374151;
        color: #f3f4f6;
    }
    
    .vertex-coord,
    .start-point-coord {
        background: #4b5563;
    }
    
    .vertex-label,
    .label,
    .stat-label {
        color: #9ca3af;
    }
    
    .coord-values,
    .value,
    .stat-value {
        color: #f3f4f6;
    }
    
    select,
    .preset-btn {
        background: #374151;
        color: #f3f4f6;
        border-color: #4b5563;
    }
    
    .preset-btn:hover {
        border-color: #9333ea;
        color: #9333ea;
    }
}

/* Smooth scrollbar */
.settings-panel::-webkit-scrollbar {
    width: 8px;
}

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

.settings-panel::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
}

.settings-panel::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}