/* ===========================================================
   undo.cafe — coastal-blend, evolved-minimal, modular-blocks
   Palette:
     #F6F2EC bleached linen (page bg)
     #2D505C deep tidal teal (primary text)
     #3A3A3A soft charcoal (secondary text)
     #8FB8C4 washed coastal blue (accent 1)
     #D4A574 weathered terracotta (accent 2)
     #A0967E driftwood tan (accent 3)
     #FDFAF5 warm parchment (module bg)
     #C8DDE5 sea foam (bubble highlight)
     #1A3A44 midnight tide (deep accent)
   =========================================================== */

:root {
    --bg: #F6F2EC;
    --primary: #2D505C;
    --secondary: #3A3A3A;
    --accent-1: #8FB8C4;
    --accent-2: #D4A574;
    --accent-3: #A0967E;
    --module-bg: #FDFAF5;
    --foam: #C8DDE5;
    --deep: #1A3A44;

    --gutter: clamp(24px, 4vw, 56px);
    --radius: 16px;
    --shadow: 0 2px 20px rgba(45, 80, 92, 0.06);
    --shadow-lift: 0 8px 36px rgba(45, 80, 92, 0.12);

    --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
    --font-body: "Libre Baskerville", Georgia, serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

    --ease-elastic: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-soft: cubic-bezier(0.4, 0.0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--secondary);
    font-family: var(--font-body);
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    position: relative;
    min-height: 100vh;
    background-image:
        repeating-conic-gradient(
            from 0deg at 50% 50%,
            rgba(160, 150, 126, 0.04) 0deg 1deg,
            transparent 1deg 3deg
        ),
        radial-gradient(circle at 18% 22%, rgba(200, 221, 229, 0.25), transparent 45%),
        radial-gradient(circle at 84% 78%, rgba(212, 165, 116, 0.10), transparent 50%);
    background-attachment: fixed;
}

/* ============================== Layers ============================== */

.ambient-bubbles,
.cursor-bubbles {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.cursor-bubbles { z-index: 5; }

.ambient-bubble {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%,
        rgba(200, 221, 229, 0.30),
        rgba(143, 184, 196, 0.15) 70%,
        rgba(143, 184, 196, 0.05));
    border: 1px solid rgba(143, 184, 196, 0.22);
    will-change: transform, opacity;
    box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.25);
}

.cursor-bubble {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%,
        rgba(200, 221, 229, 0.45),
        rgba(143, 184, 196, 0.18) 70%);
    border: 1px solid rgba(143, 184, 196, 0.28);
    pointer-events: none;
    will-change: transform, opacity;
}

/* ============================== Rewind Button ============================== */

.rewind-button {
    position: fixed;
    top: clamp(18px, 2.5vw, 28px);
    left: clamp(18px, 2.5vw, 28px);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(45, 80, 92, 0.18);
    background: var(--module-bg);
    box-shadow: var(--shadow);
    cursor: pointer;
    display: grid;
    place-items: center;
    z-index: 50;
    transition: transform 0.4s var(--ease-soft), box-shadow 0.4s var(--ease-soft), background 0.4s var(--ease-soft);
}

.rewind-button:hover {
    background: var(--foam);
    box-shadow: var(--shadow-lift);
}

.rewind-button:hover svg {
    animation: rewindSpin 2s linear infinite;
}

.rewind-button svg {
    transition: transform 0.4s var(--ease-soft);
}

@keyframes rewindSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(-360deg); }
}

.rewind-button.rewinding svg {
    animation: rewindSpin 0.8s linear 2;
}

/* ============================== Page / Layout ============================== */

.page {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: clamp(48px, 8vw, 96px);
    padding: clamp(60px, 10vh, 120px) clamp(24px, 5vw, 80px) clamp(80px, 12vw, 140px);
    max-width: 100%;
}

/* ============================== Modules (shared) ============================== */

