/* =========================================
   SCRIBAMUS — Ink & Vellum Design System
   ========================================= */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,600;0,700;0,900;1,400;1,600&family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300&family=Lato:ital,wght@0,300;0,400;0,700;1,300;1,400&display=swap');

/* --- Design Tokens (Dark / Ink) --- */
:root {
    --bg:            #0d0d0f;
    --bg-raised:     #131316;
    --bg-card:       #1a1a1f;
    --bg-card-hover: #1f1f26;
    --surface:       #232329;

    --text:          #e8e2d9;
    --text-dim:      #9e9890;
    --text-faint:    #5a5652;

    --crimson:       #8b1a2f;
    --crimson-bright:#b02240;
    --crimson-glow:  rgba(139,26,47,0.35);
    --gold:          #c9a84c;
    --gold-dim:      rgba(201,168,76,0.18);
    --gold-glow:     rgba(201,168,76,0.30);

    --border:        rgba(255,255,255,0.07);
    --border-accent: rgba(201,168,76,0.25);
    --danger:        #c0392b;
    --success:       #27ae60;

    --font-display: 'Playfair Display', Georgia, serif;
    --font-body:    'Lato', system-ui, sans-serif;
    --font-mono:    'DM Mono', 'Courier New', monospace;

    --radius-sm:   3px;
    --radius-md:   6px;
    --radius-lg:   12px;
    --radius-pill: 100px;

    --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
    --shadow-md:  0 4px 16px rgba(0,0,0,0.5);
    --shadow-lg:  0 12px 40px rgba(0,0,0,0.7);
    --shadow-ink: 0 0 0 1px var(--border), var(--shadow-md);

    --t-fast:   0.15s ease;
    --t-med:    0.28s ease;
    --t-slow:   0.45s ease;

    --header-h: 60px;
}

[data-theme="light"] {
    --bg:            #f2ede4;
    --bg-raised:     #ede8de;
    --bg-card:       #e8e2d6;
    --bg-card-hover: #e0d9cc;
    --surface:       #d9d2c4;

    --text:          #1a1714;
    --text-dim:      #5c5549;
    --text-faint:    #9c9488;

    --crimson:       #6b1222;
    --crimson-bright:#8b1a2f;
    --crimson-glow:  rgba(107,18,34,0.20);
    --gold:          #8b6914;
    --gold-dim:      rgba(139,105,20,0.12);
    --gold-glow:     rgba(139,105,20,0.25);

    --border:        rgba(0,0,0,0.10);
    --border-accent: rgba(139,105,20,0.30);
}

/* =========================================
   RESET & BASE
   ========================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background var(--t-med), color var(--t-med);
}

/* Noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.035'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 9999;
    opacity: 0.6;
}

.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* =========================================
   TYPOGRAPHY
   ========================================= */
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; }

.display-xl {
    font-family: var(--font-display);
    font-size: clamp(48px, 8vw, 96px);
    font-weight: 900;
    line-height: 0.95;
    letter-spacing: -1px;
}

.display-lg {
    font-family: var(--font-display);
    font-size: clamp(32px, 5vw, 56px);
    font-weight: 700;
    line-height: 1.05;
}

.mono { font-family: var(--font-mono); }

/* =========================================
   HEADER
   ========================================= */
header {
    height: var(--header-h);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
    min-width: 0;
}

.wordmark {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    font-style: italic;
    color: var(--gold);
    letter-spacing: 0.5px;
    text-shadow: 0 0 20px var(--gold-glow);
    flex-shrink: 0;
}

.wordmark sup {
    font-size: 9px;
    font-style: normal;
    font-family: var(--font-mono);
    color: var(--text-faint);
    vertical-align: super;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-left: 2px;
}

nav { display: flex; align-items: center; gap: 8px; }

/* =========================================
   BUTTONS
   ========================================= */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--t-fast);
    white-space: nowrap;
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text-dim);
}
.btn-ghost:hover {
    border-color: var(--gold);
    color: var(--gold);
    background: var(--gold-dim);
}

