/* BookVerse AI — Light-first, clean editorial design */
:root, [data-theme="light"] {
    --bg: #FAFAF8; --bg-card: #FFFFFF; --bg-alt: #F3F2EF; --bg-input: #F7F6F3;
    --text: #1A1A1A; --text-muted: #6B6B6B; --text-dim: #9E9E9E;
    --accent: #4F46E5; --accent-hover: #4338CA; --accent-light: #EEF2FF;
    --border: #E5E4E0; --shadow: rgba(0,0,0,.06);
    --danger: #DC2626; --success: #16A34A; --warn: #D97706;
    --radius: 10px; --radius-lg: 16px;
    --font-display: 'Playfair Display', Georgia, serif;
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --nav-h: 60px; --max-w: 1140px;
}
[data-theme="dark"] {
    --bg: #0C0C10; --bg-card: #141418; --bg-alt: #1A1A20; --bg-input: #1E1E26;
    --text: #E8E4DF; --text-muted: #8A8690; --text-dim: #5A5660;
    --accent: #818CF8; --accent-hover: #6366F1; --accent-light: #1E1B4B;
    --border: #2A2A35; --shadow: rgba(0,0,0,.3);
}
*,*::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}
a{color:var(--accent);text-decoration:none}
a:hover{text-decoration:underline}
.container{max-width:var(--max-w);margin:0 auto;padding:0 1.25rem}
.hidden{display:none!important}
.accent{color:var(--accent)}
.text-muted{color:var(--text-muted)}
.text-dim{color:var(--text-dim);font-size:.85rem}

