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

:root {
    /* Light Theme Colors */
    --primary-color: #667eea;
    --primary-dark: #764ba2;
    --secondary-color: #f093fb;
    --accent-color: #4facfe;
    --success-color: #00d2ff;
    --warning-color: #ff9a9e;
    --danger-color: #ff6b6b;
    
    /* Neutral Colors */
    --white: #ffffff;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    
    /* Theme Variables */
    --bg-primary: var(--white);
    --bg-secondary: var(--gray-50);
    --bg-tertiary: var(--gray-100);
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-700);
    --text-tertiary: var(--gray-500);
    --border-color: var(--gray-200);
    --shadow-light: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-medium: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-large: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Typography */
    --font-family-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-family-handwriting: 'Homemade Apple', cursive;
    
    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    
    /* Transitions */
    --transition-fast: 150ms ease-in-out;
    --transition-normal: 250ms ease-in-out;
    --transition-slow: 350ms ease-in-out;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: var(--gray-900);
    --bg-secondary: var(--gray-800);
    --bg-tertiary: var(--gray-700);
    --text-primary: var(--white);
    --text-secondary: var(--gray-200);
    --text-tertiary: var(--gray-400);
    --border-color: var(--gray-600);
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Glassmorphism Effect */
.glassmorphism {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-large);
}

[data-theme="dark"] .glassmorphism {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

.container-fluid {
    max-width: 100%;
    padding: 0 var(--spacing-md);
}

/* Header Styles */
.site-header {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(10px);
}

.navbar {
    padding: var(--spacing-md) 0;
}

.navbar .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.navbar-brand {
    display: flex;
    align-items: center;
}

.brand-link {
    text-decoration: none;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    font-weight: 700;
    font-size: 1.25rem;
}

.brand-icon {
    font-size: 1.5rem;
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
}

.navbar-nav {
    display: flex;
    list-style: none;
    gap: var(--spacing-lg);
    margin: 0;
}

.navbar-nav a {
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    transition: color var(--transition-fast);
}

.navbar-nav a:hover {
    color: var(--primary-color);
}

/* Theme Toggle */
.theme-toggle {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.theme-toggle:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="light"] .moon-icon {
    display: none;
}

/* Hero Section */
.hero-section {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: var(--spacing-2xl) 0;
    position: relative;
    overflow: hidden;
}

.hero-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="80" cy="40" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="40" cy="80" r="1" fill="rgba(255,255,255,0.1)"/></svg>');
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-20px); }
}

.hero-content {
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.hero-title {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: var(--spacing-lg);
    background: linear-gradient(45deg, #fff, #f0f0f0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-description {
    font-size: 1.25rem;
    margin-bottom: var(--spacing-xl);
    opacity: 0.9;
}

.cta-button {
    display: inline-block;
    background: white;
    color: var(--primary-color);
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-lg);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.125rem;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-medium);
}

.cta-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-large);
}

/* Features Section */
.features-section {
    padding: var(--spacing-2xl) 0;
}

.section-title {
    text-align: center;
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: var(--spacing-2xl);
    color: var(--text-primary);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-xl);
}

.feature-card {
    background: var(--bg-secondary);
    padding: var(--spacing-xl);
    border-radius: var(--radius-lg);
    text-align: center;
    transition: all var(--transition-normal);
    border: 1px solid var(--border-color);
}

.feature-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-large);
}

.feature-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-lg);
}

.feature-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.feature-card p {
    color: var(--text-secondary);
}

/* Converter App Styles */
.converter-app {
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: var(--spacing-xl) 0;
}

.app-header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
    color: white;
}

.app-title {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: var(--spacing-sm);
}

.app-subtitle {
    font-size: 1.125rem;
    opacity: 0.9;
}

.converter-layout {
    display: grid;
    grid-template-columns: 1fr 350px 1fr;
    gap: var(--spacing-xl);
    min-height: calc(100vh - 200px);
}

/* Card Styles */
.input-card, .controls-card, .output-card {
    padding: var(--spacing-xl);
    height: fit-content;
    position: sticky;
    top: var(--spacing-xl);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Input Section */
.character-count {
    font-size: 0.875rem;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
}

.paper-preview {
    background: white;
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    min-height: 400px;
    position: relative;
    box-shadow: var(--shadow-medium);
    border: 1px solid #e0e0e0;
}

.paper-preview.lined {
    background-image: linear-gradient(transparent 49px, #ccc 50px);
    background-size: 100% 50px;
}

.paper-preview.grid {
    background-image: 
        linear-gradient(to right, #f0f0f0 1px, transparent 1px),
        linear-gradient(to bottom, #f0f0f0 1px, transparent 1px);
    background-size: 20px 20px;
}

.paper-content {
    width: 100%;
    min-height: 300px;
    border: none;
    outline: none;
    font-family: var(--font-family-handwriting);
    font-size: 16px;
    line-height: 1.8;
    color: #000f55;
    resize: none;
}

.paper-content:empty::before {
    content: attr(placeholder);
    color: #999;
}

.input-actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
    flex-wrap: wrap;
}

/* Controls Section */
.controls-content {
    max-height: 70vh;
    overflow-y: auto;
    padding-right: var(--spacing-sm);
}

.control-group {
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.control-group:last-child {
    border-bottom: none;
}

.control-group h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: var(--spacing-lg);
    color: var(--text-primary);
}

.control-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.control-item {
    display: flex;
    flex-direction: column;
}

.control-item label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--spacing-xs);
}

/* Form Controls */
.modern-select {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modern-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.range-input {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.range-input input[type="range"] {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.range-input input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

.range-value {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-tertiary);
    min-width: 40px;
    text-align: center;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

/* Toggle Switches */
.toggle-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.toggle-switch {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    font-size: 0.875rem;
}

.toggle-slider {
    position: relative;
    width: 40px;
    height: 20px;
    background: var(--gray-300);
    border-radius: 10px;
    transition: background var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform var(--transition-fast);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary-color);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle-switch input {
    display: none;
}

/* File Upload */
.file-upload {
    position: relative;
}

.file-upload-btn {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--bg-tertiary);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.875rem;
    width: 100%;
    justify-content: center;
}

.file-upload-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    text-align: center;
    justify-content: center;
}

.action-btn.primary {
    background: var(--primary-color);
    color: white;
}

.action-btn.primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.action-btn.secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.action-btn.secondary:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.action-btn.danger {
    background: var(--danger-color);
    color: white;
}

.action-btn.danger:hover {
    background: #ff5252;
    transform: translateY(-1px);
}

/* Output Section */
.output-container {
    min-height: 300px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    border: 2px dashed var(--border-color);
}

.output-placeholder {
    text-align: center;
    padding: var(--spacing-2xl);
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: var(--spacing-lg);
    opacity: 0.5;
}

.output-placeholder h3 {
    font-size: 1.25rem;
    margin-bottom: var(--spacing-sm);
    color: var(--text-primary);
}

.output-placeholder p {
    color: var(--text-tertiary);
}

.output-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-lg);
}

