:root {
    --page-bg: #faf8f0;
    --page-text: #2e3440;
    --page-text-light: #636e7b;
    --page-border: #e8e4da;
    --cover-shadow: rgba(0,0,0,0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #1a1a2e;
    color: #ccc;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
}

/* --- Top bar --- */
.fb-topbar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(0,0,0,0.25);
    flex-shrink: 0;
}
.fb-topbar a {
    color: #aaa;
    text-decoration: none;
    font-size: 0.85em;
    transition: color 0.15s;
}
.fb-topbar a:hover { color: #fff; }
.fb-topbar .fb-title {
    font-size: 0.95em;
    color: #ddd;
    font-weight: 600;
    text-align: center;
    flex: 1;
}

/* --- Book container --- */
.fb-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    width: 100%;
    min-height: 0;
}

.fb-book-wrap {
    position: relative;
    max-width: 1100px;
    width: 100%;
}

.fb-book {
    margin: 0 auto;
}

/* --- Page base --- */
.fb-page {
    background: var(--page-bg);
    color: var(--page-text);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 14px;
    line-height: 1.65;
    padding: 36px 32px 44px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--page-border);
}

.fb-page .page-num {
    position: absolute;
    bottom: 14px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 11px;
    color: var(--page-text-light);
}
.fb-page .page-num.left { left: 32px; }
.fb-page .page-num.right { right: 32px; }

