:root {
    --bg: #080607;
    --bg-soft: #130d0f;
    --surface: rgba(18, 13, 12, 0.92);
    --surface-strong: rgba(10, 7, 7, 0.96);
    --surface-soft: rgba(32, 23, 21, 0.9);
    --border: rgba(213, 179, 112, 0.18);
    --border-strong: rgba(213, 179, 112, 0.34);
    --text: #f1e7d6;
    --muted: #b9ab96;
    --muted-strong: #8c7d69;
    --accent: #d3ac63;
    --accent-strong: #a64128;
    --accent-soft: #e1c894;
    --shadow: 0 28px 80px rgba(0, 0, 0, 0.46);
    --index-width: 280px;
    --topbar-height: 92px;
    --page-radius: 26px;
    --turn-duration: 0.6s;
}

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

html,
body {
    height: 100%;
}

body {
    background:
        radial-gradient(circle at top, rgba(163, 65, 40, 0.22), transparent 30%),
        radial-gradient(circle at right, rgba(211, 172, 99, 0.12), transparent 24%),
        linear-gradient(180deg, #120d10 0%, #090607 48%, #050405 100%);
    color: var(--text);
    font-family: "Crimson Pro", serif;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.22) 1px, transparent 1px),
        linear-gradient(rgba(0, 0, 0, 0.18) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(circle at center, black 20%, transparent 82%);
    pointer-events: none;
    opacity: 0.14;
}

button {
    font: inherit;
}

a {
    color: var(--accent-soft);
}

a:hover {
    color: var(--accent);
}

.ambient {
    position: fixed;
    inset: auto;
    pointer-events: none;
    filter: blur(22px);
    opacity: 0.5;
}

.ambient-top {
    top: -120px;
    left: 14%;
    width: 360px;
    height: 260px;
    background: radial-gradient(circle, rgba(166, 69, 46, 0.6) 0%, transparent 70%);
}

.ambient-side {
    right: -90px;
    bottom: 12%;
    width: 280px;
    height: 320px;
    background: radial-gradient(circle, rgba(211, 172, 99, 0.26) 0%, transparent 72%);
}

/* ---------- Índice ---------- */

.quick-index {
    position: fixed;
    top: 24px;
    left: 24px;
    bottom: 24px;
    width: var(--index-width);
    padding: 24px 16px 16px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: linear-gradient(180deg, rgba(16, 12, 12, 0.94), rgba(8, 6, 6, 0.86));
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.index-header {
    padding: 2px 12px 14px;
    border-bottom: 1px solid rgba(213, 179, 112, 0.12);
}

.index-kicker,
.status-kicker,
.chapter-kicker,
.cover-kicker {
    font-family: "Cinzel", serif;
    font-size: 0.7rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--accent-soft);
}

.index-title {
    margin-top: 10px;
    font-family: "Cinzel", serif;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.45;
    color: var(--muted);
}

.index-list {
    list-style: none;
    overflow-y: auto;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.index-list::-webkit-scrollbar,
.page-scroll::-webkit-scrollbar {
    width: 8px;
}

.index-list::-webkit-scrollbar-thumb,
.page-scroll::-webkit-scrollbar-thumb {
    background: rgba(213, 179, 112, 0.28);
    border-radius: 999px;
}

.index-item {
    width: 100%;
    border: 1px solid transparent;
    border-left: 2px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 10px 12px;
    text-align: left;
    transition: border-color 0.25s ease, background-color 0.25s ease, color 0.25s ease;
}

.index-item:hover,
.index-item:focus-visible {
    background: rgba(255, 255, 255, 0.035);
    color: var(--text);
    outline: none;
}

.index-item.active {
    background: linear-gradient(90deg, rgba(166, 69, 46, 0.22), rgba(211, 172, 99, 0.06));
    border-left-color: var(--accent);
    color: var(--text);
}

.index-item-label {
    display: block;
    font-family: "Cinzel", serif;
    font-size: 0.68rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted-strong);
    margin-bottom: 3px;
}

.index-item.active .index-item-label {
    color: var(--accent-soft);
}

.index-item-title {
    display: block;
    font-size: 1.02rem;
    line-height: 1.3;
}

/* ---------- Botões ---------- */

