/* ============================================================
   Scriptorium — design tokens
   Palette: illuminated-manuscript inspired — deep ink navy, warm
   parchment, library gold leaf, and a deep emerald "morocco leather"
   accent. Type: Fraunces (serif, book titles/headlines) + Inter
   (UI/body). Every color below carries through light and (where the
   shell defines it) dark surfaces consistently.
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600;9..144,700;9..144,800&family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --ink:        #121B33;   /* deep navy-charcoal — chrome, headers */
    --ink-light:  #202B4C;
    --ink-rgb:    18,27,51;
    --parchment:  #FBF6EC;   /* warm off-white page background */
    --paper:      #FFFFFF;
    --gold:       #C89B3C;   /* library gold leaf — used for accents, active states, illumination */
    --gold-rgb:   200,155,60;
    --gold-soft:  #F3E6C4;
    --gold-dark:  #93701F;
    --accent:       #1B6F5C;   /* deep emerald "morocco leather" — primary CTAs, progress, links */
    --accent-dark:  #114D3F;
    --accent-soft:  #DFEEE8;
    --accent-rgb:   27,111,92;
    --ink-text:   #1C2027;
    --muted:      #6B7280;
    --hairline:   #E7E1D2;
    --success:    #2F7D51;
    --danger:     #B03B2E;
    --radius:     12px;
    --radius-lg:  20px;
    --shadow-sm:  0 1px 2px rgba(18,27,51,0.05), 0 2px 8px rgba(18,27,51,0.05);
    --shadow:     0 1px 2px rgba(18,27,51,0.06), 0 10px 28px rgba(18,27,51,0.08);
    --shadow-lg:  0 4px 10px rgba(18,27,51,0.08), 0 24px 56px rgba(18,27,51,0.14);
    --serif: 'Fraunces', Georgia, serif;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bottom-nav-h: 66px;
    /* A faint paper-grain texture, applied at very low opacity behind
       parchment surfaces so large flat areas feel tactile instead of flat
       digital fills — one inline SVG, no image request. */
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

.icon { flex-shrink: 0; display: inline-block; vertical-align: -3px; }
.logo-mark { color: var(--gold); vertical-align: -5px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--sans);
    background-color: var(--parchment);
    background-image: var(--grain);
    background-size: 180px 180px;
    color: var(--ink-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; margin: 0 0 0.4em; letter-spacing: -0.01em; }
p { margin: 0 0 1em; }