.btn-primary {
    background: var(--crimson);
    border-color: var(--crimson);
    color: #fff;
}
.btn-primary:hover {
    background: var(--crimson-bright);
    box-shadow: 0 0 20px var(--crimson-glow);
    transform: translateY(-1px);
}

.btn-gold {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--bg);
    font-weight: 700;
}
.btn-gold:hover {
    background: #d4b25a;
    box-shadow: 0 0 20px var(--gold-glow);
    transform: translateY(-1px);
}

.btn-outline-gold {
    background: transparent;
    border-color: var(--gold);
    color: var(--gold);
}
.btn-outline-gold:hover {
    background: var(--gold-dim);
    box-shadow: 0 0 12px var(--gold-glow);
}

.btn-lg {
    font-size: 14px;
    padding: 14px 32px;
    letter-spacing: 1px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

/* =========================================
   MODALS
   ========================================= */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.78);
    z-index: 500;
    justify-content: center;
    align-items: center;
    animation: fadeIn var(--t-fast);
}
.modal-backdrop.open { display: flex; }

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 40px;
    width: min(420px, 92vw);
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.25s ease;
}

#settings-modal .modal-box {
    max-height: 85vh;
    overflow-y: auto;
}

.modal-box h2 {
    font-family: var(--font-display);
    color: var(--gold);
    font-size: 26px;
    margin-bottom: 28px;
    font-style: italic;
}

.modal-close {
    position: absolute;
    top: 16px; right: 16px;
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 22px;
    cursor: pointer;
    transition: color var(--t-fast);
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* =========================================
   FORM ELEMENTS
   ========================================= */
.field { margin-bottom: 20px; }

.field label {
    display: block;
    font-size: 11px;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-faint);
    margin-bottom: 8px;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}

.field input::placeholder { color: var(--text-faint); }

.error-msg {
    color: var(--danger);
    font-size: 12px;
    font-family: var(--font-mono);
    margin-top: -12px;
    margin-bottom: 16px;
    display: none;
}
.error-msg.show { display: block; }

/* Auth tabs */
.auth-tabs {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 28px;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all var(--t-fast);
}
.auth-tab.active {
    background: var(--crimson);
    color: #fff;
}

/* =========================================
   HOME — LOGGED OUT
   ========================================= */
#home-screen { min-height: 100vh; }

.home-hero {
    min-height: calc(100vh - var(--header-h));
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    overflow: hidden;
}

.hero-left {
    padding: 80px 60px 80px 64px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border-right: 1px solid var(--border);
}

.hero-eyebrow {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: var(--crimson-bright);
    margin-bottom: 32px;
    display: flex;
    align-items: center;
    gap: 12px;
}
.hero-eyebrow::before {
    content: '';
    display: block;
    width: 40px;
    height: 1px;
    background: var(--crimson-bright);
}

.hero-title {
    font-family: var(--font-display);
    font-size: clamp(48px, 6vw, 78px);
    font-weight: 900;
    line-height: 0.96;
    letter-spacing: -1px;
    color: var(--text);
    margin-bottom: 36px;
}
.hero-title em {
    color: var(--gold);
    font-style: italic;
    display: block;
}

.hero-sub {
    font-size: 16px;
    color: var(--text-dim);
    max-width: 400px;
    line-height: 1.7;
    margin-bottom: 48px;
    font-style: italic;
}

.hero-cta { display: flex; gap: 12px; flex-wrap: wrap; }

/* Hero right — book mosaic */
.hero-right {
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 16px;
    background: var(--bg-raised);
    position: relative;
    overflow: hidden;
}

.hero-right::before {
    content: '"';
    position: absolute;
    top: -40px; right: 20px;
    font-family: var(--font-display);
    font-size: 300px;
    color: var(--gold);
    opacity: 0.04;
    line-height: 1;
    pointer-events: none;
    font-style: italic;
}

.featured-label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-faint);
    margin-bottom: 8px;
}

/* =========================================
   BOOK CARDS — General
   ========================================= */
.book-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px 22px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: border-color var(--t-med), transform var(--t-med), box-shadow var(--t-med), background var(--t-med);
}

.book-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--gold-dim), transparent 60%);
    opacity: 0;
    transition: opacity var(--t-med);
    pointer-events: none;
}