.module {
    position: relative;
    background: var(--module-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: clamp(28px, 3.5vw, 48px);
    overflow: hidden;
    transform: scale(0.85) rotate(-2deg);
    opacity: 0;
    transition:
        transform 0.8s var(--ease-elastic),
        opacity 0.8s var(--ease-soft),
        box-shadow 0.6s var(--ease-soft);
    background-image:
        repeating-conic-gradient(
            from 0deg at 50% 50%,
            rgba(160, 150, 126, 0.05) 0deg 1deg,
            transparent 1deg 3deg
        );
    background-blend-mode: multiply;
}

.module.is-revealed {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

.module.is-rewinding {
    transform: scale(0.85) rotate(-2deg);
    opacity: 0;
    transition:
        transform 0.6s var(--ease-elastic),
        opacity 0.6s var(--ease-soft);
}

.module:hover {
    box-shadow: var(--shadow-lift);
}

/* Eyebrows / labels */
.eyebrow {
    display: inline-block;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-1);
    margin-bottom: 0.85em;
}

.eyebrow-bottom {
    margin-bottom: 0;
    margin-top: 1.2em;
}

/* Headings */
.module-title,
.interlude-title {
    font-family: var(--font-display);
    font-weight: 500;
    color: var(--primary);
    letter-spacing: -0.02em;
    line-height: 1.18;
    font-size: clamp(1.4rem, 2.4vw, 2rem);
    margin: 0 0 0.7em 0;
}

/* Mono helper */
.mono {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-3);
    letter-spacing: 0.01em;
}

/* ============================== Hero Story Block ============================== */

.module-hero {
    align-self: center;
    width: min(1200px, 90vw);
    min-height: clamp(380px, 60vh, 620px);
    padding: clamp(36px, 5vw, 64px);
    background:
        radial-gradient(ellipse at 30% 30%, rgba(200, 221, 229, 0.35), transparent 60%),
        var(--module-bg);
    margin-top: clamp(20px, 3vw, 40px);
}

.hero-inner {
    display: grid;
    grid-template-columns: 1fr 1.1fr;
    gap: clamp(24px, 4vw, 56px);
    align-items: center;
    height: 100%;
}

@media (max-width: 760px) {
    .hero-inner {
        grid-template-columns: 1fr;
    }
}

.hero-lottie {
    width: 100%;
    aspect-ratio: 16 / 10;
    display: grid;
    place-items: center;
}

.lottie-coffee {
    max-width: 100%;
    height: auto;
}

/* Reverse-tipping coffee animation: tip forward then reverse */
.cup-group {
    transform-origin: 160px 160px;
    animation: cupReverseTip 6s var(--ease-soft) infinite;
}

@keyframes cupReverseTip {
    0%, 18% { transform: rotate(0deg); }
    32%, 48% { transform: rotate(-22deg); }
    62%, 78% { transform: rotate(0deg); }
    92%, 100% { transform: rotate(0deg); }
}

.drop {
    transform-origin: center;
    animation: dropReverse 6s var(--ease-soft) infinite;
}

.drop1 { animation-delay: 0s; }
.drop2 { animation-delay: 0.1s; }
.drop3 { animation-delay: 0.2s; }

@keyframes dropReverse {
    0%, 32% { opacity: 0; transform: translate(0, 0) scale(0.6); }
    48% { opacity: 1; transform: translate(0, 0) scale(1); }
    64% { opacity: 1; transform: translate(40px, -50px) scale(0.8); }
    78% { opacity: 0; transform: translate(60px, -56px) scale(0.4); }
    100% { opacity: 0; transform: translate(0, 0) scale(0.6); }
}

.steam {
    stroke-dasharray: 60;
    animation: steamDraw 6s var(--ease-soft) infinite;
}

.steam2 { animation-delay: 0.3s; }

@keyframes steamDraw {
    0% { stroke-dashoffset: 60; opacity: 0; }
    20% { stroke-dashoffset: 0; opacity: 0.7; }
    50% { stroke-dashoffset: 0; opacity: 0.7; }
    80% { stroke-dashoffset: -60; opacity: 0; }
    100% { stroke-dashoffset: -60; opacity: 0; }
}

.hero-text {
    display: flex;
    flex-direction: column;
    gap: 0.6em;
}

.hero-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(2.4rem, 6vw, 4.4rem);
    letter-spacing: -0.035em;
    line-height: 1;
    color: var(--primary);
    margin: 0;
    display: inline-flex;
    flex-wrap: wrap;
}

.hero-title .letter {
    display: inline-block;
    filter: blur(8px);
    opacity: 0.3;
    transform: translateY(4px);
    transition:
        filter 0.45s var(--ease-soft),
        opacity 0.45s var(--ease-soft),
        transform 0.6s var(--ease-elastic);
}

.hero-title .letter.is-clear {
    filter: blur(0px);
    opacity: 1;
    transform: translateY(0);
}

