/* ============================================
   mazzola.dev — Style System
   ============================================ */

/* ---------- Reset & Custom Properties ---------- */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Background layers */
    --bg:             #050506;
    --surface:        #0c0c0f;
    --card:           #101015;
    --card-hover:     #16161d;

    /* Borders */
    --border:         rgba(255, 255, 255, 0.06);
    --border-hover:   rgba(255, 255, 255, 0.12);
    --border-accent:  rgba(99, 102, 241, 0.3);

    /* Text */
    --text:           #ededef;
    --text-secondary: #8b8b9e;
    --text-muted:     #55556a;

    /* Accent */
    --accent:         #6366f1;
    --accent-light:   #818cf8;
    --accent-dim:     rgba(99, 102, 241, 0.08);
    --accent-glow:    rgba(99, 102, 241, 0.12);

    /* Layout */
    --nav-h:          64px;
    --container:      1120px;
    --radius-sm:      8px;
    --radius-md:      12px;
    --radius-lg:      20px;

    /* Typography */
    --font-sans:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono:      'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

    /* Transitions */
    --ease-out:       cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring:    cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration:       0.3s;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--nav-h) + 2rem);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-weight: 400;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background: rgba(99, 102, 241, 0.25);
    color: #fff;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    display: block;
    max-width: 100%;
}

button {
    border: none;
    background: none;
    cursor: pointer;
    color: inherit;
    font: inherit;
}

.container {
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 clamp(1.25rem, 4vw, 2.5rem);
}

/* ---------- Grain Overlay ---------- */

.grain {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    opacity: 0.028;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 180px 180px;
}

/* ---------- Navigation ---------- */

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 500;
    height: var(--nav-h);
    background: rgba(5, 5, 6, 0.7);
    backdrop-filter: blur(16px) saturate(1.5);
    -webkit-backdrop-filter: blur(16px) saturate(1.5);
    border-bottom: 1px solid var(--border);
    transition: background var(--duration);
}

.header.scrolled {
    background: rgba(5, 5, 6, 0.92);
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    transition: opacity var(--duration);
    z-index: 10;
}

.nav-brand:hover {
    opacity: 0.75;
}

.brand-icon {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--accent);
    background: var(--accent-dim);
    padding: 0.25rem 0.45rem;
    border-radius: 6px;
    border: 1px solid rgba(99, 102, 241, 0.15);
    line-height: 1;
}

.brand-tld {
    color: var(--text-muted);
    font-weight: 400;
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 2rem;
}

.nav-link {
    font-size: 0.82rem;
    font-weight: 450;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
    transition: color var(--duration);
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    position: relative;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: right;
    transition: transform 0.4s var(--ease-out);
}

.nav-link:hover {
    color: var(--text);
}

.nav-link:hover::after {
    transform: scaleX(1);
    transform-origin: left;
}

.external-icon {
    opacity: 0.4;
    transition: opacity var(--duration);
}

.nav-link:hover .external-icon {
    opacity: 0.8;
}

/* Mobile hamburger */
.nav-toggle {
    display: none;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.hamburger,
.hamburger::before,
.hamburger::after {
    display: block;
    width: 18px;
    height: 1.5px;
    background: var(--text);
    border-radius: 1px;
    transition: all 0.35s var(--ease-out);
}

.hamburger {
    position: relative;
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    left: 0;
}

.hamburger::before { top: -6px; }
.hamburger::after  { top: 6px; }

/* Hamburger → X state */
.nav-toggle[aria-expanded="true"] .hamburger {
    background: transparent;
}

.nav-toggle[aria-expanded="true"] .hamburger::before {
    top: 0;
    transform: rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .hamburger::after {
    top: 0;
    transform: rotate(-45deg);
}

/* ---------- Hero Section ---------- */

.hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: var(--nav-h);
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.hero-glow {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 700px;
    height: 700px;
    background: radial-gradient(
        circle,
        rgba(99, 102, 241, 0.08) 0%,
        rgba(99, 102, 241, 0.03) 35%,
        transparent 70%
    );
    filter: blur(40px);
    transition: transform 0.15s ease-out, opacity 0.3s;
    will-change: transform;
}

.hero-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 20%, transparent 70%);
    -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 20%, transparent 70%);
}

