
:root {
    --lavender: #e9d7f7;
    --pink: #ffe7ef;
    --cream: #fff9f0;
    --purple: #59436d;
    --purple-dark: #30243a;
    --muted: #786982;
    --heart: #ff6f91;
    --blue: #b9ddf4;
    --yellow: #fff0c8;
    --outline: 2px solid var(--purple);
    --shadow: 0 7px 0 rgba(89, 67, 109, 0.13),
              0 15px 30px rgba(48, 36, 58, 0.09);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 20px;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--purple-dark);
    font-family: "Nunito", sans-serif;
    background:
        radial-gradient(circle at 10% 10%, #fff 0, transparent 25%),
        radial-gradient(circle at 90% 35%, #ffe7ef 0, transparent 28%),
        linear-gradient(140deg, #e9d7f7, #f9e9f4 55%, #f8e4ed);
    overflow-x: hidden;
}

button,
input,
a {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 3px dashed var(--heart);
    outline-offset: 4px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

/* Header */

.topbar {
    width: min(1050px, calc(100% - 32px));
    min-height: 76px;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.back-button,
.music-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: var(--outline);
    border-radius: 13px 11px 14px 10px;
    background: var(--cream);
    color: var(--purple);
    padding: 9px 13px;
    box-shadow: 0 4px 0 rgba(89, 67, 109, 0.14);
    text-decoration: none;
    font-weight: 900;
    font-size: 0.9rem;
    transition: transform 0.2s ease;
}

.back-button:hover,
.music-button:hover {
    transform: translateY(-2px) rotate(-1deg);
}

.music-button {
    background: #fff0f5;
}

.topbar-title {
    font: 1.2rem "Patrick Hand", cursive;
    color: var(--purple);
}

/* Main scrapbook */

.scrapbook {
    width: min(850px, calc(100% - 28px));
    margin: 15px auto 70px;
}

.paper {
    position: relative;
    background: var(--cream);
    border: 3px solid var(--purple);
    border-radius: 26px 21px 29px 23px;
    box-shadow: var(--shadow);
}

.cover {
    text-align: center;
    padding: clamp(28px, 6vw, 55px) clamp(18px, 6vw, 60px) 25px;
    overflow: hidden;
}

.cover::before,
.ending::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 1px dashed rgba(89, 67, 109, 0.3);
    border-radius: 18px;
    pointer-events: none;
}

.eyebrow {
    margin: 0 0 10px;
    color: #9776ac;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.15em;
}

.cover h1 {
    margin: 0;
    font-size: clamp(2.8rem, 9vw, 5.3rem);
    line-height: 1;
    letter-spacing: -0.05em;
    overflow-wrap: anywhere;
}

.cover-description {
    max-width: 430px;
    margin: 15px auto 0;
    color: var(--muted);
    line-height: 1.7;
}

.cover-character {
    display: block;
    width: min(320px, 85%);
    height: clamp(180px, 35vw, 270px);
    object-fit: contain;
    margin: 12px auto 0;
    animation: floaty 5s ease-in-out infinite;
}

.handwritten {
    margin: 0 0 22px;
    color: var(--purple);
    font: 1.25rem "Patrick Hand", cursive;
    transform: rotate(-2deg);
}

.start-button,
.secret-button {
    position: relative;
    z-index: 1;
    border: 2px solid var(--purple);
    border-radius: 13px 11px 15px 10px;
    background: #ffd4e1;
    color: var(--purple-dark);
    padding: 12px 19px;
    font-weight: 900;
    box-shadow: 0 5px 0 rgba(89, 67, 109, 0.16);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.start-button:hover,
.secret-button:hover {
    transform: translateY(-3px) rotate(-1deg);
    box-shadow: 0 8px 0 rgba(89, 67, 109, 0.13);
}

.start-button span {
    margin-left: 6px;
}

.cover-footer {
    margin-top: 25px;
    color: #9a879f;
    font: 1rem "Patrick Hand", cursive;
}

.sticker {
    position: absolute;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 43px;
    height: 43px;
    border: var(--outline);
    border-radius: 50%;
    box-shadow: 2px 3px 0 rgba(89, 67, 109, 0.13);
}

.sticker-one {
    top: 24px;
    right: 25px;
    background: #ffd3e0;
    color: var(--heart);
    font-size: 1.5rem;
    transform: rotate(12deg);
}

.sticker-two {
    bottom: 90px;
    left: 25px;
    background: var(--blue);
    transform: rotate(-10deg);
}

/* Reading progress */

.reading-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 32px auto;
    max-width: 590px;
    padding: 0 8px;
    color: var(--purple);
}

#progressText {
    font: 1.05rem "Patrick Hand", cursive;
    white-space: nowrap;
}

.progress-track {
    height: 10px;
    flex: 1;
    overflow: hidden;
    border: 1.5px solid var(--purple);
    border-radius: 99px;
    background: rgba(255, 249, 240, 0.8);
}

#progressFill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: repeating-linear-gradient(
        135deg,
        #ff8eac 0 8px,
        #ffc1d2 8px 16px
    );
    transition: width 0.3s ease;
}

