:root {
    --bg-color: #0a0a0c;
    --nav-bg: rgba(10, 10, 12, 0.85);
    --text-primary: #ffffff;
    --text-secondary: #a0a0a5;
    --accent: #d8b068;
    --font-main: 'Rubik', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

img {
    pointer-events: none;
}

/* ── Navigation Bar ───────────────────────────────────────────────────────── */
.flipbook-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 2rem;
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.btn-back {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.3s ease;
}
.btn-back:hover { color: var(--text-primary); }

.logo img { height: 35px; object-fit: contain; }

.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.book-title {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--accent);
    letter-spacing: 0.5px;
    line-height: 1;
}

.view-stats {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0.8;
}
.view-stats svg { margin-top: 1px; }

/* ── Main Wrapper ─────────────────────────────────────────────────────────── */
.flipbook-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    height: calc(100vh - 67px);
    height: calc(100dvh - 67px);
    padding: 0;
    touch-action: pan-x pan-y pinch-zoom;
}

/* ── Splash Loading Screen ────────────────────────────────────────────────── */
.loading-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    z-index: 50;
    transition: opacity 0.5s ease;
    text-align: center;
    padding: 0 2rem;
}

.loading-state p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.6;
    min-height: 2em;        /* prevent layout shift during message swap */
    transition: opacity 0.5s ease;
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    flex-shrink: 0;
}
.spinner.small {
    width: 24px;
    height: 24px;
    border-width: 2px;
}

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

/* ── Main Container ───────────────────────────────────────────────────────── */
.container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

/* ── Vertical / Webtoon Mode ──────────────────────────────────────────────── */
.container.vertical-mode {
    display: block;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    height: 100%;
    padding-bottom: 60px;
}

.container.vertical-mode .flipbook-sizer {
    width: 92% !important;
    max-width: 900px !important;
    margin: 0 auto !important;
    height: auto !important;
    display: block;
}

.container.vertical-mode #book {
    width: 100% !important;
    height: auto !important;
    box-shadow: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

/* Pages in vertical mode */
.container.vertical-mode .page {
    position: relative !important;
    width: 100% !important;
    height: auto !important;
    aspect-ratio: auto !important;
    transform: none !important;
    display: block !important;
    border: none;
    margin-bottom: 2px;
}

.container.vertical-mode .page-content {
    height: auto;
    position: relative;
    min-height: 40px;
}

.container.vertical-mode .page-image {
    height: auto;
    object-fit: contain;
    display: block;
}

/* ── Per-page Loading Spinner ─────────────────────────────────────────────── */
.page-loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    height: 100%; /* Fill the container for centering */
    background: #0e0e10;
}

/* In vertical mode, show spinners for individual pages (NOT hidden) */
.container.vertical-mode .page-loading-spinner {
    display: flex;
}

/* Empty placeholder pages never need a spinner */
.container.vertical-mode .page-empty {
    display: none !important;
}


.page-loading-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: center;
    padding: 0 1rem;
    line-height: 1.5;
    transition: opacity 0.5s ease;
    min-height: 1.3em;
}

/* ── Page Styles ──────────────────────────────────────────────────────────── */
.page {
    background-color: #111;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.05);
}

.page-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #000;
}

.page-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.page-image.loaded { opacity: 1; }

.page.--page-hard {
    background-color: #000;
    border: 2px solid rgba(255,255,255,0.1);
}

/* ── Flipbook Sizer ───────────────────────────────────────────────────────── */
.flipbook-sizer {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flipbook {
    width: 100%;
    height: 100%;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    border-radius: 4px;
}

/* ── Bottom Controls (Desktop only) ──────────────────────────────────────── */
.bottom-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: row-reverse; /* Fullscreen on the right */
    align-items: center;
    gap: 1rem;
    background: rgba(20, 20, 25, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 0.6rem 1.2rem;
    border-radius: 50px;
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 15px 35px rgba(0,0,0,0.6);
    z-index: 100;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                opacity  0.4s ease;
}

/* Hides the bar below the fold */
.bottom-controls.hidden-auto {
    transform: translate(-50%, 100px);
    opacity: 0;
    pointer-events: none;
}

/* Initial hidden state before viewer is ready */
.bottom-controls.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Completely hide on mobile */
@media screen and (max-width: 768px) {
    .bottom-controls { display: none !important; }
}

/* ── View Mode Toggle Buttons ─────────────────────────────────────────────── */
.view-mode-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.5rem;
}

.controls-separator {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,0.15);
    margin: 0 0.5rem;
}

.btn-toggle {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-family: var(--font-main);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.btn-toggle:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
}
.btn-toggle.active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    font-weight: 600;
}

/* ── Icon Buttons ─────────────────────────────────────────────────────────── */
.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
}
.btn-icon:hover {
    background: rgba(255,255,255,0.1);
    color: var(--accent);
}

#btn-prev, #btn-next, .page-counter {
    display: none !important;
}

/* ── Desktop / Mobile visibility helpers ─────────────────────────────────── */
.mobile-only  { display: none !important; }
.desktop-only { display: flex !important; }

@media screen and (max-width: 768px) {
    .desktop-only { display: none !important; }
}
@media screen and (min-width: 769px) {
    .mobile-only { display: none !important; }
}

/* ── Fullscreen ───────────────────────────────────────────────────────────── */
body.fullscreen-active .flipbook-nav { display: none !important; }
body.fullscreen-active .flipbook-wrapper {
    height: 100vh !important;
    height: 100dvh !important;
}

/* ── Zoom (kept for compatibility) ───────────────────────────────────────── */
.flipbook-sizer.zoomed { cursor: grab; z-index: 150; }
.flipbook-sizer.zoomed:active { cursor: grabbing; }
.container.zoom-active {
    overflow: auto;
    display: block;
    white-space: nowrap;
}
.container.zoom-active .flipbook-sizer {
    margin: auto;
    transition: transform 0.3s ease;
}

/* ── Swipe indicator removed ─────────────────────────────────────────────── */
.swipe-indicator { display: none !important; }
