/* ============================================
   GIA PHẢ HỌ NGUYỄN — Warm Light Theme
   ============================================ */

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

:root {
    --bg-primary: #f0e6d6;
    --bg-warm: #e8dbc8;
    --bg-glass: rgba(180, 150, 110, 0.15);
    --bg-glass-hover: rgba(180, 150, 110, 0.25);
    --border-glass: rgba(160, 130, 90, 0.2);
    --text-primary: #3d2e1e;
    --text-secondary: #6b5740;
    --text-muted: #8a7560;
    --accent: #a0734a;
    --accent-glow: rgba(160, 115, 74, 0.3);
    --accent-light: #c49060;
    --shadow-book: 0 20px 60px rgba(80, 50, 20, 0.2),
                   0 8px 25px rgba(80, 50, 20, 0.15);
    --shadow-btn: 0 3px 10px rgba(80, 50, 20, 0.12);
    --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 50%;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Warm Light Misty Background with Heritage Pattern --- */
body {
    background-image: 
        radial-gradient(ellipse 90% 70% at 25% 15%, rgba(255, 252, 245, 0.25) 0%, transparent 70%),
        radial-gradient(ellipse 80% 60% at 80% 25%, rgba(250, 242, 230, 0.2) 0%, transparent 65%),
        linear-gradient(160deg, rgba(255, 252, 245, 0.35) 0%, rgba(245, 235, 220, 0.45) 100%),
        url('vietnam_motif_bg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

/* Floating warm light mist */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle 350px at 15% 50%, rgba(220, 185, 130, 0.2) 0%, transparent 100%),
        radial-gradient(circle 450px at 85% 40%, rgba(210, 175, 120, 0.15) 0%, transparent 100%),
        radial-gradient(circle 300px at 50% 15%, rgba(230, 200, 150, 0.15) 0%, transparent 100%);
    pointer-events: none;
    z-index: 0;
    animation: floatMist 20s ease-in-out infinite alternate;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle 250px at 35% 75%, rgba(200, 165, 110, 0.15) 0%, transparent 100%),
        radial-gradient(circle 400px at 70% 60%, rgba(215, 180, 125, 0.12) 0%, transparent 100%);
    pointer-events: none;
    z-index: 0;
    animation: floatMist 25s ease-in-out 5s infinite alternate-reverse;
}

/* --- Utility --- */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* --- Loading Overlay --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 60% 50% at 50% 50%, rgba(220, 190, 140, 0.25) 0%, transparent 70%),
        linear-gradient(160deg, #f5ebe0 0%, #efe2d0 40%, #e8d8c2 100%);
    transition: opacity 0.6s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    animation: fadeInUp 0.8s ease;
}

.spinner {
    width: 48px;
    height: 48px;
    margin: 0 auto 24px;
    border: 3px solid rgba(160, 115, 74, 0.2);
    border-top-color: var(--accent);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

.loading-text {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.loading-subtext {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* --- App Layout --- */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    transition: opacity 0.6s ease;
    position: relative;
    z-index: 1;
}

.app:not(.hidden) {
    opacity: 1;
}

/* --- Header --- */
.header {
    flex-shrink: 0;
    padding: 12px 24px;
    background: rgba(240, 230, 214, 0.7);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-bottom: 1px solid rgba(180, 155, 120, 0.2);
    z-index: 10;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1400px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 1.4rem;
}

.logo-text {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    background: linear-gradient(135deg, #6b4226, #a0734a, #8b5e3c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.page-info {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: rgba(255, 245, 230, 0.6);
    padding: 6px 16px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(180, 155, 120, 0.2);
}

.page-info #current-page {
    color: var(--accent);
    font-weight: 600;
    min-width: 20px;
    text-align: right;
}

.page-divider {
    color: var(--text-muted);
}

/* --- Flipbook Wrapper --- */
.flipbook-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 8px 56px;
    overflow: hidden;
}

/* Warm ambient glow behind the book */
.flipbook-wrapper::before {
    content: '';
    position: absolute;
    width: 50%;
    height: 50%;
    background: radial-gradient(ellipse, rgba(200, 160, 100, 0.15) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.flipbook {
    position: relative;
    z-index: 1;
    box-shadow: var(--shadow-book);
    border-radius: 4px;
    transition: transform var(--transition-smooth);
}

/* --- Cover Centered State ---
   StPageFlip places the cover on the RIGHT half of the container.
   Container width = 2 * singlePageWidth.
   To center the cover, shift the container LEFT by 25% of its own width.
*/
.flipbook.is-cover {
    transform: translateX(-25%);
}

/* Style for each page inside the flipbook */
.flipbook .page-wrapper {
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.flipbook .page-wrapper canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    margin: auto;
}

/* Page placeholder while loading */
.flipbook .page-wrapper .page-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #faf6f1 0%, #f0e8dd 100%);
    color: #a89478;
    gap: 12px;
}

.flipbook .page-wrapper .page-placeholder .mini-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid #e2d8cc;
    border-top-color: var(--accent);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

.flipbook .page-wrapper .page-placeholder span {
    font-size: 0.75rem;
    font-family: var(--font-main);
}

/* --- Navigation Buttons (Side Arrows) --- */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(180, 155, 120, 0.25);
    border-radius: var(--radius-full);
    background: rgba(255, 245, 230, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-btn);
}

.nav-btn:hover {
    background: rgba(255, 245, 230, 0.85);
    color: var(--text-primary);
    border-color: var(--accent);
    box-shadow: 0 0 18px var(--accent-glow);
    transform: translateY(-50%) scale(1.08);
}

.nav-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.nav-prev {
    left: 16px;
}

.nav-next {
    right: 16px;
}

/* --- Bottom Controls --- */
.controls {
    flex-shrink: 0;
    padding: 12px 24px 16px;
    background: rgba(240, 230, 214, 0.7);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid rgba(180, 155, 120, 0.2);
    z-index: 10;
}

.controls-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.ctrl-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: 1px solid rgba(180, 155, 120, 0.25);
    border-radius: var(--radius-sm);
    background: rgba(255, 245, 230, 0.5);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.ctrl-btn:hover {
    background: rgba(255, 245, 230, 0.85);
    color: var(--text-primary);
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

.ctrl-btn:active {
    transform: scale(0.92);
}

/* --- Page Slider --- */
.slider-container {
    flex: 1;
    max-width: 360px;
    padding: 0 8px;
}

.page-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(160, 130, 90, 0.15);
    outline: none;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.page-slider:hover {
    background: rgba(160, 130, 90, 0.25);
}

/* Webkit (Chrome, Edge, Safari) */
.page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-glow);
    transition: all var(--transition-fast);
}

