/* ====================================
   Theme Variables
==================================== */
:root {
    --bg: #FAF4E6;
    --text: #3E2F1C;
    --accent: #4C6B47;
    --link: #4A7C8C;
    --border: #CBB89D;
}

/* ====================================
   Global Reset & Base
==================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 100%;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

@supports not (scrollbar-gutter: stable) {
    html {
        overflow-y: scroll;
    }
}

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: 'Merriweather', serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1;
    padding-top: 5rem; /* approximate header height for backup */
}

header,
aside,
.card,
.translation-block,
footer {
    background: white;
}

.hidden {
    display: none !important;
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ====================================
   Header & Navigation
==================================== */
header {
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
}

header h1 {
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
}

header h1 a {
    color: inherit;
}

a {
    transition: color 0.3s ease;
    text-decoration: none;
    color: var(--link);
    cursor: pointer;
}

nav a,
aside a,
footer a,
.chapter-update a {
    position: relative;
    font-weight: 500;
}

nav a::after,
.card a::after,
footer a::after,
.chapter-update a::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -3px;
    height: 2px;
    width: 100%;
    background-color: var(--accent);
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.5s ease;
}

nav a:hover::after,
.card a:hover::after,
footer a:hover::after,
.chapter-update a:hover::after {
    transform: scaleX(1);
}

nav a {
    margin-left: 1.5rem;
}

nav a:hover,
.card a:hover,
footer a:hover,
.translation strong,
.chapter-update a:hover {
    color: var(--accent);
}

nav a[aria-current="page"] {
    color: var(--accent);
    font-weight: bold;
    border-bottom: 2px solid var(--accent);
    padding-bottom: 0.2rem;
}

nav a[aria-current="page"]::after {
    display: none;
}

/* ====================================
   Back to Top Button
==================================== */
.back-to-top {
    position: fixed;
    bottom: 2.5rem;
    right: 2rem;
    width: 2.7rem;
    height: 2.7rem;
    background: transparent;
    color: var(--accent);
    border: 1.5px solid var(--accent);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
}

.back-to-top svg {
    width: 1.2rem;
    height: 1.2rem;
}

.back-to-top:hover {
    transform: scale(1.1);
    background-color: rgba(76, 107, 71, 0.08);
}

body.scrolled .back-to-top {
    opacity: 1;
    pointer-events: auto;
}

/* ====================================
   Buttons
==================================== */
.button {
    font-family: 'Merriweather', serif;
    font-size: 1rem;
    font-weight: bold;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    border: none;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: inline-block;
    text-align: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
}

.button:hover {
    transform: scale(1.02);
    box-shadow: 0 0 4px 1px rgba(76, 107, 71, 0.5);
    background-color: #436141;
}

/* ====================================
   Error Message
==================================== */
#error-wrapper {
    display: none;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

#error-message {
    background-color: #ffdddd;
    color: #a94442;
    border: 1px solid #a94442;
    padding: 1rem 2rem;
    margin: 1rem auto;
    max-width: 50%;
    border-radius: 8px;
    font-weight: bold;
}

.error-p {
    color: gray;
    font-size: 0.9rem;
    font-style: italic;
}

/* ====================================
   Sections & Text Styling
==================================== */
.section {
    padding: 3rem 2rem;
    max-width: 75%;
    margin: 0 auto;
    opacity: 0;
}

