/* ===================================
   Vintage Letter Studio - "The Writing Desk" Redesign
   Clean, Warm, Elegant, Focused
   =================================== */

/* === ROOT VARIABLES === */
:root {
    /* Color Palette - Warm & Natural */
    --color-paper: #FDFBF7;
    --color-paper-shadow: #E8E4D9;
    --color-ink: #2C3338;
    --color-ink-light: #5C6B73;
    
    --color-accent: #D4AF37; /* Gold */
    --color-primary: #8B4513; /* Saddle Brown */
    --color-primary-light: #A0522D;
    
    --color-success: #10B981;
    --color-error: #EF4444;
    --color-info: #3B82F6;

    /* Backgrounds */
    --bg-main: #F8F5F0; /* Refined Warm Alabaster */
    --bg-panel: #FFFFFF;
    
    /* Borders */
    --border-light: #E8E2D8;
    --border-focus: #D4AF37;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -1px rgba(0,0,0,0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.05), 0 4px 6px -2px rgba(0,0,0,0.025);
    --shadow-paper: 0 1px 3px rgba(0,0,0,0.1), 0 10px 20px rgba(0,0,0,0.05);

    /* Typography */
    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-heading: 'Playfair Display', serif;
    --font-body: 'Crimson Text', serif;
    
    /* Layout */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    
    /* Transitions */
    --transition: 0.2s ease-in-out;
}

/* Dark Mode Overrides - "Midnight Study" */
.dark {
    --color-paper: #1E1E24;
    --color-paper-shadow: #121216;
    --color-ink: #E4E4E7;
    --color-ink-light: #A1A1AA;
    
    --bg-main: #121212;
    --bg-panel: #1C1C1E;
    
    --border-light: #27272A;
}

/* === BASE RESET & TYPOGRAPHY === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    background-image: radial-gradient(circle, rgba(255,255,255,0.8) 0%, rgba(232,226,216,0.3) 100%);
    color: var(--color-ink);
    font-family: var(--font-ui);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3, h4 {
    font-family: var(--font-heading);
    color: var(--color-ink);
    font-weight: 700;
}

button, input, textarea {
    font-family: inherit;
}

/* === LAYOUT STRUCTURE === */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    color: var(--color-ink);
}

.brand-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.brand-text h1 {
    font-size: 1.5rem;
    line-height: 1.2;
}

.brand-text p {
    font-size: 0.875rem;
    color: var(--color-ink-light);
    font-family: var(--font-ui);
}

/* Navigation Actions */
.nav-actions {
    display: flex;
    gap: 0.75rem;
}

/* Main Editor Area */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    align-items: start;
}

/* === PANELS & CARDS === */
.panel {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    overflow: hidden;
}

/* === LEFT SIDE: EDITOR === */
.editor-pane {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Theme Selector - Horizontal Scroll */
.theme-selector-container {
    background: var(--bg-panel);
    padding: 1.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

.section-title {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-ink-light);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.85rem;
    font-weight: 600;
}

.theme-scroll {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
}

.theme-option {
    flex: 0 0 auto;
    width: 100px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    border: 2px solid transparent;
    padding: 0.5rem;
    transition: var(--transition);
    text-align: center;
}

.theme-option:hover {
    background: var(--color-paper);
}

.theme-option.active {
    border-color: var(--color-accent);
    background: var(--color-paper);
}

.theme-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin: 0 auto 0.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--color-ink);
    background-color: #fff; /* Default background */
}