.index-toggle,
.audio-button,
.nav-button {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(14, 10, 10, 0.55);
    color: var(--text);
    cursor: pointer;
    backdrop-filter: blur(12px);
    transition: transform 0.25s ease, border-color 0.25s ease, background-color 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.index-toggle:hover,
.audio-button:hover,
.nav-button:hover,
.index-toggle:focus-visible,
.audio-button:focus-visible,
.nav-button:focus-visible {
    transform: translateY(-1px);
    border-color: var(--border-strong);
    background: rgba(255, 255, 255, 0.07);
    outline: none;
}

.index-toggle {
    position: fixed;
    top: 22px;
    left: 20px;
    z-index: 70;
    padding: 0.8rem 1.1rem;
    font-family: "Cinzel", serif;
    font-size: 0.8rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    display: none;
}

.index-scrim {
    position: fixed;
    inset: 0;
    background: rgba(3, 2, 2, 0.62);
    backdrop-filter: blur(6px);
    z-index: 35;
}

/* ---------- Topo ---------- */

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 18px;
    padding: 26px 30px 0 calc(var(--index-width) + 56px);
    z-index: 30;
    pointer-events: none;
}

.status-block {
    pointer-events: auto;
    padding: 4px 2px;
}

.status-title {
    margin-top: 8px;
    font-family: "Cinzel", serif;
    font-size: clamp(1.1rem, 1.8vw, 1.5rem);
    font-weight: 500;
    line-height: 1.25;
    text-shadow: 0 2px 18px rgba(0, 0, 0, 0.8);
}

.audio-panel {
    pointer-events: auto;
    display: flex;
    gap: 8px;
    align-items: center;
}

.audio-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    color: var(--accent-soft);
}

.audio-button.playing {
    border-color: rgba(213, 179, 112, 0.45);
    box-shadow: 0 0 18px rgba(211, 172, 99, 0.22);
}

.audio-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.audio-button.ghost {
    color: var(--muted);
}

.audio-button.muted {
    color: var(--muted-strong);
    text-decoration: line-through;
}

/* ---------- Indicador + progresso ---------- */

.page-indicator {
    position: fixed;
    bottom: 26px;
    right: 32px;
    z-index: 25;
    font-family: "Cinzel", serif;
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    color: var(--muted-strong);
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}

.current-page {
    color: var(--accent-soft);
}

.page-separator {
    margin: 0 4px;
}

.progress-rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.05);
    z-index: 45;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent-strong), var(--accent));
    box-shadow: 0 0 20px rgba(211, 172, 99, 0.45);
    transition: width 0.35s ease;
}

.navigation {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    display: flex;
    gap: 14px;
    z-index: 50;
}

.nav-button {
    width: 46px;
    height: 46px;
    font-size: 1.1rem;
    color: var(--accent-soft);
}

.nav-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

/* ---------- Páginas + virar de página ---------- */

.ebook-container {
    width: 100%;
    min-height: 100vh;
    position: relative;
}

.single-page {
    position: fixed;
    inset: 0;
    padding: calc(var(--topbar-height) + 34px) 30px 92px calc(var(--index-width) + 56px);
    perspective: 2200px;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--turn-duration) ease;
}

.single-page .page-content {
    transform: rotateY(0deg);
    transition: transform var(--turn-duration) cubic-bezier(0.22, 0.75, 0.25, 1), box-shadow var(--turn-duration) ease;
}

.single-page.from-next .page-content {
    transform-origin: left center;
    transform: rotateY(38deg) translateX(48px);
}

.single-page.from-prev .page-content {
    transform-origin: right center;
    transform: rotateY(-38deg) translateX(-48px);
}

.single-page.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 20;
}

.single-page.active .page-content {
    transform: rotateY(0deg) translateX(0);
}

.page-content {
    max-width: 920px;
    height: calc(100vh - 200px);
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: var(--page-radius);
    background:
        linear-gradient(180deg, rgba(22, 16, 15, 0.98), rgba(10, 8, 8, 0.97)),
        radial-gradient(circle at top, rgba(211, 172, 99, 0.06), transparent 28%);
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
}

.page-content::before {
    content: "";
    position: absolute;
    inset: 14px;
    border-radius: calc(var(--page-radius) - 10px);
    border: 1px solid rgba(213, 179, 112, 0.07);
    pointer-events: none;
    z-index: 2;
}

.page-scroll {
    position: relative;
    height: 100%;
    overflow-y: auto;
    padding: 56px clamp(24px, 5vw, 84px) 72px;
}

