/* ============================================
   prototype.rs — Muji Atelier Styling
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --rice-paper: #faf8f5;
    --fog-white: #f0ede8;
    --mist: #e8e4de;
    --warm-charcoal: #3d3d3d;
    --slate: #6b7b8d;
    --medium-gray: #5a5a5a;
    --dusty-iris: #8b9dc3;
    --blush-clay: #c4a08a;
    --sage-mist: #7a9e7e;
    --dusty-rose: #b88a8a;
    --slate-blue: #7889a0;
    --iris-haze: rgba(139, 157, 195, 0.25);
    --code-bg: #f5f2ee;
    --annotation-gray: #7a8a9a;
    --comment-gray: #b0b0b0;
    --code-base: #4a5568;

    --font-heading: 'Nunito', sans-serif;
    --font-body: 'Quicksand', sans-serif;
    --font-code: 'Fira Code', monospace;

    --gap: 20px;
    --radius-card: 12px;
    --radius-code: 8px;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--rice-paper);
    color: var(--medium-gray);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.72;
    overflow-x: hidden;
}

/* --- Background Bubbles --- */
.bg-bubble {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: -1;
}

.bg-bubble-1 {
    width: 180px;
    height: 180px;
    background: rgba(139, 157, 195, 0.06);
    top: 10%;
    left: 5%;
    animation: drift-1 60s ease-in-out infinite;
}

.bg-bubble-2 {
    width: 140px;
    height: 140px;
    background: rgba(196, 160, 138, 0.05);
    top: 30%;
    right: 8%;
    animation: drift-2 72s ease-in-out infinite;
}

.bg-bubble-3 {
    width: 200px;
    height: 200px;
    background: rgba(139, 157, 195, 0.04);
    top: 55%;
    left: 15%;
    animation: drift-3 80s ease-in-out infinite;
}

.bg-bubble-4 {
    width: 100px;
    height: 100px;
    background: rgba(196, 160, 138, 0.06);
    top: 70%;
    right: 20%;
    animation: drift-4 55s ease-in-out infinite;
}

.bg-bubble-5 {
    width: 160px;
    height: 160px;
    background: rgba(139, 157, 195, 0.05);
    top: 85%;
    left: 40%;
    animation: drift-5 68s ease-in-out infinite;
}

@keyframes drift-1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -40px) scale(1.05); }
    50% { transform: translate(-20px, -80px) scale(0.95); }
    75% { transform: translate(40px, -30px) scale(1.02); }
}

@keyframes drift-2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(-40px, 30px) scale(0.97); }
    50% { transform: translate(20px, 60px) scale(1.04); }
    75% { transform: translate(-30px, -20px) scale(0.98); }
}

@keyframes drift-3 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(50px, -20px) scale(1.03); }
    50% { transform: translate(-30px, 40px) scale(0.96); }
    75% { transform: translate(20px, 50px) scale(1.01); }
}

@keyframes drift-4 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(-25px, -35px) scale(1.06); }
    50% { transform: translate(40px, -10px) scale(0.94); }
    75% { transform: translate(-15px, 30px) scale(1.03); }
}

@keyframes drift-5 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(35px, 25px) scale(0.98); }
    50% { transform: translate(-45px, -30px) scale(1.05); }
    75% { transform: translate(25px, -45px) scale(0.97); }
}

/* --- Assembly Header --- */
.assembly-header {
    padding: 6rem 2rem 3rem;
    max-width: 1200px;
    margin: 0 auto;
}

/* Component Rail */
.component-rail-wrapper {
    position: relative;
    margin-bottom: 3rem;
}

.component-rail-wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to right, var(--rice-paper) 0%, transparent 8%, transparent 92%, var(--rice-paper) 100%);
    z-index: 2;
    pointer-events: none;
}

.component-rail {
    display: flex;
    gap: 16px;
    padding: 12px 24px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}

.component-rail::-webkit-scrollbar {
    display: none;
}

.component-rail {
    scrollbar-width: none;
}

.rail-item {
    flex: 0 0 auto;
    width: 64px;
    height: 78px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(232, 228, 222, 0.6);
    border-radius: var(--radius-card);
    scroll-snap-align: start;
    cursor: pointer;
    transition: box-shadow 300ms ease, transform 200ms ease;
    color: var(--dusty-iris);
}