.book-card:hover {
    border-color: var(--border-accent);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), 0 0 0 1px var(--border-accent);
}
.book-card:hover::after { opacity: 1; }

.book-card-genre {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--crimson-bright);
    margin-bottom: 8px;
}

.book-card-title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    line-height: 1.25;
}

.book-card-meta {
    font-size: 12px;
    color: var(--text-faint);
    font-family: var(--font-mono);
}

.book-card-writers {
    display: flex;
    gap: 6px;
    margin-top: 12px;
    flex-wrap: wrap;
}

/* Featured book card (larger) */
.book-card-featured {
    padding: 28px;
}
.book-card-featured .book-card-title { font-size: 24px; margin-bottom: 10px; }
.book-card-featured .book-card-desc {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 16px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Home featured cards row */
.home-books-col {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* =========================================
   WRITER CHIPS / AVATARS
   ========================================= */
.writer-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 3px 10px 3px 3px;
    cursor: pointer;
    transition: all var(--t-fast);
    text-decoration: none;
}
.writer-chip:hover {
    border-color: var(--gold);
    color: var(--gold);
    background: var(--gold-dim);
}

.avatar-xs {
    width: 22px; height: 22px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 9px;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--bg);
    flex-shrink: 0;
}

.avatar-sm {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--bg);
    flex-shrink: 0;
}

.avatar-lg {
    width: 64px; height: 64px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--bg);
    flex-shrink: 0;
    box-shadow: 0 0 0 3px var(--bg-card), 0 0 0 5px var(--border-accent);
}

/* =========================================
   DASHBOARD
   ========================================= */
#dashboard { display: none; }
#dashboard.show { display: block; }

.dashboard-layout {
    max-width: 1100px;
    margin: 0 auto;
    padding: 48px 32px 80px;
}

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.section-header h2 {
    font-size: 28px;
    font-style: italic;
    color: var(--gold);
}

.section-header .section-sub {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-faint);
}

/* Horizontal scroll row */
.scroll-row {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding: 4px 2px 12px;
    margin-bottom: 48px;
    scrollbar-width: thin;
}
.scroll-row::-webkit-scrollbar { height: 4px; }

.scroll-row .book-card { min-width: 220px; max-width: 260px; flex-shrink: 0; }

/* New manuscript card */
.card-new {
    border-style: dashed;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 12px;
    background: transparent;
    color: var(--text-faint);
    min-width: 180px;
    max-width: 200px;
}
.card-new:hover { color: var(--gold); border-color: var(--gold); background: var(--gold-dim); }
.card-new-icon {
    width: 40px; height: 40px;
    border: 1px solid currentColor;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    transition: all var(--t-fast);
}
.card-new-label {
    font-size: 12px;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Search */
.search-bar-wrap {
    position: relative;
    margin-bottom: 20px;
}
.search-bar-wrap input {
    width: 100%;
    padding: 13px 18px 13px 44px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.search-bar-wrap input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}
.search-bar-wrap input::placeholder { color: var(--text-faint); }
.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
    font-size: 16px;
}

.tag-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 28px; }

.tag-btn {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: all var(--t-fast);
}
.tag-btn:hover { border-color: var(--gold); color: var(--gold); }
.tag-btn.active { background: var(--crimson); border-color: var(--crimson); color: #fff; }

/* Top 50 list */
.top50-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 48px;
}

.top50-item {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    cursor: pointer;
    transition: all var(--t-fast);
}
.top50-item:hover {
    border-color: var(--border-accent);
    background: var(--bg-card-hover);
}
.top50-rank {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 500;
    color: var(--text-faint);
    min-width: 32px;
    text-align: right;
}
.top50-rank.top3 { color: var(--gold); }
.top50-info { flex: 1; min-width: 0; }
.top50-title {
    font-family: var(--font-display);
    font-size: 15px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.top50-meta { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); margin-top: 2px; }

/* =========================================
   BOOK INFO PAGE
   ========================================= */
.book-page-layout {
    max-width: 860px;
    margin: 0 auto;
    padding: 64px 32px 100px;
}

.book-header { margin-bottom: 40px; }