.page-scroll,
.chapter-content,
.chapter-content * {
    user-select: none;
    -webkit-user-select: none;
}

/* ---------- Capa ---------- */

.page-cover .page-scroll {
    padding: 0;
}

.title-page {
    min-height: 100%;
    display: grid;
    align-content: center;
    justify-items: start;
    text-align: center;
    gap: 26px;
    padding: clamp(34px, 6vw, 72px);
    background:
        linear-gradient(90deg, rgba(3, 2, 2, 0.88) 0%, rgba(3, 2, 2, 0.56) 46%, rgba(3, 2, 2, 0.08) 76%),
        linear-gradient(180deg, rgba(3, 2, 2, 0.14), rgba(3, 2, 2, 0.42)),
        url("assets/cover-landscape.png") center center / contain no-repeat,
        #050403;
    overflow: hidden;
    position: relative;
}

.cover-frame {
    display: grid;
    justify-items: start;
    gap: 26px;
    width: min(52%, 500px);
    padding: clamp(28px, 5vh, 56px) clamp(20px, 4vw, 56px);
    border-top: 1px solid rgba(213, 179, 112, 0.3);
    border-bottom: 1px solid rgba(213, 179, 112, 0.3);
    position: relative;
    text-align: left;
    z-index: 1;
}

.cover-frame::before,
.cover-frame::after {
    content: "✦";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    color: var(--accent);
    font-size: 0.85rem;
    background: transparent;
}

.cover-frame::before {
    top: -0.55em;
}

.cover-frame::after {
    bottom: -0.55em;
}

.main-title {
    font-family: "UnifrakturMaguntia", cursive;
    max-width: 9ch;
    font-size: clamp(3.1rem, 5.5vw, 5.8rem);
    font-weight: 400;
    line-height: 1.05;
    color: var(--accent);
    text-shadow:
        0 0 34px rgba(211, 172, 99, 0.28),
        0 0 90px rgba(166, 69, 46, 0.3);
}

.cover-rule {
    display: flex;
    align-items: center;
    gap: 16px;
    width: min(340px, 60%);
    color: var(--accent);
    font-size: 1rem;
}

.cover-rule::before,
.cover-rule::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(213, 179, 112, 0.5));
}

.cover-rule::after {
    background: linear-gradient(90deg, rgba(213, 179, 112, 0.5), transparent);
}

.cover-subtitle {
    font-family: "Cinzel", serif;
    font-size: clamp(0.95rem, 1.8vw, 1.3rem);
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: #d8d0c1;
}

.cover-meta {
    font-family: "Cinzel", serif;
    font-size: 0.8rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--muted-strong);
}

.cover-hint {
    margin-top: 12px;
    font-family: "Cinzel", serif;
    font-size: 0.78rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--muted-strong);
    animation: hint-breathe 4s ease-in-out infinite;
    position: relative;
    text-align: left;
    z-index: 1;
}

@keyframes hint-breathe {
    0%, 100% { opacity: 0.55; }
    50% { opacity: 1; }
}

/* ---------- Capítulos ---------- */

.chapter-page {
    min-height: 100%;
}

.chapter-header {
    margin-bottom: 44px;
    padding-bottom: 30px;
    border-bottom: 1px solid rgba(213, 179, 112, 0.14);
    position: relative;
}

.chapter-header::after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 72px;
    height: 1px;
    background: var(--accent);
}

.chapter-title {
    margin-top: 14px;
    font-family: "Cinzel", serif;
    font-size: clamp(2.1rem, 4.6vw, 3.3rem);
    font-weight: 500;
    line-height: 1.14;
    color: #f7f0e2;
    text-wrap: balance;
}

.chapter-subtitle {
    margin-top: 12px;
    font-family: "Cinzel", serif;
    font-size: 0.95rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--muted);
}

.chapter-content {
    max-width: 66ch;
    margin: 0 auto;
    font-size: 1.24rem;
    line-height: 1.85;
}

.chapter-paragraph,
.lead-in {
    margin-bottom: 1.5rem;
}

.chapter-paragraph {
    color: var(--text);
    text-align: justify;
    hyphens: auto;
    -webkit-hyphens: auto;
    text-wrap: pretty;
}

.chapter-paragraph.stanza {
    text-align: left;
    hyphens: none;
    color: #f0e4d0;
}