/* NAV */
.nav{position:fixed;top:0;left:0;right:0;z-index:100;background:var(--bg-card);border-bottom:1px solid var(--border);height:var(--nav-h)}
.nav__inner{max-width:var(--max-w);margin:0 auto;padding:0 1.25rem;display:flex;align-items:center;justify-content:space-between;height:100%}
.nav__logo{display:flex;align-items:center;gap:.4rem;font-family:var(--font-display);font-size:1.35rem;font-weight:700;color:var(--text);text-decoration:none}
.nav__logo-icon{width:22px;height:22px;color:var(--accent)}
.nav__links{display:flex;align-items:center;gap:.15rem}
.nav__link{padding:.45rem .85rem;border-radius:8px;font-size:.88rem;font-weight:500;color:var(--text-muted);transition:.2s;text-decoration:none;display:flex;align-items:center;gap:.3rem;white-space:nowrap}
.nav__link:hover{color:var(--text);background:var(--bg-alt);text-decoration:none}
.nav__link--cta{background:var(--accent);color:#fff!important;font-weight:600}
.nav__link--cta:hover{background:var(--accent-hover)}
.nav__link--cta-outline{border:1px solid var(--accent);color:var(--accent)!important}
.nav__link--muted{color:var(--text-dim)}
.nav__link [data-lucide]{width:16px;height:16px}
.nav__sep{width:1px;height:20px;background:var(--border);margin:0 .3rem}
.theme-toggle{background:none;border:1px solid var(--border);border-radius:8px;width:36px;height:36px;display:flex;align-items:center;justify-content:center;cursor:pointer;color:var(--text-muted);transition:.2s;margin-left:.25rem}
.theme-toggle:hover{border-color:var(--accent);color:var(--accent)}
.theme-toggle [data-lucide]{width:16px;height:16px}
.nav__burger{display:none;background:none;border:none;cursor:pointer;flex-direction:column;gap:5px;padding:8px}
.nav__burger span{display:block;width:22px;height:2px;background:var(--text);border-radius:2px;transition:.3s}

/* BUTTONS */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:.4rem;padding:.6rem 1.3rem;border-radius:var(--radius);font-family:var(--font-body);font-size:.88rem;font-weight:600;border:none;cursor:pointer;transition:.2s;text-decoration:none;white-space:nowrap}
.btn [data-lucide]{width:16px;height:16px}
.btn--primary{background:var(--accent);color:#fff;box-shadow:0 2px 8px rgba(79,70,229,.2)}
.btn--primary:hover{background:var(--accent-hover);transform:translateY(-1px);text-decoration:none;color:#fff}
.btn--outline{background:transparent;color:var(--text-muted);border:1px solid var(--border)}
.btn--outline:hover{border-color:var(--accent);color:var(--accent);text-decoration:none}
.btn--lg{padding:.8rem 1.8rem;font-size:.95rem}
.btn--sm{padding:.35rem .75rem;font-size:.8rem}
.btn--full{width:100%}

/* FLASH */
.flash-container{position:fixed;top:calc(var(--nav-h)+.5rem);right:1rem;z-index:200;display:flex;flex-direction:column;gap:.5rem;max-width:400px}
.flash{padding:.75rem 1rem;border-radius:var(--radius);font-size:.88rem;display:flex;justify-content:space-between;align-items:center;gap:1rem;box-shadow:0 4px 12px var(--shadow)}
.flash--success{background:#F0FDF4;color:#166534;border:1px solid #BBF7D0}
.flash--error{background:#FEF2F2;color:#991B1B;border:1px solid #FECACA}
.flash button{background:none;border:none;font-size:1.1rem;cursor:pointer;color:inherit}
[data-theme="dark"] .flash--success{background:#052E16;color:#4ADE80;border-color:#166534}
[data-theme="dark"] .flash--error{background:#450A0A;color:#FCA5A5;border-color:#991B1B}

/* HERO */
.hero{min-height:90vh;display:flex;align-items:center;position:relative;padding-top:var(--nav-h)}
.hero__bg{position:absolute;inset:0;background:linear-gradient(135deg,var(--accent-light) 0%,var(--bg) 50%,var(--bg-alt) 100%);pointer-events:none}
.hero__inner{text-align:center;width:100%;position:relative;z-index:1;padding:3rem 0}
.hero__tag{font-size:.8rem;text-transform:uppercase;letter-spacing:2px;color:var(--accent);margin-bottom:1.25rem;font-weight:600;display:flex;align-items:center;justify-content:center;gap:.4rem}
.hero__tag [data-lucide]{width:16px;height:16px}
.hero__title{font-family:var(--font-display);font-size:clamp(2.4rem,5.5vw,4.2rem);font-weight:700;line-height:1.15;margin-bottom:1.25rem;color:var(--text)}
.hero__sub{font-size:1.05rem;color:var(--text-muted);max-width:560px;margin:0 auto 2.5rem;line-height:1.7}
.hero__actions{display:flex;gap:1rem;justify-content:center;flex-wrap:wrap;margin-bottom:3rem}
.hero__stats{display:flex;gap:3rem;justify-content:center;padding-top:2rem;border-top:1px solid var(--border);max-width:400px;margin:0 auto}
.stat{text-align:center}
.stat__num{display:block;font-family:var(--font-display);font-size:1.8rem;font-weight:700;color:var(--accent)}
.stat__label{font-size:.8rem;color:var(--text-dim)}

/* SECTIONS */
.section{padding:4.5rem 0}
.section--alt{background:var(--bg-alt)}
.section--cta{background:var(--accent-light);border-top:1px solid var(--border)}
.section__title{font-family:var(--font-display);font-size:1.8rem;font-weight:700;margin-bottom:2rem;display:flex;align-items:center;gap:.5rem}
.section__title [data-lucide]{width:24px;height:24px;color:var(--accent)}
.section__sub{color:var(--text-muted);margin-bottom:2rem;max-width:500px;margin-left:auto;margin-right:auto}
.section__header{display:flex;justify-content:space-between;align-items:center;margin-bottom:2rem}
.section__header .section__title{margin-bottom:0}

/* STEPS */
.steps{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:1.5rem}
.step{background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-lg);padding:2rem;text-align:center;transition:.3s}
.step:hover{border-color:var(--accent);box-shadow:0 8px 30px var(--shadow)}
.step__icon{width:48px;height:48px;background:var(--accent-light);border-radius:12px;display:flex;align-items:center;justify-content:center;margin:0 auto 1rem;color:var(--accent)}
.step__icon [data-lucide]{width:24px;height:24px}
.step h3{font-size:1.05rem;margin-bottom:.4rem}
.step p{color:var(--text-muted);font-size:.9rem;line-height:1.6}

/* BOOK GRID */
.book-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:1.25rem}
.book-card{background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-lg);overflow:hidden;transition:.3s;display:flex;flex-direction:column;text-decoration:none;color:var(--text)}
.book-card:hover{transform:translateY(-3px);box-shadow:0 12px 40px var(--shadow);border-color:var(--accent);text-decoration:none}
.book-card__cover{background:var(--cover);height:160px;display:flex;align-items:center;justify-content:center;position:relative}
.book-card__icon{width:48px;height:48px;color:rgba(255,255,255,.7)}
.book-card__genre{position:absolute;top:.6rem;left:.6rem;background:rgba(255,255,255,.15);backdrop-filter:blur(8px);padding:.15rem .5rem;border-radius:6px;font-size:.7rem;color:#fff}
.book-card__info{padding:.85rem;flex:1;display:flex;flex-direction:column}
.book-card__title{font-family:var(--font-display);font-size:1rem;font-weight:600;margin-bottom:.15rem;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
.book-card__author{color:var(--text-muted);font-size:.82rem;margin-bottom:auto}
.book-card__meta{display:flex;gap:.6rem;font-size:.72rem;color:var(--text-dim);padding-top:.6rem;border-top:1px solid var(--border);margin-top:.6rem;align-items:center}
.book-card__meta [data-lucide]{width:12px;height:12px}

/* CARDS */
.card{background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-lg);padding:1.5rem}
.card h2,.card h3{font-family:var(--font-display);display:flex;align-items:center;gap:.4rem;margin-bottom:1rem}
.card h2 [data-lucide],.card h3 [data-lucide]{width:20px;height:20px;color:var(--accent)}

/* BADGE */
.badge{display:inline-block;background:var(--accent-light);color:var(--accent);padding:.15rem .6rem;border-radius:6px;font-size:.75rem;font-weight:600}
.badge--success{background:#F0FDF4;color:#16A34A}
.badge--warn{background:#FFFBEB;color:#D97706}
.badge--error{background:#FEF2F2;color:#DC2626}
.badge--accent{background:var(--accent);color:#fff}
[data-theme="dark"] .badge--success{background:#052E16;color:#4ADE80}
[data-theme="dark"] .badge--warn{background:#422006;color:#FBBF24}
[data-theme="dark"] .badge--error{background:#450A0A;color:#FCA5A5}

/* TABLES */
.table{width:100%;border-collapse:collapse;font-size:.85rem}
.table th{text-align:left;padding:.6rem .5rem;border-bottom:2px solid var(--border);color:var(--text-dim);font-weight:600;font-size:.78rem;text-transform:uppercase;letter-spacing:.5px}
.table td{padding:.6rem .5rem;border-bottom:1px solid var(--border)}
.table tr:hover td{background:var(--bg-alt)}

/* FORMS */
.form-group{margin-bottom:1.15rem}
.form-group label{display:flex;align-items:center;gap:.35rem;margin-bottom:.4rem;font-weight:500;font-size:.88rem}
.form-group label [data-lucide]{width:16px;height:16px;color:var(--accent)}
.form-input,.form-textarea,.form-select{width:100%;padding:.7rem .9rem;background:var(--bg-input);border:1px solid var(--border);border-radius:var(--radius);color:var(--text);font-family:var(--font-body);font-size:.92rem;transition:border .2s}
.form-input:focus,.form-textarea:focus,.form-select:focus{outline:none;border-color:var(--accent);box-shadow:0 0 0 3px rgba(79,70,229,.1)}
.form-textarea{resize:vertical;min-height:100px}
.form-select{cursor:pointer}
.form-select--sm{padding:.4rem .7rem;font-size:.83rem}
.form-row{display:grid;grid-template-columns:1fr 1fr;gap:1rem}
.form-checkbox{display:flex;align-items:center;gap:.5rem;cursor:pointer;font-size:.88rem;color:var(--text-muted)}
.form-checkbox input{accent-color:var(--accent);width:16px;height:16px}

/* GENRE PICKER */
.genre-picker{display:flex;flex-wrap:wrap;gap:.4rem}
.genre-btn{padding:.4rem .85rem;border-radius:20px;background:var(--bg-input);border:1px solid var(--border);color:var(--text-muted);font-size:.82rem;cursor:pointer;transition:.2s;font-family:var(--font-body)}
.genre-btn:hover{border-color:var(--accent);color:var(--accent)}
.genre-btn.active{background:var(--accent);color:#fff;border-color:var(--accent)}

/* AUTH */
.page-auth{padding-top:calc(var(--nav-h) + 4rem)}
.auth-card{max-width:420px;margin:0 auto;background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-lg);padding:2.5rem}
.auth-card__title{font-family:var(--font-display);font-size:1.6rem;margin-bottom:1.5rem;display:flex;align-items:center;gap:.5rem}
.auth-card__title [data-lucide]{width:24px;height:24px;color:var(--accent)}
.auth-card__footer{text-align:center;margin-top:1.25rem;font-size:.88rem;color:var(--text-muted)}
.auth-card__legal{text-align:center;margin-top:.75rem;font-size:.75rem;color:var(--text-dim)}

/* PROFILE */
.page-profile{padding-top:calc(var(--nav-h) + 2rem)}
.profile-grid{display:grid;grid-template-columns:1fr 1fr;gap:1.5rem}
.balance{font-family:var(--font-display);font-size:2.5rem;font-weight:700;color:var(--accent);margin:.5rem 0 1.25rem}
.topup-form{display:flex;flex-direction:column;gap:.5rem}
.profile-stats{display:flex;gap:2rem}
.profile-stats div{text-align:center}

/* GENERATE */
.page-gen{padding-top:calc(var(--nav-h) + 2rem)}
.gen-form{background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-lg);padding:2rem;max-width:800px}
.gen-progress{max-width:500px;margin:3rem auto;text-align:center}
.gen-progress__card{background:var(--bg-card);border:1px solid var(--border);border-radius:var(--radius-lg);padding:3rem 2rem}
.gen-progress__spinner{margin-bottom:1rem;color:var(--accent)}
.gen-progress__spinner [data-lucide]{width:48px;height:48px}
.spin{animation:spin 1.5s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}
.gen-progress__card h2{font-family:var(--font-display);font-size:1.3rem;margin-bottom:1.5rem}
.progress-bar{height:6px;background:var(--bg-alt);border-radius:3px;overflow:hidden;margin-bottom:1rem}
.progress-bar__fill{height:100%;background:linear-gradient(90deg,var(--accent),#818CF8);border-radius:3px;transition:width .5s;width:0}

/* LIBRARY */
.page-lib{padding-top:calc(var(--nav-h) + 2rem)}
.filters{margin-bottom:2rem}
.filters__row{display:flex;justify-content:space-between;align-items:flex-start;gap:1rem;flex-wrap:wrap;margin-top:.75rem}
.filters__tags{display:flex;flex-wrap:wrap;gap:.35rem;flex:1}
.tag{padding:.35rem .7rem;border-radius:20px;font-size:.78rem;background:var(--bg-input);border:1px solid var(--border);color:var(--text-muted);transition:.2s;white-space:nowrap;text-decoration:none}
.tag:hover{border-color:var(--accent);color:var(--accent);text-decoration:none}
.tag.active{background:var(--accent);color:#fff;border-color:var(--accent)}
.empty{text-align:center;padding:4rem 1rem;color:var(--text-muted)}
.empty [data-lucide]{width:48px;height:48px;margin-bottom:1rem;color:var(--text-dim)}
.empty h3{margin-bottom:.75rem}
.empty .btn{margin-top:1rem}

/* BOOK DETAIL */
.page-book{padding-top:calc(var(--nav-h) + 2rem)}
.book-hero{display:flex;gap:2rem;align-items:flex-start;margin-bottom:2.5rem}
.book-hero__cover{flex-shrink:0;width:180px;height:250px;background:var(--cover);border-radius:var(--radius-lg);display:flex;align-items:center;justify-content:center;box-shadow:0 16px 48px var(--shadow)}
.book-hero__icon{width:56px;height:56px;color:rgba(255,255,255,.6)}
.book-hero h1{font-family:var(--font-display);font-size:2rem;font-weight:700;margin:.5rem 0 .25rem}
.book-hero__author{color:var(--accent);font-weight:500;margin:.25rem 0 .5rem}
.book-hero__stats{display:flex;gap:1.25rem;flex-wrap:wrap;font-size:.85rem;color:var(--text-dim);margin:.75rem 0 1.25rem;align-items:center}
.book-hero__stats [data-lucide]{width:14px;height:14px}
.book-hero__stats span{display:flex;align-items:center;gap:.25rem}
.book-hero__actions{display:flex;gap:.6rem;flex-wrap:wrap}

.toc{display:flex;flex-direction:column;gap:.15rem}
.toc__item{display:flex;align-items:center;gap:.75rem;padding:.6rem .75rem;border-radius:8px;transition:.2s;text-decoration:none;color:var(--text)}
.toc__item:hover{background:var(--bg-alt);text-decoration:none}
.toc__num{color:var(--accent);font-weight:600;min-width:1.5rem}
.comment-form{margin-bottom:1.5rem}
.comment{background:var(--bg-alt);border-radius:var(--radius);padding:.85rem 1rem;margin-top:.6rem}
.comment__head{display:flex;justify-content:space-between;margin-bottom:.3rem;font-size:.85rem}

/* READER */
.reader{padding-top:var(--nav-h);min-height:100vh;background:var(--bg)}
.reader--dark{background:#0A0A0E;--text:#D4D0CC;--text-muted:#7A7670;--text-dim:#504C46;--bg-card:#111115;--border:#222228;--bg-alt:#1A1A1E}
.reader__top{display:flex;align-items:center;justify-content:space-between;padding:.6rem 1.25rem;border-bottom:1px solid var(--border);background:var(--bg-card);gap:.5rem}
.reader__btns{display:flex;gap:.25rem}
.reader__body{max-width:680px;margin:0 auto;padding:2.5rem 1.25rem 4rem;font-size:18px;color:var(--text)}
.reader__ch-head{text-align:center;margin-bottom:2rem}
.reader__ch-head h1{font-family:var(--font-display);font-size:1.8rem;margin:.5rem 0}
.reader__orn{color:var(--text-dim);font-size:.8rem;margin-top:.5rem}
.reader__p{font-family:var(--font-display);line-height:1.85;text-indent:1.5em;margin-bottom:.15em;text-align:justify}
.reader__p--i{font-style:italic}
.reader__sb{text-align:center;padding:1.25rem 0;color:var(--text-dim);letter-spacing:.5em}
.reader__nav{display:flex;align-items:center;justify-content:space-between;padding:.75rem 1.25rem;border-top:1px solid var(--border);background:var(--bg-card);max-width:680px;margin:0 auto}

/* ADMIN */
.admin{padding-top:calc(var(--nav-h) + 2rem)}
.admin-nav{display:flex;gap:.4rem;flex-wrap:wrap;margin-bottom:1.5rem}
.admin-stats{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:1rem;margin-bottom:1.5rem}
.admin-stats .card{text-align:center;display:flex;flex-direction:column;align-items:center;gap:.25rem}
.admin-stats .card [data-lucide]{width:24px;height:24px;color:var(--accent)}
.admin-grid{display:grid;grid-template-columns:1fr 1fr;gap:1.25rem}

/* LEGAL */
.legal-page{padding-top:calc(var(--nav-h) + 2rem)}
.legal-content{max-width:800px}
.legal-content h1{font-family:var(--font-display);font-size:2rem;font-weight:700;margin-bottom:1.5rem}
.legal-content h2{font-family:var(--font-display);font-size:1.25rem;margin:2rem 0 .75rem;color:var(--text)}
.legal-content p{margin-bottom:.75rem;line-height:1.75;color:var(--text-muted)}

/* PAGE TITLES */
.page-title{font-family:var(--font-display);font-size:2.2rem;font-weight:700;margin-bottom:.5rem;display:flex;align-items:center;gap:.5rem}
.page-title [data-lucide]{width:28px;height:28px;color:var(--accent)}
.page-desc{color:var(--text-muted);margin-bottom:2rem;font-size:.95rem}

/* FOOTER */
.footer{border-top:1px solid var(--border);padding:3rem 0 1.5rem;margin-top:2rem;background:var(--bg-card)}
.footer__grid{display:grid;grid-template-columns:2fr 1fr 1fr 1fr;gap:2rem;margin-bottom:2rem}
.footer__logo{font-family:var(--font-display);font-size:1.2rem;font-weight:700;margin-bottom:.5rem;display:flex;align-items:center;gap:.35rem;color:var(--text)}
.footer__logo [data-lucide]{width:18px;height:18px;color:var(--accent)}
.footer__desc{color:var(--text-dim);font-size:.82rem;line-height:1.6}
.footer__col h4{font-size:.8rem;text-transform:uppercase;letter-spacing:.5px;color:var(--text-dim);margin-bottom:.75rem}
.footer__col a,.footer__col p{display:flex;align-items:center;gap:.35rem;color:var(--text-muted);font-size:.82rem;margin-bottom:.4rem;text-decoration:none}
.footer__col a:hover{color:var(--accent)}
.footer__col [data-lucide]{flex-shrink:0}
.footer__legal{border-top:1px solid var(--border);padding-top:1.25rem;text-align:center}
.footer__legal p{font-size:.78rem;color:var(--text-dim);margin-bottom:.25rem}

/* MOBILE */
@media(max-width:768px){
    body {
        padding-top: calc(var(--nav-h) + 1rem);
    }
    .nav__links{
        display:none;
        position:fixed;
        top:0;
        left:-280px;
        width:280px;
        height:100vh;
        background:var(--bg-card);
        border-right:1px solid var(--border);
        padding:calc(var(--nav-h) + 1rem) 1.25rem 1rem;
        flex-direction:column;
        gap:.5rem;
        z-index:999;
        transition:left 0.3s ease;
        overflow-y:auto;
        box-shadow: 4px 0 12px var(--shadow);
    }
    .nav__links.open{
        display:flex;
        left:0;
    }
    /* Overlay for sidebar */
    .nav__links.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 280px;
        width: calc(100vw - 280px);
        height: 100vh;
        background: rgba(0,0,0,0.5);
        z-index: -1;
    }
    .nav__link {
        padding: 0.75rem 1rem;
        width: 100%;
        justify-content: flex-start;
    }
    .nav__sep{display:none}
    .nav__burger{display:flex}
    .hero{min-height:auto;padding-bottom:3rem}
    .hero__title{font-size:2rem}
    .hero__stats{gap:1.5rem}
    .book-grid{grid-template-columns:repeat(auto-fill,minmax(155px,1fr));gap:.75rem}
    .book-card__cover{height:130px}
    .book-hero{flex-direction:column;align-items:center;text-align:center}
    .book-hero__cover{width:140px;height:200px}
    .book-hero__actions{justify-content:center}
    .book-hero__stats{justify-content:center}
    .form-row{grid-template-columns:1fr}
    .profile-grid{grid-template-columns:1fr}
    .admin-grid{grid-template-columns:1fr}
    .footer__grid{grid-template-columns:1fr 1fr}
    .reader__body{padding:1.5rem 1rem 3rem;font-size:16px}
    .section{padding:3rem 0}
    .page-title{font-size:1.8rem}
    .auth-card{padding:1.75rem 1.25rem;margin:0 1rem}
    .page-auth{padding-top:calc(var(--nav-h) + 2rem)}
}
@media(max-width:480px){
    .hero__actions{flex-direction:column;align-items:stretch}
    .book-grid{grid-template-columns:repeat(2,1fr)}
    .genre-btn{font-size:.75rem;padding:.35rem .65rem}
    .footer__grid{grid-template-columns:1fr}
}