.book-genre-tag {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--crimson-bright);
    margin-bottom: 20px;
}

.book-main-title {
    font-family: var(--font-display);
    font-size: clamp(38px, 6vw, 62px);
    font-weight: 900;
    line-height: 1.05;
    color: var(--text);
    margin-bottom: 28px;
}

.book-writers-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 40px;
}

.book-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 40px 0;
}

.book-synopsis {
    font-family: var(--font-display);
    font-size: 19px;
    line-height: 1.75;
    color: var(--text-dim);
    font-style: italic;
    position: relative;
    padding-left: 32px;
    margin-bottom: 48px;
}
.book-synopsis::before {
    content: '';
    position: absolute;
    left: 0; top: 4px;
    width: 3px;
    height: calc(100% - 8px);
    background: linear-gradient(to bottom, var(--crimson), var(--gold));
    border-radius: 2px;
}

.book-meta-pills { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 48px; }
.meta-pill {
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 5px 14px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border-accent);
    color: var(--gold);
    background: var(--gold-dim);
}

.book-read-btn-wrap { margin-bottom: 64px; }

.btn-read {
    display: inline-flex;
    align-items: center;
    gap: 14px;
    background: var(--crimson);
    color: #fff;
    font-family: var(--font-display);
    font-size: 20px;
    font-style: italic;
    font-weight: 600;
    padding: 18px 48px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: all var(--t-med);
    text-decoration: none;
}
.btn-read:hover {
    background: var(--crimson-bright);
    box-shadow: 0 0 32px var(--crimson-glow);
    transform: translateY(-2px);
}
.btn-read .arrow { font-size: 24px; transition: transform var(--t-fast); font-style: normal; }
.btn-read:hover .arrow { transform: translateX(6px); }

/* Writer profile cards */
.writer-profiles { display: flex; flex-direction: column; gap: 20px; }

.writer-profile-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    display: flex;
    align-items: flex-start;
    gap: 20px;
    cursor: pointer;
    transition: all var(--t-fast);
    text-decoration: none;
    color: inherit;
}
.writer-profile-card:hover {
    border-color: var(--border-accent);
    background: var(--bg-card-hover);
}

.writer-profile-info { flex: 1; }
.writer-profile-name {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.writer-profile-handle {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--gold);
    margin-bottom: 10px;
}
.writer-profile-bio {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.5;
}
.writer-profile-stats {
    display: flex;
    gap: 20px;
    margin-top: 14px;
}
.writer-stat {
    text-align: center;
}
.writer-stat strong {
    display: block;
    font-family: var(--font-mono);
    font-size: 18px;
    color: var(--gold);
}
.writer-stat span {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-faint);
    font-family: var(--font-mono);
}