/* Theme Icon Colors */
.peacock-preview { color: #0F6B6B; background: #FFF9F0; }
.sepia-preview { color: #8B4513; background: #F5E6D3; }
.romantic-preview { color: #EC4899; background: #FDF2F8; }
.autumn-preview { color: #D97706; background: #FFF7ED; }
.midnight-preview { color: #FFD700; background: #0F1C2E; }
.minimal-preview { color: #64748B; background: #FFFFFF; }

.theme-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-ink);
}

/* Writing Form */
.writing-form {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-ink-light);
}

.form-input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    background: var(--color-paper);
    color: var(--color-ink);
    transition: var(--transition);
    width: 100%;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-accent);
    background: #FFF;
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

textarea.form-input {
    min-height: 300px;
    resize: vertical;
    line-height: 1.8;
    font-family: var(--font-body);
    font-size: 1.1rem;
}

/* Toolbar */
.editor-toolbar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.tool-btn {
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
    color: var(--color-ink-light);
    transition: var(--transition);
}

.tool-btn:hover {
    background: var(--color-paper);
    color: var(--color-ink);
    border-color: var(--color-ink-light);
}

/* Action Bar */
.action-bar {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-light);
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
}

.btn-primary {
    background: var(--color-primary);
    color: #FFF;
    box-shadow: 0 2px 4px rgba(139, 69, 19, 0.2);
}

.btn-primary:hover {
    background: var(--color-primary-light);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(139, 69, 19, 0.3);
}

.btn-secondary {
    background: white;
    border: 1px solid var(--border-light);
    color: var(--color-ink);
}

.btn-secondary:hover {
    background: var(--color-paper);
    border-color: var(--color-ink-light);
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--color-ink-light);
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover {
    background: var(--color-paper);
    color: var(--color-ink);
    border-color: var(--border-light);
}

/* === RIGHT SIDE: PREVIEW === */
.preview-pane {
    position: sticky;
    top: 2rem;
}

.preview-container {
    background: var(--bg-panel); /* Base background behind paper */
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05); /* Subtle inset depth */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 600px;
    border: 1px solid var(--border-light);
}

/* The Paper Itself */
.letter-paper {
    background: #FFF;
    width: 100%;
    max-width: 600px; /* A4-ish ratio */
    min-height: 800px;
    padding: 4rem;
    box-shadow: 
        0 1px 1px rgba(0,0,0,0.1), 
        0 2px 2px rgba(0,0,0,0.1), 
        0 4px 4px rgba(0,0,0,0.1), 
        0 8px 8px rgba(0,0,0,0.1),
        0 16px 16px rgba(0,0,0,0.1);
    position: relative;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    /* Default typography for paper */
    font-family: var(--font-body);
    font-size: 1.15rem;
    color: #1A1A1A;
}

.letter-content {
    position: relative;
    z-index: 2; /* Above decorations */
    height: 100%;
    display: flex;
    flex-direction: column;
}

.letter-header {
    margin-bottom: 2rem;
    text-align: left;
}

.letter-recipient {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.letter-date {
    font-size: 0.9rem;
    opacity: 0.7;
    font-style: italic;
}

.letter-body {
    flex: 1;
    white-space: pre-wrap;
    line-height: 1.8;
}

.letter-footer {
    margin-top: 3rem;
    text-align: right;
}

.letter-sign-off {
    margin-bottom: 0.5rem;
}

.letter-signature {
    font-family: 'Great Vibes', cursive; /* Default signature font */
    font-size: 2rem;
}

/* === MODALS === */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
}

.modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-panel);
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-backdrop.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-title {
    font-size: 1.5rem;
    font-family: var(--font-heading);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-ink-light);
}

/* === UTILITIES & ANIMATIONS === */
.hidden { display: none !important; }

.fade-in { animation: fadeIn 0.3s ease-out forwards; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === MOBILE RESPONSIVENESS === */
.mobile-tabs {
    display: none; /* Hidden on desktop */
}

@media (max-width: 1024px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }
    
    .preview-pane {
        display: none; /* Hidden by default on mobile, toggled via tabs */
    }
    
    .preview-pane.active {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;
        background: var(--bg-main);
        padding: 1rem;
        padding-bottom: 80px; /* Space for tabs */
        overflow-y: auto;
    }

    .mobile-tabs {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-panel);
        border-top: 1px solid var(--border-light);
        z-index: 500;
        padding: 0.5rem;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    }

    .mobile-tab {
        flex: 1;
        padding: 0.75rem;
        border: none;
        background: none;
        font-weight: 600;
        color: var(--color-ink-light);
        cursor: pointer;
        border-radius: var(--radius-sm);
    }

    .mobile-tab.active {
        background: var(--color-paper);
        color: var(--color-primary);
    }
    
    .app-container {
        padding: 1rem;
        padding-bottom: 80px; /* Space for tabs */
    }
    
    .letter-paper {
        padding: 1.5rem;
        min-height: auto;
    }
}

/* === TOAST === */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 2000;
}

.toast {
    background: var(--bg-panel);
    border-left: 4px solid var(--color-success);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: slideInRight 0.3s ease;
    max-width: 350px;
}

.toast.error { border-color: var(--color-error); }
.toast.info { border-color: var(--color-info); }

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
