/* ============================================
   chrono.games — Cottagecore Horology Studio
   ============================================ */

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

:root {
    --sage: #6B8F71;
    --deep-moss: #3D5A40;
    --warm-linen: #F5F0E8;
    --parchment: #D4C9B0;
    --dried-rose: #C4726C;
    --bark: #3B2F25;
    --driftwood: #7B6B5A;
    --honeycomb: #E8B44D;
    --ease-clock: cubic-bezier(0.25, 0.1, 0.25, 1);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Lora', serif;
    color: var(--bark);
    background-color: var(--parchment);
}

/* --- Grain Overlay --- */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
    mix-blend-mode: multiply;
    opacity: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
    animation: grainFadeIn 200ms ease forwards;
}

@keyframes grainFadeIn {
    to { opacity: 0.04; }
}

/* --- Particle Canvas --- */
#particle-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

/* --- Navigation Strip --- */
#nav-strip {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 24px;
    background: var(--warm-linen);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-bottom: 1px solid var(--parchment);
}

.nav-label {
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.18em;
    color: var(--driftwood);
    cursor: pointer;
    transition: color 300ms var(--ease-clock);
    user-select: none;
}

.nav-label:hover,
.nav-label.active {
    color: var(--deep-moss);
}

.nav-separator {
    color: var(--parchment);
    font-size: 0.6rem;
    user-select: none;
}

#gear-butterfly {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.7;
}

#gear-butterfly svg {
    display: block;
}

.butterfly-left-wing,
.butterfly-right-wing {
    transform-origin: 20px 15px;
    animation: none;
}

.butterfly-flap .butterfly-left-wing {
    animation: flapLeft 400ms ease-in-out;
}

.butterfly-flap .butterfly-right-wing {
    animation: flapRight 400ms ease-in-out;
}

@keyframes flapLeft {
    0%, 100% { transform: rotateY(0deg); }
    25% { transform: rotateY(60deg); }
    50% { transform: rotateY(0deg); }
    75% { transform: rotateY(40deg); }
}

@keyframes flapRight {
    0%, 100% { transform: rotateY(0deg); }
    25% { transform: rotateY(-60deg); }
    50% { transform: rotateY(0deg); }
    75% { transform: rotateY(-40deg); }
}

/* --- Bento Grid --- */
#bento-grid {
    position: fixed;
    top: 24px;
    left: 0;
    width: 100%;
    height: calc(100% - 24px);
    padding: 6px;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 6px;
    background: var(--parchment);
}

/* Cell assignments */
#cell-hero {
    grid-column: 1 / 6;
    grid-row: 1 / 3;
}

#cell-tagline {
    grid-column: 6 / 13;
    grid-row: 1 / 2;
}

#cell-season {
    grid-column: 6 / 10;
    grid-row: 2 / 3;
}

#cell-quote {
    grid-column: 10 / 13;
    grid-row: 2 / 3;
}

#cell-project {
    grid-column: 1 / 4;
    grid-row: 3 / 5;
}

#cell-timeline {
    grid-column: 4 / 7;
    grid-row: 3 / 5;
}

#cell-clock {
    grid-column: 7 / 10;
    grid-row: 3 / 5;
}

#cell-fieldnotes {
    grid-column: 10 / 13;
    grid-row: 3 / 5;
}

/* --- Bento Cell Base --- */
.bento-cell {
    background: var(--warm-linen);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(87, 62, 40, 0.12);
    opacity: 0;
    animation: cellFadeIn 400ms var(--ease-clock) forwards;
}

.bento-cell:nth-child(1) { animation-delay: 300ms; }
.bento-cell:nth-child(2) { animation-delay: 450ms; }
.bento-cell:nth-child(3) { animation-delay: 600ms; }
.bento-cell:nth-child(4) { animation-delay: 750ms; }
.bento-cell:nth-child(5) { animation-delay: 900ms; }
.bento-cell:nth-child(6) { animation-delay: 1050ms; }
.bento-cell:nth-child(7) { animation-delay: 1200ms; }
.bento-cell:nth-child(8) { animation-delay: 1350ms; }

@keyframes cellFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cell-content {
    padding: 16px;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 2;
}

/* --- Cell Labels --- */
.cell-label {
    font-family: 'Space Mono', monospace;
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: 0.18em;
    color: var(--driftwood);
    margin-bottom: 10px;
    display: block;
}

/* --- Hero Cell --- */
#cell-hero {
    background: var(--warm-linen);
}

#cell-hero .cell-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

#clockwork-meadow {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

#meadow-clock {
    width: 120px;
    height: 120px;
    opacity: 0.6;
}

.meadow-flowers {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    padding: 0 20px;
}

.flower {
    animation: flowerSway 4s ease-in-out infinite;
}

.flower-1 { animation-delay: 0s; }
.flower-2 { animation-delay: 0.5s; }
.flower-3 { animation-delay: 1s; }
.flower-4 { animation-delay: 1.5s; }
.flower-5 { animation-delay: 0.8s; }