.hero-content {
    position: relative;
    text-align: center;
    padding: 4rem 0 6rem;
    z-index: 2;
}

/* Badge */
.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.04em;
    padding: 0.45rem 1rem 0.45rem 0.75rem;
    background: var(--accent-dim);
    border: 1px solid rgba(99, 102, 241, 0.12);
    border-radius: 100px;
    margin-bottom: 2.5rem;
}

.badge-pulse {
    width: 7px;
    height: 7px;
    background: var(--accent);
    border-radius: 50%;
    animation: pulse 2.5s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
    50%      { opacity: 0.6; box-shadow: 0 0 0 6px rgba(99, 102, 241, 0); }
}

/* Title */
.hero-title {
    font-size: clamp(3.5rem, 10vw, 9rem);
    font-weight: 800;
    line-height: 0.95;
    letter-spacing: -0.035em;
    margin-bottom: 1.75rem;
}

.title-line {
    display: block;
}

.accent {
    color: var(--accent);
}

/* Description */
.hero-description {
    font-size: clamp(1rem, 1.8vw, 1.2rem);
    line-height: 1.7;
    color: var(--text-secondary);
    max-width: 540px;
    margin: 0 auto 2.5rem;
    font-weight: 350;
}

.hide-mobile {
    display: inline;
}

/* Buttons */
.hero-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 4rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    font-size: 0.85rem;
    font-weight: 550;
    border-radius: var(--radius-sm);
    transition: all var(--duration) var(--ease-out);
    letter-spacing: 0.005em;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.5), 0 2px 12px rgba(99, 102, 241, 0.25);
}

.btn-primary:hover {
    background: var(--accent-light);
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.6), 0 4px 24px rgba(99, 102, 241, 0.3);
    transform: translateY(-1px);
}

.btn-ghost {
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: transparent;
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--border-hover);
    background: rgba(255, 255, 255, 0.03);
    transform: translateY(-1px);
}

/* Stats */
.hero-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.stat-divider {
    width: 1px;
    height: 32px;
    background: var(--border);
}

/* Scroll indicator */
.scroll-indicator {
    position: absolute;
    bottom: 2.5rem;
    left: 50%;
    transform: translateX(-50%);
}

.scroll-line {
    width: 1px;
    height: 48px;
    background: linear-gradient(to bottom, var(--accent), transparent);
    animation: scrollDown 2s ease-in-out infinite;
}

@keyframes scrollDown {
    0%   { opacity: 0; transform: translateY(-10px); }
    40%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(16px); }
}

/* ---------- Writing / Blog Section ---------- */

.writing {
    padding: 7rem 0 8rem;
    position: relative;
}

.writing::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* Section header */
.section-header {
    margin-bottom: 4rem;
}

.section-label {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.label-line {
    width: 40px;
    height: 1px;
    background: var(--accent);
}

.label-text {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--accent);
}

.section-title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 0.75rem;
}

.section-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    font-weight: 350;
}

/* Featured post */
.post-featured {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(1.5rem, 3vw, 2.5rem);
    margin-bottom: 2rem;
    transition: all 0.4s var(--ease-out);
    position: relative;
    overflow: hidden;
}

.post-featured::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(to bottom, var(--accent), transparent);
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.4s;
}

.post-featured:hover {
    border-color: var(--border-hover);
    background: var(--card-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--border-hover);
}

.post-featured:hover::before {
    opacity: 1;
}

.post-featured-inner {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 2rem;
}

.post-featured-content {
    flex: 1;
    min-width: 0;
}

.post-featured-number {
    font-size: clamp(4rem, 8vw, 7rem);
    font-weight: 900;
    line-height: 1;
    color: rgba(255, 255, 255, 0.02);
    letter-spacing: -0.04em;
    flex-shrink: 0;
    user-select: none;
    transition: color 0.4s;
}

.post-featured:hover .post-featured-number {
    color: rgba(99, 102, 241, 0.06);
}

.post-featured .post-title {
    font-size: clamp(1.3rem, 2.5vw, 1.75rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0.75rem 0;
    line-height: 1.3;
}

.post-featured .post-excerpt {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    max-width: 600px;
}

/* Post meta */
.post-meta {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 450;
}

.post-tag {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-light);
    background: var(--accent-dim);
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
}