.section h2 {
    font-family: 'Cinzel', serif;
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.section h3 {
    font-size: 1.3rem;
}

h3.section-heading {
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    color: var(--accent);
}

.section p:not(.card-description) {
    font-size: 1.1rem;
}

.tip {
    margin: 2rem 0 0.5rem 0;
    font-style: italic;
    font-size: 0.85rem;
}

/* ====================================
   Animation
==================================== */
.animate:not(.card) {
    animation: fadeInUpBlur 1s ease-out both;
}

@keyframes fadeInUpBlur {
    0% {
        opacity: 0;
        transform: translateY(2.5rem);
        filter: blur(4px);
    }

    40% {
        filter: blur(0);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

@keyframes popupIn {
    from {
        transform: scale(0.9) translateY(20px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* ====================================
   Images
==================================== */
img.loaded {
    opacity: 1;
}

/* ====================================
   Popup and banner styles
==================================== */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    z-index: 2000;
}

.popup-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.popup {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem 3rem 2rem;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
    animation: popupIn 0.4s ease;
    text-align: center;
    font-family: 'Merriweather', serif;
    color: var(--text);
}

.popup-close {
    position: absolute;
    top: 50%;
    bottom: 50%;
    right: 0.5rem;
    background: transparent;
    border: none;
    font-size: 2.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-close svg {
    width: 2rem;
    height: 2rem;
    stroke-width: 1.5;
    color: #a38f7d;
    transition: color 0.25s ease, transform 0.25s ease;
}

.popup-close:hover svg {
    color: var(--text);
    transform: scale(1.1);
}

[data-id="close"] {
    top: 0.5rem;
    bottom: auto;
}

[data-id="close"] svg {
    width: 2.5rem;
    height: 2.5rem;
}

.popup-intro {
    font-family: 'Cinzel', serif;
    font-size: 1.2rem;
    font-style: italic;
    margin-bottom: 0.8rem;
    color: var(--accent);
    border-bottom: 1.5px solid var(--accent);
}

.popup-text {
    font-size: 1rem;
    margin-bottom: 1.5rem;
    line-height: 1.4;
}

.chapter-stepper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--accent);
}

[data-id="chapter-display"] {
    min-width: 2ch;
    text-align: center;
    font-size: 1.3rem;
    color: var(--text);
}

.stepper-btn {
    background: none;
    color: var(--accent);
    border: none;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.stepper-btn svg {
    width: 2.5rem;
    height: 2.5rem;
}

.stepper-btn:hover:not(:disabled) {
    transform: scale(1.1);
}

.stepper-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.popup-checkbox {
    display: flex;
    justify-content: center;
    margin: 0.8rem 0;
    font-size: 0.95rem;
    color: var(--text);
}

.popup-checkbox label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.popup-checkbox input {
    accent-color: var(--accent);
    width: 1.3rem;
    height: 1.3rem;
    cursor: pointer;
}

.popup-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.popup-actions .button {
    font-weight: 500;
    padding: 0.6rem 1.4rem;
    transition: color 0.3s ease;
}

.button--primary {
    background-color: var(--accent);
    color: var(--bg);
    border: 1.5px solid var(--accent);
}

.button--primary:hover {
    background-color: #5c7b58;
    box-shadow: none;
}

.button--secondary {
    background-color: transparent;
    color: var(--text);
    border: 1.5px solid var(--text);
}

.button--secondary:hover {
    background-color: rgba(0, 0, 0, 0.05);
    box-shadow: none;
}

.chapter-update {
    padding: 0.5rem;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: center;
    font-style: italic;
    background: var(--bg);
    position: fixed;
    top: 0;
    width: 100%;
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.6s ease, opacity 0.6s ease;
    z-index: 50;
}

.chapter-update.show {
    transform: translateY(0);
    opacity: 1;
}

/* ====================================
   Card Layouts (Cards)
==================================== */
.cards,
.major-characters {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    border: 1px solid var(--border);
    text-align: left;
    padding: 1.2rem;
    border-radius: 8px;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.05);
    opacity: 0;
    transform: translateY(1.5rem);
    transition: opacity 1s ease, transform 0.3s ease, box-shadow 0.3s ease;
}

.card h3 {
    margin-bottom: 0.5rem;
}

.card strong {
    display: inline-block;
    min-width: 12ch;
}

.card.animate {
    opacity: 1;
    transform: translateY(0);
}

.card:hover {
    transform: translateY(-6px);
    box-shadow: 4px 6px 18px rgba(0, 0, 0, 0.1);
}

.card-underline {
    margin-bottom: 0.7rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

.card-description {
    font-size: 1rem;
    line-height: 1.5;
    text-align: justify;
}

/* ====================================
   Footer
==================================== */

footer {
    padding: 2rem;
    text-align: center;
    font-size: 0.9rem;
    color: #6b5c47;
    border-top: 1px solid var(--border);
    margin-top: 3rem;
}