@keyframes flowerSway {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(2deg); }
    75% { transform: rotate(-2deg); }
}

.flower-1, .flower-3, .flower-5 {
    animation-name: flowerGrow;
    animation-duration: 8s;
    animation-iteration-count: infinite;
}

@keyframes flowerGrow {
    0%, 100% { transform: scaleY(1) rotate(0deg); opacity: 0.9; }
    25% { transform: scaleY(1.05) rotate(1deg); opacity: 1; }
    50% { transform: scaleY(1) rotate(-1deg); opacity: 0.85; }
    75% { transform: scaleY(0.95) rotate(0deg); opacity: 0.9; }
}

#hero-typewriter {
    padding: 12px 0;
    min-height: 100px;
}

.typewriter-line {
    display: block;
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--deep-moss);
    line-height: 1.6;
    min-height: 1.6em;
    white-space: nowrap;
    overflow: hidden;
}

#typewriter-cursor {
    display: inline-block;
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    color: var(--dried-rose);
    animation: cursorBlink 800ms step-end infinite;
    font-size: clamp(0.85rem, 2vw, 1.1rem);
}

@keyframes cursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* --- Clock Watermark --- */
.clock-watermark {
    position: absolute;
    width: 200px;
    height: 200px;
    color: var(--parchment);
    opacity: 0.03;
    transform: rotate(7deg);
    z-index: 1;
    pointer-events: none;
    right: -20px;
    top: -20px;
}

.clock-watermark.cw-small {
    width: 150px;
    height: 150px;
    left: -30px;
    bottom: -20px;
    top: auto;
    right: auto;
    transform: rotate(-12deg);
}

/* --- Pressed Flower --- */
.pressed-flower {
    position: absolute;
    opacity: 0.15;
    z-index: 1;
    pointer-events: none;
}

.pf-top-right {
    top: 10px;
    right: 10px;
}

.pf-bottom-left {
    bottom: 10px;
    left: 10px;
}

/* --- Tagline Cell --- */
#cell-tagline .cell-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 24px 32px;
}

.tagline-heading {
    font-family: 'Space Mono', monospace;
    font-size: clamp(1.6rem, 3.5vw, 2.8rem);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--deep-moss);
    line-height: 1.2;
    margin-bottom: 16px;
}

.tagline-body {
    font-family: 'Lora', serif;
    font-size: clamp(0.95rem, 1.8vw, 1.1rem);
    font-weight: 400;
    line-height: 1.72;
    letter-spacing: 0.01em;
    color: var(--bark);
    max-width: 50ch;
}

/* --- Season Cell --- */
#cell-season {
    background: var(--warm-linen);
}

#season-display {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
}

#hourglass-container {
    flex-shrink: 0;
}

#hourglass-svg {
    display: block;
}

#falling-petal {
    animation: petalFall 3s ease-in infinite;
}

@keyframes petalFall {
    0% { cy: 38; opacity: 0.8; }
    50% { cy: 55; opacity: 0.6; }
    100% { cy: 78; opacity: 0; }
}

#season-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.season-name {
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--sage);
}

.season-time {
    font-family: 'Space Mono', monospace;
    font-size: 1.2rem;
    font-weight: 400;
    letter-spacing: 0.08em;
    color: var(--driftwood);
}

/* --- Quote Cell --- */
#cell-quote {
    background: var(--warm-linen);
}

#cell-quote .cell-content {
    justify-content: center;
}

#rotating-quote {
    flex: 1;
    display: flex;
    align-items: center;
}

#quote-text {
    font-family: 'Space Mono', monospace;
    font-size: clamp(0.8rem, 1.2vw, 0.95rem);
    font-weight: 400;
    line-height: 1.6;
    color: var(--driftwood);
    font-style: italic;
    transition: opacity 400ms var(--ease-clock);
}

/* --- Project Cell --- */
#cell-project {
    background: var(--warm-linen);
}

.project-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.project-thumbnail {
    border-radius: 2px;
    overflow: hidden;
    filter: grayscale(100%) sepia(30%) hue-rotate(70deg) saturate(60%);
    transition: filter 600ms var(--ease-clock), transform 600ms var(--ease-clock);
}

.project-thumbnail:hover {
    filter: none;
    transform: scale(1.02);
}

.project-title {
    font-family: 'Space Mono', monospace;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--deep-moss);
    text-transform: uppercase;
}

.project-desc {
    font-family: 'Lora', serif;
    font-size: 0.85rem;
    font-weight: 400;
    line-height: 1.6;
    color: var(--bark);
}

/* --- Timeline Cell --- */
#cell-timeline {
    background: var(--warm-linen);
}

#garden-timeline {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 4px 0;
    position: relative;
}

#garden-timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--parchment);
}

.timeline-node {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 2px 0;
    cursor: default;
    transition: transform 300ms var(--ease-clock);
}

.timeline-node:hover {
    transform: translateX(4px);
}

.timeline-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--parchment);
    border: 2px solid var(--sage);
    flex-shrink: 0;
    transition: background 300ms var(--ease-clock), border-color 300ms var(--ease-clock);
    position: relative;
    z-index: 1;
}

