/* ============================================
   bada.coffee - Cottagecore Coffee Almanac
   ============================================ */

/* --- Color Palette --- */
:root {
    --espresso-ink: #2C1810;
    --deep-loam: #3A2A1A;
    --cream-linen: #F5EDE0;
    --morning-parchment: #EDE0CE;
    --copper-bloom: #B87333;
    --terracotta-annotation: #A0522D;
    --plantation-sage: #7A8B6F;
    --coffee-leaf: #4A5D3E;
    --dried-cherry: #C4654A;
    --linen-shadow: #D4C5B2;
    --sidebar-dark: #3D2B1F;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: 'Source Serif 4', Georgia, serif;
    font-weight: 400;
    color: var(--deep-loam);
    background-color: var(--cream-linen);
    line-height: 1.75;
    overflow-x: hidden;
}

/* --- SIDEBAR --- */
#sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: clamp(180px, 16vw, 260px);
    background-color: var(--sidebar-dark);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 2rem 0;
    position: relative;
}

.sidebar-brand {
    padding: 0 1.2rem;
    margin-bottom: 2.5rem;
    text-align: center;
}

.sidebar-brand-text {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(0.9rem, 1.2vw, 1.1rem);
    color: var(--cream-linen);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.85;
}

.sidebar-nav {
    list-style: none;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0 0.5rem;
}

.sidebar-tab {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.8rem;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.3s ease, border-left 0.3s ease;
    border-left: 3px solid transparent;
    position: relative;
}

.sidebar-tab:hover {
    background-color: rgba(245, 237, 224, 0.08);
}

.sidebar-tab.active {
    border-left-color: var(--coffee-leaf);
    background-color: rgba(245, 237, 224, 0.06);
    box-shadow: -3px 0 12px rgba(74, 93, 62, 0.3);
}

.tab-icon {
    width: 28px;
    height: 28px;
    color: var(--cream-linen);
    opacity: 0.7;
    flex-shrink: 0;
}

.sidebar-tab.active .tab-icon {
    opacity: 1;
    color: var(--copper-bloom);
}

.tab-label {
    font-family: 'Source Serif 4', serif;
    font-weight: 600;
    font-size: 0.7rem;
    color: var(--cream-linen);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0.6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-tab.active .tab-label {
    opacity: 0.9;
}

/* Floating tab icon animation */
.sidebar-tab .tab-icon {
    animation: floatTab 3s ease-in-out infinite;
}

.sidebar-tab:nth-child(1) .tab-icon { animation-delay: 0s; }
.sidebar-tab:nth-child(2) .tab-icon { animation-delay: 0.5s; }
.sidebar-tab:nth-child(3) .tab-icon { animation-delay: 1s; }
.sidebar-tab:nth-child(4) .tab-icon { animation-delay: 1.5s; }
.sidebar-tab:nth-child(5) .tab-icon { animation-delay: 2s; }
.sidebar-tab:nth-child(6) .tab-icon { animation-delay: 2.5s; }

@keyframes floatTab {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.sidebar-tab:hover .tab-icon {
    animation-play-state: paused;
}

/* Tooltip on hover */
.sidebar-tab .tab-label {
    transition: opacity 0.3s ease, transform 0.3s ease;
    transform: translateX(0);
}

.sidebar-tab:hover .tab-label {
    opacity: 1;
    transform: translateX(2px);
}

/* Sidebar botanical decoration */
.sidebar-botanical {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
    opacity: 0.5;
}

.sidebar-vine {
    width: 40px;
    height: auto;
}

/* --- READING PANE --- */
#reading-pane {
    margin-left: clamp(180px, 16vw, 260px);
    width: calc(100% - clamp(180px, 16vw, 260px));
    min-height: 100vh;
}

/* --- CHAPTERS --- */
.chapter {
    position: relative;
    overflow: hidden;
}

.chapter-light {
    background-color: var(--cream-linen);
}

.chapter-dark {
    background-color: var(--espresso-ink);
    color: var(--cream-linen);
}

.chapter-dark .body-text {
    color: var(--cream-linen);
    opacity: 0.92;
}

.chapter-dark .chapter-title {
    color: var(--cream-linen);
}

/* --- CHAPTER HEADERS --- */
.chapter-header {
    min-height: 60vh;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4rem clamp(2rem, 5vw, 6rem);
    position: relative;
}

.chapter-title {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(1.8rem, 4vw, 3.2rem);
    color: var(--espresso-ink);
    letter-spacing: 0.04em;
    line-height: 1.2;
}

.chapter-illustration {
    position: relative;
    flex-shrink: 0;
    width: 40%;
    max-width: 400px;
}

/* --- CHAPTER 1: THE ORIGIN --- */
#chapter-origin {
    min-height: 100vh;
    display: flex;
    align-items: center;
    position: relative;
}

