:root {
    /* Color Palette - Earthy, Muted */
    /* Color Palette - Winter/Pink Theme */
    --bg-color: #ffd1dc;
    /* Pastel Pink */
    /* Off-white/Paper */
    --text-color: #5d4037;
    /* Warm Brown for contrast */
    /* Soft Gray */
    --text-light: #7a7a7a;
    /* Muted text */
    --accent-color: #7e9aa8;
    /* Muted Blue */
    --highlight-color: #c4a4a4;
    /* Desaturated Rose/Mauve */
    --input-bg: #ffffff;
    --border-color: #e0dcd5;

    /* Typography */
    --font-serif: 'Playfair Display', serif;
    --font-sans: 'Lato', sans-serif;

    /* Spacing */
    --spacing-sm: 1rem;
    --spacing-md: 2rem;
    --spacing-lg: 4rem;

    /* UI */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 24px;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;

    /* Subtle Grain Texture */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.05'/%3E%3C/svg%3E");
}

h1,
h2,
h3 {
    font-family: var(--font-serif);
    font-weight: 400;
    color: var(--text-color);
    margin-bottom: var(--spacing-sm);
}

h1 {
    font-size: 2.5rem;
    line-height: 1.2;
}

h2 {
    font-size: 1.8rem;
}

p {
    font-size: 1.05rem;
    margin-bottom: var(--spacing-sm);
    color: var(--text-color);
}

.hint-text {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-top: 0.5rem;
    font-style: italic;
}

.error-text {
    color: #bfa1a1;
    font-size: 0.9rem;
    margin-top: 1rem;
    animation: fadeIn 0.3s ease;
}

/* Utilities */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.centered {
    text-align: center;
}

/* Sections */
.app-container {
    max-width: 800px;
    margin: 0 auto;
    min-height: 100vh;
    padding: var(--spacing-md);
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* Centers content vertically by default */
}

section {
    width: 100%;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
    display: none;
    /* JS will toggle display flex/block */
}

section.active-section {
    opacity: 1;
    transform: translateY(0);
    display: flex;
    /* Or block depending on layout */
    flex-direction: column;
    align-items: center;
}

/* Login Section */
#login-section {
    min-height: 60vh;
    justify-content: center;
    width: 100%;
    /* Ensure full width availability */
}

/* Ensure the wrapper is centered content-wise */
.content-wrapper.centered {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.login-form {
    margin-top: var(--spacing-md);
    width: 100%;
    max-width: 320px;
    margin-left: auto;
    /* Force center */
    margin-right: auto;
    /* Force center */
    text-align: center;
}

.input-group {
    margin-bottom: 1rem;
    width: 100%;
    /* Consistently use full width of form container */
}

input {
    width: 100%;
    padding: 12px 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--text-color);
    transition: border-color 0.3s ease;
    text-align: center;
}

input:focus {
    outline: none;
    border-bottom-color: var(--highlight-color);
}

/* Buttons */
.primary-btn,
.secondary-btn {
    margin-top: var(--spacing-md);
    padding: 12px 32px;
    background: transparent;
    border: 1px solid var(--text-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: var(--radius-sm);
}

.primary-btn:hover {
    background: var(--text-color);
    color: var(--bg-color);
}

.secondary-btn {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.secondary-btn:hover {
    background: var(--accent-color);
    color: white;
    /* Clean white for contrast on hover */
}

/* Chapters Section */
#chapters-section {
    display: none;
    /* Overridden by active-section */
    padding-top: var(--spacing-lg);
    padding-bottom: var(--spacing-lg);
}

#chapters-section.active-section {
    display: block;
    /* Chapters is a block flow */
}

.chapter {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-md);
    align-items: center;
    margin-bottom: var(--spacing-lg);
}

.chapter.reverse-layout {
    direction: rtl;
}

.chapter.reverse-layout .chapter-content {
    direction: ltr;
    /* Reset text direction */
}