.progress-heart {
    color: var(--heart);
}

/* Comic pages */

.comic-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 38px;
}

.loading-message {
    color: var(--purple);
    font: 1.25rem "Patrick Hand", cursive;
}

.comic-page {
    --tilt: -0.8deg;
    width: min(660px, 100%);
    position: relative;
    padding: 15px 15px 18px;
    background: var(--cream);
    border: 2.5px solid var(--purple);
    border-radius: 10px 17px 11px 14px;
    box-shadow: 6px 7px 0 rgba(89, 67, 109, 0.14),
                0 14px 28px rgba(48, 36, 58, 0.07);
    transform: rotate(var(--tilt));
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    animation: panel-appear 0.55s ease both;
}

.comic-page:nth-child(even) {
    --tilt: 0.9deg;
}

.comic-page:nth-child(3n) {
    --tilt: -0.4deg;
}

.comic-page:hover {
    transform: rotate(0) translateY(-3px);
    box-shadow: 8px 10px 0 rgba(89, 67, 109, 0.12);
}

.page-heading {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin: 0 2px 12px;
}

.page-label {
    color: #957ba6;
    font: 1.1rem "Patrick Hand", cursive;
}

.page-number {
    border: 1.5px solid var(--purple);
    border-radius: 6px 9px 5px 8px;
    background: #e4f2fb;
    padding: 4px 9px;
    font: 0.95rem "Patrick Hand", cursive;
    transform: rotate(2deg);
}

.comic-image-frame {
    position: relative;
    padding: 9px 9px 12px;
    border: 1.5px solid #e0d4e2;
    background: white;
    box-shadow: 0 3px 7px rgba(48, 36, 58, 0.08);
}

.comic-image {
    display: block;
    width: 100%;
    height: auto;
    max-height: 760px;
    object-fit: contain;
    background: #f8edf8;
}

.image-caption {
    margin: 10px 3px 0;
    text-align: center;
    color: #6e5b78;
    font: 1.2rem "Patrick Hand", cursive;
}

.page-tape {
    position: absolute;
    z-index: 2;
    top: -10px;
    left: calc(50% - 45px);
    width: 90px;
    height: 22px;
    background: rgba(255, 205, 222, 0.78);
    border-left: 1px dashed rgba(89, 67, 109, 0.2);
    border-right: 1px dashed rgba(89, 67, 109, 0.2);
    transform: rotate(-3deg);
}

.page-reaction {
    display: flex;
    justify-content: center;
    margin-top: 13px;
}

.heart-button {
    border: 1.5px dashed #d47c9a;
    border-radius: 99px;
    padding: 7px 13px;
    background: #fff2f6;
    color: #c95178;
    font-weight: 800;
    font-size: 0.88rem;
}

.heart-button:hover {
    background: #ffe0ea;
}

.page-separator {
    color: var(--heart);
    text-align: center;
    letter-spacing: 0.4rem;
    font-size: 1.4rem;
    margin-top: -23px;
}