/* Skeleton loaders */
@keyframes shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.skel {
    background: linear-gradient(90deg, var(--bg-card) 25%, var(--surface) 50%, var(--bg-card) 75%);
    background-size: 400px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

/* =========================================
   READER PAGE
   ========================================= */
.reader-body {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

.reader-toolbar {
    height: var(--header-h);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    position: relative;
    z-index: 50;
}

.reader-title-wrap {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.reader-doc-title {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 16px;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.progress-rail {
    position: absolute;
    bottom: 0; left: 0;
    width: 100%;
    height: 2px;
    background: var(--border);
}
.progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--crimson), var(--gold));
    width: 0%;
    transition: width 0.1s linear;
    box-shadow: 0 0 6px var(--gold-glow);
}

.reader-main-wrap {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.reader-scroll {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.reader-content {
    max-width: 680px;
    margin: 60px auto;
    padding: 0 24px 80px;
    font-family: var(--font-display);
    font-size: 19px;
    line-height: 1.85;
    color: var(--text);
}

.reader-content h1 {
    font-size: clamp(28px, 4vw, 40px);
    color: var(--gold);
    margin-top: 60px;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 900;
}

.reader-content h1:first-child { margin-top: 0; }

.reader-content p { margin-bottom: 28px; }

/* Paywall blur / gradient */
.paywall-wrap {
    position: relative;
}

.paywall-blur {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 280px;
    background: linear-gradient(to bottom, transparent 0%, var(--bg) 70%);
    pointer-events: none;
    z-index: 10;
}

.paywall-cta {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    z-index: 20;
    padding: 40px 24px;
}

.paywall-cta h3 {
    font-family: var(--font-display);
    font-size: 28px;
    font-style: italic;
    color: var(--text);
}

.paywall-cta p {
    font-size: 14px;
    color: var(--text-dim);
    max-width: 360px;
    font-family: var(--font-body);
    font-style: normal;
}

/* TOC Side Panel */
.side-panel {
    width: 0;
    background: var(--bg-raised);
    border-left: none;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
    transition: width var(--t-med), border-color var(--t-med);
}
.side-panel.open {
    width: 280px;
    border-left: 1px solid var(--border);
}

.side-panel-header {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.side-panel-header h3 {
    font-family: var(--font-display);
    font-size: 16px;
    color: var(--gold);
    font-style: italic;
}

.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.side-panel-section-label {
    font-family: var(--font-mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text-faint);
    margin: 16px 0 8px;
}
.side-panel-section-label:first-child { margin-top: 0; }

.toc-link {
    display: block;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--t-fast);
    font-family: var(--font-display);
    font-style: italic;
}
.toc-link:hover { background: var(--bg-card); color: var(--gold); padding-left: 16px; }

.bookmark-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all var(--t-fast);
}
.bookmark-item:hover { border-color: var(--border-accent); }
.bookmark-note { font-size: 13px; color: var(--text); margin-bottom: 3px; }
.bookmark-pos { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }
.bookmark-del {
    float: right;
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: color var(--t-fast);
}
.bookmark-del:hover { color: var(--danger); }

.side-panel-footer {
    padding: 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.side-panel-footer input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font-body);
    margin-bottom: 8px;
    transition: border-color var(--t-fast);
}
.side-panel-footer input:focus { outline: none; border-color: var(--gold); }
.side-panel-footer input::placeholder { color: var(--text-faint); }

/* =========================================
   EDITOR PAGE
   ========================================= */
.editor-body {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-toolbar {
    height: var(--header-h);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    gap: 16px;
}

.editor-left { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.editor-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.editor-doc-title {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 16px;
    color: var(--gold);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 260px;
}

.editor-stat {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-faint);
    padding-left: 12px;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}

/* Format buttons */
.fmt-group {
    display: flex;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.fmt-btn {
    background: none;
    border: none;
    border-right: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 12px;
    cursor: pointer;
    font-family: var(--font-display);
    font-size: 14px;
    transition: all var(--t-fast);
}
.fmt-btn:last-child { border-right: none; }
.fmt-btn:hover { background: var(--surface); color: var(--gold); }
.fmt-btn.active { background: var(--surface); color: var(--gold); }

/* Font select */
.font-select {
    padding: 6px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
    transition: border-color var(--t-fast);
}
.font-select:focus { outline: none; border-color: var(--gold); }

/* Workspace */
.workspace { display: flex; flex: 1; overflow: hidden; }

.doc-container {
    flex: 1;
    overflow-y: auto;
    background: var(--bg);
    padding: 40px 24px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Paper */
.paper {
    background: var(--bg-card);
    width: min(6in, 92vw);
    min-height: 9in;
    height: max-content;
    padding: 0.8in 0.85in;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--text);
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 17px;
    line-height: 1.9;
    caret-color: var(--gold);
    margin-bottom: 40px;
    transition: font-family 0.1s;
}
[contenteditable]:focus { outline: none; }

.paper h1 {
    font-family: inherit;
    font-size: 28px;
    color: var(--gold);
    margin-top: 40px;
    margin-bottom: 20px;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}
.paper h1:first-child { margin-top: 0; }

/* Chat & chapters side panels (editor) */
.editor-panel {
    width: 300px;
    background: var(--bg-raised);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: width var(--t-med);
}
.editor-panel.collapsed { width: 0; overflow: hidden; }
.editor-panel.left-panel { border-left: none; border-right: 1px solid var(--border); }

.editor-panel-header {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.editor-panel-header h3 {
    font-family: var(--font-display);
    font-size: 14px;
    font-style: italic;
    color: var(--gold);
}

.editor-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
}

.chat-msg-wrap {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
}
.chat-msg.me { align-self: flex-end; align-items: flex-end; }
.chat-msg.them { align-self: flex-start; align-items: flex-start; }

.chat-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}
.chat-msg.me .chat-bubble {
    background: var(--crimson);
    color: #fff;
    border-radius: 12px 12px 2px 12px;
}
.chat-msg.them .chat-bubble {
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px 12px 12px 2px;
}
.chat-meta {
    font-size: 10px;
    color: var(--text-faint);
    font-family: var(--font-mono);
    margin-bottom: 3px;
}

.editor-panel-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.editor-panel-footer input {
    flex: 1;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font-body);
    transition: border-color var(--t-fast);
}
.editor-panel-footer input:focus { outline: none; border-color: var(--gold); }
.editor-panel-footer input::placeholder { color: var(--text-faint); }

.chapter-item {
    padding: 9px 10px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-display);
    font-style: italic;
    color: var(--text-dim);
    transition: all var(--t-fast);
    margin-bottom: 4px;
}
.chapter-item:hover { background: var(--bg-card); color: var(--gold); padding-left: 16px; }