.origin-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 4rem clamp(2rem, 5vw, 6rem);
    min-height: 100vh;
}

.origin-text {
    flex: 1;
    max-width: 55%;
    padding-right: 3rem;
}

.domain-title {
    font-family: 'Playfair Display', serif;
    font-weight: 900;
    font-size: clamp(3rem, 7vw, 6rem);
    color: var(--espresso-ink);
    letter-spacing: 0.04em;
    line-height: 1.05;
    margin-bottom: 1.5rem;
}

.domain-title .letter-group {
    display: inline-block;
    opacity: 0;
    transform: translateY(40px);
}

.domain-title.revealed .letter-group {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.origin-declaration {
    font-family: 'Source Serif 4', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 1.5vw, 1.35rem);
    color: var(--deep-loam);
    line-height: 1.8;
    max-width: 50ch;
}

.origin-illustration {
    width: 40%;
    max-width: 400px;
    flex-shrink: 0;
}

.botanical-arabica {
    width: 100%;
    height: auto;
}

/* --- STEAM WISPS --- */
.floating-steam {
    position: absolute;
    pointer-events: none;
    z-index: 5;
}

.steam-1 {
    right: 25%;
    bottom: 20%;
    animation: steamRise 8s ease-in-out infinite;
}

.steam-2 {
    right: 35%;
    bottom: 15%;
    animation: steamRise 8s ease-in-out infinite 2s;
}

.steam-3 {
    right: 18%;
    bottom: 25%;
    animation: steamRise 8s ease-in-out infinite 4s;
}

@keyframes steamRise {
    0% {
        transform: translateY(0) translateX(0);
        opacity: 0.4;
    }
    50% {
        transform: translateY(-20px) translateX(5px);
        opacity: 0.6;
    }
    100% {
        transform: translateY(0) translateX(-5px);
        opacity: 0.4;
    }
}

/* Ritual steam - more prominent */
.ritual-steam {
    opacity: 0.6;
}

.steam-r1 { right: 15%; bottom: 30%; animation: steamRise 7s ease-in-out infinite 0s; }
.steam-r2 { right: 25%; bottom: 25%; animation: steamRise 9s ease-in-out infinite 1s; }
.steam-r3 { right: 35%; bottom: 35%; animation: steamRise 8s ease-in-out infinite 2s; }
.steam-r4 { right: 45%; bottom: 20%; animation: steamRise 7.5s ease-in-out infinite 3s; }
.steam-r5 { right: 55%; bottom: 30%; animation: steamRise 8.5s ease-in-out infinite 1.5s; }
.steam-r6 { right: 65%; bottom: 25%; animation: steamRise 9.5s ease-in-out infinite 4s; }

/* --- BOTANICAL FRIEZE DIVIDERS --- */
.botanical-frieze {
    padding: 0.5rem 0;
    overflow: hidden;
    background-color: var(--cream-linen);
}

.botanical-frieze-dark {
    background-color: var(--espresso-ink);
}

/* --- READING COLUMN --- */
.reading-column {
    max-width: 68ch;
    margin: 0 auto;
    padding: 3rem clamp(2rem, 5vw, 6rem) 4rem;
    position: relative;
}

