/* =============================================================================
   SiraAI Journal — Book UI
   Premium two-page digital diary on the dark SiraAI canvas.
   ========================================================================== */

/* ---- Design tokens ---- */
.journal-book-page {
    --book-cover: #6E5B9B;
    --book-cover-edge: #463A6B;
    --book-spine: #2B2245;
    --paper-bg: #FBF7EE;
    --paper-text: #2A2438;
    --paper-line: rgba(110, 91, 155, 0.18);
    --paper-rule: rgba(60, 50, 90, 0.10);
    --paper-shadow: rgba(0, 0, 0, 0.45);

    --je-toolbar-bg: rgba(20, 16, 38, 0.92);
    --je-toolbar-border: rgba(180, 160, 230, 0.22);
}

/* ---- Cover themes (apply to .journal-book) ---- */
.journal-book[data-cover="lavender"]   { --book-cover: #6E5B9B; --book-cover-edge: #463A6B; --book-spine: #2B2245; }
.journal-book[data-cover="sage"]       { --book-cover: #5F8B57; --book-cover-edge: #3F5F3A; --book-spine: #243B22; }
.journal-book[data-cover="parchment"]  { --book-cover: #B7976A; --book-cover-edge: #8A6F4E; --book-spine: #5F4B33; }
.journal-book[data-cover="midnight"]   { --book-cover: #2A2952; --book-cover-edge: #1A1A38; --book-spine: #10102A; }
.journal-book[data-cover="rose"]       { --book-cover: #B27490; --book-cover-edge: #8A526D; --book-spine: #56304A; }
.journal-book[data-cover="ocean"]      { --book-cover: #5C7DAE; --book-cover-edge: #3F5980; --book-spine: #1F3654; }
.journal-book[data-cover="goldenhour"] { --book-cover: #F4B860; --book-cover-edge: #E89B3D; --book-spine: #8A5A12; }

/* Parchment cover gets a warmer paper too */
.journal-book[data-cover="parchment"] {
    --paper-bg: #F2E6CC;
    --paper-text: #3A2F1F;
}
.journal-book[data-cover="midnight"] {
    --paper-bg: #F6F4FA;
    --paper-text: #1A1830;
}
.journal-book[data-cover="goldenhour"] {
    --paper-bg: #FBF1D9;
    --paper-text: #3B2A0F;
    --paper-line: rgba(232, 155, 61, 0.22);
}

/* =============================================================================
   Page wrapper — sits inside the dark SiraAI canvas
   ========================================================================== */

.journal-book-page {
    min-height: calc(100vh - 80px);
    padding: 50px 24px 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    perspective: 2500px;
    perspective-origin: center top;
    position: relative;
}

.journal-book-mode-bar {
    display: flex;
    gap: 4px;
    padding: 6px;
    background: rgba(20, 16, 38, 0.72);
    border: 1px solid rgba(180, 160, 230, 0.16);
    border-radius: 999px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.journal-book-mode-bar button {
    background: transparent;
    border: 0;
    color: rgba(245, 240, 255, 0.65);
    font: 500 13px/1 'Inter', system-ui, sans-serif;
    letter-spacing: 0.02em;
    padding: 9px 18px;
    border-radius: 999px;
    cursor: pointer;
    transition: color 180ms ease, background 180ms ease;
}
.journal-book-mode-bar button:hover { color: #fff; }
.journal-book-mode-bar button.active {
    background: linear-gradient(135deg, var(--book-cover), var(--book-cover-edge));
    color: #fff;
}
.journal-book-mode-bar button:focus-visible {
    outline: 2px solid var(--book-cover);
    outline-offset: 2px;
}

/* Meta lives back inside the book's left page — see `Left page (meta info, title, prompts)` below. */
.journal-meta-bar { display: none; }   /* legacy hook from the meta-strip iteration; hidden if anyone leaves it in */

/* =============================================================================
   The Book itself
   ========================================================================== */

.journal-book {
    --book-w: 920px;
    --book-h: 620px;
    width: min(100%, var(--book-w));
    height: var(--book-h);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 600ms cubic-bezier(0.22, 1, 0.36, 1);
}
/* The book stays a fixed-size object in every mode — overflow cascades to new pages, not to scrollbars. */

/* Outer drop shadow — gives the book weight */
.journal-book::before {
    content: '';
    position: absolute;
    inset: -10px -16px -28px -16px;
    background: radial-gradient(ellipse at center bottom,
        rgba(0, 0, 0, 0.55) 0%,
        rgba(0, 0, 0, 0) 65%);
    z-index: -1;
    filter: blur(8px);
}

/* The two pages live in a grid row that explicitly fills the full book height,
   so the writing surface inside can be measured against a stable container. */
.journal-book-spread {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 100%;
    width: 100%;
    height: 100%;
    background: var(--book-spine);
    border-radius: 6px 14px 14px 6px;
    box-shadow:
        0 30px 60px -20px var(--paper-shadow),
        0 0 0 6px var(--book-cover-edge),
        0 0 0 14px var(--book-cover);
    overflow: hidden;
    position: relative;
}

/* Spine gradient — soft seam down the middle */
.journal-book-spread::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 36px;
    height: 100%;
    transform: translateX(-50%);
    background: linear-gradient(to right,
        transparent 0%,
        rgba(0, 0, 0, 0.18) 30%,
        rgba(0, 0, 0, 0.32) 50%,
        rgba(0, 0, 0, 0.18) 70%,
        transparent 100%);
    pointer-events: none;
    z-index: 2;
}

/* =============================================================================
   Pages
   ========================================================================== */

.book-page {
    background: var(--paper-bg);
    color: var(--paper-text);
    padding: 38px 44px 32px;
    position: relative;
    height: 100%;                /* explicit fill of the grid row */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: right center;
    transition: transform 1200ms cubic-bezier(0.7, 0, 0.3, 1);
    backface-visibility: hidden;
}

.book-page--right {
    transform-origin: left center;
}

/* Page edge gradient — subtle aging toward the spine and outer edge */
.book-page--left::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.06) 0%,
        transparent 6%,
        transparent 88%,
        rgba(0, 0, 0, 0.16) 100%);
    pointer-events: none;
}
.book-page--right::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to left,
        rgba(0, 0, 0, 0.06) 0%,
        transparent 6%,
        transparent 88%,
        rgba(0, 0, 0, 0.16) 100%);
    pointer-events: none;
}

/* ---- Paper styles (apply to .book-page--right specifically for the writing surface) ---- */
.journal-book[data-paper="lined"] .book-page--right {
    background-image:
        linear-gradient(var(--paper-bg), var(--paper-bg)),
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent 31px,
            var(--paper-line) 31px,
            var(--paper-line) 32px
        );
    background-blend-mode: normal;
    background-size: 100% 100%, 100% 100%;
}
.journal-book[data-paper="dotted"] .book-page--right {
    background-image:
        radial-gradient(circle, var(--paper-line) 1px, transparent 1.5px);
    background-size: 18px 18px;
    background-position: 0 8px;
}
.journal-book[data-paper="parchment"] .book-page--right {
    background-image:
        radial-gradient(ellipse at 30% 20%, rgba(180, 140, 80, 0.10) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(160, 120, 70, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(200, 170, 110, 0.06) 0%, transparent 70%);
}
/* Plain = no extra background image */

/* =============================================================================
   Left page (meta info, title, prompts)
   ========================================================================== */

.book-page--left {
    gap: 22px;
}

.bp-section-label {
    font: 500 10px/1 'Inter', system-ui, sans-serif;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(0, 0, 0, 0.42);
}

.bp-date {
    font: 600 14px/1.3 'Inter', system-ui, sans-serif;
    color: var(--paper-text);
}
.bp-date-day {
    font: 600 36px/1 'Lora', Georgia, serif;
    color: var(--book-cover);
    margin-bottom: 4px;
}

.bp-title-input {
    width: 100%;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--paper-line);
    color: var(--paper-text);
    font: 600 22px/1.3 'Lora', Georgia, serif;
    padding: 6px 0 10px;
    outline: none;
    transition: border-color 180ms ease;
}
.bp-title-input:focus { border-bottom-color: var(--book-cover); }
.bp-title-input::placeholder { color: rgba(0, 0, 0, 0.32); font-style: italic; }

.bp-space-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.bp-space-chip {
    background: transparent;
    border: 1px solid var(--paper-line);
    color: var(--paper-text);
    font: 500 12px/1 'Inter', sans-serif;
    padding: 7px 12px 7px 8px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 180ms ease;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}
.bp-space-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.18);
    flex-shrink: 0;
}
.bp-space-chip:hover { border-color: var(--book-cover); }
.bp-space-chip.active {
    background: var(--book-cover);
    color: #fff;
    border-color: var(--book-cover);
}

