/* Chapters use the site's existing header/footer and memory authoring forms. */
body.memories-page { background: #f6f0e6; }
.memories-main {
    --chapter-ink: #503e34;
    --chapter-muted: #786454;
    --chapter-line: #dbcfc0;
    --chapter-paper: #fffbf5;
    --chapter-wash: #eee4d7;
    --text-primary: var(--chapter-ink);
    --text-secondary: var(--chapter-muted);
    --accent-cool: #76513d;
    --bg-light: var(--chapter-paper);
    --bg-section: var(--chapter-wash);
    --border-subtle: var(--chapter-line);
    padding: 140px 0 64px;
    min-height: 85vh;
    color: var(--chapter-ink);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 16px;
    letter-spacing: 0;
}
.memories-main .container { max-width: 1280px; padding: 0 36px; }
.memories-main [hidden] { display: none !important; }
.memories-main button, .memories-main input, .memories-main select { font-family: inherit; }
.memories-main button { cursor: pointer; }
.memories-main button:disabled { cursor: default; opacity: .55; }
.memories-main :is(button,input,select,textarea,a):focus-visible { outline: 3px solid #a6572b; outline-offset: 4px; }
.memories-main :is(button,input:not([type="checkbox"]),select) { min-height: 44px; }
.memories-header { padding: 0; margin-bottom: 36px; display: flex; justify-content: space-between; align-items: end; gap: 28px; }
.memories-header h1 { font: normal clamp(40px,4.5vw,62px)/1.12 Georgia,serif; letter-spacing: -2px; text-wrap: balance; margin: 14px 0 20px; }
.memories-header h1 em { color: #80523e; }
.memories-header p { font-size: 14px; max-width: 680px; color: var(--chapter-muted); }
.memories-main .chapter-eyebrow { font: 11px/1.6 'SFMono-Regular',Consolas,monospace; letter-spacing: 1.6px; text-transform: uppercase; color: var(--chapter-muted); }
.memories-action-buttons { display: flex; flex-wrap: wrap; gap: 10px; flex-shrink: 0; max-width: 210px; }
.add-memory-btn, .add-mutual-memory-btn { padding: 10px 18px; border: 1px solid var(--chapter-ink); border-radius: 5px; font-size: 13px; background: var(--chapter-ink); color: var(--chapter-paper); }
.add-memory-btn:hover, .add-mutual-memory-btn:hover { background: #715541; }
.memories-filters { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; background: none; padding: 0 0 24px; border: 0; border-bottom: 1px solid var(--chapter-line); margin-bottom: 18px; border-radius: 0; }
.filter-group { display: flex; flex-direction: column; min-width: 0; }
.filter-group label { font-size: 11px; color: var(--chapter-muted); margin-bottom: 6px; }
.filter-search { flex: 1; }
.filter-select, .filter-input { width: 100%; padding: 9px 13px; background: var(--chapter-paper); color: var(--chapter-ink); border: 1px solid var(--chapter-line); border-radius: 5px; font-size: 13px; }
.filter-select { min-width: 130px; }
.filter-input { min-width: 200px; }
.filter-clear, .chapter-back { border: 1px solid var(--chapter-line); background: var(--chapter-paper); color: var(--chapter-ink); border-radius: 5px; padding: 9px 14px; font-size: 12px; }
.filter-clear:hover, .chapter-back:hover { background: var(--chapter-wash); }
.chapter-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; min-height: 60px; margin-bottom: 26px; flex-wrap: wrap; }
.chapter-toolbar p { flex: 1; font-size: 12px; color: var(--chapter-muted); }
.chapter-toolbar .filter-group { flex-direction: row; align-items: center; gap: 10px; }
.chapter-toolbar .filter-group label { margin: 0; }
.memory-chapters { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 28px; padding: 0 0 35px; }
#chapterContents { padding: 0; }
.chapter-card { display: flex; flex-direction: column; text-align: left; padding: 0; background: var(--chapter-paper); border: 1px solid var(--chapter-line); color: var(--chapter-ink); border-radius: 5px; box-shadow: 5px 6px 0 #e6dccd; min-width: 0; overflow: hidden; transition: transform .18s,box-shadow .18s; }
.chapter-card:hover:not(:disabled) { transform: translateY(-4px); box-shadow: 5px 10px 0 #e6dccd; }
.chapter-cover { display: block; width: 100%; aspect-ratio: 1.6; border-bottom: 1px solid var(--chapter-line); overflow: hidden; background: var(--chapter-wash); }
.chapter-art { display: block; width: 100%; height: 100%; }
.chapter-copy { display: flex; flex: 1; flex-direction: column; gap: 14px; padding: 28px 24px; border-left: 7px solid #b9ba9b; width: 100%; }
.chapter-card:nth-child(2) .chapter-copy { border-left-color: #c6a480; }
.chapter-card:nth-child(3) .chapter-copy { border-left-color: #acb9ae; }
.chapter-name { font: normal 35px/1.15 Georgia,serif; letter-spacing: -1px; text-wrap: balance; }
.chapter-description { display: block; font-size: 14px; line-height: 1.7; color: var(--chapter-muted); padding-bottom: 10px; }
.chapter-enter { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
.chapter-enter > span { font-size: 26px; line-height: 1; }
.chapter-title { font: normal 36px/1.2 Georgia,serif; letter-spacing: -1px; margin-bottom: 26px; scroll-margin-top: 100px; }
.memories-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 32px 26px; margin-bottom: 32px; }
.memory-card { min-width: 0; border: 0; border-radius: 0; padding: 0; background: none; box-shadow: none; position: relative; }
.memory-open { width: 100%; display: block; text-align: left; background: none; border: 0; padding: 0; color: inherit; }
.memory-cover { position: relative; display: block; aspect-ratio: 1.6; background: var(--chapter-wash); border-radius: 5px; overflow: hidden; }
.memory-cover .chapter-art { transition: transform .25s; }
.memory-open:hover .chapter-art { transform: scale(1.02); }
.memory-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .15s; }
.memory-cover img.cover-ready { opacity: 1; }
.memory-card-copy { display: block; padding: 18px 0 0; }
.memory-card-meta { display: flex; justify-content: space-between; align-items: start; gap: 12px; color: var(--chapter-muted); font-size: 11px; margin-bottom: 14px; }
.memory-card-meta > span:first-child { text-transform: capitalize; }
.memory-title { display: block; font: normal 28px/1.2 Georgia,serif; letter-spacing: -.7px; margin-bottom: 12px; color: var(--chapter-ink); overflow-wrap: anywhere; }
.memory-open:hover .memory-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.memory-preview { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; line-height: 1.75; color: var(--chapter-muted); margin-bottom: 15px; }
.memory-contributor { display: block; font-size: 12px; color: var(--chapter-muted); margin: 10px 0; }
.memory-card-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; border-top: 1px solid var(--chapter-line); font-size: 12px; color: var(--chapter-muted); }
.memory-card-bottom > span:last-child { font-size: 24px; line-height: 1; }
.memory-media-count { display: block; font-size: 11px; color: var(--chapter-muted); margin-top: 10px; }
.memory-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.memory-actions button { border: 1px solid var(--chapter-line); background: var(--chapter-paper); border-radius: 5px; min-width: 60px; padding: 8px 14px; color: var(--chapter-ink); font-size: 12px; }
.memory-actions button:hover { background: var(--chapter-wash); }
.loading { text-align: center; padding: 45px 20px; color: var(--chapter-muted); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--chapter-line); border-top-color: var(--chapter-ink); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
.memory-load-error, .no-results { text-align: center; border: 1px dashed var(--chapter-line); border-radius: 6px; padding: 45px 20px; background: var(--chapter-paper); }
.memory-load-error h2, .no-results h2 { font: normal 30px Georgia,serif; margin-bottom: 12px; }
.memory-load-error p, .no-results p { font-size: 14px; color: var(--chapter-muted); margin-bottom: 20px; }
.memory-reading { overflow: hidden; }
.memory-reader { padding: 0; border: 1px solid var(--chapter-line); border-radius: 10px; width: min(820px,calc(100% - 32px)); max-height: calc(100dvh - 40px); margin: auto; color: var(--chapter-ink); background: var(--chapter-paper); overscroll-behavior: contain; }
.memory-reader::backdrop { background: #2b241eca; backdrop-filter: blur(4px); }
.memory-reader .modal-content { margin: 0; width: 100%; max-width: none; max-height: none; border: 0; border-radius: 0; box-shadow: none; padding: 40px; overflow: visible; }
.memory-reader .memory-detail-title { font: normal 40px/1.15 Georgia,serif; letter-spacing: -1px; }
.memory-reader .memory-detail-content { font: 18px/1.85 Georgia,serif; }
.memory-reader .memory-type { text-transform: uppercase; letter-spacing: 1.5px; font-size: 11px; color: var(--chapter-muted); margin-bottom: 12px; }
.memory-reader .memory-detail-meta { font-size: 13px; color: var(--chapter-muted); }
.memory-reader .memory-detail-attributes { font-size: 12px; color: var(--chapter-muted); border-top: 1px solid var(--chapter-line); padding-top: 18px; }
.mutual-memory-notice { color: var(--chapter-muted); font-size: 14px; margin-bottom: 20px; }
.memories-main .modal-close { background: var(--chapter-paper); border: 1px solid var(--chapter-line); border-radius: 50%; min-width: 44px; min-height: 44px; display: grid; place-items: center; font-size: 27px; line-height: 1; padding: 0; }
.memories-main .modal-close:hover { color: #8c432b; background: var(--chapter-wash); }

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin: 2rem 0;
}

.pagination button {
    min-width: 44px;
    padding: 8px 12px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-light);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 4px;
    font-family: inherit;
    transition: all 0.3s ease;
}

.pagination button:hover:not(:disabled) {
    background: var(--accent-cool);
    color: white;
    border-color: var(--accent-cool);
}

.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination .current-page {
    background: var(--accent-cool);
    color: white;
    border-color: var(--accent-cool);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    animation: fade-in 0.3s ease-out;
}

.modal-content {
    background-color: var(--bg-light);
    margin: 5% auto;
    padding: 2rem;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 8px 32px rgba(0, 0, 0, 0.1);
    animation: slide-up 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-close {
    color: var(--text-secondary);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 1rem;
    top: 1rem;
    transition: color 0.3s ease;
}

.modal-close:hover {
    color: var(--accent-warm);
}

.memory-detail-header {
    margin-bottom: 1.5rem;
    padding-right: 2rem;
}

.memory-detail-title {
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.memory-detail-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.memory-detail-content {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 2rem;
    white-space: pre-wrap;
}

/* Formatted content styling */
.memory-detail-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.memory-detail-content em {
    font-style: italic;
    color: var(--text-primary);
}

.memory-detail-content h3 {
    color: var(--text-primary);
    font-size: 1.3rem;
    font-weight: 500;
    margin: 1rem 0 0.5rem 0;
    line-height: 1.4;
}

/* Embedded images within content */
.memory-detail-content .embedded-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1rem 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    display: block;
}

.memory-detail-content .embedded-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* Handle missing images */
.memory-detail-content .missing-image {
    display: inline-block;
    background: #f8f9fa;
    color: #6c757d;
    padding: 8px 12px;
    border: 1px dashed #dee2e6;
    border-radius: 4px;
    font-style: italic;
    margin: 4px 0;
}

.memory-detail-content .non-image-attachment {
    display: inline-block;
    background: #fff3cd;
    color: #856404;
    padding: 8px 12px;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    font-style: italic;
    margin: 4px 0;
}

.memory-attachments-section {
    margin-top: 2rem;
}

/* Modern Content Editor */
.content-editor {
    background: var(--background-light);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
}

.content-editor:focus-within {
    box-shadow: 0 4px 20px rgba(52, 152, 219, 0.08), 0 2px 8px rgba(0, 0, 0, 0.12);
    transform: translateY(-1px);
}

.content-toolbar {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    backdrop-filter: blur(10px);
}

.content-toolbar::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(52, 152, 219, 0.2) 50%, transparent 100%);
}

.toolbar-btn {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 44px;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.toolbar-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s;
}

.toolbar-btn:hover::before {
    left: 100%;
}

.toolbar-btn:hover {
    background: rgba(52, 152, 219, 0.1);
    border-color: rgba(52, 152, 219, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.2), 0 2px 8px rgba(0, 0, 0, 0.1);
    color: var(--accent-cool);
}

.toolbar-btn:active {
    transform: translateY(-1px) scale(0.98);
    transition: all 0.1s ease;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.15);
}

.toolbar-btn.active {
    background: linear-gradient(135deg, var(--accent-cool) 0%, #2980b9 100%);
    color: white;
    border-color: var(--accent-cool);
    box-shadow: 0 4px 16px rgba(52, 152, 219, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.toolbar-btn.active:hover {
    background: linear-gradient(135deg, #2980b9 0%, var(--accent-cool) 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.toolbar-separator {
    width: 1px;
    height: 32px;
    background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.08), transparent);
    margin: 0 12px;
    position: relative;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.content-editor:focus-within .toolbar-separator {
    opacity: 1;
    background: linear-gradient(to bottom, transparent, rgba(52, 152, 219, 0.2), transparent);
}

.toolbar-help {
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 400;
    margin-left: auto;
    opacity: 0.7;
    transition: all 0.3s ease;
    padding: 4px 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.content-editor:focus-within .toolbar-help {
    opacity: 1;
    background: rgba(52, 152, 219, 0.05);
    border-color: rgba(52, 152, 219, 0.1);
    color: var(--text-primary);
}

.content-editor textarea {
    border: none;
    border-radius: 0;
    outline: none;
    resize: vertical;
    font-family: 'SF Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    padding: 20px;
    background: transparent;
    color: var(--text-primary);
    min-height: 120px;
    transition: all 0.3s ease;
}

.content-editor textarea::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
    font-style: italic;
}

.content-editor textarea:focus {
    background: rgba(52, 152, 219, 0.02);
}

/* Loading state for image paste */
.content-editor textarea.uploading {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.05) 0%, rgba(52, 152, 219, 0.02) 100%);
    position: relative;
    animation: pulse-glow 2s ease-in-out infinite;
}

.content-editor textarea.uploading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(52, 152, 219, 0.15), transparent);
    animation: loading-shimmer 1.2s infinite;
    pointer-events: none;
}

@keyframes loading-shimmer {
    0% { 
        transform: translateX(-100%);
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% { 
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes pulse-glow {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.2);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.1);
    }
}

.memory-attachments-section h3 {
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.attachments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.attachment-item {
    background: var(--code-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    overflow: hidden;
    transition: transform 0.3s ease;
    position: relative;
}

.attachment-item:hover {
    transform: translateY(-2px);
}

.attachment-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.attachment-item:hover .attachment-actions {
    opacity: 1;
}

.attachment-delete-btn {
    background: rgba(231, 76, 60, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.attachment-delete-btn:hover {
    background: rgba(231, 76, 60, 1);
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(231, 76, 60, 0.3);
}

.attachment-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
}

.attachment-info {
    padding: 0.75rem;
}

.attachment-name {
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
    word-break: break-word;
}

.attachment-caption {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* No results */
.no-results {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

/* Add Memory Form */
.add-memory-modal {
    max-width: 700px;
}

.add-memory-modal h2 {
    color: var(--text-primary);
    margin-bottom: 2rem;
    margin-top: 0;
    padding-right: 3rem;
    font-size: 1.8rem;
    font-weight: 500;
    position: relative;
}

.add-memory-modal h2::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    width: 60px;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-cool), rgba(52, 152, 219, 0.3));
    border-radius: 2px;
}

.form-group {
    margin-bottom: 2rem;
    position: relative;
}

.form-group label {
    display: block;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    position: relative;
    padding-left: 2px;
}

.form-group label::before {
    content: '';
    position: absolute;
    left: -2px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent-cool);
    border-radius: 1px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.form-group:focus-within label::before {
    opacity: 1;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    backdrop-filter: blur(10px);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-cool);
    box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.15), 0 4px 12px rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.95);
    transform: translateY(-1px);
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.5;
}

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

.form-group label input[type="checkbox"] {
    width: auto;
    margin-right: 0.75rem;
    transform: scale(1.2);
    accent-color: var(--accent-cool);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1.25rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    position: relative;
}

.form-actions::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, rgba(52, 152, 219, 0.2) 50%, transparent 100%);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-cool) 0%, #2980b9 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.25);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.btn-primary:hover::before {
    left: 100%;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #2980b9 0%, var(--accent-cool) 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.35);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-secondary);
    border: 1px solid rgba(0, 0, 0, 0.08);
    padding: 12px 24px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.12);
}