/* Collab pending state */
.collab-pending {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 40px;
    gap: 20px;
}
.collab-pending-icon {
    font-size: 48px;
    animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:0.6;transform:scale(0.95)} }
.collab-pending h3 {
    font-family: var(--font-display);
    font-style: italic;
    font-size: 22px;
    color: var(--text);
}
.collab-pending p { font-size: 14px; color: var(--text-dim); line-height: 1.6; }

/* Settings modal wider */
.modal-box-wide { width: min(560px, 92vw); }

.link-copy-row {
    display: flex;
    gap: 10px;
}
.link-copy-row input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--gold);
    font-family: var(--font-mono);
    font-size: 13px;
}
.link-copy-row input:focus { outline: none; border-color: var(--gold); }

/* =========================================
   PUBLIC PROFILE PAGE
   ========================================= */
.profile-layout {
    max-width: 760px;
    margin: 0 auto;
    padding: 64px 32px 100px;
}

.profile-hero {
    display: flex;
    gap: 32px;
    align-items: flex-start;
    margin-bottom: 48px;
    padding-bottom: 40px;
    border-bottom: 1px solid var(--border);
}

.profile-avatar-wrap { position: relative; }
.profile-avatar-xl {
    width: 88px; height: 88px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 36px;
    font-weight: 900;
    font-family: var(--font-display);
    color: var(--bg);
    box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--gold);
}

.profile-info { flex: 1; }
.profile-username {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 900;
    color: var(--text);
    margin-bottom: 4px;
}
.profile-handle {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--gold);
    margin-bottom: 16px;
}
.profile-bio { font-size: 15px; color: var(--text-dim); line-height: 1.6; margin-bottom: 20px; }

.profile-stats-row {
    display: flex;
    gap: 32px;
}
.profile-stat strong {
    display: block;
    font-family: var(--font-mono);
    font-size: 24px;
    color: var(--gold);
    line-height: 1;
}
.profile-stat span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-faint);
    font-family: var(--font-mono);
}

/* =========================================
   SHARED UTILS
   ========================================= */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 32px 0;
}

.muted { color: var(--text-dim); }
.gold  { color: var(--gold); }

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-faint);
}
.empty-state p { font-style: italic; font-family: var(--font-display); font-size: 16px; }

/* =========================================
   ANIMATIONS
   ========================================= */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

.anim-fade-up {
    opacity: 0;
    transform: translateY(14px);
    animation: fadeUp var(--t-slow) ease both;
}

.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.22s; }
.delay-3 { animation-delay: 0.34s; }
.delay-4 { animation-delay: 0.46s; }
.delay-5 { animation-delay: 0.58s; }

/* =========================================
   RESPONSIVE
   ========================================= */