.bp-prompts {
    margin-top: auto;
    padding: 16px 18px;
    background: rgba(0, 0, 0, 0.04);
    border-left: 3px solid var(--book-cover);
    border-radius: 0 8px 8px 0;
}
.bp-prompts-title {
    font: 500 10px/1 'Inter', sans-serif;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--book-cover);
    margin-bottom: 8px;
}
.bp-prompt {
    font: italic 400 14px/1.6 'Lora', Georgia, serif;
    color: rgba(0, 0, 0, 0.6);
    cursor: pointer;
    padding: 4px 0;
    transition: color 180ms ease;
}
.bp-prompt:hover { color: var(--book-cover); }

.bp-page-num {
    position: absolute;
    bottom: 16px;
    left: 0;
    right: 0;
    text-align: center;
    font: 400 11px/1 'Lora', Georgia, serif;
    color: rgba(0, 0, 0, 0.35);
    letter-spacing: 0.1em;
}

/* =============================================================================
   Right page — writing surface
   ========================================================================== */

.book-page--right {
    padding-top: 38px;
    padding-bottom: 56px;
}

/* === BOOK PAGINATION v3 — absolute-positioned writing surface ===
   The editor sits inside .book-page--right as an absolute rectangle with explicit
   top/left/right/bottom values. Its size is therefore fixed by CSS alone — no flex
   sizing, no content-driven growth. Content that doesn't fit gets clipped by
   overflow:hidden and is then cascaded to the next page by the JS overflow handler. */
