/* ============================================
   THE PAPER ATELIER
   Handwriting Practice Generator
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,500;0,600;0,700;1,400&family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    --parchment: #faf8f5;
    --parchment-dark: #f0ece4;
    --cream: #f5f2eb;
    --ink: #1a1f2e;
    --ink-soft: #3d4559;
    --ink-muted: #6b7280;
    --terracotta: #c4704b;
    --terracotta-soft: #d4896a;
    --terracotta-glow: rgba(196, 112, 75, 0.15);
    --navy: #2c3654;
    --border: #e5e0d5;
    --border-dark: #d4cfc2;
    --shadow-soft: rgba(26, 31, 46, 0.06);
    --shadow-medium: rgba(26, 31, 46, 0.12);
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, sans-serif;
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ============================================
   BASE
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-body);
    background: var(--parchment);
    color: var(--ink);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   APP CONTAINER - FULL HEIGHT
   ============================================ */
.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================
   HEADER - COMPACT
   ============================================ */
.app-header {
    background: linear-gradient(135deg, var(--ink) 0%, var(--navy) 100%);
    color: var(--parchment);
    padding: 1rem 2rem;
    flex-shrink: 0;
}

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

.app-header h1 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.app-header p {
    font-size: 0.9rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}

/* ============================================
   MAIN CONTENT - FILLS REMAINING HEIGHT
   ============================================ */
.main-content {
    flex: 1;
    display: grid;
    grid-template-columns: 340px 1fr;
    min-height: 0; /* Important for nested flex/scroll */
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* ============================================
   LEFT PANEL - SCROLLABLE
   ============================================ */
.content-panel {
    background: var(--cream);
    border-right: 1px solid var(--border);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.panel-title {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--ink);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--terracotta);
    display: inline-block;
}

/* Source Tabs */
.source-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    background: var(--parchment-dark);
    padding: 4px;
    border-radius: 8px;
}

.tab-btn {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.5rem 0.25rem;
    border: none;
    background: transparent;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s var(--ease-out);
}

.tab-btn:hover {
    color: var(--ink);
    background: rgba(255, 255, 255, 0.5);
}

.tab-btn.active {
    background: white;
    color: var(--ink);
    box-shadow: 0 2px 8px var(--shadow-soft);
}

/* Tab Content */
.tab-content {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
}

.tab-content.active {
    display: flex;
}

/* Form Elements */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--ink-soft);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

select,
input[type="text"],
input[type="number"],
textarea {
    font-family: var(--font-body);
    font-size: 0.9rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--ink);
    transition: all 0.2s var(--ease-out);
    width: 100%;
}

select:focus,
input:focus,
textarea:focus {
    outline: none;
    border-color: var(--terracotta);
    box-shadow: 0 0 0 3px var(--terracotta-glow);
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 2rem;
}

textarea {
    resize: vertical;
    min-height: 100px;
}

.char-count {
    font-size: 0.75rem;
    color: var(--ink-muted);
    text-align: right;
}

/* Buttons */
.btn-primary {
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.75rem 1.25rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s var(--ease-out);
    background: linear-gradient(135deg, var(--terracotta) 0%, var(--terracotta-soft) 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(196, 112, 75, 0.3);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(196, 112, 75, 0.35);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-dark);
    border-radius: 6px;
    background: white;
    color: var(--ink-soft);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.2s var(--ease-out);
}

.btn-secondary:hover {
    border-color: var(--terracotta);
    color: var(--terracotta);
    background: var(--terracotta-glow);
}

.content-panel .btn-primary {
    width: 100%;
}

/* Content Preview */
.content-preview {
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-top: auto;
}

.content-preview h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

#content-preview-text {
    font-size: 0.85rem;
    color: var(--ink-soft);
    line-height: 1.6;
    max-height: 120px;
    overflow-y: auto;
}

#content-preview-text strong {
    color: var(--terracotta);
}

/* ============================================
   RIGHT PANEL - PREVIEW FOCUSED
   ============================================ */
.preview-panel {
    display: flex;
    flex-direction: column;
    background: var(--parchment);
    min-height: 0;
}

/* ============================================
   SETTINGS TOOLBAR - COMPACT HORIZONTAL
   ============================================ */
.settings-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.25rem;
    background: white;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toolbar-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--ink-muted);
    white-space: nowrap;
}

.toolbar-label span {
    color: var(--terracotta);
    font-weight: 600;
}

.toolbar-select {
    font-family: var(--font-body);
    font-size: 0.85rem;
    padding: 0.4rem 1.75rem 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.4rem center;
    min-width: 110px;
}

.toolbar-select-sm {
    font-family: var(--font-body);
    font-size: 0.8rem;
    padding: 0.4rem 1.5rem 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.3rem center;
    min-width: 75px;
}

.toolbar-range {
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.toolbar-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--terracotta);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(196, 112, 75, 0.3);
}

.toolbar-color {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    padding: 2px;
    background: white;
    -webkit-appearance: none;
    appearance: none;
}

