/* ── PARLOUR LETTER WRITER v1.1 ── */
/* Split layout: form left, live letter right */

@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,wght@0,400;0,500;0,600;1,400&family=Inter:wght@400;500;600&family=Caveat:wght@400;500;600&display=swap');

:root {
    --pl-white: #FFFFFF;
    --pl-off-white: #FAFAFA;
    --pl-ink: #2C2420;
    --pl-ink-light: #5C524A;
    --pl-blush: #E8C4B8;
    --pl-blush-light: #F5E6DF;
    --pl-sage: #8FA68B;
    --pl-border: #E8E4E0;
    --pl-border-light: #F0ECE8;
    --pl-shadow: rgba(44, 36, 32, 0.06);
    --pl-paper: #FFFDF8;
    --pl-line: #E8E4DF;
}

.pl-writer {
    font-family: 'Inter', -apple-system, sans-serif;
    position: relative;
    background: var(--pl-white);
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 60px;
}

/* ── SPLIT LAYOUT ── */
.pl-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    min-height: 70vh;
    border: 1px solid var(--pl-border-light);
    border-radius: 12px;
    overflow: hidden;
}

/* ── LEFT: FORM SIDE ── */
.pl-form-side {
    padding: 48px 40px;
    overflow-y: auto;
    max-height: 90vh;
    border-right: 1px solid var(--pl-border-light);
}

/* ── RIGHT: LETTER SIDE ── */
.pl-letter-side {
    padding: 48px 40px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: var(--pl-off-white);
    overflow-y: auto;
    max-height: 90vh;
}

/* ── STEPS ── */
.pl-step {
    display: none;
}
.pl-step-active {
    display: block;
}
.pl-step-header {
    margin-bottom: 32px;
}
.pl-step-header h3 {
    font-family: 'Newsreader', Georgia, serif;
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
    color: var(--pl-ink);
}
.pl-step-header p {
    font-size: 0.9rem;
    color: var(--pl-ink-light);
}

/* ── FORM ── */
.pl-form {
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.pl-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--pl-ink);
    margin-bottom: 7px;
}
.pl-field input[type="text"],
.pl-field textarea,
.pl-field select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--pl-border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: 'Inter', -apple-system, sans-serif;
    color: var(--pl-ink);
    background: var(--pl-white);
    transition: border-color 0.2s;
    -webkit-appearance: none;
}
.pl-field input[type="text"]:focus,
.pl-field textarea:focus,
.pl-field select:focus {
    outline: none;
    border-color: var(--pl-blush);
}
.pl-field textarea {
    resize: vertical;
    min-height: 90px;
}
.pl-hint {
    display: block;
    font-size: 0.78rem;
    color: var(--pl-ink-light);
    margin-top: 5px;
    font-style: italic;
}

/* ── TONE CHIPS ── */
.pl-tone-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.pl-tone-chip {
    display: inline-flex;
    align-items: center;
    padding: 7px 16px;
    border: 1.5px solid var(--pl-border);
    border-radius: 40px;
    font-size: 0.83rem;
    font-weight: 500;
    color: var(--pl-ink-light);
    cursor: pointer;
    transition: all 0.2s;
    background: transparent;
}
.pl-tone-chip:hover {
    border-color: var(--pl-ink-light);
    color: var(--pl-ink);
}
.pl-tone-chip input[type="radio"] {
    display: none;
}
.pl-tone-chip:has(input:checked),
.pl-tone-chip.selected {
    background: var(--pl-ink);
    color: var(--pl-white);
    border-color: var(--pl-ink);
}

/* ── BUTTONS ── */
.pl-actions {
    display: flex;
    gap: 12px;
    margin-top: 6px;
}
.pl-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: 'Inter', -apple-system, sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.pl-btn-primary {
    background: var(--pl-ink);
    color: var(--pl-white);
}
.pl-btn-primary:hover {
    opacity: 0.85;
}
.pl-btn-secondary {
    background: transparent;
    color: var(--pl-ink);
    border: 1.5px solid var(--pl-border);
}
.pl-btn-secondary:hover {
    border-color: var(--pl-ink-light);
}