/* --- Cover pages --- */
.fb-cover {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 30px;
    color: #fff;
    border: none;
    font-family: 'Segoe UI', system-ui, sans-serif;
}
.fb-cover .cover-series {
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    opacity: 0.7;
    margin-bottom: 16px;
}
.fb-cover .cover-title {
    font-size: 1.6em;
    font-weight: 700;
    line-height: 1.25;
    margin-bottom: 8px;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.fb-cover .cover-subtitle {
    font-size: 0.95em;
    font-weight: 400;
    opacity: 0.85;
    margin-bottom: 20px;
}
.fb-cover .cover-author {
    font-size: 0.8em;
    opacity: 0.65;
    letter-spacing: 0.08em;
}
.fb-cover .cover-badge {
    display: inline-block;
    margin-top: 18px;
    padding: 4px 16px;
    border-radius: 20px;
    background: rgba(255,255,255,0.2);
    font-size: 0.75em;
    letter-spacing: 0.05em;
}

.cover-book1 { background: linear-gradient(135deg, #f6b93b, #e58e26); }
.cover-book2 { background: linear-gradient(135deg, #38ada9, #1a7a76); }
.cover-book3 { background: linear-gradient(135deg, #6c5ce7, #4834a8); }
.cover-book4 { background: linear-gradient(135deg, #2d3436, #4a6fa5); }

.fb-back-cover {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 30px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    border: none;
}
.fb-back-cover .back-msg {
    font-style: italic;
    font-size: 1em;
    line-height: 1.6;
    max-width: 320px;
    opacity: 0.85;
}
.fb-back-cover .back-author {
    margin-top: 24px;
    font-size: 0.8em;
    opacity: 0.6;
}

/* --- Content styling inside pages --- */
.fb-page h2 {
    font-size: 1.25em;
    margin: 0 0 14px;
    color: #3b4252;
    font-weight: 700;
    border-bottom: 1px solid var(--page-border);
    padding-bottom: 8px;
}
.fb-page h3 {
    font-size: 1.05em;
    margin: 12px 0 8px;
    color: #4a5568;
}
.fb-page p {
    margin: 0 0 10px;
    text-align: justify;
    hyphens: auto;
}
.fb-page img {
    display: block;
    max-width: 90%;
    max-height: 55%;
    margin: 10px auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    object-fit: contain;
}
.fb-page blockquote {
    margin: 8px 0;
    padding: 8px 14px;
    border-left: 3px solid #d8dee9;
    background: #f0ede5;
    font-size: 0.92em;
    border-radius: 0 4px 4px 0;
}
.fb-page em { font-style: italic; }
.fb-page strong { font-weight: 700; color: #3b4252; }
.fb-page hr {
    border: none;
    border-top: 1px solid var(--page-border);
    margin: 14px 0;
}
.fb-page ul, .fb-page ol {
    margin: 6px 0 10px 20px;
    font-size: 0.95em;
}
.fb-page table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
    margin: 8px 0;
}
.fb-page th, .fb-page td {
    padding: 5px 8px;
    border: 1px solid var(--page-border);
    text-align: left;
}
.fb-page th { background: #f0ede5; font-weight: 600; }

/* Callout boxes (breathing, silver lining, etc.) */
.fb-page .callout {
    margin: 10px 0;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.92em;
}
.fb-page .callout-breathing { background: #e8f4f8; border-left: 3px solid #5e9ccd; }
.fb-page .callout-silver { background: #fdf3d4; border-left: 3px solid #e8b931; }
.fb-page .callout-buddy { background: #e8f8e8; border-left: 3px solid #38ada9; }
.fb-page .callout-storm { background: #f0e8f8; border-left: 3px solid #6c5ce7; }

/* --- Picture book pages (full-bleed) --- */
.fb-page.picture-page {
    padding: 0;
    position: relative;
    overflow: hidden;
    border: none;
    background: #1a1520;
}
.fb-page.picture-page img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    margin: 0;
    max-width: none;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
}
.fb-page.picture-page .page-text {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 40px 24px 20px;
    background: linear-gradient(to top, rgba(15,10,25,0.82) 0%, rgba(15,10,25,0.5) 60%, transparent 100%);
    color: #fff;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 1.1em;
    line-height: 1.55;
    text-align: center;
    text-shadow:
        0 0 12px rgba(218,165,32,0.8),
        0 0 28px rgba(218,165,32,0.45),
        0 0 4px rgba(255,255,255,0.5);
    z-index: 1;
}
.fb-page.picture-page .page-text strong {
    color: #ffd700;
    text-shadow:
        0 0 14px rgba(218,165,32,0.9),
        0 0 32px rgba(218,165,32,0.5),
        0 0 4px rgba(255,255,255,0.6);
}
/* Text at top variant */
.fb-page.picture-page.text-top .page-text {
    bottom: auto;
    top: 0;
    padding: 20px 24px 40px;
    background: linear-gradient(to bottom, rgba(15,10,25,0.82) 0%, rgba(15,10,25,0.5) 60%, transparent 100%);
}
/* Full-bleed back cover for picture book */
.fb-page.fb-back-cover-pic {
    padding: 0;
    border: none;
}
.fb-page.fb-back-cover-pic .page-text {
    font-style: italic;
}

/* --- Controls --- */
.fb-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 14px 20px;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.fb-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: #ccc;
    padding: 8px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.88em;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}
.fb-btn:hover { background: rgba(255,255,255,0.2); color: #fff; }
.fb-btn:disabled { opacity: 0.35; cursor: default; }

.fb-page-info {
    color: #999;
    font-size: 0.85em;
    min-width: 120px;
    text-align: center;
}

.fb-chapter-select {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.15);
    color: #ccc;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    font-family: inherit;
    cursor: pointer;
    max-width: 220px;
}
.fb-chapter-select option { background: #2d2d44; color: #ccc; }

/* --- Loading --- */
.fb-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60vh;
    color: #888;
    font-size: 1.1em;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .fb-page { font-size: 12px; padding: 24px 18px 36px; }
    .fb-cover .cover-title { font-size: 1.3em; }
    .fb-controls { gap: 8px; padding: 10px 12px; }
    .fb-btn { padding: 6px 12px; font-size: 0.82em; }
}
@media (max-width: 480px) {
    .fb-page { font-size: 11px; padding: 16px 12px 30px; }
    .fb-topbar { padding: 8px 12px; }
}