.bp-editor {
    background: transparent;
    color: var(--paper-text);
    border: 0;
    outline: none;
    padding: 0;
    font: 400 17px/32px 'Lora', Georgia, serif;
    overflow: hidden;
}
.book-page--right .bp-editor {
    position: absolute;
    top: 38px;
    left: 44px;
    right: 44px;
    bottom: 56px;
    overflow: hidden;
}
.bp-editor--paged, .bp-editor--write { overflow: hidden; }
.bp-editor:empty::before {
    content: attr(data-placeholder);
    color: rgba(0, 0, 0, 0.30);
    font-style: italic;
    pointer-events: none;
}
.bp-editor p { margin: 0 0 0 0; min-height: 32px; }
.bp-editor p + p { margin-top: 0; }
.bp-editor strong, .bp-editor b { color: inherit; font-weight: 700; }
.bp-editor em, .bp-editor i { font-style: italic; }

/* Font family swap (apply to .journal-book) */
.journal-book[data-font="handwriting"] .bp-editor,
.journal-book[data-font="handwriting"] .bp-title-input { font-family: 'Caveat', cursive; font-size: 22px; line-height: 36px; }
.journal-book[data-font="modern"] .bp-editor,
.journal-book[data-font="modern"] .bp-title-input { font-family: 'Inter', system-ui, sans-serif; font-size: 16px; line-height: 28px; }

.bp-footer-row {
    position: absolute;
    bottom: 16px;
    left: 44px;
    right: 44px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font: 400 11px/1 'Lora', Georgia, serif;
    color: rgba(0, 0, 0, 0.4);
    letter-spacing: 0.1em;
}
.bp-word-count { font-variant-numeric: tabular-nums; }

/* =============================================================================
   User highlights
   ========================================================================== */

.bp-editor mark.user-yellow   { background: rgba(255, 230, 120, 0.55); color: inherit; padding: 0.05em 0.1em; border-radius: 2px; }
.bp-editor mark.user-lavender { background: rgba(180, 160, 230, 0.45); color: inherit; padding: 0.05em 0.1em; border-radius: 2px; }
.bp-editor mark.user-mint     { background: rgba(140, 220, 180, 0.45); color: inherit; padding: 0.05em 0.1em; border-radius: 2px; }
.bp-editor mark.user-rose     { background: rgba(244, 154, 182, 0.45); color: inherit; padding: 0.05em 0.1em; border-radius: 2px; }
.bp-editor mark.user-sky      { background: rgba(140, 200, 240, 0.45); color: inherit; padding: 0.05em 0.1em; border-radius: 2px; }