.body-text {
    font-family: 'Source Serif 4', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.15vw, 1.15rem);
    color: var(--deep-loam);
    line-height: 1.75;
    margin-bottom: 1.5em;
}

/* --- HANDWRITTEN ANNOTATIONS --- */
.annotation-margin {
    position: relative;
    margin: 1.5rem 0;
    padding-left: 1rem;
}

.annotation-right {
    text-align: right;
    padding-left: 0;
    padding-right: 1rem;
}

.handwritten-note {
    font-family: 'Caveat', cursive;
    font-weight: 400;
    font-size: clamp(1.1rem, 1.5vw, 1.4rem);
    color: var(--terracotta-annotation);
    display: inline-block;
    line-height: 1.4;
}

/* --- ORIGIN STAMPS --- */
.origin-stamp {
    position: absolute;
    pointer-events: none;
    z-index: 3;
}

.stamp-1 {
    right: clamp(2rem, 8vw, 8rem);
    top: 35%;
    animation: floatStamp 5s ease-in-out infinite;
    transform: rotate(4deg);
}

.stamp-2 {
    right: clamp(1rem, 5vw, 5rem);
    top: 65%;
    animation: floatStamp 6s ease-in-out infinite 1.5s;
    transform: rotate(-3deg);
}

@keyframes floatStamp {
    0%, 100% { transform: translateY(0) rotate(var(--stamp-rotation, 4deg)); }
    50% { transform: translateY(-6px) rotate(var(--stamp-rotation, 4deg)); }
}

/* --- PHOTO FRAGMENTS --- */
.photo-fragment {
    width: 100%;
    max-width: 350px;
    height: 280px;
    position: relative;
    overflow: hidden;
}

.fragment-inner {
    width: 100%;
    height: 100%;
    clip-path: polygon(2% 0%, 98% 2%, 100% 97%, 3% 100%);
    overflow: hidden;
}

.texture-fill {
    width: 100%;
    height: 100%;
    filter: sepia(20%) contrast(1.05) brightness(0.98);
}

.terroir-texture {
    background: linear-gradient(
        135deg,
        var(--morning-parchment) 0%,
        var(--linen-shadow) 25%,
        var(--plantation-sage) 50%,
        var(--linen-shadow) 75%,
        var(--morning-parchment) 100%
    );
    background-size: 200% 200%;
    animation: textureShift 12s ease-in-out infinite;
}

.roast-texture {
    background: linear-gradient(
        135deg,
        var(--espresso-ink) 0%,
        #4a3528 25%,
        var(--sidebar-dark) 50%,
        #5a3f2e 75%,
        var(--espresso-ink) 100%
    );
    background-size: 200% 200%;
    animation: textureShift 15s ease-in-out infinite;
}

@keyframes textureShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.fragment-terroir,
.fragment-roast {
    box-shadow: 4px 4px 16px rgba(212, 197, 178, 0.5);
    transform: rotate(1.5deg);
}

.fragment-roast {
    transform: rotate(-2deg);
}

/* Roaster illustration overlay */
.roaster-illustration {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* --- CHAPTER 3: THE ROAST (Dark) --- */
#chapter-roast {
    background: linear-gradient(to bottom, var(--cream-linen) 0%, var(--espresso-ink) 8%);
}

#chapter-roast .chapter-header {
    padding-top: 8rem;
}

/* Falling cherry silhouettes */
.floating-cherry {
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--dried-cherry);
    opacity: 0.15;
    pointer-events: none;
    z-index: 2;
}

.cherry-fall-1 {
    left: 20%;
    top: 30%;
    width: 16px;
    height: 16px;
    animation: cherryFall 5s ease-in-out infinite;
}

.cherry-fall-2 {
    left: 50%;
    top: 25%;
    width: 20px;
    height: 20px;
    animation: cherryFall 6s ease-in-out infinite 1s;
}

.cherry-fall-3 {
    left: 70%;
    top: 40%;
    width: 14px;
    height: 14px;
    animation: cherryFall 5.5s ease-in-out infinite 2s;
}