.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 1px solid transparent; border-radius: 8px;
    padding: 11px 20px; font-weight: 600; font-size: 15px; cursor: pointer;
    text-decoration: none; transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:active { transform: translateY(1px); }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { box-shadow: 0 4px 14px rgba(200,155,60,0.35); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { box-shadow: 0 4px 14px rgba(27,111,92,0.35); }
.btn-ink { background: var(--ink); color: #fff; }
.btn-ink:hover { background: var(--ink-light); }
.btn-outline { background: transparent; border-color: var(--hairline); color: var(--ink-text); }
.btn-outline:hover { border-color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Form ---------- */
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field input[type=text], .field input[type=email], .field input[type=password],
.field input[type=number], .field select, .field textarea {
    width: 100%; padding: 11px 13px; border: 1px solid var(--hairline);
    border-radius: 8px; background: var(--paper); color: var(--ink-text);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--gold); }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.field input[type=file] { padding: 8px 0; }

.alert { padding: 12px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 18px; }
.alert-success { background: #E7F1EB; color: var(--success); }
.alert-error { background: #F7E7E1; color: var(--danger); }

/* ============================================================
   Public site chrome
   ============================================================ */
.topbar {
    background: var(--ink); color: #fff; padding: 14px 0;
    position: sticky; top: 0; z-index: 40;
}
.topbar .container { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { font-family: var(--serif); font-size: 22px; color: #fff; text-decoration: none; display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; }
.brand .mark { color: var(--gold); }
.topbar nav { display: flex; align-items: center; gap: 22px; flex-shrink: 0; }
.topbar .container { flex-wrap: nowrap; }
.topbar nav .nav-links { display: contents; }
.topbar nav a { color: #D9DEEB; text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap; }
.topbar nav a:hover { color: #fff; }
.topbar .search { flex: 1; max-width: 360px; }
.topbar .search input {
    width: 100%; padding: 9px 14px; border-radius: 20px; border: 1px solid #33406A;
    background: #1B2A4D; color: #fff; font-size: 14px;
}
.topbar .search input::placeholder { color: #8892AC; }
.menu-toggle { display: none; background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }

/* ---------- Hero ---------- */
.hero { padding: 72px 0 56px; }
.hero .container { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 48px; align-items: center; }
.hero-eyebrow { color: var(--gold); font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.hero h1 { font-size: clamp(32px, 5vw, 52px); line-height: 1.05; max-width: 14ch; }
.hero p.lead { font-size: 18px; color: var(--muted); max-width: 46ch; }
.hero-actions { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; }

/* ---------- Hero book mockup — a genuine open-book illustration built from
   CSS shapes (no image asset needed), replacing generic placeholder slabs. */
.book-mockup-wrap { display: flex; align-items: center; justify-content: center; height: 360px; perspective: 1400px; }
.book-mockup {
    position: relative; width: 340px; height: 240px; transform: rotateX(8deg) rotateZ(-2deg);
    filter: drop-shadow(0 30px 40px rgba(18,27,51,0.28));
}
.book-mockup .spine {
    position: absolute; left: 50%; top: -6px; width: 10px; height: 252px; margin-left: -5px;
    background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dark) 100%); border-radius: 2px; z-index: 3;
}
.book-mockup .page {
    position: absolute; top: 0; width: 168px; height: 240px; background: #FFFDF8;
    border: 1px solid #EDE6D3; box-shadow: inset 0 0 24px rgba(18,27,51,0.05);
    padding: 22px 18px; overflow: hidden;
}
.book-mockup .page.left { left: 2px; border-radius: 6px 2px 2px 6px; transform-origin: right center; transform: rotateY(6deg); }
.book-mockup .page.right { right: 2px; border-radius: 2px 6px 6px 2px; transform-origin: left center; transform: rotateY(-6deg); }
.book-mockup .page .ln { height: 7px; background: #E7DFCB; border-radius: 3px; margin-bottom: 10px; }
.book-mockup .page .ln.short { width: 62%; }
.book-mockup .page .ln.title { height: 11px; width: 74%; background: var(--gold-soft); margin-bottom: 16px; }
.book-mockup .ribbon {
    position: absolute; top: -14px; right: 66px; width: 20px; height: 96px; z-index: 4;
    background: var(--accent); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%);
    box-shadow: 0 6px 14px rgba(27,111,92,0.35);
}
.book-mockup .sparkle-badge {
    position: absolute; bottom: -18px; left: -22px; z-index: 5; background: var(--paper);
    border-radius: 50px; padding: 9px 16px 9px 12px; box-shadow: var(--shadow-lg);
    display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 700; color: var(--ink);
}
.book-mockup .sparkle-badge .icon { color: var(--gold); }
.book-mockup .float-chip {
    position: absolute; top: -22px; right: -30px; z-index: 5; background: var(--ink); color: #fff;
    border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow-lg); font-size: 12px; max-width: 150px;
}
.book-mockup .float-chip strong { display: block; font-family: var(--serif); font-size: 15px; color: var(--gold-soft); }

/* ---------- How it works ---------- */
.how-it-works { padding: 12px 0 60px; }
.how-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 26px; }
.how-step {
    background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--radius-lg);
    padding: 26px 24px; box-shadow: var(--shadow-sm);
}
.how-num { font-family: var(--serif); font-size: 15px; font-weight: 700; color: var(--gold-dark); margin-bottom: 10px; }
.how-step h3 { font-size: 18px; margin-bottom: 8px; }
.how-step p { color: var(--muted); font-size: 14.5px; margin-bottom: 0; }

/* ---------- Plans ---------- */
.plans { padding: 56px 0; border-top: 1px solid var(--hairline); }
.plans h2 { font-size: 30px; text-align: center; }
.plans .sub { text-align: center; color: var(--muted); margin-bottom: 40px; }
.plan-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 24px; max-width: 780px; margin: 0 auto; }
.plan-card {
    background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--radius-lg);
    padding: 30px; display: flex; flex-direction: column; transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.plan-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.plan-card.featured { border-color: var(--gold); box-shadow: 0 8px 26px rgba(200,155,60,0.18); position: relative; }
.plan-card.featured::before {
    content: '★ MOST POPULAR'; position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
    background: var(--gold); color: var(--ink); font-size: 10.5px; font-weight: 800; letter-spacing: 0.04em;
    padding: 4px 12px; border-radius: 20px; box-shadow: var(--shadow-sm);
}
.plan-card .plan-tag { font-size: 12px; font-weight: 700; color: var(--gold); margin-bottom: 8px; }
.plan-card .plan-name { font-family: var(--serif); font-size: 22px; margin-bottom: 4px; }
.plan-card .plan-price { font-size: 34px; font-weight: 700; margin: 14px 0 4px; }
.plan-card .plan-price span { font-size: 14px; font-weight: 500; color: var(--muted); }
.plan-card ul { list-style: none; padding: 0; margin: 18px 0 24px; font-size: 14px; color: var(--ink-text); }
.plan-card li { padding: 6px 0; border-top: 1px solid var(--hairline); }
.plan-card li:first-child { border-top: none; }

/* ============================================================
   Dashboard shell (logged-in area)
   ============================================================ */
.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
/* The backdrop must be taken out of grid flow at every viewport width, not
   only inside the mobile media query below — otherwise this empty div
   silently claims the sidebar's grid column, pushing the real sidebar into
   the wide content column and main content into a phantom second row. */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(20,33,61,0.5); z-index: 55; }
.sidebar-backdrop.open { display: block; }
.sidebar {
    background: var(--ink); color: #E9ECF5; padding: 22px 16px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .brand { margin-bottom: 28px; padding: 0 8px; }
.sidebar nav a {
    display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
    text-decoration: none; color: #C7CDE0; font-size: 14px; font-weight: 500; margin-bottom: 2px;
}
.sidebar nav a:hover { background: var(--ink-light); color: #fff; }
.sidebar nav a.active { background: var(--gold); color: var(--ink); }
.sidebar .section-label { font-size: 11px; text-transform: none; color: #6E7797; margin: 20px 0 8px; padding: 0 12px; }
.main { padding: 28px 32px 60px; min-width: 0; }
.main-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 26px; flex-wrap: wrap; gap: 12px; }
.main-header h1 { font-size: 26px; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card { background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--radius-lg); padding: 18px 20px; }
.stat-card .num { font-family: var(--serif); font-size: 28px; }
.stat-card .label { font-size: 13px; color: var(--muted); }

/* ---------- Admin: manuscript source toggle (book-edit) ---------- */
.source-toggle { display: flex; gap: 10px; flex-wrap: wrap; }
.source-toggle-opt {
    display: flex; align-items: center; gap: 7px; padding: 10px 14px; border-radius: 10px;
    border: 1.5px solid var(--hairline); font-size: 13.5px; font-weight: 600; cursor: pointer;
    color: var(--muted); transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.source-toggle-opt:has(input:checked) { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); }
.source-toggle-opt input { width: auto; margin: 0; accent-color: var(--accent); }

/* ---------- Admin: revenue sparkline ---------- */
.sparkline-card { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.sparkline-card svg { display: block; overflow: visible; max-width: 100%; height: auto; }
.sparkline-legend { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.sparkline-legend strong { display: block; font-family: var(--serif); font-size: 22px; color: var(--ink); }

/* ---------- Mobile app header (dashboard-area pages) ---------- */
.app-header { display: none; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.app-header .brand {
    color: var(--ink); font-size: 20px; font-weight: 700; font-family: var(--sans);
    min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.avatar-circle {
    width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
    text-decoration: none; flex-shrink: 0;
}

/* ---------- Search pill ---------- */
.search-pill-form { position: relative; margin-bottom: 22px; }
.search-pill-form input {
    width: 100%; padding: 13px 16px 13px 42px; border-radius: 24px; border: none;
    background: #F1EFE6; font-size: 15px; color: var(--ink-text);
}
.search-pill-form input::placeholder { color: #97928A; }
.search-pill-form::before {
    content: ''; position: absolute; left: 16px; top: 50%; width: 17px; height: 17px;
    transform: translateY(-50%); pointer-events: none; background: var(--muted);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* ---------- Genre chips ---------- */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.genre-chip {
    flex-shrink: 0; padding: 8px 16px; border-radius: 20px; border: 1px solid var(--hairline);
    background: var(--paper); color: var(--ink-text); font-size: 13px; font-weight: 500;
    text-decoration: none; white-space: nowrap;
}
.genre-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Featured banner ---------- */
.featured-banner {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    border-radius: 18px; padding: 18px; display: flex; gap: 14px; align-items: center;
    color: #fff; margin-bottom: 28px;
}
.featured-banner .cover { width: 60px; height: 86px; border-radius: 8px; object-fit: cover; flex-shrink: 0; background: rgba(255,255,255,0.15); }
.featured-banner .eyebrow { font-size: 10.5px; font-weight: 700; letter-spacing: 0.04em; opacity: 0.8; margin-bottom: 3px; }
.featured-banner h3 { font-size: 17px; color: #fff; margin-bottom: 2px; }
.featured-banner .byline { font-size: 13px; opacity: 0.85; margin-bottom: 12px; }
.featured-banner .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.featured-banner .btn-white { background: #fff; color: var(--accent-dark); }
.featured-banner .btn-ghost { background: rgba(255,255,255,0.12); color: #fff; border-color: rgba(255,255,255,0.4); }

/* ---------- Section heading ---------- */
.section-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 0 14px; }
.section-heading h2 { font-size: 18px; }
.section-heading a { font-size: 13px; color: var(--accent); text-decoration: none; font-weight: 600; }

/* ---------- Horizontal scroll rows (Continue Reading) ---------- */
.scroll-row { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; }
.continue-card { flex-shrink: 0; width: 150px; text-decoration: none; color: var(--ink-text); }
.continue-card .book-cover { width: 150px; margin-bottom: 8px; }
.continue-card .book-title { font-size: 13px; }
.progress-track { height: 5px; background: var(--hairline); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 4px; }
.progress-label { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- Bottom tab bar (mobile app nav) ---------- */
.bottom-tab-bar {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 70;
    background: var(--paper); border-top: 1px solid var(--hairline);
    padding: 8px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; align-items: center;
}
.bottom-tab-bar a {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500;
    flex: 1; padding: 4px 0; position: relative;
}
.bottom-tab-bar a .tab-icon { display: block; margin: 0 auto; }
.bottom-tab-bar a.active { color: var(--accent); font-weight: 700; }
.bottom-tab-bar a.active::before {
    content: ''; position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
    width: 22px; height: 3px; border-radius: 3px; background: var(--accent);
}

/* ---------- Book grid ---------- */
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 22px; }
.book-card { text-decoration: none; color: var(--ink-text); }
.book-cover {
    aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; background: var(--ink);
    box-shadow: var(--shadow); margin-bottom: 10px; position: relative;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover .no-thumb {
    display: flex; align-items: center; justify-content: center; height: 100%;
    color: var(--gold-soft); font-family: var(--serif); font-size: 14px; text-align: center; padding: 10px;
}
.book-title {
    font-family: var(--serif); font-size: 15px; line-height: 1.3; margin-bottom: 2px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; overflow-wrap: anywhere;
}
.book-author {
    font-size: 12px; color: var(--muted); margin-bottom: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-genre-tag {
    display: inline-block; font-size: 10px; font-weight: 600; color: var(--muted);
    background: #F1EFE6; padding: 3px 9px; border-radius: 12px;
}

/* ---------- Tables (admin) ---------- */
.table-wrap { background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--radius); overflow: hidden; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 560px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--hairline); }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #FAF8F3; }
tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-ready, .badge-published, .badge-active, .badge-success { background: #E7F1EB; color: var(--success); }
.badge-draft, .badge-pending { background: #F1EEE3; color: var(--muted); }
.badge-processing { background: #FCF0DA; color: #9B6B12; }
.badge-failed, .badge-suspended { background: #F7E7E1; color: var(--danger); }

.card { background: var(--paper); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 24px; margin-bottom: 22px; }
.card h3 { font-size: 17px; margin-bottom: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.thumb-preview { width: 120px; aspect-ratio: 2/3; border-radius: 4px; object-fit: cover; border: 1px solid var(--hairline); }

/* ============================================================
   Reader — a genuine paginated book, not a scrolling webpage.
   `.reader-pager` is a CSS multi-column box with a fixed height equal to
   `.reader-viewport`'s content box; the browser lays content out into
   discrete same-width "screens" left to right instead of vertically. We
   just translateX() by one viewport-width per turn — that's the whole
   trick, no JS text-reflow engine required.

   Three reading themes (parchment / sepia / night) are scoped with
   [data-reader-theme] on .reader-root and override the handful of tokens
   the reader surface actually uses.
   ============================================================ */
:root {
    --rt-bg: var(--parchment);
    --rt-page: #FFFDF8;
    --rt-text: #241F16;
    --rt-muted: #8A7F68;
    --rt-hairline: #E9E1CC;
    --rt-chrome: rgba(251,246,236,0.94);
}
.reader-root[data-reader-theme="sepia"] {
    --rt-bg: #F1E5C8; --rt-page: #F6ECD3; --rt-text: #3A2E19; --rt-muted: #8C7A50;
    --rt-hairline: #E2D3A9; --rt-chrome: rgba(241,229,200,0.94);
}
.reader-root[data-reader-theme="night"] {
    --rt-bg: #14171F; --rt-page: #14171F; --rt-text: #DCDEE6; --rt-muted: #7B8093;
    --rt-hairline: #262B38; --rt-chrome: rgba(20,23,31,0.92);
}
.reader-root { background: var(--rt-bg); min-height: 100vh; min-height: 100dvh; color: var(--rt-text); }

.reader-progress-track { position: fixed; top: 0; left: 0; right: 0; height: 3px; background: var(--rt-hairline); z-index: 90; }
.reader-progress-fill { height: 100%; background: var(--gold); transition: width 0.2s ease; }

.reader-topbar {
    position: fixed; top: 3px; left: 0; right: 0; z-index: 60; background: var(--rt-chrome);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 18px; border-bottom: 1px solid var(--rt-hairline);
    transition: transform 0.25s ease, opacity 0.25s ease;
}
.reader-root.chrome-hidden .reader-topbar { transform: translateY(-100%); opacity: 0; }
.reader-back { color: var(--rt-text); text-decoration: none; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.reader-back:hover { color: var(--accent); }
.reader-chapter-label {
    font-size: 12.5px; color: var(--rt-muted); text-align: center; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px;
}
.reader-controls { display: flex; gap: 5px; flex-shrink: 0; }
.reader-controls button {
    width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--rt-hairline); background: transparent;
    color: var(--rt-text); font-weight: 700; font-size: 13px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; position: relative;
}
.reader-controls button:hover { border-color: var(--accent); color: var(--accent); }

.reader-viewport {
    position: relative;
    height: 100vh; height: 100dvh;
    max-width: 900px; margin: 0 auto;
}
/* .reader-clip is the true clipping box: it must carry NO padding of its
   own, because CSS `overflow:hidden` clips at an element's padding edge
   (i.e. padding stays visible), not its content edge. Padding here would
   let the neighbouring (translated, off-screen) multicol pages bleed a
   sliver of text into that padding band. Instead the old padding values
   become an `inset` on this absolutely-positioned box, which shrinks its
   actual border-box to exactly the reading column's footprint — so the
   clip lands exactly flush with the visible page. */
.reader-clip {
    position: absolute; inset: 66px 26px 78px;
    overflow: hidden;
}
.reader-pager {
    height: 100%; width: 100%;
    column-gap: 56px;
    column-fill: auto;
    will-change: transform;
}
.reader-pager.sliding { transition: transform 0.32s cubic-bezier(.22,.61,.36,1); }
.reader-root[data-cols="1"] .reader-pager { column-count: 1; }
.reader-root[data-cols="2"] .reader-pager { column-count: 2; }

.reader-title { font-size: 28px; break-after: avoid; }
.reader-meta { color: var(--rt-muted); font-size: 14px; margin-bottom: 20px; }
.reader-summary { font-style: italic; color: var(--rt-muted); border-left: 3px solid var(--gold); padding-left: 14px; margin-bottom: 28px; break-inside: avoid; }
.reader-body { font-family: var(--serif); line-height: 1.75; overflow-wrap: normal; word-break: normal; hyphens: none; color: var(--rt-text); }
.reader-body h2 { font-size: 1.3em; margin: 1.6em 0 0.6em; break-after: avoid; break-before: column; color: var(--rt-text); }
.reader-body h2:first-child { break-before: avoid; }
.reader-body p { margin: 0 0 1.1em; orphans: 2; widows: 2; }
.reader-body ul, .reader-body ol { margin: 0 0 1.1em; padding-left: 1.4em; }
.reader-body img { break-inside: avoid; margin: 0 auto 1em; border-radius: 6px; }

/* ------------------------------------------------------------------
 * Direct PDF pager (assets/js/pdf-reader.js) — renders the manuscript's
 * own PDF pages straight to canvas instead of reflowed HTML text, so a
 * book is instantly readable the moment it's uploaded (no processing
 * wait of any kind). Shares .reader-viewport/.reader-clip with the HTML
 * reader for identical chrome; only what's inside .reader-clip differs.
 * ------------------------------------------------------------------ */
.pdf-strip {
    position: absolute; inset: 0;
    display: flex; width: 300%; height: 100%;
    transform: translateX(-33.3333%);
    will-change: transform;
}
.pdf-strip.sliding { transition: transform 0.32s cubic-bezier(.22,.61,.36,1); }
.pdf-slot {
    width: 33.3333%; height: 100%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; gap: 16px;
    position: relative;
}
.pdf-slot canvas {
    max-width: 100%; max-height: 100%;
    background: #fff; border-radius: 2px;
    box-shadow: 0 2px 22px rgba(20,15,5,0.16);
}
.pdf-slot .spinner { position: absolute; }
/* Approximate reading themes on top of a page image that's otherwise
   just "whatever color the PDF actually is" — the same trick many PDF
   readers use for a dark mode. Not pixel-perfect on colour pages, but
   correct and legible for the overwhelming majority of book PDFs
   (plain black text on a white page). */
.reader-root[data-reader-theme="sepia"] .pdf-slot canvas { filter: sepia(0.55) contrast(0.92) brightness(0.97); }
.reader-root[data-reader-theme="night"] .pdf-slot canvas { filter: invert(0.92) hue-rotate(180deg) brightness(0.92) contrast(0.9); }

/* Invisible left/right tap zones for page-turns, middle zone toggles chrome */
.reader-tapzones { position: fixed; inset: 66px 0 78px; z-index: 55; display: flex; }
.reader-tapzones .z { flex: 1; }
.reader-tapzones .z.mid { flex: 1.6; }

.reader-bottombar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60; background: var(--rt-chrome);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    border-top: 1px solid var(--rt-hairline);
    padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
    display: flex; align-items: center; gap: 14px;
    transition: transform 0.25s ease, opacity 0.25s ease;
}
.reader-root.chrome-hidden .reader-bottombar { transform: translateY(100%); opacity: 0; }
.reader-nav-btn {
    width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--rt-hairline); background: transparent;
    color: var(--rt-text); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
}
.reader-nav-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.reader-nav-btn:disabled { opacity: 0.3; cursor: default; }
.reader-page-indicator { flex: 1; text-align: center; font-size: 12.5px; color: var(--rt-muted); }
.reader-page-indicator .bar { height: 3px; background: var(--rt-hairline); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.reader-page-indicator .bar span { display: block; height: 100%; background: var(--gold); transition: width 0.2s ease; }

/* Theme picker popover */
.theme-popover {
    position: absolute; top: 42px; right: 0; background: var(--paper); color: var(--ink-text);
    border: 1px solid var(--hairline); border-radius: 12px; box-shadow: var(--shadow-lg);
    padding: 10px; display: none; gap: 8px; z-index: 70;
}
.theme-popover.open { display: flex; }
.theme-swatch {
    width: 40px; height: 40px; border-radius: 9px; border: 2px solid transparent; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 15px; font-family: var(--serif); font-weight: 700;
}
.theme-swatch[data-theme="parchment"] { background: #FBF6EC; color: #241F16; }
.theme-swatch[data-theme="sepia"] { background: #F1E5C8; color: #3A2E19; }
.theme-swatch[data-theme="night"] { background: #14171F; color: #DCDEE6; border-color: #333; }
.theme-swatch.active { border-color: var(--accent); }

/* TOC slide-in panel */
.toc-panel {
    position: fixed; inset: 0; z-index: 80; display: flex; justify-content: flex-end;
    visibility: hidden;
}
.toc-panel.open { visibility: visible; }
.toc-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.4); opacity: 0; transition: opacity 0.2s ease; }
.toc-panel.open .toc-backdrop { opacity: 1; }
.toc-sheet {
    position: relative; width: 320px; max-width: 84vw; height: 100%; background: var(--rt-page); color: var(--rt-text);
    padding: 20px; overflow-y: auto; transform: translateX(100%); transition: transform 0.25s ease;
    box-shadow: -12px 0 30px rgba(0,0,0,0.15);
}
.toc-panel.open .toc-sheet { transform: translateX(0); }
.toc-sheet h3 { font-size: 16px; margin-bottom: 14px; }
.toc-sheet .toc-item {
    display: block; width: 100%; text-align: left; background: none; border: none; cursor: pointer;
    padding: 11px 8px; border-radius: 8px; color: var(--rt-text); font-size: 14.5px; font-family: var(--serif);
    border-bottom: 1px solid var(--rt-hairline);
}
.toc-sheet .toc-item:hover { color: var(--accent); }
.toc-sheet .toc-item.current { color: var(--accent); font-weight: 700; }

@media (max-width: 640px) {
    .reader-clip { inset: 60px 18px 84px; }
    .reader-pager { column-gap: 0; }
    .reader-root[data-cols="2"] .reader-pager { column-count: 1; }
    .reader-tapzones { inset: 60px 0 84px; }
    .reader-title { font-size: 23px; }
    .reader-chapter-label { display: none; }
}

/* ---------- Sitewide loading feedback ---------- */
.top-loading-bar {
    position: fixed; top: 0; left: 0; height: 3px; width: 0%; z-index: 9999;
    background: var(--gold); box-shadow: 0 0 8px rgba(200,155,60,0.6);
    transition: width 0.25s ease, opacity 0.3s ease; opacity: 0; pointer-events: none;
}
.top-loading-bar.active { opacity: 1; }
.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
    content: ''; position: absolute; left: 50%; top: 50%; width: 16px; height: 16px;
    margin: -8px 0 0 -8px; border: 2.5px solid rgba(255,255,255,0.5); border-top-color: #fff;
    border-radius: 50%; animation: spin 0.7s linear infinite;
}
.btn-outline.is-loading::after, .btn-danger.is-loading.btn-outline::after { border-color: rgba(20,33,61,0.25); border-top-color: var(--ink); }

/* ---------- Auth pages ---------- */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--ink); }
.auth-card { background: var(--paper); border-radius: var(--radius); padding: 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.auth-card .brand { color: var(--ink); margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 26px; }
.auth-foot { text-align: center; font-size: 14px; color: var(--muted); margin-top: 18px; }
.auth-foot a { color: var(--ink); font-weight: 600; text-decoration: none; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-state h3 { color: var(--ink-text); }

footer.site-footer { border-top: 1px solid var(--hairline); padding: 30px 0; text-align: center; color: var(--muted); font-size: 13px; }


/* ============================================================
   Admin workspace — consistent content placement
   ============================================================ */
.admin-shell {
    display: grid;
    grid-template-columns: 252px minmax(0, 1fr);
    grid-template-areas: "admin-sidebar admin-main";
    align-items: start;
    background: #F6F2E9;
    min-height: 100vh;
}
/* Explicit placement prevents the sidebar/main columns from being swapped by
   an extra grid child, stale CSS, or browser auto-placement. */
.admin-shell > .sidebar-backdrop {
    position: fixed;
    inset: 0;
    grid-area: unset;
}
.admin-shell > .sidebar {
    grid-area: admin-sidebar;
    grid-column: 1;
    grid-row: 1;
    width: 252px;
    min-width: 252px;
    max-width: 252px;
    padding: 24px 18px;
    justify-self: stretch;
}
.admin-main {
    grid-area: admin-main;
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    max-width: 1480px;
    margin: 0 auto;
    padding: 32px 38px 56px;
}
.admin-main > .main-header,
.admin-main > .alert,
.admin-main > .stat-row,
.admin-main > .card,
.admin-main > .table-wrap,
.admin-main > .two-col,
.admin-main > form {
    width: 100%;
}
.admin-main > .main-header {
    min-height: 46px;
    margin-bottom: 24px;
}
.admin-main > .main-header h1 {
    font-size: clamp(24px, 2vw, 30px);
    line-height: 1.15;
}
.admin-main .stat-row {
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 14px;
}
.admin-main .stat-card,
.admin-main .card,
.admin-main > .table-wrap {
    box-shadow: 0 1px 2px rgba(20,33,61,.03), 0 8px 24px rgba(20,33,61,.04);
}
.admin-main > .table-wrap {
    background: var(--paper);
}
.admin-main .two-col {
    align-items: start;
}
.admin-main .two-col > .card {
    min-width: 0;
}
.admin-main form > .card:last-of-type {
    margin-bottom: 18px;
}
.admin-main .card p:last-child,
.admin-main .card .field:last-child {
    margin-bottom: 0;
}
.admin-main .table-wrap table {
    min-width: 720px;
}
.admin-main th {
    white-space: nowrap;
}
.admin-main td {
    vertical-align: middle;
}
.admin-main code {
    overflow-wrap: anywhere;
}

@media (max-width: 1180px) {
    .admin-main .stat-row {
        grid-template-columns: repeat(3, minmax(160px, 1fr));
    }
}

@media (max-width: 980px) {
    .admin-main {
        padding: 26px 24px 48px;
    }
    .admin-main .two-col {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
    .hero .container { grid-template-columns: 1fr; }
    .book-mockup-wrap { height: 260px; order: -1; }
    .book-mockup { transform: rotateX(6deg) rotateZ(-1deg) scale(0.82); }
    .plan-grid { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
    .how-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
    .app-shell { grid-template-columns: 1fr; }
    .admin-shell {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "admin-main";
    }
    .main { padding: 18px 16px; }
    .admin-main {
        grid-area: admin-main;
        grid-column: 1;
        grid-row: 1;
        max-width: none;
        padding: 18px 16px 42px;
    }
    .admin-main > .main-header { margin-bottom: 18px; }
    .admin-main .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

    /* Admin (and any shell without .app-mobile-tabs) keeps the off-canvas
       hamburger sidebar — it's a desktop-first tool used occasionally on
       mobile, not the reader-facing app. */
    .sidebar {
        position: fixed; inset: 0 30% 0 0; width: 78%; max-width: 280px; z-index: 60;
        transform: translateX(-100%); transition: transform 0.2s ease; height: 100dvh;
    }
    .sidebar.open { transform: translateX(0); box-shadow: 20px 0 40px rgba(0,0,0,0.3); }
    .admin-shell > .sidebar {
        grid-area: unset;
        grid-column: auto;
        grid-row: auto;
        width: 78%;
        min-width: 0;
        max-width: 280px;
    }
    .menu-toggle { display: block; }

    /* Reader-facing app shells (dashboard, library, community, account) use
       the bottom tab bar instead — matches the reference mobile UI. */
    .app-shell.app-mobile-tabs .sidebar { display: none; }
    .app-shell.app-mobile-tabs .menu-toggle { display: none; }
    .main.has-bottom-nav { padding-bottom: calc(var(--bottom-nav-h) + 20px); }
    .bottom-tab-bar { display: flex; }
    .app-header { display: flex; }
}

@media (max-width: 640px) {
    .topbar .search { display: none; }
    .admin-main .stat-row { grid-template-columns: 1fr 1fr; }
    .admin-main .stat-card { padding: 15px 16px; }
    .admin-main .stat-card .num { font-size: 24px; }
    .admin-main .card { padding: 18px; }
    .admin-main > .main-header { align-items: center; }
    .admin-main > .main-header > div { min-width: 0; }
    .admin-main > .main-header h1 { font-size: 22px; }
    .admin-main > .main-header .btn { width: auto; }
    .topbar nav .nav-links { display: none; }
    .book-grid { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 14px; }
    .reader-body { font-size: 17px; }
    .hero { padding: 40px 0 32px; }
    .featured-banner { flex-direction: column; align-items: flex-start; text-align: left; }
    .featured-banner .cover { width: 56px; height: 80px; }
}

/* Prevent any accidental horizontal scroll on narrow viewports */
html, body { max-width: 100%; overflow-x: hidden; }


/* Premium responsive upgrade */
.progress-bar{height:10px;background:#e9e5db;border-radius:999px;overflow:hidden}
.progress-bar span{display:block;height:100%;background:var(--accent);transition:width .3s ease}
.loading-state{display:flex;align-items:center;gap:10px;padding:16px;border-radius:12px;background:#fff;box-shadow:var(--shadow)}
.spinner{width:18px;height:18px;border:3px solid var(--hairline);border-top-color:var(--accent);border-radius:50%;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
@media(max-width:768px){
 .container{padding:0 14px}
 .two-col,.stat-row{display:block!important}
 .card,.table-wrap{overflow-x:auto}
 .btn{width:100%}
 table{min-width:700px}
 h1{font-size:28px}
 textarea{min-height:220px}
}