.timeline-dot.active {
    background: var(--dried-rose);
    border-color: var(--dried-rose);
}

.timeline-node:hover .timeline-dot {
    background: var(--sage);
}

.timeline-year {
    font-family: 'Space Mono', monospace;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--driftwood);
    min-width: 40px;
}

.timeline-event {
    font-family: 'Lora', serif;
    font-size: 0.78rem;
    color: var(--bark);
    line-height: 1.4;
}

/* --- Clock Canvas Cell --- */
#cell-clock {
    background: var(--warm-linen);
}

#cell-clock .cell-content {
    align-items: center;
    justify-content: center;
}

#clock-canvas {
    width: 100%;
    height: 100%;
    max-width: 250px;
    max-height: 250px;
}

/* --- Field Notes Cell --- */
#cell-fieldnotes {
    background: var(--warm-linen);
}

#field-notes-scroll {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--parchment) transparent;
}

#field-notes-scroll::-webkit-scrollbar {
    width: 4px;
}

#field-notes-scroll::-webkit-scrollbar-track {
    background: transparent;
}

#field-notes-scroll::-webkit-scrollbar-thumb {
    background: var(--parchment);
    border-radius: 2px;
}

.field-note {
    padding: 10px 0;
    border-bottom: 1px dashed var(--parchment);
}

.field-note:last-child {
    border-bottom: none;
}

.note-date {
    font-family: 'Space Mono', monospace;
    font-size: 0.65rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    color: var(--driftwood);
    display: block;
    margin-bottom: 4px;
}

.note-text {
    font-family: 'Lora', serif;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: 1.6;
    color: var(--bark);
}

/* --- Cross-stitch borders on select cells --- */
#cell-season::before,
#cell-quote::before,
#cell-fieldnotes::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 1px dashed var(--parchment);
    border-radius: 3px;
    pointer-events: none;
    z-index: 3;
    background-image:
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 6px,
            var(--parchment) 6px,
            var(--parchment) 7px
        );
    background-size: 7px 1px;
    background-position: top left, bottom left;
    background-repeat: repeat-x;
    opacity: 0.5;
}

/* --- Duotone filter for game thumbnails --- */
.duotone {
    filter: grayscale(100%) sepia(30%) hue-rotate(70deg) saturate(60%);
    transition: filter 600ms var(--ease-clock), transform 600ms var(--ease-clock);
}

.duotone:hover {
    filter: none;
    transform: scale(1.02);
}

/* --- Games grid (for template) --- */
.games-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    height: 100%;
    align-content: center;
}

.game-entry {
    text-align: center;
}

.game-entry h3 {
    font-family: 'Space Mono', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--deep-moss);
    text-transform: uppercase;
    margin-top: 8px;
}

.game-entry p {
    font-family: 'Lora', serif;
    font-size: 0.78rem;
    color: var(--driftwood);
    line-height: 1.5;
}

.game-thumb {
    border-radius: 3px;
    overflow: hidden;
}

/* --- Clockroom content --- */
.clockroom-content {
    display: flex;
    gap: 24px;
    height: 100%;
    align-items: center;
}

.clockroom-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clockroom-info {
    flex: 1;
}

.clockroom-info h2 {
    font-family: 'Space Mono', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    color: var(--deep-moss);
    margin-bottom: 16px;
}

.clockroom-info p {
    font-family: 'Lora', serif;
    font-size: 0.9rem;
    line-height: 1.72;
    color: var(--bark);
    margin-bottom: 12px;
}

/* --- Entrance animation for grid borders --- */
#bento-grid {
    animation: gridReveal 400ms var(--ease-clock) forwards;
    clip-path: inset(50% 50% 50% 50%);
}

@keyframes gridReveal {
    from {
        clip-path: inset(50% 50% 50% 50%);
    }
    to {
        clip-path: inset(0% 0% 0% 0%);
    }
}

/* --- Mobile Layout --- */
@media (max-width: 768px) {
    html, body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    #bento-grid {
        position: relative;
        top: 24px;
        height: auto;
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 6px;
    }

    .bento-cell {
        min-height: 250px;
    }

    #cell-hero {
        min-height: 400px;
    }

    #cell-clock {
        min-height: 300px;
    }

    .tagline-heading {
        font-size: clamp(1.2rem, 5vw, 1.8rem);
    }

    .nav-label {
        font-size: 0.6rem;
        letter-spacing: 0.1em;
    }

    #gear-butterfly {
        display: none;
    }

    .games-grid {
        grid-template-columns: 1fr;
    }

    .clockroom-content {
        flex-direction: column;
    }

    /* Mobile scroll reveal */
    .bento-cell {
        animation: none;
        opacity: 0;
        transform: translateY(20px);
        transition: opacity 500ms var(--ease-clock), transform 500ms var(--ease-clock);
    }

    .bento-cell.in-view {
        opacity: 1;
        transform: translateY(0);
    }
}