.lead-in {
    font-family: "Cinzel", serif;
    color: var(--accent-soft);
    letter-spacing: 0.04em;
}

.minor-heading {
    margin: 2.6rem 0 1rem;
    font-family: "Cinzel", serif;
    font-size: 1.1rem;
    letter-spacing: 0.08em;
    color: var(--accent);
}

.section-divider {
    display: grid;
    justify-items: center;
    gap: 10px;
    margin: 2.7rem 0 2.3rem;
}

.divider-icon {
    font-size: 1.8rem;
    color: var(--accent);
}

.divider-text {
    font-family: "Cinzel", serif;
    font-size: 0.88rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--muted);
}

.chapter-paragraph:first-of-type::first-letter {
    float: left;
    margin: 0.32rem 0.85rem 0 0;
    font-family: "UnifrakturMaguntia", cursive;
    font-size: 4rem;
    line-height: 0.72;
    color: var(--accent);
    text-shadow: 0 0 22px rgba(211, 172, 99, 0.3);
}

/* ---------- Responsivo ---------- */

@media (max-width: 1220px) {
    .topbar {
        grid-template-columns: minmax(0, 1fr) auto;
        padding-right: 24px;
    }
}

@media (max-width: 1080px) {
    .index-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .quick-index {
        transform: translateX(-112%);
        transition: transform 0.32s ease;
        z-index: 60;
    }

    body.index-open .quick-index {
        transform: translateX(0);
    }

    .topbar,
    .single-page {
        padding-left: 24px;
    }

    .topbar {
        padding-top: 24px;
        padding-left: 118px;
    }

    .single-page {
        padding-right: 24px;
    }
}

@media (max-width: 820px) {
    :root {
        --topbar-height: 96px;
    }

    .page-content {
        height: calc(100vh - 200px);
    }
}

@media (orientation: portrait) {
    .title-page {
        align-content: start;
        padding: clamp(34px, 8vw, 68px);
        background:
            linear-gradient(180deg, rgba(3, 2, 2, 0.6) 0%, rgba(3, 2, 2, 0.18) 42%, rgba(3, 2, 2, 0.56) 100%),
            linear-gradient(90deg, rgba(3, 2, 2, 0.62), rgba(3, 2, 2, 0.06) 72%),
            url("assets/cover-portrait.png") center center / cover no-repeat;
    }

    .cover-frame {
        width: min(82%, 520px);
    }
}

@media (max-width: 640px) {
    :root {
        --topbar-height: 128px;
    }

    .quick-index {
        top: 16px;
        left: 16px;
        bottom: 16px;
        width: min(82vw, 320px);
    }

    .topbar {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        padding: 78px 16px 0;
    }

    .audio-panel {
        position: fixed;
        top: 20px;
        right: 16px;
    }

    .audio-button {
        width: 40px;
        height: 40px;
    }

    .status-block {
        padding: 0;
    }

    .status-title {
        font-size: 1.05rem;
    }

    .page-indicator {
        bottom: 34px;
        right: 16px;
        font-size: 0.8rem;
    }

    .navigation {
        left: auto;
        right: auto;
        transform: none;
        width: 100%;
        justify-content: center;
        bottom: 18px;
    }

    .nav-button {
        width: 48px;
        height: 48px;
    }

    .single-page {
        padding: calc(var(--topbar-height) + 20px) 14px 84px;
    }

    .page-content {
        height: calc(100vh - var(--topbar-height) - 110px);
        border-radius: 20px;
    }

    .page-scroll {
        padding: 32px 20px 48px;
    }

    .chapter-content {
        font-size: 1.12rem;
        line-height: 1.8;
    }

    .chapter-paragraph {
        text-align: left;
    }

    .main-title {
        font-size: clamp(2.8rem, 13vw, 4rem);
    }

    .title-page {
        gap: 18px;
        padding: 30px 22px 76px;
    }

    .cover-frame {
        gap: 16px;
        width: min(88%, 420px);
        padding: 24px 16px;
    }

    .cover-subtitle {
        font-size: 0.78rem;
        letter-spacing: 0.22em;
    }

    .cover-meta {
        font-size: 0.64rem;
        letter-spacing: 0.14em;
        line-height: 1.6;
    }

    .cover-hint {
        position: absolute;
        right: 22px;
        bottom: 24px;
        left: 22px;
        margin: 0;
        font-size: 0.62rem;
        line-height: 1.6;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