.toolbar-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.toolbar-color::-webkit-color-swatch {
    border: none;
    border-radius: 3px;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
}

.toolbar-more-btn {
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--ink-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s var(--ease-out);
    margin-left: auto;
}

.toolbar-more-btn:hover {
    border-color: var(--terracotta);
    color: var(--terracotta);
    background: var(--terracotta-glow);
}

.toolbar-more-btn.active {
    background: var(--terracotta);
    border-color: var(--terracotta);
    color: white;
}

/* ============================================
   ADVANCED SETTINGS - EXPANDABLE
   ============================================ */
.advanced-settings {
    background: var(--cream);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.25rem;
    flex-shrink: 0;
    animation: slideDown 0.2s var(--ease-out);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.advanced-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: flex-start;
}

.advanced-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 120px;
}

.advanced-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--ink-soft);
}

.advanced-group label span {
    color: var(--terracotta);
    font-weight: 600;
}

.advanced-group input[type="range"] {
    width: 100px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-dark);
    cursor: pointer;
    -webkit-appearance: none;
}

.advanced-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--terracotta);
    border-radius: 50%;
    cursor: pointer;
}

.line-toggles .toggle-row {
    display: flex;
    gap: 0.75rem;
}

.toggle-label {
    font-size: 0.75rem;
    color: var(--ink-soft);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--terracotta);
}

.custom-size .size-inputs {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.custom-size input {
    width: 60px;
    padding: 0.4rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-align: center;
}

.custom-size span {
    color: var(--ink-muted);
    font-size: 0.85rem;
}

/* ============================================
   PREVIEW AREA - FILLS REMAINING SPACE
   ============================================ */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem 1.25rem;
    min-height: 0;
    gap: 0.75rem;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.preview-header h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
}

#page-indicator {
    font-size: 0.8rem;
    color: var(--ink-muted);
    background: var(--cream);
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
}

.preview-container {
    flex: 1;
    background: var(--cream);
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    overflow-y: auto;
    min-height: 0;
}

.preview-container canvas {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    background: white;
    box-shadow:
        0 2px 4px var(--shadow-soft),
        0 8px 24px var(--shadow-medium);
    border-radius: 4px;
}

/* Pagination */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-shrink: 0;
}

.btn-nav {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
    color: var(--ink-soft);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.2s var(--ease-out);
}

.btn-nav:hover:not(:disabled) {
    border-color: var(--ink-soft);
    color: var(--ink);
}

.btn-nav:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#current-page-display {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-soft);
}

/* ============================================
   DOWNLOAD ACTIONS
   ============================================ */
.download-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    padding: 1rem 1.25rem;
    background: white;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.download-actions .btn-primary,
.download-actions .btn-secondary {
    flex: 1;
    max-width: 180px;
}

/* ============================================
   FONT SELECT STYLING
   ============================================ */
#font-select {
    transition: font-family 0.2s var(--ease-out);
}

#font-select option[value="Caveat"] { font-family: 'Caveat', cursive; }
#font-select option[value="Patrick Hand"] { font-family: 'Patrick Hand', cursive; }
#font-select option[value="Kalam"] { font-family: 'Kalam', cursive; }
#font-select option[value="Handlee"] { font-family: 'Handlee', cursive; }
#font-select option[value="Indie Flower"] { font-family: 'Indie Flower', cursive; }
#font-select option[value="Architects Daughter"] { font-family: 'Architects Daughter', cursive; }
#font-select option[value="Shadows Into Light"] { font-family: 'Shadows Into Light', cursive; }
#font-select option[value="Dancing Script"] { font-family: 'Dancing Script', cursive; }
#font-select option[value="Sacramento"] { font-family: 'Sacramento', cursive; }
#font-select option[value="Permanent Marker"] { font-family: 'Permanent Marker', cursive; }

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-dark);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--ink-muted);
}

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

    .app-container {
        height: auto;
        min-height: 100vh;
    }

    .content-panel {
        max-height: 50vh;
    }

    .preview-panel {
        min-height: 60vh;
    }

    .settings-toolbar {
        gap: 0.75rem;
    }

    .toolbar-range {
        width: 60px;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 0.75rem 1rem;
    }

    .app-header h1 {
        font-size: 1.25rem;
    }

    .source-tabs {
        grid-template-columns: repeat(2, 1fr);
    }

    .settings-toolbar {
        padding: 0.5rem 1rem;
    }

    .toolbar-divider {
        display: none;
    }

    .download-actions {
        flex-direction: column;
    }

    .download-actions .btn-primary,
    .download-actions .btn-secondary {
        max-width: none;
    }
}

/* ============================================
   FOCUS & ACCESSIBILITY
   ============================================ */
*:focus-visible {
    outline: 2px solid var(--terracotta);
    outline-offset: 2px;
}

::selection {
    background: var(--terracotta-glow);
    color: var(--ink);
}