.loading-message,
.error-message {
    text-align: center;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

/* Ending */

.ending {
    margin: 60px auto 0;
    max-width: 660px;
    padding: 35px 25px 25px;
    text-align: center;
    overflow: hidden;
}

.ending-decoration {
    display: block;
    margin-bottom: 12px;
    color: var(--heart);
    letter-spacing: 0.6rem;
}

.ending h2 {
    margin: 6px 0 12px;
    color: var(--purple-dark);
    font-size: clamp(1.9rem, 5vw, 2.8rem);
    line-height: 1.1;
}

.ending > p:not(.eyebrow) {
    max-width: 440px;
    margin: 0 auto 22px;
    color: var(--muted);
    line-height: 1.7;
}

.secret-button {
    display: block;
    margin: 0 auto 13px;
}

.read-again-button {
    border: 0;
    padding: 9px 12px;
    background: transparent;
    color: var(--purple);
    text-decoration: underline;
    font-weight: 800;
}

.ending-character {
    display: block;
    width: min(230px, 75%);
    max-height: 200px;
    object-fit: contain;
    margin: 12px auto 0;
    animation: floaty 5s ease-in-out infinite;
}

/* Password popup */

.secret-dialog {
    position: fixed;
    width: min(430px, calc(100% - 28px));
    max-width: none;
    max-height: min(85vh, 700px);
    overflow-y: auto;
    border: 3px solid var(--purple);
    border-radius: 23px;
    padding: 35px 27px 27px;
    background: var(--cream);
    color: var(--purple-dark);
    text-align: center;
    box-shadow: 0 20px 80px rgba(48, 36, 58, 0.28);
}

.secret-dialog[open] {
    animation: popup-appear 0.25s ease both;
}

.secret-dialog::backdrop {
    background: rgba(48, 36, 58, 0.48);
    backdrop-filter: blur(4px);
}

.close-dialog {
    position: absolute;
    top: 8px;
    right: 12px;
    border: 0;
    background: transparent;
    color: var(--purple);
    font-size: 1.8rem;
}

.envelope-icon {
    font-size: 2.7rem;
    margin-bottom: 8px;
}

.secret-dialog h2 {
    margin: 0 0 12px;
    font-size: 1.9rem;
}

.secret-dialog p {
    line-height: 1.65;
    color: var(--muted);
}

#passwordForm {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 11px;
    margin-top: 22px;
}

#passwordForm label {
    text-align: left;
    font-size: 0.9rem;
    font-weight: 800;
}

#secretPasswordInput {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #c6b3d2;
    border-radius: 11px;
    background: white;
    color: var(--purple-dark);
}

#passwordForm .start-button {
    width: 100%;
}

.password-error {
    min-height: 0;
    margin: 0;
    color: #c53f63 !important;
    font-size: 0.9rem;
}

.password-error:empty {
    display: none;
}

.secret-hearts {
    margin: 16px 0;
    color: var(--heart);
    font-size: 1.6rem;
}

/* Toast and heart effects */

.toast {
    position: fixed;
    z-index: 20;
    left: 50%;
    bottom: 22px;
    max-width: calc(100% - 30px);
    padding: 11px 17px;
    border-radius: 99px;
    background: var(--purple-dark);
    color: white;
    box-shadow: 0 5px 18px rgba(48, 36, 58, 0.2);
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 18px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.floating-effects {
    position: fixed;
    inset: 0;
    z-index: 30;
    overflow: hidden;
    pointer-events: none;
}

.floating-heart {
    position: absolute;
    bottom: 12%;
    font-size: var(--size, 22px);
    color: var(--heart);
    animation: heart-rise 1.5s ease-out forwards;
}

/* Animations */

@keyframes floaty {
    0%, 100% { transform: translateY(0) rotate(-1deg); }
    50% { transform: translateY(-9px) rotate(1deg); }
}

@keyframes panel-appear {
    from { opacity: 0; translate: 0 14px; }
    to { opacity: 1; translate: 0 0; }
}

@keyframes popup-appear {
    from { opacity: 0; transform: scale(0.94) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes heart-rise {
    0% { opacity: 0; transform: translateY(0) scale(0.4) rotate(0); }
    15% { opacity: 1; }
    100% {
        opacity: 0;
        transform: translate(var(--drift, 20px), -75vh) scale(1.3) rotate(35deg);
    }
}

[hidden] {
    display: none !important;
}

/* Mobile */

@media (max-width: 600px) {
    .topbar {
        width: calc(100% - 20px);
        min-height: 65px;
    }

    .topbar-title {
        display: none;
    }

    .back-button,
    .music-button {
        padding: 8px 10px;
        font-size: 0.83rem;
    }

    .scrapbook {
        width: calc(100% - 20px);
        margin-top: 5px;
    }

    .cover {
        padding: 32px 18px 22px;
    }

    .sticker-one {
        top: 12px;
        right: 9px;
    }

    .sticker-two {
        left: 8px;
        bottom: 78px;
    }

    .cover-character {
        height: 210px;
    }

    .reading-progress {
        gap: 8px;
        margin: 25px auto 29px;
    }

    #progressText {
        font-size: 0.95rem;
    }

    .comic-container {
        gap: 32px;
    }

    .comic-page {
        padding: 11px 10px 15px;
        box-shadow: 4px 5px 0 rgba(89, 67, 109, 0.13);
    }

    .comic-image-frame {
        padding: 6px 6px 9px;
    }

    .ending {
        margin-top: 45px;
        padding: 30px 17px 22px;
    }
}

/* Accessibility: don't animate for users who request reduced motion. */

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