.cherry-fall-4 {
    left: 35%;
    top: 55%;
    width: 18px;
    height: 18px;
    animation: cherryFall 7s ease-in-out infinite 3s;
}

@keyframes cherryFall {
    0%, 100% { transform: translateY(0); opacity: 0.15; }
    50% { transform: translateY(20px); opacity: 0.25; }
}

/* --- CHAPTER 4: THE BREW --- */
.brew-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin: 2.5rem 0;
}

.brew-card {
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    padding: 2rem 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: var(--morning-parchment);
    box-shadow: 2px 3px 12px rgba(212, 197, 178, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.brew-card:hover {
    transform: translateY(-4px);
    box-shadow: 3px 5px 18px rgba(212, 197, 178, 0.6);
}

.brew-card-texture {
    position: absolute;
    inset: 0;
    opacity: 0.06;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 2px,
        var(--linen-shadow) 2px,
        var(--linen-shadow) 4px
    );
    pointer-events: none;
}

.brew-card-svg {
    margin-bottom: 1rem;
    width: 80px;
    height: 100px;
}

.brew-card-label {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    color: var(--deep-loam);
    display: block;
}

/* --- PULL QUOTE --- */
.pull-quote {
    margin: 3rem 0;
    padding: 1.5rem 0 1.5rem 1.5rem;
    border-left: 3px solid var(--copper-bloom);
}

.pull-quote p {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-style: italic;
    font-size: clamp(1.2rem, 2.5vw, 1.8rem);
    color: var(--espresso-ink);
    line-height: 1.5;
    letter-spacing: 0.01em;
}

/* --- FLOATING LEAVES --- */
.floating-leaf {
    position: absolute;
    width: 24px;
    height: 24px;
    pointer-events: none;
    z-index: 2;
    background: var(--plantation-sage);
    opacity: 0.15;
    clip-path: ellipse(50% 30% at 50% 50%);
}

.leaf-1 {
    left: 15%;
    top: 40%;
    width: 26px;
    height: 26px;
    animation: leafDrift 20s linear infinite;
}

.leaf-2 {
    right: 20%;
    top: 55%;
    width: 20px;
    height: 20px;
    animation: leafDrift 20s linear infinite 6s;
    transform: rotate(45deg);
}

.leaf-3 {
    left: 60%;
    top: 30%;
    width: 22px;
    height: 22px;
    animation: leafDrift 20s linear infinite 12s;
}

@keyframes leafDrift {
    0% { transform: rotate(0deg) translateY(0); opacity: 0.15; }
    25% { transform: rotate(90deg) translateY(-6px); opacity: 0.2; }
    50% { transform: rotate(180deg) translateY(0); opacity: 0.15; }
    75% { transform: rotate(270deg) translateY(6px); opacity: 0.2; }
    100% { transform: rotate(360deg) translateY(0); opacity: 0.15; }
}

/* --- DUST MOTES --- */
.dust-mote {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, var(--copper-bloom) 0%, transparent 70%);
    opacity: 0.12;
    pointer-events: none;
    z-index: 1;
}

.mote-1 { width: 4px; height: 4px; left: 30%; top: 25%; animation: moteDrift 6s ease-in-out infinite; }
.mote-2 { width: 5px; height: 5px; left: 55%; top: 45%; animation: moteDrift 7s ease-in-out infinite 1s; }
.mote-3 { width: 3px; height: 3px; left: 75%; top: 35%; animation: moteDrift 5s ease-in-out infinite 2s; }
.mote-4 { width: 6px; height: 6px; left: 20%; top: 60%; animation: moteDrift 8s ease-in-out infinite 3s; }
.mote-5 { width: 4px; height: 4px; left: 80%; top: 55%; animation: moteDrift 6.5s ease-in-out infinite 1.5s; }

@keyframes moteDrift {
    0%, 100% { transform: translateY(0) translateX(0); }
    33% { transform: translateY(-8px) translateX(3px); }
    66% { transform: translateY(4px) translateX(-5px); }
}