.chapter-content {
    padding: var(--spacing-sm);
}

.chapter-content p {
    font-weight: 400;
}

.chapter-image {
    width: 100%;
    aspect-ratio: 4/5;
    background-color: #eee;
    border-radius: var(--radius-lg);
    /* Soft rounded corners */
    overflow: hidden;
    position: relative;
    /* specific positioning context */
}

.chapter-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.img-placeholder {
    width: 100%;
    height: 100%;
    opacity: 0.3;
    /* Muted placeholder colors */
}

.soft-divider {
    border: 0;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--border-color), transparent);
    margin: var(--spacing-lg) 0;
    width: 60%;
    margin-left: auto;
    margin-right: auto;
}

.next-action-container {
    text-align: center;
    margin-top: var(--spacing-lg);
}

/* Puzzle Section */
#puzzle-section.active-section {
    display: flex;
    justify-content: center;
    min-height: 70vh;
}

.puzzle-form {
    margin-top: var(--spacing-md);
    width: 100%;
    max-width: 400px;
    text-align: left;
}

.puzzle-item {
    margin-bottom: var(--spacing-md);
}

.puzzle-item label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--text-light);
    text-align: center;
}

.puzzle-input {
    text-align: center;
}

/* Letter Section */
#letter-section.active-section {
    display: block;
    max-width: 600px;
    margin: 0 auto;
    padding-top: var(--spacing-lg);
}

.letter-container {
    background: #fff;
    padding: var(--spacing-lg);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
    /* Extremely subtle shadow */
    border-radius: 2px;
}

.letter-header {
    text-align: center;
    margin-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: var(--spacing-md);
}

.letter-body {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    line-height: 1.8;
}

.signature {
    text-align: right;
    font-style: italic;
    margin-top: var(--spacing-md);
}

.music-player-container {
    text-align: center;
    margin-top: var(--spacing-lg);
}

.music-btn {
    text-decoration: none;
    color: var(--text-light);
    font-size: 0.8rem;
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 20px;
    transition: all 0.2s;
}

.music-btn:hover {
    color: var(--text-color);
    border-color: var(--text-color);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .chapter {
        grid-template-columns: 1fr;
        gap: var(--spacing-sm);
        text-align: center;
    }

    .chapter.reverse-layout {
        direction: ltr;
    }

    .chapter-image {
        order: -1;
        /* Image always on top on mobile */
        max-width: 80%;
        margin: 0 auto;
    }

    h1 {
        font-size: 2rem;
    }
}

/* content readability for long text */
.chapter-content,
.letter-body {
    max-width: 65ch;
    /* Optimal line length */
    margin-left: auto;
    margin-right: auto;
}

/* Music Control */
#music-control {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
}

#stop-music-btn {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--text-color);
    padding: 10px 15px;
    font-size: 0.8rem;
    cursor: pointer;
    font-family: var(--font-sans);
    border-radius: var(--radius-sm);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

#stop-music-btn:hover {
    background: var(--highlight-color);
    color: white;
    border-color: var(--highlight-color);
}

/* Sad Emoji Animation */
#sad-emoji-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through */
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sad-emoji {
    font-size: 10rem;
    animation: jumpIn 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes jumpIn {
    0% {
        opacity: 0;
        transform: scale(0) translateY(100px);
    }

    60% {
        opacity: 1;
        transform: scale(1.1) translateY(-20px);
    }

    100% {
        transform: scale(1) translateY(0);
    }
}

/* Snow Effect */
#snow-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
    display: none;
    /* Hidden by default */
    opacity: 0;
    transition: opacity 1s ease;
}

.snowflake {
    position: absolute;
    top: -10px;
    color: white;
    font-size: 1.5rem;
    user-select: none;
    z-index: 10000;
    opacity: 0.8;
    animation-name: fall;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

@keyframes fall {
    0% {
        transform: translateY(-10vh) translateX(0);
    }

    100% {
        transform: translateY(110vh) translateX(20px);
    }
}