/* ── EDIT CONTROLS (step 2 left side) ── */
.pl-edit-controls {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.pl-edit-hint {
    font-size: 0.88rem;
    color: var(--pl-ink-light);
    padding: 14px 18px;
    background: var(--pl-blush-light);
    border-radius: 8px;
}
.pl-reassurance {
    font-size: 0.78rem;
    color: var(--pl-ink-light);
    font-style: italic;
}
.pl-btn-back {
    width: 100%;
    margin-top: 8px;
    display: none;
}
.pl-btn-back.visible {
    display: inline-flex;
}

/* ── LETTER PAPER ── */
.pl-letter-paper {
    width: 100%;
    max-width: 420px;
    min-height: 560px;
    background: var(--pl-paper);
    border: 1px solid var(--pl-border);
    border-radius: 4px;
    padding: 48px 40px 40px;
    box-shadow:
        0 2px 8px var(--pl-shadow),
        0 12px 40px rgba(44, 36, 32, 0.04);
    position: relative;
    overflow: hidden;
}

/* Subtle top accent line */
.pl-letter-paper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 36px;
    right: 36px;
    height: 3px;
    background: var(--pl-blush);
    border-radius: 0 0 3px 3px;
}

/* Ruled lines on the paper */
.pl-letter-lines {
    position: absolute;
    top: 48px;
    left: 40px;
    right: 40px;
    bottom: 40px;
    pointer-events: none;
}
.pl-letter-line {
    border-bottom: 1px solid var(--pl-line);
    height: 34px;
}

/* Placeholder text */
.pl-letter-placeholder {
    position: relative;
    z-index: 1;
    text-align: center;
    padding-top: 100px;
}
.pl-letter-placeholder p {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    color: #C0B8B0;
}

/* The handwritten text */
.pl-letter-text {
    position: relative;
    z-index: 1;
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
    line-height: 34px;
    color: #2A3A5C;
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 200px;
}

/* Blinking cursor during typing animation */
.pl-letter-text .pl-cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: #2A3A5C;
    margin-left: 1px;
    vertical-align: text-bottom;
    animation: pl-blink 0.7s step-end infinite;
}

@keyframes pl-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Editable textarea (shown when clicking letter to edit) */
.pl-letter-edit {
    position: relative;
    z-index: 2;
    width: 100%;
    border: none;
    font-family: 'Caveat', cursive;
    font-size: 1.15rem;
    line-height: 34px;
    color: #2A3A5C;
    background: transparent;
    resize: none;
    min-height: 400px;
    padding: 0;
}
.pl-letter-edit:focus {
    outline: none;
}

/* ── LOADING ── */
.pl-loading {
    display: none;
    text-align: center;
    padding: 60px 20px;
}
.pl-loading.active {
    display: block;
}
.pl-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--pl-border);
    border-top-color: var(--pl-ink);
    border-radius: 50%;
    animation: pl-spin 0.8s linear infinite;
    margin: 0 auto 14px;
}
@keyframes pl-spin {
    to { transform: rotate(360deg); }
}
.pl-loading p {
    font-size: 0.9rem;
    color: var(--pl-ink-light);
    font-style: italic;
}

/* ── ERROR ── */
.pl-error {
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
    color: #991B1B;
    margin-bottom: 14px;
    display: none;
}
.pl-error.active {
    display: block;
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
    .pl-split {
        grid-template-columns: 1fr;
        min-height: auto;
    }
    .pl-form-side {
        padding: 32px 24px;
        border-right: none;
        border-bottom: 1px solid var(--pl-border-light);
        max-height: none;
        overflow-y: visible;
    }
    .pl-letter-side {
        padding: 32px 24px;
        max-height: none;
        overflow-y: visible;
    }
    .pl-letter-paper {
        max-width: 100%;
        min-height: 400px;
        padding: 36px 28px 28px;
    }
    .pl-letter-lines {
        top: 36px;
        left: 28px;
        right: 28px;
        bottom: 28px;
    }
    .pl-letter-paper::before {
        left: 24px;
        right: 24px;
    }
}

@media (max-width: 520px) {
    .pl-form-side {
        padding: 24px 18px;
    }
    .pl-letter-side {
        padding: 24px 18px;
    }
    .pl-letter-paper {
        padding: 28px 20px 20px;
    }
    .pl-actions {
        flex-direction: column;
    }
    .pl-btn {
        width: 100%;
    }
}
