:root {
    --bg: #0f1226;
    --bg-soft: #1a1f3d;
    --card: #ffffff;
    --text: #e8eaf6;
    --muted: #9aa0c7;
    --primary: #6c5ce7;
    --primary-2: #a55eea;
    --accent: #00d2d3;
    --danger: #ff5e7e;
    --radius: 16px;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    font-synthesis: none;
}

* { box-sizing: border-box; }

/* L'attributo hidden deve sempre nascondere, anche su elementi con display impostato. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
}

body {
    background: radial-gradient(1200px 800px at 20% -10%, #2b2160 0%, transparent 55%),
                radial-gradient(1000px 700px at 100% 0%, #143b5a 0%, transparent 50%),
                var(--bg);
}

.btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
    display: inline-block;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn--primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border: none;
    box-shadow: 0 10px 30px rgba(108, 92, 231, 0.45);
}
.btn--primary:hover { box-shadow: 0 14px 36px rgba(108, 92, 231, 0.6); }

/* ----------------------------- Upload page ----------------------------- */
.page-upload {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
}

.uploader {
    width: 100%;
    max-width: 560px;
    text-align: center;
}

.uploader__head .logo {
    font-size: 56px;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.4));
}
.uploader__head h1 {
    font-size: 32px;
    margin: 8px 0 6px;
    background: linear-gradient(135deg, #fff, #b8b5ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.uploader__head p {
    color: var(--muted);
    margin: 0 auto 28px;
    max-width: 440px;
    line-height: 1.5;
}

.dropzone {
    background: rgba(255, 255, 255, 0.04);
    border: 2px dashed rgba(255, 255, 255, 0.22);
    border-radius: var(--radius);
    padding: 36px 28px;
    transition: border-color 0.2s ease, background 0.2s ease;
}
.dropzone--over {
    border-color: var(--accent);
    background: rgba(0, 210, 211, 0.08);
}

.dropzone__icon { font-size: 40px; }
.dropzone__title { font-size: 18px; font-weight: 600; margin: 10px 0 2px; }
.dropzone__sub { color: var(--muted); margin: 6px 0; }
.dropzone__hint { color: var(--muted); font-size: 13px; margin-top: 14px; }

.dropzone__file {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 8px;
}
.dropzone__file .file-icon { font-size: 24px; }
.dropzone__file .file-name {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}
.file-remove {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 18px;
    cursor: pointer;
}

#submit-btn { margin-top: 22px; width: 100%; }

.progress {
    margin-top: 16px;
    height: 8px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.12);
    overflow: hidden;
}
.progress__bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    transition: width 0.2s ease;
}

.result {
    margin-top: 26px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    padding: 28px;
}
.result h2 { margin: 0 0 6px; }
.result p { color: var(--muted); margin: 0 0 16px; }
.share { display: flex; gap: 8px; margin-bottom: 16px; }
.share input {
    flex: 1;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    font-size: 14px;
}

.uploader__foot { margin-top: 26px; color: var(--muted); font-size: 12px; }

/* ----------------------------- Viewer ----------------------------- */
.page-viewer {
    overflow: hidden;
    height: 100vh;
}

.viewer {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.viewer__topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 5;
}
.topbar__back {
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.08);
    padding: 8px 12px;
    border-radius: 10px;
}
.topbar__title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 50%;
}
.topbar__actions { display: flex; gap: 8px; }
.icon-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: var(--text);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    font-size: 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.18); }

.stage {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    min-height: 0;
}

.book-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flipbook {
    margin: 0 auto;
}

/* Pagine del flipbook */
.page {
    background-color: #fff;
    overflow: hidden;
}
.page .page__content {
    width: 100%;
    height: 100%;
    background-color: #fff;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.06);
}
/* Pagina non ancora renderizzata: leggero effetto "skeleton". */
.page__content--loading {
    background-image: linear-gradient(100deg, #f2f2f5 30%, #e9e9ef 50%, #f2f2f5 70%);
    background-size: 200% 100%;
    animation: shimmer 1.2s linear infinite;
}
.page__content--loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid rgba(0, 0, 0, 0.12);
    border-top-color: rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}
/* Copertina/quarta: aspetto rigido con leggero spessore e ombre. */
.page--cover .page__content {
    box-shadow:
        inset 0 0 60px rgba(0, 0, 0, 0.22),   /* vignettatura interna */
        inset 0 1px 0 rgba(255, 255, 255, 0.25), /* riflesso sul bordo alto */
        0 10px 22px rgba(0, 0, 0, 0.35);       /* ombra portata = profondità */
    border-radius: 2px;
}
/* Ombra morbida della rilegatura sul lato della costa (dà profondità senza barre nette). */
.page--cover .page__content::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 26px;
    z-index: 2;
    pointer-events: none;
}
/* Copertina: rilegatura a SINISTRA (libro che si apre verso destra). */
.page--front .page__content::before {
    left: 0;
    background: linear-gradient(90deg,
        rgba(0, 0, 0, 0.38) 0%,
        rgba(0, 0, 0, 0.16) 35%,
        rgba(0, 0, 0, 0) 100%);
}
/* Quarta di copertina: a libro chiuso la rilegatura è sul lato OPPOSTO, a DESTRA. */
.page--back .page__content::before {
    right: 0;
    background: linear-gradient(270deg,
        rgba(0, 0, 0, 0.38) 0%,
        rgba(0, 0, 0, 0.16) 35%,
        rgba(0, 0, 0, 0) 100%);
}
/* Frecce di navigazione */
.nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    z-index: 20;
    transition: background 0.2s ease, transform 0.12s ease;
    backdrop-filter: blur(6px);
}
.nav:hover { background: var(--primary); transform: translateY(-50%) scale(1.06); }
.nav--prev { left: 16px; }
.nav--next { right: 16px; }

.viewer__bottombar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.25);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.page-indicator {
    font-size: 14px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.06);
    padding: 6px 14px;
    border-radius: 99px;
}

/* Loader */
.loader {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 7;
}
.loader__spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
.loader p { color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Not found */
.notfound {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    padding: 20px;
}
.notfound .logo { font-size: 56px; }
.notfound h1 { margin: 6px 0; }
.notfound p { color: var(--muted); margin-bottom: 18px; }

@media (max-width: 640px) {
    .nav { width: 44px; height: 44px; font-size: 24px; }
    .topbar__title { max-width: 38%; }
    .stage { padding: 12px; }
}