.hero-tagline {
    font-family: var(--font-body);
    font-style: italic;
    font-size: clamp(1.1rem, 1.6vw, 1.35rem);
    color: var(--secondary);
    opacity: 0;
    transition: opacity 1s var(--ease-soft) 1.2s;
    margin: 0;
}

.hero-tagline.is-visible {
    opacity: 1;
}

.hero-meta {
    margin-top: 1em;
    margin-bottom: 0;
    opacity: 0;
    transition: opacity 1s var(--ease-soft) 1.7s;
}

.hero-meta.is-visible {
    opacity: 1;
}

/* ============================== Module Grid ============================== */

.grid-section {
    align-self: center;
    width: min(1200px, 90vw);
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--gutter);
    align-items: stretch;
}

.module-wide {
    grid-column: 1 / -1;
}

@media (min-width: 900px) {
    .module-wide {
        grid-column: span 3;
    }
    .module-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================== Text Module ============================== */

.module-text { display: flex; flex-direction: column; }

.text-columns {
    column-count: 1;
    column-gap: clamp(20px, 3vw, 40px);
    color: var(--secondary);
}

.text-columns p { margin: 0 0 1em 0; break-inside: avoid; }
.text-columns p:last-child { margin-bottom: 0; }

@media (min-width: 720px) {
    .text-columns-2 { column-count: 2; }
}

.text-columns em {
    color: var(--primary);
    font-style: italic;
}

/* Menu list */
.menu-list, .undo-log {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.7em;
}

.menu-list li,
.undo-log li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1em;
    padding-bottom: 0.5em;
    border-bottom: 1px dashed rgba(143, 184, 196, 0.4);
}

.menu-list li:last-child,
.undo-log li:last-child {
    border-bottom: none;
}

.menu-name {
    color: var(--primary);
    font-family: var(--font-display);
    font-weight: 500;
    letter-spacing: -0.01em;
}

.undo-log li {
    color: var(--secondary);
    font-size: 0.95rem;
}

/* ============================== Bubble Module ============================== */

.module-bubble {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    background:
        radial-gradient(circle at 50% 45%, rgba(200, 221, 229, 0.35), transparent 65%),
        var(--module-bg);
}

.module-bubble .bubble {
    flex: 1;
    margin: auto;
    width: clamp(140px, 60%, 200px);
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 32%,
        rgba(200, 221, 229, 0.55),
        rgba(143, 184, 196, 0.25) 60%,
        rgba(143, 184, 196, 0.15));
    border: 1px solid rgba(143, 184, 196, 0.35);
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow:
        inset -10px -14px 26px rgba(143, 184, 196, 0.15),
        inset 10px 12px 24px rgba(255, 255, 255, 0.5),
        0 6px 18px rgba(45, 80, 92, 0.05);
    transition:
        transform 0.5s var(--ease-elastic),
        box-shadow 0.5s var(--ease-soft);
    animation: bubbleWobble 4s ease-in-out infinite;
    will-change: transform;
}

.bubble-primary {
    background: radial-gradient(circle at 35% 32%,
        rgba(200, 221, 229, 0.7),
        rgba(143, 184, 196, 0.32) 60%,
        rgba(45, 80, 92, 0.15));
    border-color: rgba(45, 80, 92, 0.3);
}

@keyframes bubbleWobble {
    0%, 100% { transform: scale(1) translateY(0); }
    50% { transform: scale(1.03) translateY(-3px); }
}

.module-bubble .bubble:hover {
    transform: scale(1.08);
    box-shadow:
        inset -12px -18px 32px rgba(143, 184, 196, 0.22),
        inset 12px 14px 28px rgba(255, 255, 255, 0.6),
        0 12px 30px rgba(45, 80, 92, 0.12);
    animation-play-state: paused;
}

.module-bubble .bubble:hover .bubble-word {
    color: var(--primary);
}

.bubble-word {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(1.1rem, 1.8vw, 1.5rem);
    letter-spacing: -0.01em;
    color: var(--accent-1);
    transition: color 0.4s var(--ease-soft);
    user-select: none;
}

.bubble.popping {
    animation: bubblePop 0.32s var(--ease-soft) forwards;
}

@keyframes bubblePop {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

.bubble.reforming {
    animation: bubbleReform 0.6s var(--ease-elastic) forwards;
}

@keyframes bubbleReform {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.1); opacity: 0.9; }
    100% { transform: scale(1); opacity: 1; }
}

