/* =====================================================================
   Базовые стили
===================================================================== */
* { box-sizing: border-box; }

/* Атрибут hidden должен перебивать display у элементов с высокоспецифичными селекторами */
[hidden] { display: none !important; }

:root {
    --bg-1: #dbeafe;   /* небесный */
    --bg-2: #ede9fe;   /* лавандовый */
    --bg-3: #fce7f3;   /* розовый закат */

    --primary: #6366f1;        /* индиго */
    --primary-hover: #818cf8;
    --accent: #f59e0b;         /* солнечно-оранжевый */
    --accent-2: #ec4899;       /* фуксия */

    --surface: #ffffff;
    --surface-soft: rgba(255, 255, 255, 0.85);
    --border: rgba(99, 102, 241, 0.15);

    --text: #1e293b;
    --text-muted: #64748b;

    --shadow-soft: 0 4px 20px rgba(99, 102, 241, 0.12);
    --shadow-book: 0 20px 60px rgba(30, 41, 59, 0.18),
                   0 8px 20px rgba(30, 41, 59, 0.08);
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background:
        radial-gradient(circle at 15% 20%, var(--bg-1) 0%, transparent 55%),
        radial-gradient(circle at 85% 85%, var(--bg-3) 0%, transparent 55%),
        linear-gradient(135deg, var(--bg-2), #f5f3ff);
    background-attachment: fixed;
    font-family: ui-rounded, "SF Pro Rounded", "SF Pro Display",
                 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 system-ui, sans-serif;
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* =====================================================================
   Loader
===================================================================== */
#loader {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    z-index: 100;
}

.loader-text {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.loader-bar {
    width: 280px;
    height: 10px;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 999px;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(99, 102, 241, 0.1);
}

#loader-progress {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--accent-2), var(--accent));
    background-size: 200% 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
    animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
    0%   { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.loader-sub {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
    min-height: 18px;
}

/* =====================================================================
   File picker
===================================================================== */
#picker {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
    padding: 20px;
}

#error-box {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 95;
    padding: 20px;
}

.picker-box {
    max-width: 500px;
    background: var(--surface);
    border-radius: 24px;
    padding: 40px;
    box-shadow: var(--shadow-soft),
                0 20px 50px rgba(30, 41, 59, 0.1);
    text-align: center;
    border: 1px solid var(--border);
}

.picker-title {
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 16px;
    letter-spacing: -0.02em;
    color: var(--text);
}

.picker-hint {
    font-size: 15px;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 28px;
}

.picker-hint code {
    background: var(--bg-2);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 13px;
    font-family: ui-monospace, "SF Mono", Monaco, monospace;
    font-weight: 600;
}

.picker-button {
    display: inline-block;
    background: linear-gradient(135deg, var(--primary), var(--accent-2));
    color: #fff;
    padding: 16px 32px;
    border-radius: 16px;
    font-weight: 700;
    cursor: pointer;
    font-size: 16px;
    letter-spacing: -0.01em;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.picker-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.picker-button:active {
    transform: translateY(0);
}

/* =====================================================================
   App
===================================================================== */
#app {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 24px 120px 24px;  /* снизу оставляем место под фиксированную панель */
}

#flipbook {
    /* размеры задаются из JS, чтобы StPageFlip не растягивался */
    position: relative;
}

/* В DOM-режиме (loadFromHTML) каждая страница — .stf__item с <img> внутри */
.stf__item {
    background: transparent !important;
    box-shadow:
        0 1px 0 rgba(30, 41, 59, 0.08),
        0 15px 35px rgba(30, 41, 59, 0.2),
        0 6px 12px rgba(30, 41, 59, 0.1);
    overflow: hidden;
}

.stf__item img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    background: #fff;
    user-select: none;
    -webkit-user-drag: none;
}

/* =====================================================================
   Controls — фиксированная плавающая панель
===================================================================== */
#controls {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    padding: 10px 14px;
    border-radius: 20px;
    box-shadow: var(--shadow-soft),
                0 10px 30px rgba(30, 41, 59, 0.15);
    border: 1px solid var(--border);
}

#controls button {
    background: var(--bg-2);
    color: var(--primary);
    border: none;
    border-radius: 14px;
    padding: 0;
    width: 48px;
    height: 48px;
    font-size: 26px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

#controls button:hover {
    background: var(--primary);
    color: #fff;
    transform: translateY(-1px);
}

#controls button:active {
    transform: translateY(0) scale(0.96);
}

#btn-fullscreen,
#btn-sound {
    font-size: 20px !important;
}

#page-jump {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 600;
    padding: 0 10px;
}

#page-jump span { white-space: nowrap; }

#page-input {
    width: 60px;
    background: var(--bg-2);
    border: 2px solid transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 8px 6px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    transition: border-color 0.15s ease, background 0.15s ease;
}

#page-input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
}

#page-input::-webkit-inner-spin-button,
#page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#page-total {
    color: var(--primary);
    font-weight: 800;
}

/* =====================================================================
   Адаптив под маленькие экраны
===================================================================== */
@media (max-width: 600px) {
    #controls {
        padding: 8px 10px;
        gap: 6px;
    }
    #controls button {
        width: 42px;
        height: 42px;
        font-size: 22px;
    }
    #page-jump { font-size: 13px; padding: 0 4px; }
    #page-input { width: 50px; font-size: 14px; }
}