/* AI highlights — softer than user marks, with a hint of underline */
.bp-editor mark[class^="ai-"] {
    background: transparent;
    color: inherit;
    padding: 0.05em 0;
    border-bottom: 2px solid currentColor;
    border-radius: 0;
    transition: background 200ms ease;
}
.bp-editor mark.ai-anxiety   { color: #7C5CC4; border-color: rgba(124, 92, 196, 0.55); }
.bp-editor mark.ai-fear      { color: #6442B0; border-color: rgba(100, 66, 176, 0.55); }
.bp-editor mark.ai-sadness   { color: #4A7BB5; border-color: rgba(74, 123, 181, 0.55); }
.bp-editor mark.ai-anger     { color: #C04B4B; border-color: rgba(192, 75, 75, 0.55); }
.bp-editor mark.ai-disgust   { color: #6F8A22; border-color: rgba(111, 138, 34, 0.55); }
.bp-editor mark.ai-joy       { color: #B89A00; border-color: rgba(184, 154, 0, 0.55); }
.bp-editor mark.ai-surprise  { color: #C77B30; border-color: rgba(199, 123, 48, 0.55); }
.bp-editor mark.ai-love      { color: #C73D7E; border-color: rgba(199, 61, 126, 0.55); }
.bp-editor mark.ai-gratitude { color: #1B7E55; border-color: rgba(27, 126, 85, 0.55); }
.bp-editor mark.ai-neutral   { color: #5F6C7C; border-color: rgba(95, 108, 124, 0.45); }
.bp-editor mark.ai-crisis    { color: #B11515; border-color: rgba(177, 21, 21, 0.65); background: rgba(177, 21, 21, 0.06); }

/* In Write mode, hide AI marks (they live as data only until Reflect) */
.journal-book[data-mode="write"] .bp-editor mark[class^="ai-"] {
    background: transparent;
    border-bottom: 0;
    color: inherit;
}

/* =============================================================================
   Floating bubble toolbar
   ========================================================================== */

.je-toolbar {
    position: absolute;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px;
    background: var(--je-toolbar-bg);
    border: 1px solid var(--je-toolbar-border);
    border-radius: 12px;
    box-shadow: 0 18px 40px -10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    user-select: none;
    animation: je-fade-in 140ms ease-out;
}
@keyframes je-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.je-btn {
    background: transparent;
    border: 0;
    color: rgba(245, 240, 255, 0.85);
    width: 32px; height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: 600 14px 'Lora', Georgia, serif;
    transition: background 150ms ease, color 150ms ease;
}
.je-btn:hover { background: rgba(180, 160, 230, 0.20); color: #fff; }
.je-btn:focus-visible { outline: 2px solid #B4A0E6; outline-offset: 1px; }

.je-sep {
    width: 1px; height: 22px;
    background: rgba(180, 160, 230, 0.22);
    margin: 0 4px;
}

.je-swatch {
    background: var(--swatch-color, #FFE678);
    border: 0;
    width: 22px; height: 22px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
    transition: transform 150ms ease, box-shadow 150ms ease;
}
.je-swatch:hover { transform: scale(1.15); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25), 0 0 0 2px rgba(255, 255, 255, 0.2); }
.je-swatch:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.je-swatch-yellow   { --swatch-color: #FFE678; }
.je-swatch-lavender { --swatch-color: #C7B5F2; }
.je-swatch-mint     { --swatch-color: #9DDDB6; }
.je-swatch-rose     { --swatch-color: #F4A0BC; }
.je-swatch-sky      { --swatch-color: #9BCFEC; }

/* =============================================================================
   Bookmark ribbon
   ========================================================================== */

.book-bookmark {
    position: absolute;
    top: -10px;
    right: 64px;
    width: 38px;
    height: 110px;
    background: linear-gradient(to bottom, var(--book-cover), var(--book-cover-edge));
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
    box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.4);
    z-index: 3;
    pointer-events: none;
}

/* =============================================================================
   Customization drawer (cover / paper / font)
   ========================================================================== */

.book-custom-toggle {
    position: fixed;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(20, 16, 38, 0.85);
    border: 1px solid rgba(180, 160, 230, 0.22);
    color: rgba(245, 240, 255, 0.85);
    cursor: pointer;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: background 180ms ease, transform 180ms ease;
}
.book-custom-toggle:hover { background: rgba(40, 32, 70, 0.92); transform: translateY(-50%) scale(1.05); }

.book-custom-panel {
    position: fixed;
    right: -340px;
    top: 0;
    bottom: 0;
    width: 320px;
    background: rgba(15, 12, 28, 0.97);
    border-left: 1px solid rgba(180, 160, 230, 0.18);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 100;
    padding: 32px 24px;
    overflow-y: auto;
    transition: right 360ms cubic-bezier(0.22, 1, 0.36, 1);
    color: rgba(245, 240, 255, 0.92);
}
.book-custom-panel.open { right: 0; }

.book-custom-panel h3 {
    font: 500 11px/1 'Inter', sans-serif;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(245, 240, 255, 0.5);
    margin: 24px 0 12px;
}
.book-custom-panel h3:first-child { margin-top: 0; }

.bcp-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.bcp-cover-swatch {
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 180ms ease, border-color 180ms ease;
}
.bcp-cover-swatch:hover { transform: scale(1.08); }
.bcp-cover-swatch.active { border-color: #fff; }
.bcp-cover-swatch[data-c="lavender"]   { background: linear-gradient(135deg, #6E5B9B, #463A6B); }
.bcp-cover-swatch[data-c="sage"]       { background: linear-gradient(135deg, #5F8B57, #3F5F3A); }
.bcp-cover-swatch[data-c="parchment"]  { background: linear-gradient(135deg, #B7976A, #8A6F4E); }
.bcp-cover-swatch[data-c="midnight"]   { background: linear-gradient(135deg, #2A2952, #1A1A38); }
.bcp-cover-swatch[data-c="rose"]       { background: linear-gradient(135deg, #B27490, #8A526D); }
.bcp-cover-swatch[data-c="ocean"]      { background: linear-gradient(135deg, #5C7DAE, #3F5980); }
.bcp-cover-swatch[data-c="goldenhour"] { background: linear-gradient(135deg, #F4B860, #E89B3D); }

.bcp-paper-option, .bcp-font-option {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(180, 160, 230, 0.16);
    color: rgba(245, 240, 255, 0.85);
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font: 500 12px/1.3 'Inter', sans-serif;
    transition: all 180ms ease;
}
.bcp-paper-option:hover, .bcp-font-option:hover {
    background: rgba(180, 160, 230, 0.16);
    border-color: rgba(180, 160, 230, 0.32);
}
.bcp-paper-option.active, .bcp-font-option.active {
    background: linear-gradient(135deg, var(--book-cover, #6E5B9B), var(--book-cover-edge, #463A6B));
    border-color: transparent;
    color: #fff;
}
.bcp-font-option { font-size: 16px; padding: 14px; }
.bcp-font-option[data-f="serif"]       { font-family: 'Lora', Georgia, serif; }
.bcp-font-option[data-f="handwriting"] { font-family: 'Caveat', cursive; font-size: 22px; }
.bcp-font-option[data-f="modern"]      { font-family: 'Inter', sans-serif; }

/* =============================================================================
   AI sticky note (Reflect mode)
   ========================================================================== */

.book-ai-sticky {
    position: absolute;
    top: 60px;
    right: -28px;
    width: 220px;
    background: linear-gradient(135deg, #FFF4B8, #FFE678);
    color: #3D3208;
    padding: 16px 16px 18px;
    border-radius: 2px;
    box-shadow: 8px 12px 24px -6px rgba(0, 0, 0, 0.5), 1px 1px 2px rgba(0, 0, 0, 0.2);
    transform: rotate(3deg);
    transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 4;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    cursor: grab;
}
.book-ai-sticky:hover { transform: rotate(0) scale(1.04); }
.book-ai-sticky::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 14px;
    background: rgba(180, 140, 50, 0.32);
    border-radius: 2px;
}
.book-ai-sticky-title {
    font: 600 10px/1 'Inter', sans-serif;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(74, 63, 14, 0.78);
    margin-bottom: 10px;
}
.book-ai-sticky-emotion {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font: 600 18px/1.1 'Inter', system-ui, sans-serif;
    color: #3D3208;
    margin-bottom: 10px;
    text-transform: capitalize;
    letter-spacing: -0.005em;
}
.book-ai-sticky-emotion small {
    font: 500 11px 'Inter', sans-serif;
    color: rgba(74, 63, 14, 0.65);
}
.book-ai-sticky-text {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    font-weight: 400;
    color: #2E2406;
}

/* =============================================================================
   Page flip animation (long, used once after save)
   ========================================================================== */

.journal-book.flipping .book-page--right {
    transform: rotateY(-180deg);
}

.journal-book.flipping {
    /* Subtle shake/settle to feel weighty */
    animation: book-settle 1200ms cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes book-settle {
    0%   { transform: translateY(0); }
    30%  { transform: translateY(-3px); }
    100% { transform: translateY(0); }
}

/* =============================================================================
   Page-turn animation (short, used for prev/next pagination)
   ========================================================================== */

.journal-book.turning-next .book-page--right,
.journal-book.turning-prev .book-page--right {
    animation: page-turn-next 520ms cubic-bezier(0.55, 0.05, 0.35, 1);
}
.journal-book.turning-prev .book-page--right {
    animation-name: page-turn-prev;
}
@keyframes page-turn-next {
    0%   { transform: rotateY(0); }
    50%  { transform: rotateY(-90deg); }
    50.01%, 100% { transform: rotateY(0); }
}
@keyframes page-turn-prev {
    0%   { transform: rotateY(0); }
    50%  { transform: rotateY(90deg); }
    50.01%, 100% { transform: rotateY(0); }
}

/* =============================================================================
   Pager controls (prev/next + page count)
   ========================================================================== */

.book-pager {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    padding: 6px 10px;
    background: rgba(20, 16, 38, 0.55);
    border: 1px solid rgba(180, 160, 230, 0.18);
    border-radius: 999px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    margin-top: -4px;
}
.book-pager-btn {
    background: transparent;
    border: 0;
    color: rgba(245, 240, 255, 0.78);
    width: 34px; height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 180ms ease, color 180ms ease, transform 180ms ease;
}
.book-pager-btn:hover:not(:disabled) {
    background: rgba(180, 160, 230, 0.18);
    color: #fff;
    transform: scale(1.08);
}
.book-pager-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.book-pager-btn:focus-visible {
    outline: 2px solid #B4A0E6;
    outline-offset: 2px;
}
.book-pager-count {
    font: 600 13px/1 'Inter', system-ui, sans-serif;
    color: rgba(245, 240, 255, 0.85);
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
    min-width: 48px;
    text-align: center;
}

/* =============================================================================
   Save/analyze action button
   ========================================================================== */

.book-action-row {
    display: flex;
    gap: 14px;
    align-items: center;
}
.book-save-btn {
    background: linear-gradient(135deg, #B4A0E6, #8CB482);
    color: #1A1530;
    border: 0;
    padding: 14px 28px;
    border-radius: 999px;
    font: 600 14px/1 'Inter', sans-serif;
    letter-spacing: 0.04em;
    cursor: pointer;
    box-shadow: 0 14px 32px -8px rgba(180, 160, 230, 0.5);
    transition: transform 200ms ease, box-shadow 200ms ease;
}
.book-save-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 20px 40px -8px rgba(180, 160, 230, 0.6);
}
.book-save-btn:active:not(:disabled) { transform: translateY(0); }
.book-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.book-save-btn:focus-visible { outline: 2px solid #B4A0E6; outline-offset: 4px; }

.book-talk-btn {
    background: rgba(20, 16, 38, 0.65);
    border: 1px solid rgba(180, 160, 230, 0.32);
    color: rgba(245, 240, 255, 0.92);
    padding: 12px 22px;
    border-radius: 999px;
    font: 500 13px/1 'Inter', sans-serif;
    cursor: pointer;
    transition: all 180ms ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.book-talk-btn:hover {
    background: rgba(180, 160, 230, 0.16);
    border-color: rgba(180, 160, 230, 0.55);
    color: #fff;
}

/* =============================================================================
   Reduced motion + Mobile
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .journal-book, .book-page, .book-custom-panel, .je-toolbar { transition: none !important; animation: none !important; }
    .journal-book.flipping { animation: none; }
}

@media (max-width: 768px) {
    /* Outer page — minimize horizontal padding so the book uses near-full width */
    .journal-book-page {
        padding: 14px 8px 110px;   /* leave room at bottom for sticky save button + pager */
        gap: 14px;
        perspective: none;         /* 3D perspective looks cramped on phones */
    }
    .journal-book-mode-bar {
        position: sticky;
        top: 8px;
        z-index: 20;
    }
    .journal-book-mode-bar button {
        padding: 9px 14px;
        font-size: 13px;
    }

    /* Book — full width, stacked pages on mobile: meta on top, writing below */
    .journal-book {
        width: 100%;
        height: auto;
        --book-h: auto;
    }
    .journal-book::before { display: none; }
    .journal-book-spread {
        grid-template-columns: 1fr;
        grid-auto-rows: auto;
        border-radius: 10px;
        box-shadow:
            0 12px 24px -10px rgba(0, 0, 0, 0.45),
            0 0 0 2px var(--book-cover-edge),
            0 0 0 4px var(--book-cover);
    }
    .journal-book-spread::after { display: none; }
    .book-bookmark { display: none; }

    /* Left page (meta) stays visible as a compact strip on top of the writing page */
    .book-page {
        padding: 22px 20px;
        transform: none !important;
    }
    .book-page--left {
        gap: 12px;
        padding: 18px 20px;
        border-bottom: 1px solid var(--paper-line);
    }
    .book-page--left .bp-date-day { font-size: 30px; }
    .book-page--left .bp-prompts { margin-top: 6px; padding: 10px 14px; }
    .book-page--left .bp-prompt { font-size: 13px; padding: 3px 0; }
    .book-page--left::after, .book-page--right::after { display: none; }

    /* Right page (writing) — fixed height so overflow cascades, no inner scroll */
    .book-page--right {
        padding: 0;            /* padding now lives on the absolutely-positioned editor */
        height: 58vh;
        min-height: 380px;
    }
    /* Mobile: tighter padding inside the writing rectangle */
    .book-page--right .bp-editor {
        top: 22px;
        left: 18px;
        right: 18px;
        bottom: 48px;
    }
    .bp-page-num {
        position: absolute;
        bottom: 12px;
        left: 0;
        right: 0;
        text-align: center;
    }
    .book-page--left .bp-page-num {
        position: static;
        text-align: center;
        padding-top: 4px;
    }

    /* Editor — bigger, more breathing room */
    .bp-editor {
        font-size: 17px;
        line-height: 30px;
    }
    .journal-book[data-font="handwriting"] .bp-editor { font-size: 22px; line-height: 34px; }
    .journal-book[data-font="modern"] .bp-editor { font-size: 16px; line-height: 28px; }

    /* Sticky save button — fixed at the bottom of the viewport, doesn't cover content */
    .book-action-row {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 30;
        padding: 12px 16px calc(env(safe-area-inset-bottom, 0) + 12px);
        background: linear-gradient(to top, rgba(8, 8, 18, 0.96) 65%, rgba(8, 8, 18, 0));
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    .book-save-btn {
        flex: 1;
        max-width: 360px;
        padding: 14px 20px;
    }
    .book-talk-btn {
        padding: 10px 16px;
        font-size: 12px;
    }

    /* Pager — sits above the sticky save button */
    .book-pager {
        position: sticky;
        bottom: 80px;
        z-index: 25;
    }

    /* Customization — small fixed button in the top-right, out of the way of writing */
    .book-custom-toggle {
        position: fixed;
        right: 10px;
        top: 70px;
        bottom: auto;
        transform: none;
        width: 36px;
        height: 36px;
        border-radius: 10px;
        z-index: 15;
    }
    .book-custom-toggle:hover { transform: scale(1.05); }
    .book-custom-panel { width: 86vw; right: -90vw; }
    .book-custom-panel.open { right: 0; }

    /* AI sticky note — fits inside the page, not hanging off the edge */
    .book-ai-sticky {
        position: relative;
        top: auto;
        right: auto;
        width: auto;
        margin: 18px 0 0;
        transform: rotate(0);
    }

    /* Floating bubble toolbar — wider tap targets */
    .je-btn { width: 36px; height: 36px; }
    .je-swatch { width: 26px; height: 26px; }
}

/* Smaller phones */
@media (max-width: 380px) {
    .journal-book-page { padding: 14px 4px 96px; }
    .book-page { padding: 20px 16px; }
    .book-page--right { padding: 22px 16px 28px; }
    .journal-book-mode-bar button { padding: 8px 12px; font-size: 12px; }
}