.btn-danger {
    background: linear-gradient(135deg, var(--accent-warm) 0%, #c0392b 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.25);
}

.btn-danger:hover {
    background: linear-gradient(135deg, #c0392b 0%, var(--accent-warm) 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.35);
}

/* Confirmation Dialog */
.memory-confirm {
    padding: 0;
    border: 0;
    border-radius: 12px;
    width: min(400px, calc(100% - 32px));
    margin: auto;
    background: var(--chapter-paper);
}
.memory-confirm::backdrop { background: #2b241eaa; }

.confirm-dialog-content {
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    max-width: 400px;
    width: 100%;
    text-align: center;
    animation: slideInRight 0.3s ease-out;
}

.confirm-dialog-content h3 {
    color: var(--text-primary);
    margin: 0 0 1rem 0;
    font-size: 1.3rem;
}

.confirm-dialog-content p {
    color: var(--text-secondary);
    margin: 0 0 2rem 0;
    line-height: 1.5;
}

.confirm-dialog-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

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

@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slide-up {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 1024px) {
    .content-toolbar {
        padding: 14px 18px;
    }
    
    .toolbar-btn {
        padding: 9px 14px;
        font-size: 0.88rem;
    }
}

@media (max-width: 768px) {
    .memories-main {
        padding-top: 80px;
    }
    
    .memories-header {
        padding-left: 0;
        text-align: center;
    }
    
    .memories-header h1 {
        font-size: 2rem;
    }
    
    .memories-filters {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        margin-bottom: 0.5rem;
    }
    
    .filter-select, .filter-input {
        min-width: auto;
        width: 100%;
    }
    
    .memories-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 2% auto;
        padding: 1.5rem;
    }
    
    .memory-detail-meta {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .form-group {
        margin-bottom: 1.5rem;
    }
    
    .add-memory-modal h2 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
        padding-right: 2rem;
    }
    
    .form-actions {
        flex-direction: column-reverse;
        gap: 1rem;
        margin-top: 2rem;
        padding-top: 1.5rem;
    }
    
    .btn-primary,
    .btn-secondary,
    .btn-danger {
        width: 100%;
        text-align: center;
    }
    
    .confirm-dialog-actions {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .memory-actions {
        opacity: 1; /* Always show on mobile for better UX */
    }
    
    .content-toolbar {
        padding: 12px 16px;
        gap: 6px;
        flex-wrap: wrap;
    }
    
    .toolbar-btn {
        padding: 8px 12px;
        min-width: 40px;
        font-size: 0.85rem;
    }
    
    .toolbar-separator {
        display: none; /* Hide separators on mobile to save space */
    }
    
    .toolbar-help {
        font-size: 0.75rem;
        padding: 2px 6px;
        margin-top: 4px;
        flex: 1 1 100%;
        text-align: center;
    }
    
    .content-editor textarea {
        padding: 16px;
        font-size: 0.9rem;
    }
}
/* Responsive chapter layouts, after the shared editor styles. */
@media (max-width: 1024px) {
    .memories-main .container { padding: 0 28px; }
    .memories-header { align-items: start; }
    .memories-header h1 { font-size: 48px; }
    .memory-chapters { gap: 20px; }
    .chapter-copy { padding: 22px 18px; }
    .chapter-name { font-size: 30px; }
    .memories-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 768px) {
    .memories-main { padding-top: 115px; }
    .memories-main .container { padding: 0 22px; }
    .memories-header { display: block; padding-left: 0; margin-bottom: 28px; }
    .memories-header h1 { font-size: 43px; }
    .memories-action-buttons { max-width: none; margin-top: 20px; }
    .memories-filters { display: grid; grid-template-columns: 1fr 1fr; padding: 0 0 20px; gap: 12px; }
    .filter-search { grid-column: 1/-1; grid-row: 1; }
    .filter-clear { grid-column: 1/-1; }
    .filter-input, .filter-select { min-width: 0; }
    .chapter-toolbar { gap: 10px; }
    .chapter-toolbar p { min-width: 115px; }
    .chapter-toolbar .filter-group { margin-left: auto; }
    .chapter-toolbar .filter-group label { font-size: 11px; }
    .memory-chapters { grid-template-columns: 1fr; gap: 28px; max-width: 510px; margin: 0 auto; }
    .chapter-cover { aspect-ratio: 1.7; }
    .chapter-copy { padding: 26px; }
    .chapter-name { font-size: 36px; }
    .memories-grid { gap: 28px 20px; }
    .memory-title { font-size: 26px; }
    .memory-reader .modal-content { padding: 28px 22px; }
    .memory-reader .memory-detail-title { font-size: 33px; }
    .memory-reader .memory-detail-content { font-size: 17px; }
}
@media (max-width: 480px) {
    .memories-main .container { padding: 0 20px; }
    .memories-grid { grid-template-columns: 1fr; }
    .chapter-toolbar .filter-group { width: 100%; justify-content: space-between; }
    .memories-header h1 { font-size: 41px; }
}
@media (prefers-reduced-motion: reduce) {
    .memories-main *, .memories-main *::before, .memories-main *::after { transition: none !important; animation: none !important; }
    .chapter-card:hover:not(:disabled), .memory-open:hover .chapter-art { transform: none; }
}