.micro-bubble {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(200, 221, 229, 0.7), rgba(143, 184, 196, 0.3));
    border: 1px solid rgba(143, 184, 196, 0.3);
    pointer-events: none;
    will-change: transform, opacity;
}

/* ============================== Image Module ============================== */

.module-image {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.6em;
    background:
        radial-gradient(circle at 70% 30%, rgba(212, 165, 116, 0.10), transparent 60%),
        var(--module-bg);
}

.illustration {
    width: 70%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
}

.illustration .hand-hour,
.illustration .hand-minute {
    transform-origin: 100px 100px;
    animation: counterClock 12s linear infinite;
}

.illustration .hand-minute {
    animation-duration: 4s;
}

@keyframes counterClock {
    from { transform: rotate(0deg); }
    to { transform: rotate(-360deg); }
}

.caption {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--accent-3);
    margin: 0;
    text-align: center;
}

/* ============================== Interlude Story Block ============================== */

.module-interlude {
    align-self: center;
    width: min(1200px, 90vw);
    background:
        radial-gradient(circle at 50% 50%, rgba(200, 221, 229, 0.5) 0%, var(--module-bg) 50%, var(--bg) 90%);
    padding: clamp(40px, 6vw, 80px);
}

.interlude-inner {
    display: grid;
    grid-template-columns: 1.1fr 1fr;
    gap: clamp(24px, 4vw, 56px);
    align-items: center;
}

@media (max-width: 760px) {
    .interlude-inner {
        grid-template-columns: 1fr;
    }
}

.uncrumple-lottie {
    width: 100%;
    aspect-ratio: 16 / 12;
    display: grid;
    place-items: center;
}

.paper-shape {
    transform-origin: 160px 130px;
    animation: paperUncrumple 8s ease-in-out infinite;
}

@keyframes paperUncrumple {
    0%, 12% {
        transform: scale(0.4) rotate(-12deg);
        d: path("M70 60 L130 70 L160 50 L210 80 L240 60 L250 110 L220 150 L180 140 L120 180 L70 160 L90 110 Z");
    }
    50%, 70% {
        transform: scale(1) rotate(0deg);
    }
    100% {
        transform: scale(0.4) rotate(-12deg);
    }
}

.handwritten path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    animation: handwriteReveal 8s ease-in-out infinite;
}

.handwritten path:nth-child(1) { animation-delay: 0s; }
.handwritten path:nth-child(2) { animation-delay: 0.2s; }
.handwritten path:nth-child(3) { animation-delay: 0.4s; }
.handwritten path:nth-child(4) { animation-delay: 0.6s; }

@keyframes handwriteReveal {
    0%, 30% { stroke-dashoffset: 200; opacity: 0; }
    50%, 70% { stroke-dashoffset: 0; opacity: 0.7; }
    90%, 100% { stroke-dashoffset: 200; opacity: 0; }
}

.interlude-text { display: flex; flex-direction: column; }

/* ============================== Closing ============================== */

.closing {
    align-self: center;
    width: min(900px, 90vw);
    text-align: center;
    padding: clamp(48px, 8vw, 96px) clamp(24px, 5vw, 64px);
    background: var(--module-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transform: scale(0.85) rotate(-2deg);
    opacity: 0;
    transition: transform 0.8s var(--ease-elastic), opacity 0.8s var(--ease-soft);
}

.closing.is-revealed {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

.closing-line {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: clamp(1.4rem, 2.5vw, 2rem);
    color: var(--accent-3);
    margin: 0 0 1.2em 0;
    letter-spacing: -0.015em;
    line-height: 1.3;
}

.closing-meta {
    display: block;
    color: var(--accent-3);
}

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

.footer {
    align-self: center;
    text-align: center;
    padding-top: clamp(24px, 4vw, 48px);
    color: var(--accent-3);
    opacity: 0.7;
}

/* ============================== Reduced Motion ============================== */

@media (prefers-reduced-motion: reduce) {
    .module,
    .closing {
        transform: scale(1) rotate(0deg) !important;
        opacity: 1 !important;
        transition: none !important;
    }
    .module-bubble .bubble,
    .cup-group,
    .drop,
    .steam,
    .paper-shape,
    .handwritten path,
    .illustration .hand-hour,
    .illustration .hand-minute {
        animation: none !important;
    }
    .hero-title .letter {
        filter: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    .hero-tagline,
    .hero-meta {
        opacity: 1 !important;
    }
}
