/* CSS Variables for theming */
:root {
    --primary-color: #4a6cf7;
    --primary-hover: #3a5ce5;
    --secondary-color: #6c757d;
    --secondary-hover: #5a6268;
    --background-color: #f8f9fc;
    --surface-color: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

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

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #6366f1 100%);
    color: white;
    padding: 2rem 1.5rem;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.logo h1 {
    font-size: 2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Main Content */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Controls Panel */
.controls-panel {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
    height: fit-content;
    position: sticky;
    top: 1.5rem;
}

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

.control-group:last-of-type {
    margin-bottom: 1.5rem;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.control-icon {
    font-size: 1rem;
    opacity: 0.7;
}

/* Select Inputs */
select {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9375rem;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--surface-color);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
}

select:hover {
    border-color: var(--primary-color);
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.15);
}

/* Color Picker */
.color-picker-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

input[type="color"] {
    width: 100%;
    height: 44px;
    padding: 4px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

input[type="color"]:hover {
    border-color: var(--primary-color);
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

.color-presets {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.color-preset {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.color-preset:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

.color-preset:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Range Inputs */
input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    appearance: none;
    cursor: pointer;
}

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

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

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

/* Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon {
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #6366f1 100%);
    color: white;
    box-shadow: var(--shadow-md);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

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

.btn-secondary {
    background: var(--surface-color);
    color: var(--text-secondary);
    border: 1.5px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--background-color);
    color: var(--text-primary);
}

/* Preview Section */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-container,
.preview-container {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.input-container label,
.preview-container label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.75rem;
}

textarea {
    width: 100%;
    min-height: 150px;
    padding: 1rem;
    font-size: 1rem;
    font-family: inherit;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    resize: vertical;
    transition: var(--transition);
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.15);
}

textarea::placeholder {
    color: var(--text-secondary);
}

/* Paper Styles */
.paper {
    min-height: 400px;
    padding: 2rem;
    border-radius: var(--radius-md);
    overflow: auto;
    position: relative;
}

.paper.white {
    background: #ffffff;
    border: 1px solid var(--border-color);
}

.paper.lined {
    background:
        repeating-linear-gradient(
            transparent,
            transparent 31px,
            #c4d6eb 31px,
            #c4d6eb 32px
        );
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    padding-top: 32px;
}

.paper.grid {
    background:
        linear-gradient(to right, #e8e8e8 1px, transparent 1px),
        linear-gradient(to bottom, #e8e8e8 1px, transparent 1px);
    background-size: 20px 20px;
    background-color: #ffffff;
    border: 1px solid var(--border-color);
}

.paper.yellow {
    background: linear-gradient(
        to bottom,
        #fff9c4 0%,
        #fff59d 100%
    );
    background-color: #fff9c4;
    border: 1px solid #f0e68c;
    box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.03);
}

.paper.aged {
    background:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.08'/%3E%3C/svg%3E"),
        linear-gradient(to bottom right, #f5f0e1, #e8e0c8);
    background-color: #f5f0e1;
    border: 1px solid #d4c9a8;
}

.paper.blue-lined {
    background:
        linear-gradient(#e8f0ff 0px, #e8f0ff 31px, #a0c4ff 31px, #a0c4ff 32px);
    background-size: 100% 32px;
    background-color: #e8f0ff;
    border: 1px solid #a0c4ff;
    padding-top: 32px;
    position: relative;
}

.paper.blue-lined::before {
    content: '';
    position: absolute;
    top: 0;
    left: 60px;
    width: 2px;
    height: 100%;
    background: #ffb3b3;
}

#handwriting-output {
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 100%;
}

/* Footer */
.footer {
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 1.5rem;
    text-align: center;
    margin-top: auto;
}

.footer p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

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

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

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        position: static;
        order: 1;
    }

    .preview-section {
        order: 2;
    }

    .header {
        padding: 1.5rem 1rem;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .logo-img {
        width: 36px;
        height: 36px;
    }

    .tagline {
        font-size: 0.95rem;
    }

    .paper {
        min-height: 300px;
        padding: 1.5rem;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 1rem;
        gap: 1rem;
    }

    .controls-panel,
    .input-container,
    .preview-container {
        padding: 1rem;
    }

    .action-buttons {
        flex-direction: column;
    }

    .color-presets {
        justify-content: flex-start;
    }

    .logo {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* Print Styles */
@media print {
    .header,
    .controls-panel,
    .input-container,
    .footer,
    .action-buttons {
        display: none !important;
    }

    .main-content {
        display: block;
        padding: 0;
    }

    .paper {
        box-shadow: none;
        border: none;
    }
}

/* Animation for download feedback */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(0.98);
    }
}

.btn-downloading {
    animation: pulse 0.3s ease-in-out;
}

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

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

button:focus:not(:focus-visible),
select:focus:not(:focus-visible),
input:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
    outline: none;
}