.output-image {
    position: relative;
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-medium);
    transition: transform var(--transition-fast);
}

.output-image:hover {
    transform: scale(1.02);
}

.output-image img {
    width: 100%;
    height: auto;
    display: block;
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.output-image:hover .image-overlay {
    opacity: 1;
}

.overlay-actions {
    display: flex;
    gap: var(--spacing-sm);
}

.overlay-btn {
    background: white;
    border: none;
    border-radius: var(--radius-md);
    padding: var(--spacing-sm);
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.overlay-btn:hover {
    transform: scale(1.1);
}

.output-controls {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-lg);
    flex-wrap: wrap;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    backdrop-filter: blur(5px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-large);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: var(--spacing-lg);
}

#drawing-canvas {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: crosshair;
    display: block;
    margin-bottom: var(--spacing-lg);
}

.drawing-controls {
    display: flex;
    gap: var(--spacing-sm);
    justify-content: center;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    backdrop-filter: blur(5px);
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    text-align: center;
    color: white;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--spacing-lg);
}

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

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: var(--spacing-lg);
    right: var(--spacing-lg);
    z-index: 10002;
}

.toast {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-sm);
    box-shadow: var(--shadow-large);
    max-width: 300px;
    transform: translateX(400px);
    transition: transform var(--transition-normal);
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left: 4px solid var(--success-color);
}

.toast.error {
    border-left: 4px solid var(--danger-color);
}

.toast.warning {
    border-left: 4px solid var(--warning-color);
}

/* Footer */
.site-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-2xl) 0 var(--spacing-lg);
    margin-top: var(--spacing-2xl);
}

.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-xl);
    margin-bottom: var(--spacing-xl);
}

.footer-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: var(--spacing-md);
    color: var(--text-primary);
}

.footer-section p {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-md);
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: var(--spacing-xs);
}

.footer-section ul a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-section ul a:hover {
    color: var(--primary-color);
}

.footer-bottom {
    text-align: center;
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--border-color);
    color: var(--text-tertiary);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .converter-layout {
        grid-template-columns: 1fr;
        gap: var(--spacing-lg);
    }
    
    .controls-card {
        order: -1;
    }
    
    .control-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .hero-title {
        font-size: 2rem;
    }
    
    .hero-description {
        font-size: 1rem;
    }
    
    .section-title {
        font-size: 2rem;
    }
    
    .features-grid {
        grid-template-columns: 1fr;
    }
    
    .app-title {
        font-size: 2rem;
    }
    
    .navbar .container {
        flex-direction: column;
        gap: var(--spacing-md);
    }
    
    .input-actions,
    .output-controls,
    .drawing-controls {
        flex-direction: column;
    }
    
    .modal-content {
        margin: var(--spacing-md);
        max-width: calc(100vw - 2rem);
    }
    
    #drawing-canvas {
        width: 100%;
        max-width: 300px;
        height: 200px;
    }
    
    .toast-container {
        top: var(--spacing-sm);
        right: var(--spacing-sm);
        left: var(--spacing-sm);
    }
    
    .toast {
        max-width: none;
    }
}

@media (max-width: 480px) {
    .container,
    .container-fluid {
        padding: 0 var(--spacing-sm);
    }
    
    .hero-section,
    .features-section,
    .converter-app {
        padding: var(--spacing-lg) 0;
    }
    
    .input-card,
    .controls-card,
    .output-card {
        padding: var(--spacing-lg);
    }
    
    .paper-preview {
        padding: var(--spacing-md);
        min-height: 300px;
    }
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    .glassmorphism {
        background: var(--bg-primary);
        border: 2px solid var(--text-primary);
    }
    
    .action-btn {
        border: 2px solid currentColor;
    }
}

/* Focus styles for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Custom scrollbar */
.controls-content::-webkit-scrollbar {
    width: 6px;
}

.controls-content::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.controls-content::-webkit-scrollbar-thumb {
    background: var(--gray-400);
    border-radius: 3px;
}

.controls-content::-webkit-scrollbar-thumb:hover {
    background: var(--gray-500);
}