/* ========================
   Design Tokens
======================== */
:root {
    --bg:        #0e0c0a;
    --surface:   #161310;
    --surface2:  #1f1b17;
    --border:    rgba(255, 255, 255, 0.07);
    --accent:    #c9a84c;
    --accent-dim: rgba(201, 168, 76, 0.15);
    --text:      #e8e0d0;
    --text2:     #8a8070;
    --danger:    #c9504c;
    --success:   #4caf50;
    --radius:    12px;
    --radius-sm: 8px;
    --ease:      0.2s ease;
}

/* ========================
   Reset & Base
======================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; scroll-behavior: smooth; }

body {
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font-family: inherit; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

/* ========================
   Typography
======================== */
h1, h2, h3, h4 {
    font-family: 'Playfair Display', serif;
    font-weight: 600;
    color: var(--text);
    line-height: 1.25;
}

/* ========================
   Layout Helpers
======================== */
.page { min-height: 100vh; padding-bottom: 88px; }

.content {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

/* ========================
   Top Bar
======================== */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(14, 12, 10, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.top-bar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    font-family: 'Playfair Display', serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
    letter-spacing: -0.01em;
}

.page-title {
    font-family: 'Playfair Display', serif;
    font-size: 17px;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.top-bar-username {
    font-size: 12px;
    color: var(--text2);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ========================
   Bottom Tab Bar
======================== */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: rgba(22, 19, 16, 0.97);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--border);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 4px 14px;
    color: var(--text2);
    transition: color var(--ease);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    -webkit-tap-highlight-color: transparent;
}

.tab.active { color: var(--accent); }
.tab svg { flex-shrink: 0; transition: transform var(--ease); }
.tab.active svg { transform: scale(1.1); }

/* ========================
   Buttons
======================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--ease);
    text-align: center;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--accent);
    color: #0e0c0a;
}
.btn-primary:hover { background: #d4b660; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: rgba(255,255,255,0.07); }

.btn-danger {
    background: rgba(201, 80, 76, 0.12);
    color: #e07370;
    border: 1px solid rgba(201, 80, 76, 0.25);
}
.btn-danger:hover { background: rgba(201, 80, 76, 0.22); }

.btn-full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    transition: all var(--ease);
    flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }

/* ========================
   Forms
======================== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.form-group input,
.form-group select,
.form-group textarea {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    outline: none;
    transition: border-color var(--ease), box-shadow var(--ease);
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
}

.form-group input::placeholder,
.form-group textarea::placeholder { color: var(--text2); opacity: 0.6; }

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-group textarea { resize: vertical; min-height: 100px; }
select option { background: var(--surface2); color: var(--text); }

/* ========================
   Book Cards
======================== */
.books-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 20px;
}

@media (min-width: 480px) {
    .books-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 700px) {
    .books-grid { grid-template-columns: repeat(4, 1fr); max-width: 800px; margin: 0 auto; }
}

.book-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--ease), transform var(--ease), box-shadow var(--ease);
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
}
.book-card:hover {
    border-color: rgba(201, 168, 76, 0.35);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    background: var(--surface2);
}

.book-cover-placeholder {
    width: 100%;
    aspect-ratio: 2/3;
    background: var(--surface2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text2);
    font-size: 11px;
    text-align: center;
    padding: 16px;
}

.book-info {
    padding: 10px 12px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.book-title {
    font-family: 'Playfair Display', serif;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

.book-author { font-size: 11px; color: var(--text2); }

.book-genre {
    font-size: 10px;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: auto;
    padding-top: 4px;
}

.book-card-wrapper {
    display: grid;
}

.book-card-wrapper > .book-card {
    grid-area: 1 / 1;
}

.book-delete-btn {
    grid-area: 1 / 1;
    align-self: start;
    justify-self: end;
    margin: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.65);
    border: none;
    padding: 0;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s, background 0.18s;
    z-index: 2;
    -webkit-appearance: none;
    appearance: none;
}
.book-card-wrapper:hover .book-delete-btn {
    opacity: 1;
    pointer-events: auto;
}
.book-delete-btn:hover {
    background: #c0392b;
}

/* ========================
   Progress Bar
======================== */
.progress-bar {
    height: 3px;
    background: var(--surface2);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.4s ease;
}

.progress-label {
    font-size: 10px;
    color: var(--text2);
    margin-top: 3px;
}

/* ========================
   Sections
======================== */
.section { margin-bottom: 28px; }

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-title { font-family: 'Playfair Display', serif; font-size: 18px; font-weight: 600; }
.section-link  { font-size: 13px; color: var(--accent); }

/* ========================
   Alerts
======================== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 16px;
}
.alert-error {
    background: rgba(201, 80, 76, 0.12);
    border: 1px solid rgba(201, 80, 76, 0.3);
    color: #e07370;
}
.alert-success {
    background: rgba(76, 175, 80, 0.12);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: #66bb6a;
}

/* ========================
   Stats Row (Home)
======================== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 4px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 12px;
    text-align: center;
}

.stat-number {
    font-family: 'Playfair Display', serif;
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

.stat-label {
    font-size: 10px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 6px;
}

/* ========================
   Continue Reading Card
======================== */
.continue-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    gap: 14px;
    cursor: pointer;
    transition: border-color var(--ease), transform var(--ease);
    margin-bottom: 10px;
}
.continue-card:hover { border-color: rgba(201, 168, 76, 0.35); transform: translateY(-1px); }