/* --- CHAPTER 5: THE CUP --- */
.cup-centered {
    text-align: center;
}

.cup-centered .body-text {
    text-align: left;
}

.tasting-wheel-container {
    display: flex;
    justify-content: center;
    margin: 3rem 0;
    position: relative;
}

.tasting-wheel {
    max-width: 420px;
    width: 100%;
    height: auto;
    transform: scale(0.85);
    transition: transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.tasting-wheel-container.revealed .tasting-wheel {
    transform: scale(1);
}

/* Wheel annotations */
.wheel-annotation {
    position: relative;
    margin: 0.5rem 0;
}

.annotation-1 { text-align: left; }
.annotation-2 { text-align: right; }
.annotation-3 { text-align: center; }

/* --- CHAPTER 6: THE RITUAL (Dark) --- */
.chapter-ritual-section {
    min-height: 80vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background-color: var(--espresso-ink);
}

.ritual-column {
    text-align: center;
}

.ritual-text {
    font-size: 1.15rem;
    color: var(--cream-linen);
    opacity: 0.92;
    text-align: center;
    max-width: 60ch;
    margin-left: auto;
    margin-right: auto;
}

/* --- SLIDE REVEAL ANIMATION --- */
.slide-reveal {
    opacity: 0;
    transition: opacity 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 0.6s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.slide-reveal[data-direction="left"] {
    transform: translateX(-50px);
}

.slide-reveal[data-direction="right"] {
    transform: translateX(50px);
}

.slide-reveal[data-direction="up"] {
    transform: translateY(40px);
}

.slide-reveal.revealed {
    opacity: 1;
    transform: translate(0, 0);
}

/* Floating element generic */
.floating-element {
    animation: floatGeneric 5s ease-in-out infinite;
}

@keyframes floatGeneric {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

/* --- RESPONSIVE --- */
@media (max-width: 900px) {
    #sidebar {
        width: 60px;
    }

    .sidebar-brand-text {
        font-size: 0;
        visibility: hidden;
    }

    .sidebar-brand {
        margin-bottom: 1rem;
    }

    .tab-label {
        display: none;
    }

    .sidebar-tab {
        justify-content: center;
        padding: 0.7rem 0.4rem;
    }

    #reading-pane {
        margin-left: 60px;
        width: calc(100% - 60px);
    }

    .origin-layout {
        flex-direction: column;
        padding: 3rem 1.5rem;
    }

    .origin-text {
        max-width: 100%;
        padding-right: 0;
        margin-bottom: 2rem;
    }

    .origin-illustration {
        width: 70%;
        max-width: 300px;
    }

    .chapter-header {
        flex-direction: column;
        min-height: 40vh;
        padding: 3rem 1.5rem;
        gap: 2rem;
    }

    .chapter-illustration {
        width: 80%;
        max-width: 300px;
    }

    .brew-cards {
        grid-template-columns: 1fr;
        max-width: 280px;
        margin-left: auto;
        margin-right: auto;
    }

    .reading-column {
        padding: 2rem 1.5rem 3rem;
    }

    .origin-stamp {
        display: none;
    }

    .sidebar-botanical {
        display: none;
    }
}

@media (max-width: 600px) {
    #sidebar {
        width: 50px;
    }

    #reading-pane {
        margin-left: 50px;
        width: calc(100% - 50px);
    }

    .domain-title {
        font-size: clamp(2rem, 10vw, 3.5rem);
    }

    .chapter-title {
        font-size: clamp(1.5rem, 6vw, 2.2rem);
    }

    .tasting-wheel {
        max-width: 280px;
    }
}

/* --- SCROLLBAR STYLING --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--cream-linen);
}

::-webkit-scrollbar-thumb {
    background: var(--linen-shadow);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--copper-bloom);
}

/* --- SELECTION --- */
::selection {
    background: var(--copper-bloom);
    color: var(--cream-linen);
}