.rail-item:hover {
    box-shadow: 0 0 20px rgba(180, 190, 200, 0.3);
    transform: translateY(-2px);
    color: var(--blush-clay);
}

.rail-item svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.rail-item span {
    font-family: var(--font-heading);
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--annotation-gray);
    text-align: center;
    line-height: 1.2;
}

/* Header Text */
.header-text {
    text-align: center;
}

.site-title {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: clamp(2rem, 4vw, 3.2rem);
    color: var(--warm-charcoal);
    letter-spacing: -0.01em;
    margin-bottom: 0.75rem;
}

.site-tagline {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.9rem, 1.4vw, 1.05rem);
    color: var(--slate);
    max-width: 560px;
    margin: 0 auto;
    line-height: 1.72;
}

/* --- Section Bubble Dividers --- */
.section-bubble-divider {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 2rem 0;
}

.divider-bubble {
    display: inline-block;
    border-radius: 50%;
    background: var(--dusty-iris);
}

.divider-bubble:nth-child(odd) {
    width: 8px;
    height: 8px;
    opacity: 0.08;
}

.divider-bubble:nth-child(even) {
    width: 12px;
    height: 12px;
    opacity: 0.12;
}

.divider-bubble:nth-child(3n) {
    width: 16px;
    height: 16px;
    opacity: 0.06;
    background: var(--blush-clay);
}

.divider-bubble:nth-child(5n) {
    width: 10px;
    height: 10px;
    opacity: 0.15;
}

/* --- Masonry Sections --- */
.masonry-section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* --- Masonry Grid --- */
.masonry-grid {
    display: grid;
    grid-template-columns: 1fr 1.2fr 0.8fr;
    gap: var(--gap);
    padding-bottom: 1rem;
}

/* --- Card Base --- */
.card {
    background: var(--fog-white);
    border-radius: var(--radius-card);
    border: 1px solid var(--mist);
    transition: filter 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                opacity 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
                transform 500ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.card.blurred {
    filter: blur(6px);
    opacity: 0.4;
    transform: translateY(12px);
}

.card.in-focus {
    filter: blur(0);
    opacity: 1;
    transform: translateY(0);
}

/* Stagger based on column position */
.card[data-col="0"] { transition-delay: 0ms; }
.card[data-col="1"] { transition-delay: 80ms; }
.card[data-col="2"] { transition-delay: 160ms; }

/* --- Icon-Label Card --- */
.card-icon-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(232, 228, 222, 0.6);
    cursor: pointer;
    position: relative;
    overflow: hidden;
    aspect-ratio: 1 / 1;
    max-height: 180px;
}

.card-icon-label:hover {
    box-shadow: 0 0 20px rgba(180, 190, 200, 0.3);
}

.card-icon-wrap {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dusty-iris);
    transition: color 300ms ease;
    margin-bottom: 0.75rem;
    position: relative;
}

.card-icon-label:hover .card-icon-wrap {
    color: var(--blush-clay);
}

.card-icon-wrap svg {
    width: 48px;
    height: 48px;
}

/* Ripple effect on hover */
.card-icon-label .ripple {
    position: absolute;
    border-radius: 50%;
    border: 1.5px solid var(--dusty-iris);
    pointer-events: none;
    animation: icon-ripple 600ms ease-out forwards;
}

@keyframes icon-ripple {
    0% {
        width: 24px;
        height: 24px;
        opacity: 0.3;
        margin-left: -12px;
        margin-top: -12px;
    }
    100% {
        width: 48px;
        height: 48px;
        opacity: 0;
        margin-left: -24px;
        margin-top: -24px;
    }
}

.card-icon-text {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--warm-charcoal);
    text-align: center;
}

/* --- Code Specimen Card --- */
.card-code {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.code-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: var(--mist);
    border-bottom: 1px solid rgba(232, 228, 222, 0.8);
}

.code-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(139, 157, 195, 0.3);
}

.code-dot:nth-child(2) {
    background: rgba(196, 160, 138, 0.3);
}

.code-dot:nth-child(3) {
    background: rgba(122, 158, 126, 0.3);
}