.continue-card-cover {
    width: 60px;
    height: 90px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--surface2);
    flex-shrink: 0;
}

.continue-card-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.continue-card-title {
    font-family: 'Playfair Display', serif;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.continue-card-author { font-size: 13px; color: var(--text2); }

/* ========================
   Empty State
======================== */
.empty-state {
    text-align: center;
    padding: 56px 24px;
    color: var(--text2);
}
.empty-state svg    { margin: 0 auto 18px; opacity: 0.35; }
.empty-state h3     { color: var(--text); margin-bottom: 8px; font-size: 20px; }
.empty-state p      { font-size: 14px; margin-bottom: 22px; }

/* ========================
   Auth Page
======================== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 28px;
    width: 100%;
    max-width: 400px;
}

.auth-logo {
    font-family: 'Playfair Display', serif;
    font-size: 30px;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.auth-subtitle {
    text-align: center;
    color: var(--text2);
    font-size: 14px;
    margin-bottom: 28px;
    font-style: italic;
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
    gap: 0;
}

.auth-tab {
    flex: 1;
    padding: 10px 8px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: var(--text2);
    cursor: pointer;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    transition: all var(--ease);
    margin-bottom: -1px;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.auth-tab:hover:not(.active) { color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 16px; }

/* ========================
   Store Redeem Section
======================== */
.redeem-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}

.redeem-title {
    font-family: 'Playfair Display', serif;
    font-size: 17px;
    margin-bottom: 6px;
}

.redeem-row { display: flex; gap: 8px; margin-top: 12px; }

.redeem-row input {
    flex: 1;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--text);
    font-family: 'DM Sans', sans-serif;
    font-size: 16px;
    font-weight: 600;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    transition: border-color var(--ease), box-shadow var(--ease);
}
.redeem-row input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
.redeem-row input::placeholder { letter-spacing: 0.08em; font-weight: 400; }

/* ========================
   Reader
======================== */
.reader-body { overflow: hidden; }

.reader-page {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: #0a0806;
    overflow: hidden;
    animation: readerFadeIn 0.35s ease;
}
@keyframes readerFadeIn { from { opacity: 0; } to { opacity: 1; } }

.reader-top-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: rgba(10, 8, 6, 0.96);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.reader-title-block {
    flex: 1;
    overflow: hidden;
    min-width: 0;
}
.reader-title {
    font-family: 'Playfair Display', serif;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reader-chapter {
    font-size: 11px;
    color: var(--text2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
    min-height: 14px;
}

.reader-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#epub-container {
    width: 100%;
    height: 100%;
    background: #f8f5ef;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
#epub-container.page-turning {
    opacity: 0;
    transform: translateX(-12px);
}
#epub-container.page-turning-back {
    opacity: 0;
    transform: translateX(12px);
}

#epub-container iframe { border: none !important; }

#pdf-container {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    gap: 16px;
    background: #1a1714;
}

.pdf-page-canvas {
    max-width: 100%;
    border-radius: 3px;
    box-shadow: 0 4px 28px rgba(0,0,0,0.6);
}

.reader-bottom-bar {
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(10, 8, 6, 0.96);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

body.ui-hidden .reader-top-bar {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
body.ui-hidden .reader-bottom-bar {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

.reader-progress-bar {
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    margin-bottom: 10px;
    cursor: pointer;
}

.reader-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.6s ease;
    pointer-events: none;
}

.reader-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.reader-page-info {
    font-size: 12px;
    color: var(--text2);
    text-align: center;
    min-width: 80px;
}

.epub-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 80px;
    border: none;
    background: rgba(10, 8, 6, 0.5);
    color: rgba(255,255,255,0.4);
    cursor: pointer;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--ease);
    backdrop-filter: blur(4px);
}
.epub-nav-btn:hover { background: rgba(10, 8, 6, 0.85); color: var(--text); }
.epub-prev { left: 0; border-radius: 0 6px 6px 0; }
.epub-next { right: 0; border-radius: 6px 0 0 6px; }