@media (max-width: 768px) {

    /* ── Global header ── */
    header { padding: 0 12px; gap: 8px; }
    .wordmark { font-size: 17px; }
    .wordmark sup { display: none; }
    nav { gap: 4px; }
    #nav-dashboard-btn,
    #nav-lounge-btn { display: none !important; }

    /* ── Home hero ── */
    .home-hero { grid-template-columns: 1fr; }
    .hero-right { display: none; }
    .hero-left {
        padding: 40px 20px 48px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .hero-title { font-size: 42px; }
    .hero-sub   { font-size: 14px; }
    .hero-cta   { flex-direction: column; gap: 10px; }
    .hero-cta .btn { width: 100%; justify-content: center; }

    /* ── Dashboard ── */
    .dashboard-layout { padding: 24px 16px 80px; }
    .section-header h2 { font-size: 22px; }
    .scroll-row .book-card { min-width: 180px; max-width: 200px; }
    .card-new { min-width: 140px; max-width: 160px; }
    .top50-grid { grid-template-columns: 1fr; }
    .search-bar-wrap { margin-bottom: 14px; }
    .tag-row { gap: 6px; }
    .tag-btn { font-size: 10px; padding: 4px 10px; }

    /* ── Book page ── */
    .book-page-layout { padding: 32px 16px 80px; }
    .book-main-title  { font-size: 32px; }
    .book-synopsis    { font-size: 16px; padding-left: 20px; }
    .btn-read         { font-size: 16px; padding: 14px 28px; width: 100%; justify-content: center; }
    .book-meta-pills  { gap: 6px; }
    .writer-profile-card { flex-wrap: wrap; gap: 14px; }
    .writer-profile-stats { gap: 12px; }

    /* ── Modal ── */
    .modal-box { padding: 28px 20px; width: 96vw; }
    .modal-box h2 { font-size: 22px; margin-bottom: 20px; }

    /* ── Reader page ── */
    .reader-toolbar { padding: 0 10px; gap: 6px; }
    .reader-title-wrap { gap: 8px; min-width: 0; }
    .reader-doc-title { font-size: 13px; max-width: 120px; }
    #font-down-btn, #font-up-btn { display: none; }
    .reader-content {
        font-size: 17px;
        padding: 0 16px 60px;
        margin: 32px auto;
    }
    .reader-content h1 { font-size: 26px; }
    .side-panel.open {
        width: min(280px, 88vw);
        position: fixed;
        right: 0; top: var(--header-h); bottom: 0;
        z-index: 200;
        box-shadow: -4px 0 24px rgba(0,0,0,0.5);
    }

    /* ── Editor page ── */
    /* Fix: allow the workspace to scroll instead of clipping */
    .editor-body {
        height: 100dvh;
        height: 100vh;
    }
    .workspace {
        overflow-y: auto;
        overflow-x: hidden;
        flex-direction: column;
        align-items: stretch;
    }
    .doc-container {
        flex: none;
        overflow-y: visible;
        padding: 20px 12px 60px;
        min-height: calc(100dvh - var(--header-h));
        min-height: calc(100vh - var(--header-h));
        align-items: stretch;
        justify-content: stretch;
    }
    .paper {
        width: 100%;
        min-height: 70vh;
        padding: 24px 18px 60px;
        font-size: 16px;
        border-radius: var(--radius-sm);
        box-shadow: none;
        margin-bottom: 24px;
    }

    /* Editor toolbar: keep it compact, no wrapping */
    .editor-toolbar {
        padding: 0 8px;
        gap: 6px;
        height: auto;
        min-height: var(--header-h);
        flex-shrink: 0;
    }
    .editor-left  { gap: 6px; flex-shrink: 1; min-width: 0; overflow: hidden; }
    .editor-right { gap: 4px; flex-shrink: 0; }

    /* Hide lower-priority items — accessible via the ••• menu instead */
    #font-select  { display: none; }
    .fmt-group    { display: none; }
    .editor-stat  { display: none; }
    .presence-bar { display: none; }

    .editor-doc-title { font-size: 13px; max-width: 110px; }
    #publish-btn { font-size: 11px; padding: 6px 10px; letter-spacing: 0; }

    /* Mobile overflow menu (••• button + dropdown) */
    #mobile-overflow-btn { display: flex !important; }
    .mobile-overflow-menu {
        display: none;
        position: fixed;
        top: var(--header-h);
        right: 0;
        width: 220px;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-top: none;
        border-radius: 0 0 0 var(--radius-md);
        z-index: 300;
        padding: 8px 0;
        box-shadow: var(--shadow-md);
    }
    .mobile-overflow-menu.open { display: block; }
    .mob-menu-item {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 11px 18px;
        font-family: var(--font-mono);
        font-size: 12px;
        color: var(--text-dim);
        cursor: pointer;
        border: none;
        background: none;
        width: 100%;
        text-align: left;
        transition: background var(--t-fast), color var(--t-fast);
    }
    .mob-menu-item:hover { background: var(--bg-card-hover); color: var(--gold); }
    .mob-menu-item .mob-icon { font-size: 15px; }
    .mob-menu-sep {
        border: none;
        border-top: 1px solid var(--border);
        margin: 6px 0;
    }
    /* Inline format row inside menu */
    .mob-fmt-row {
        display: flex;
        gap: 0;
        margin: 4px 18px 8px;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        overflow: hidden;
    }
    .mob-fmt-row button {
        flex: 1;
        background: none;
        border: none;
        border-right: 1px solid var(--border);
        padding: 8px;
        color: var(--text-dim);
        cursor: pointer;
        font-size: 14px;
        font-family: var(--font-display);
        transition: all var(--t-fast);
    }
    .mob-fmt-row button:last-child { border-right: none; }
    .mob-fmt-row button:hover { background: var(--surface); color: var(--gold); }
    .mob-font-select {
        width: calc(100% - 36px);
        margin: 4px 18px 4px;
        padding: 7px 10px;
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        color: var(--text-dim);
        font-size: 12px;
    }
    /* Presence dots row inside menu */
    .mob-presence-row {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 18px;
        flex-wrap: wrap;
    }
    .mob-presence-label {
        font-family: var(--font-mono);
        font-size: 11px;
        color: var(--text-faint);
        width: 100%;
        margin-bottom: 4px;
    }
    /* Word count row inside menu */
    .mob-stat-row {
        padding: 6px 18px 10px;
        font-family: var(--font-mono);
        font-size: 11px;
        color: var(--text-faint);
    }

    /* Editor panels: fixed overlay drawers */
    .editor-panel {
        position: fixed;
        top: var(--header-h);
        bottom: 0;
        width: min(300px, 88vw) !important;
        z-index: 200;
        box-shadow: 2px 0 24px rgba(0,0,0,0.5);
    }
    .editor-panel.left-panel { left: 0; right: auto; }
    .editor-panel:not(.left-panel) { right: 0; left: auto; }
    .editor-panel.collapsed { width: 0 !important; overflow: hidden; }

    /* ── Profile page ── */
    .profile-page-wrap { padding: 0 0 80px; }
    .profile-card { padding: 0 16px 28px; }
    .profile-banner { height: 120px; border-radius: var(--radius-md) var(--radius-md) 0 0; }
    .profile-username { font-size: 24px; }
    .profile-stats-row { width: 100%; }
    .profile-stat { flex: 1; padding: 10px 12px; }
    .profile-stat strong { font-size: 18px; }
    .manuscripts-grid { grid-template-columns: 1fr; }
    .profile-actions { flex-wrap: wrap; gap: 6px; }
    .profile-actions .btn { font-size: 11px; padding: 6px 10px; }
    .profile-tab { padding: 10px 16px; font-size: 10px; }
}

/* Extra-small phones */
@media (max-width: 400px) {
    .hero-title { font-size: 34px; }
    header nav .btn-ghost:not(.btn-icon) { display: none; }
    #nav-profile-btn { display: flex; }
    #nav-studio-btn { display: none !important; }
    #nav-logout-btn  { font-size: 11px; padding: 6px 10px; }
    .book-main-title { font-size: 26px; }
    .profile-avatar-xl { width: 68px; height: 68px; font-size: 26px; }
}

/* ••• overflow button + menu: hidden on desktop, shown on mobile via media query */
#mobile-overflow-btn { display: none; }
.mobile-overflow-menu { display: none; }