.code-title {
    font-family: var(--font-code);
    font-size: 0.7rem;
    color: var(--annotation-gray);
    margin-left: auto;
}

.code-block {
    padding: 16px;
    background: var(--code-bg);
    font-family: var(--font-code);
    font-size: clamp(0.78rem, 1.1vw, 0.92rem);
    font-feature-settings: "liga" 1, "calt" 1;
    line-height: 1.65;
    color: var(--code-base);
    overflow-x: auto;
    flex: 1;
    white-space: pre;
}

.code-block code {
    font-family: inherit;
}

.code-keyword { color: #7a9e7e; }
.code-type { color: #b88a8a; }
.code-string { color: #7889a0; }
.code-comment { color: #b0b0b0; font-style: italic; }
.code-function { color: #8b9dc3; }

.code-bubble-annotation {
    display: inline-flex;
    align-items: center;
    margin: 12px 16px 16px;
}

.code-bubble-annotation span {
    display: inline-block;
    background: var(--fog-white);
    border: 1px solid var(--mist);
    border-radius: 14px;
    padding: 4px 14px;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--annotation-gray);
    height: 28px;
    line-height: 20px;
}

/* --- Explanation Card --- */
.card-explanation {
    display: flex;
    gap: 16px;
    padding: 1.5rem;
    align-items: flex-start;
}

.card-explain-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    color: var(--dusty-iris);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-explain-icon svg {
    width: 24px;
    height: 24px;
}

.card-explain-body h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    color: var(--warm-charcoal);
    letter-spacing: -0.01em;
    margin-bottom: 0.5rem;
}

.card-explain-body p {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(0.9rem, 1.4vw, 1.05rem);
    line-height: 1.72;
    color: var(--medium-gray);
}

/* --- Diagram Card --- */
.card-diagram {
    grid-column: span 2;
    padding: 1.5rem;
}

.card-diagram h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: clamp(1.1rem, 2vw, 1.3rem);
    color: var(--warm-charcoal);
    margin-bottom: 1rem;
}

.diagram-container {
    overflow-x: auto;
}

.diagram-svg {
    width: 100%;
    max-width: 500px;
    height: auto;
}

/* --- Bubble Annotation Card --- */
.card-bubble {
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(232, 228, 222, 0.6);
    border-radius: 20px;
    padding: 1.25rem 1.5rem;
    position: relative;
}

.card-bubble .bubble-connector {
    position: absolute;
    top: -10px;
    left: 20px;
    width: 40px;
    height: 20px;
}

.card-bubble p {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--annotation-gray);
    line-height: 1.55;
}

/* --- Footer --- */
.site-footer {
    padding: 4rem 2rem 3rem;
    text-align: center;
}

.footer-bubbles {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 2rem;
}

.footer-text {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--annotation-gray);
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .masonry-grid {
        grid-template-columns: 1fr 1fr;
    }

    .card-diagram {
        grid-column: span 2;
    }

    .bg-bubble-4,
    .bg-bubble-5 {
        display: none;
    }

    .assembly-header {
        padding: 4rem 1.5rem 2rem;
    }
}

@media (max-width: 768px) {
    .masonry-grid {
        grid-template-columns: 1fr;
    }

    .card-diagram {
        grid-column: span 1;
    }

    .card-icon-label {
        aspect-ratio: unset;
        max-height: none;
        flex-direction: row;
        gap: 1rem;
        padding: 1.25rem 1.5rem;
    }

    .card-icon-wrap {
        margin-bottom: 0;
    }

    .card-icon-wrap svg {
        width: 32px;
        height: 32px;
    }

    .bg-bubble {
        display: none;
    }

    .card.blurred {
        filter: none;
        opacity: 0.4;
        transform: translateY(12px);
    }

    .card.in-focus {
        filter: none;
        opacity: 1;
        transform: translateY(0);
    }

    .assembly-header {
        padding: 3rem 1rem 1.5rem;
    }

    .masonry-section {
        padding: 0 1rem;
    }

    .component-rail-wrapper::before {
        background: linear-gradient(to right, var(--rice-paper) 0%, transparent 4%, transparent 96%, var(--rice-paper) 100%);
    }

    .code-block {
        font-size: 0.78rem;
    }
}