/* Swipe overlay — sits above epub iframe, captures touch on mobile */
#swipe-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: transparent;
    touch-action: pan-y;
    display: none;
}

/* Mobile bottom-bar nav buttons (EPUB only) */
.btn-nav-mobile {
    display: none;
}

@media (max-width: 768px) {
    #swipe-overlay { display: block; }

    .epub-nav-btn { display: none !important; }

    .btn-nav-mobile {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: transparent;
        border: none;
        color: var(--accent);
        font-size: 32px;
        font-weight: 300;
        cursor: pointer;
        border-radius: 50%;
        -webkit-tap-highlight-color: transparent;
        opacity: 0.9;
    }
    .btn-nav-mobile:active {
        opacity: 0.5;
        transform: scale(0.92);
    }
}

/* ========================
   FAB
======================== */
.fab {
    position: fixed;
    bottom: 90px;
    right: 18px;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--accent);
    color: #0e0c0a;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(201, 168, 76, 0.45);
    transition: all var(--ease);
    z-index: 90;
    -webkit-tap-highlight-color: transparent;
}
.fab:hover { transform: scale(1.06); box-shadow: 0 6px 28px rgba(201, 168, 76, 0.55); }

/* ========================
   Modal
======================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 500;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

@media (min-width: 600px) {
    .modal-overlay { align-items: center; }
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    width: 100%;
    max-width: 520px;
    max-height: 92vh;
    overflow-y: auto;
}

@media (min-width: 600px) {
    .modal { border-radius: var(--radius); }
}

.modal-title { font-family: 'Playfair Display', serif; font-size: 20px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; }

/* ========================
   Upload Area
======================== */
.upload-area {
    background: var(--surface2);
    border: 2px dashed rgba(255,255,255,0.12);
    border-radius: var(--radius);
    padding: 36px 24px;
    text-align: center;
    cursor: pointer;
    transition: all var(--ease);
    position: relative;
}
.upload-area:hover,
.upload-area.drag-over {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.upload-area input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}
.upload-area-icon { color: var(--text2); margin-bottom: 10px; }
.upload-area-text { color: var(--text2); font-size: 14px; line-height: 1.5; }
.upload-area-text strong { color: var(--accent); }
.upload-form { display: flex; flex-direction: column; gap: 20px; max-width: 600px; }

/* ========================
   Toast
======================== */
.toast {
    position: fixed;
    bottom: 92px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 22px;
    font-size: 14px;
    z-index: 9999;
    max-width: 340px;
    width: max-content;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45);
    animation: toastIn 0.25s ease both;
    pointer-events: none;
}
.toast.error   { border-color: rgba(201, 80, 76, 0.4);  color: #e07370; }
.toast.success { border-color: rgba(76, 175, 80, 0.4);  color: #66bb6a; }

@keyframes toastIn {
    from { transform: translateX(-50%) translateY(14px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}

/* ========================
   Spinner
======================== */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========================
   Admin Layout
======================== */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 0;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.admin-logo {
    font-family: 'Playfair Display', serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    padding: 22px 20px 18px;
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.01em;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--text2);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--ease);
    border-left: 3px solid transparent;
    text-decoration: none;
}
.admin-nav-item:hover { background: var(--surface2); color: var(--text); }
.admin-nav-item.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-left-color: var(--accent);
}

.admin-main {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    min-width: 0;
}

.admin-header { margin-bottom: 28px; }
.admin-title  { font-family: 'Playfair Display', serif; font-size: 28px; margin-bottom: 4px; }
.admin-subtitle { color: var(--text2); font-size: 14px; }

.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.admin-stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 20px;
}
.admin-stat-label {
    font-size: 11px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
}
.admin-stat-number {
    font-family: 'Playfair Display', serif;
    font-size: 38px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1;
}

/* ========================
   Tables
======================== */
.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }

th {
    background: var(--surface2);
    padding: 11px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.018); }