.page-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 14px var(--accent-glow);
}

/* Firefox */
.page-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: none;
    border-radius: var(--radius-full);
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-glow);
}

/* --- Animations --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes floatMist {
    from { transform: translate(0, 0) scale(1); }
    to { transform: translate(12px, -8px) scale(1.03); }
}

/* --- View Diagram Button --- */
.view-diagram-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #a0734a, #8b5e3c);
    color: #fff;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-btn);
    transition: all var(--transition-fast);
}

.view-diagram-btn:hover {
    background: linear-gradient(135deg, #b3855a, #9c6b44);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.view-diagram-btn:active {
    transform: translateY(0);
}

/* --- Responsive — Mobile --- */
@media (max-width: 768px) {
    .flipbook-wrapper {
        padding: 4px 8px;
    }

    /* Hide side nav arrows on mobile — use swipe instead */
    .nav-btn {
        display: none;
    }

    /* Single page mode — no cover offset */
    .flipbook.is-cover {
        transform: none;
    }

    /* Compact header */
    .header {
        padding: 8px 12px;
    }

    .logo-icon {
        font-size: 1.1rem;
    }

    .logo-text {
        font-size: 0.9rem;
    }

    .view-diagram-btn {
        padding: 6px 12px;
        font-size: 0.85rem;
    }

    .page-info {
        font-size: 0.8rem;
        padding: 4px 10px;
    }

    /* Compact controls */
    .controls {
        padding: 8px 12px 12px;
    }

    .controls-inner {
        gap: 8px;
    }

    .ctrl-btn {
        width: 36px;
        height: 36px;
    }

    /* Larger touch target on slider */
    .page-slider {
        height: 6px;
    }

    .page-slider::-webkit-slider-thumb {
        width: 22px;
        height: 22px;
    }

    .page-slider::-moz-range-thumb {
        width: 22px;
        height: 22px;
    }
}

@media (max-width: 480px) {
    .flipbook-wrapper {
        padding: 2px 4px;
    }

    .header {
        padding: 6px 10px;
    }

    .logo-icon {
        display: none;
    }

    .logo-text {
        font-size: 0.85rem;
    }

    .page-info {
        font-size: 0.75rem;
        padding: 3px 8px;
    }

    .controls {
        padding: 6px 8px 10px;
    }

    .ctrl-btn {
        width: 32px;
        height: 32px;
    }

    .controls-inner {
        gap: 6px;
    }
}

/* ============================================
   ZOOM & PANNING SYSTEM
   ============================================ */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 245, 230, 0.6);
    padding: 4px 8px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(180, 155, 120, 0.2);
    user-select: none;
}

.zoom-btn {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(180, 155, 120, 0.2);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.6);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    padding: 0;
}

.zoom-btn:hover {
    background: #fff;
    border-color: var(--accent);
    color: var(--accent);
}

.zoom-btn:active {
    transform: scale(0.9);
}

#zoom-level {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 42px;
    text-align: center;
}

.zoom-container {
    transition: transform 0.15s ease-out;
    transform-origin: center center;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.flipbook-wrapper.is-zoomed {
    cursor: grab;
}

.flipbook-wrapper.is-zoomed:active {
    cursor: grabbing;
}

@media (max-width: 768px) {
    .zoom-controls {
        gap: 4px;
        padding: 2px 6px;
    }
    
    .zoom-btn {
        width: 24px;
        height: 24px;
    }
    
    #zoom-level {
        font-size: 0.75rem;
        min-width: 35px;
    }
    
    /* Tránh chồng lấp trên mobile: ẩn nút Gia phả chữ dài nếu cần, hoặc thu nhỏ chữ */
    .view-diagram-btn {
        padding: 6px 8px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .zoom-controls {
        gap: 2px;
    }
    
    .view-diagram-btn {
        padding: 4px 6px;
        font-size: 0.75rem;
    }
}