.post-divider {
    color: var(--text-muted);
    opacity: 0.3;
}

/* Post footer */
.post-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.read-time {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
}

.post-arrow {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--accent-light);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    opacity: 0;
    transform: translateX(-8px);
    transition: all 0.35s var(--ease-out);
}

.post-featured:hover .post-arrow,
.post-card:hover .post-arrow {
    opacity: 1;
    transform: translateX(0);
}

/* Post grid */
.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.25rem;
}

/* Post card */
.post-card {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: clamp(1.25rem, 2.5vw, 1.75rem);
    transition: all 0.4s var(--ease-out);
    position: relative;
    overflow: hidden;
}

.card-glow {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 0.5s;
    background: radial-gradient(
        400px circle at var(--mouse-x, 50%) var(--mouse-y, 50%),
        var(--accent-glow),
        transparent 60%
    );
    z-index: 0;
}

.post-card:hover .card-glow {
    opacity: 1;
}

.post-card:hover {
    border-color: var(--border-hover);
    background: var(--card-hover);
    transform: translateY(-3px);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.35);
}

.post-card > * {
    position: relative;
    z-index: 1;
}

.post-card .post-title {
    font-size: 1.1rem;
    font-weight: 650;
    letter-spacing: -0.015em;
    margin: 0.75rem 0 0.6rem;
    line-height: 1.35;
    transition: color var(--duration);
}

.post-card:hover .post-title {
    color: #fff;
}

.post-card .post-excerpt {
    font-size: 0.88rem;
    line-height: 1.65;
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
    flex: 1;
}

.post-card .post-arrow {
    font-size: 1rem;
}

/* ---------- Footer ---------- */

.footer {
    border-top: 1px solid var(--border);
    padding: 2.5rem 0;
    margin-top: auto;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.footer-left {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.footer-brand {
    font-weight: 600;
    font-size: 0.85rem;
}

.footer-copy {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.footer-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.footer-link {
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: color var(--duration);
}

.footer-link:hover {
    color: var(--text);
}

/* ---------- Animations ---------- */

[data-animate] {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.7s var(--ease-out), transform 0.7s var(--ease-out);
}

[data-animate].visible {
    opacity: 1;
    transform: translateY(0);
}

[data-animate][data-delay="1"] { transition-delay: 0.1s; }
[data-animate][data-delay="2"] { transition-delay: 0.2s; }
[data-animate][data-delay="3"] { transition-delay: 0.35s; }
[data-animate][data-delay="4"] { transition-delay: 0.5s; }
[data-animate][data-delay="5"] { transition-delay: 0.7s; }

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    :root {
        --nav-h: 56px;
    }

    .nav-toggle {
        display: flex;
    }

    .nav-menu {
        position: fixed;
        inset: 0;
        background: rgba(5, 5, 6, 0.97);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2.5rem;
        opacity: 0;
        visibility: hidden;
        transition: all 0.4s var(--ease-out);
        z-index: 5;
    }

    .nav-menu.open {
        opacity: 1;
        visibility: visible;
    }

    .nav-menu .nav-link {
        font-size: 1.25rem;
        font-weight: 500;
    }

    .nav-menu .nav-link::after {
        display: none;
    }

    .hero-content {
        padding: 3rem 0 5rem;
    }

    .hero-title {
        font-size: clamp(3rem, 14vw, 5rem);
    }

    .hide-mobile {
        display: none;
    }

    .hero-actions {
        flex-direction: column;
        width: 100%;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .hero-stats {
        gap: 1.25rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .post-featured-number {
        display: none;
    }

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

    .footer-inner {
        flex-direction: column;
        gap: 1.25rem;
        text-align: center;
    }

    .footer-left,
    .footer-right {
        flex-direction: column;
        gap: 0.6rem;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 2.75rem;
    }

    .hero-description {
        font-size: 0.95rem;
    }

    .hero-stats {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .stat-divider {
        display: none;
    }
}

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

    [data-animate] {
        opacity: 1;
        transform: none;
    }

    .scroll-line {
        animation: none;
        opacity: 0.3;
    }
}