/* ========================
   Badges
======================== */
.code-badge {
    display: inline-block;
    padding: 4px 10px;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    letter-spacing: 0.12em;
    font-weight: 700;
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.badge-epub  { background: rgba(76, 175, 80, 0.15);  color: #66bb6a; }
.badge-pdf   { background: rgba(201, 80, 76, 0.15);  color: #e07370; }
.badge-admin { background: var(--accent-dim);         color: var(--accent); }
.badge-store { background: rgba(66, 135, 245, 0.15);  color: #6badf5; }

/* ========================
   Responsive Tweaks
======================== */
@media (max-width: 768px) {
    .admin-layout { flex-direction: column; }
    .admin-sidebar {
        position: static;
        width: 100%;
        height: auto;
        flex-direction: row;
        overflow-x: auto;
        padding: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .admin-logo { display: none; }
    .admin-nav-item {
        flex-direction: column;
        gap: 3px;
        padding: 12px 16px;
        font-size: 11px;
        border-left: none;
        border-bottom: 3px solid transparent;
        white-space: nowrap;
        flex-shrink: 0;
    }
    .admin-nav-item.active { border-left: none; border-bottom-color: var(--accent); }
    .admin-main { padding: 20px 16px; }
    .stats-row  { gap: 8px; }
    .stat-number { font-size: 24px; }
}

/* ========================
   Reader Loading Overlay
======================== */
.reader-loading {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: #0a0806;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    transition: opacity 0.35s ease;
}
.reader-loading.fade-out { opacity: 0; pointer-events: none; }
.reader-loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}
.reader-loading-title {
    font-family: 'Playfair Display', serif;
    font-size: 15px;
    color: var(--text2);
    max-width: 220px;
    text-align: center;
    line-height: 1.4;
}

/* ========================
   Reader Slide-in Panels
======================== */
.reader-panel-backdrop {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.reader-panel-backdrop.open { opacity: 1; pointer-events: auto; }

.reader-panel {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 151;
    width: 280px;
    max-width: 85vw;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    overflow: hidden;
}
.reader-toc-panel {
    left: 0;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
}
.reader-toc-panel.open { transform: translateX(0); }
.reader-settings-panel {
    right: 0;
    border-left: 1px solid var(--border);
    transform: translateX(100%);
}
.reader-settings-panel.open { transform: translateX(0); }

.reader-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.reader-panel-header h3 {
    font-family: 'Playfair Display', serif;
    font-size: 15px;
    font-weight: 600;
}
.reader-panel-body { overflow-y: auto; padding: 16px; flex: 1; }

.toc-item {
    display: block;
    width: 100%;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 11px 0;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    line-height: 1.4;
    transition: color var(--ease), padding-left var(--ease);
}
.toc-item:last-child { border-bottom: none; }
.toc-item:hover { color: var(--accent); padding-left: 6px; }

/* ========================
   Settings Controls
======================== */
.settings-group { margin-bottom: 22px; }
.settings-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text2);
    margin-bottom: 10px;
}
.theme-options { display: flex; gap: 10px; }
.theme-dot {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.15);
    cursor: pointer;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.theme-dot:hover { transform: scale(1.1); }
.theme-dot.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }

.settings-select {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    -webkit-appearance: none;
    appearance: none;
}
.settings-select:focus { outline: none; border-color: var(--accent); }

.stepper {
    display: flex;
    align-items: center;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.stepper-btn {
    background: none;
    border: none;
    border-right: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    width: 42px;
    height: 42px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
    -webkit-appearance: none;
    appearance: none;
    transition: background var(--ease);
}
.stepper-btn:last-child { border-right: none; border-left: 1px solid var(--border); }
.stepper-btn:hover { background: rgba(255,255,255,0.06); }
.stepper-val {
    flex: 1;
    text-align: center;
    font-size: 14px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ========================
   Book Preview Modal (Store)
======================== */
.book-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.book-preview-modal.open { opacity: 1; pointer-events: auto; }

.book-preview-inner {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
@media (min-width: 500px) {
    .book-preview-inner { flex-direction: row; max-height: 70vh; }
}
.book-preview-cover-col { flex-shrink: 0; }
.book-preview-cover {
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    display: block;
}
@media (min-width: 500px) {
    .book-preview-cover-col { width: 150px; }
    .book-preview-cover { width: 150px; height: 100%; max-height: none; }
}
.book-preview-cover-placeholder {
    width: 100%;
    height: 160px;
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text2);
}
@media (min-width: 500px) {
    .book-preview-cover-placeholder { width: 150px; height: 100%; }
}
.book-preview-info {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    overflow-y: auto;
}
.book-preview-title {
    font-family: 'Playfair Display', serif;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
}
.book-preview-author { font-size: 13px; color: var(--text2); }
.book-preview-genre {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-dim);
    border-radius: 4px;
    padding: 3px 8px;
    align-self: flex-start;
}
.book-preview-desc {
    font-size: 13px;
    color: var(--text2);
    line-height: 1.6;
    flex: 1;
    overflow-y: auto;
    margin-top: 4px;
}
.book-preview-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-shrink: 0;
}
