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

:root {
    --accent: #2563EB;
    --accent-cyan: #0EA5E9;
    --private: #0EA5E9;
    --radius: 12px;
    --font: 'DM Sans', system-ui, sans-serif;
    --mono: 'JetBrains Mono', monospace;
    --sidebar-width: 260px;
    --mobile-header-h: 57px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0F172A;
    --surface: #1E293B;
    --surface-2: #273549;
    --border: #334155;
    --text: #F1F5F9;
    --muted: #94A3B8;
    --accent-dim: rgba(37, 99, 235, 0.15);
    --private-dim: rgba(14, 165, 233, 0.15);
    --sidebar-bg: rgba(15, 23, 42, 0.9);
    --header-bg: rgba(15, 23, 42, 0.95);
    --gradient-1: rgba(37, 99, 235, 0.08);
    --gradient-2: rgba(14, 165, 233, 0.06);
    --shadow-accent: rgba(37, 99, 235, 0.35);
    --hover-border: #475569;
}

[data-theme="light"] {
    color-scheme: light;
    --bg: #FFFFFF;
    --surface: #F8FAFC;
    --surface-2: #F1F5F9;
    --border: #E2E8F0;
    --text: #1E293B;
    --muted: #475569;
    --accent-dim: rgba(37, 99, 235, 0.1);
    --private-dim: rgba(14, 165, 233, 0.1);
    --sidebar-bg: rgba(255, 255, 255, 0.92);
    --header-bg: rgba(255, 255, 255, 0.95);
    --gradient-1: rgba(37, 99, 235, 0.06);
    --gradient-2: rgba(14, 165, 233, 0.04);
    --shadow-accent: rgba(37, 99, 235, 0.25);
    --hover-border: #CBD5E1;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.25s ease, color 0.25s ease;
}

img {
    max-width: 100%;
    height: auto;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 80% 50% at 10% -10%, var(--gradient-1), transparent),
        radial-gradient(ellipse 60% 40% at 90% 100%, var(--gradient-2), transparent);
    pointer-events: none;
    z-index: 0;
    transition: opacity 0.25s ease;
}

.layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
    position: relative;
    z-index: 1;
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 2.5rem 1.75rem;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    background: var(--sidebar-bg);
    backdrop-filter: blur(12px);
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.brand-initials {
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.brand h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand p {
    font-size: 0.8rem;
    color: var(--muted);
}

.nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.nav a {
    display: block;
    padding: 0.55rem 0.75rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.875rem;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
}

.nav a:hover,
.nav a.active {
    color: var(--text);
    background: var(--surface-2);
}

.nav a span {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--accent);
    margin-right: 0.5rem;
    opacity: 0.7;
}

/* Theme switch */
.theme-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    margin-top: auto;
    padding: 0.65rem 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.72rem;
    transition: border-color 0.2s, background-color 0.25s ease, color 0.25s ease;
}

.theme-switch:hover { border-color: var(--accent); }

.theme-switch-label {
    text-align: left;
}

.theme-switch-track {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
    border-radius: 999px;
    background: var(--border);
    transition: background-color 0.2s ease;
}

.theme-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    transition: transform 0.2s ease;
}

.theme-switch[aria-checked="true"] .theme-switch-track {
    background: var(--accent);
}

.theme-switch[aria-checked="true"] .theme-switch-thumb {
    transform: translateX(18px);
}

.mobile-actions .theme-switch {
    width: auto;
    margin-top: 0;
    padding: 0.35rem;
    background: transparent;
    border: none;
}

.mobile-actions .theme-switch:hover {
    border-color: transparent;
}

.mobile-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat,
.project-card,
.contact-box,
.contact-item,
.tag {
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

/* Main */
.main {
    padding: 3rem clamp(1.25rem, 4vw, 3.5rem) 4rem;
    max-width: 960px;
    width: 100%;
    min-width: 0;
}

section {
    margin-bottom: clamp(3rem, 6vw, 5rem);
    scroll-margin-top: 2rem;
}

.section-label {
    font-family: var(--mono);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--accent);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}

/* Intro */
.intro h2 {
    font-size: clamp(1.75rem, 5vw, 3.25rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin-bottom: 1.25rem;
    overflow-wrap: anywhere;
}

.intro h2 em {
    font-style: normal;
    color: var(--accent);
}

.intro-lead {
    font-size: clamp(0.95rem, 2.2vw, 1.1rem);
    color: var(--muted);
    max-width: 540px;
    margin-bottom: 2rem;
}

.intro-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--accent);
    color: #FFFFFF;
}

.btn-primary:hover {
    box-shadow: 0 0 24px var(--shadow-accent);
}

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

.btn-ghost:hover {
    background: var(--surface);
    border-color: var(--muted);
}

/* Stats row */
.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
    margin-top: 3rem;
}

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    min-width: 0;
}

.stat .stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 6px;
    background: var(--accent-dim);
    color: var(--accent);
}

.stat-icon svg {
    width: 0.8rem;
    height: 0.8rem;
}

.stat strong {
    display: block;
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.45rem;
}

.stat-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

/* About */
.about-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    min-width: 0;
}

.about-text p {
    color: var(--muted);
    margin-bottom: 1rem;
}

.about-text p:last-child { margin-bottom: 0; }

.stack-groups {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.stack-group h4 {
    font-family: var(--mono);
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.6rem;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tag {
    font-family: var(--mono);
    font-size: 0.72rem;
    padding: 0.3rem 0.65rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
}

/* Services */
.services-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.service-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}

.service-card h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.service-icon {
    width: 1.1rem;
    height: 1.1rem;
    flex-shrink: 0;
    color: var(--accent);
}

.service-card p {
    font-size: 0.875rem;
    color: var(--muted);
}

/* Projects */
.projects-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.projects-header p {
    font-size: 0.875rem;
    color: var(--muted);
    max-width: 400px;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-dot.os { background: var(--accent); }
.legend-dot.prod { background: var(--private); }

.bento {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.project-card {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0;
    display: grid;
    grid-template-columns: minmax(160px, 220px) minmax(0, 1fr) auto;
    gap: 0;
    align-items: stretch;
    transition: border-color 0.2s, transform 0.2s;
    position: relative;
    overflow: hidden;
}

.project-card--plain {
    grid-template-columns: minmax(0, 1fr) auto;
}

.project-card--featured {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "image image"
        "body aside";
}

.project-card--featured .card-image {
    grid-area: image;
    border-right: none;
    border-bottom: 1px solid var(--border);
}

.project-card--featured .card-body {
    grid-area: body;
}

.project-card--featured .card-aside {
    grid-area: aside;
    padding: 1.5rem 1.5rem 1.5rem 0;
}

.project-card--featured .card-image img,
.project-card--featured .card-image video {
    min-height: 320px;
    max-height: 440px;
    object-fit: cover;
    object-position: top center;
}

.card-image {
    overflow: hidden;
    background: var(--surface-2);
    border-right: 1px solid var(--border);
    min-width: 0;
}

.card-image img,
.card-image video {
    width: 100%;
    height: 100%;
    min-height: 200px;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.card-image video {
    background: #0F172A;
}

.project-card:hover .card-image img {
    transform: scale(1.04);
}

.project-card:hover .card-carousel img {
    transform: none;
}

.card-carousel {
    position: relative;
}

.carousel-viewport img {
    display: none;
}

.carousel-viewport img.is-active {
    display: block;
}

.carousel-btn {
    position: absolute;
    top: 50%;
    z-index: 2;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 1.35rem;
    line-height: 1;
}

.carousel-btn--prev { left: 0.75rem; }
.carousel-btn--next { right: 0.75rem; }

.carousel-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.carousel-dots {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0.75rem;
    z-index: 2;
    display: flex;
    justify-content: center;
    gap: 0.4rem;
}

.carousel-dot {
    width: 8px;
    height: 8px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    cursor: pointer;
}

.carousel-dot.is-active {
    background: var(--accent);
    border-color: var(--accent);
}

.project-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    opacity: 0;
    transition: opacity 0.2s;
}

.project-card:hover {
    border-color: var(--hover-border);
    transform: translateY(-2px);
}

.project-card:hover::before { opacity: 1; }

.project-card.os::before { background: var(--accent); }
.project-card.prod::before { background: var(--private); }

.card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.5rem;
    min-width: 0;
}

.card-aside {
    text-align: right;
    padding: 1.5rem 1.5rem 1.5rem 0;
    min-width: 100px;
}

.card-aside .metric {
    font-family: var(--mono);
    font-size: 2rem;
    font-weight: 600;
    line-height: 1;
}

.card-aside .metric.os { color: var(--accent); }
.card-aside .metric.prod { color: var(--private); }

.card-aside .metric-label {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.badge {
    font-family: var(--mono);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.25rem 0.55rem;
    border-radius: 4px;
}

.badge.os {
    background: var(--accent-dim);
    color: var(--accent);
}

.badge.prod {
    background: var(--private-dim);
    color: var(--private);
}


.project-card h3 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.project-card p {
    font-size: 0.875rem;
    color: var(--muted);
    flex: 1;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.card-meta span {
    font-family: var(--mono);
    font-size: 0.68rem;
    color: var(--muted);
    background: var(--bg);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.card-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.25rem;
}

.card-links a,
.card-links .muted-link {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.card-links a:hover { text-decoration: underline; }

.card-links .muted-link {
    color: var(--muted);
    cursor: default;
    pointer-events: none;
}

/* Contact */
.contact-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(1.25rem, 3vw, 2rem);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: center;
}

.contact-box h3 {
    font-size: clamp(1.25rem, 3vw, 1.5rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.contact-box p {
    color: var(--muted);
    font-size: 0.9rem;
}

.contact-links {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 0;
}

.contact-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    font-size: 0.875rem;
    transition: border-color 0.2s;
    min-width: 0;
    overflow-wrap: anywhere;
}

.contact-item:hover { border-color: var(--accent); }

.contact-item .label {
    font-family: var(--mono);
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    min-width: 60px;
    flex-shrink: 0;
}

footer {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--muted);
    font-family: var(--mono);
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Mobile */
.mobile-header {
    display: none;
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 1rem 1.25rem;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

.mobile-header h1 {
    font-size: 0.95rem;
    font-weight: 700;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.menu-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 0.75rem;
    cursor: pointer;
    flex-shrink: 0;
}

/* Tablet — cards empilham antes do menu mobile */
@media (max-width: 1100px) {
    .project-card {
        grid-template-columns: minmax(0, 1fr);
    }

    .project-card--featured {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "image"
            "body"
            "aside";
    }

    .card-image {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .card-image img,
    .card-image video {
        min-height: 200px;
        max-height: 280px;
        height: auto;
        aspect-ratio: 16 / 9;
    }

    .project-card--featured .card-image img,
    .project-card--featured .card-image video {
        min-height: 240px;
        max-height: 360px;
    }

    .card-aside,
    .project-card--featured .card-aside {
        text-align: left;
        padding: 0 1.5rem 1.5rem;
    }
}

/* Mobile */
@media (max-width: 860px) {
    .layout { grid-template-columns: 1fr; }

    .sidebar {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 200;
        height: 100dvh;
        max-height: 100dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-right: none;
        padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
        background: var(--bg);
    }

    .sidebar.open { display: flex; }

    body.menu-open { overflow: hidden; }

    .mobile-header { display: flex; }

    .main {
        padding: 1.75rem 1.15rem calc(3rem + env(safe-area-inset-bottom));
    }

    section {
        scroll-margin-top: calc(var(--mobile-header-h) + 1rem);
        margin-bottom: 3.5rem;
    }

    .stats {
        grid-template-columns: 1fr;
        margin-top: 2rem;
    }

    .about-grid {
        grid-template-columns: 1fr;
        gap: 1.75rem;
    }

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

    .intro-actions .btn {
        flex: 1 1 auto;
        min-width: min(100%, 160px);
    }

    .contact-box {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .card-body { padding: 1.25rem; }

    .card-aside,
    .project-card--featured .card-aside {
        padding: 0 1.25rem 1.25rem;
    }

    .card-image img,
    .card-image video {
        min-height: 160px;
        max-height: 220px;
    }

    .project-card--featured .card-image img,
    .project-card--featured .card-image video {
        min-height: 180px;
        max-height: 260px;
    }

    .card-aside .metric { font-size: 1.5rem; }
}

/* Small phones */
@media (max-width: 480px) {
    .mobile-header { padding: 0.85rem 1rem; }

    .main { padding: 1.35rem 1rem 2.5rem; }

    .intro h2 br { display: none; }

    .intro-actions {
        flex-direction: column;
    }

    .intro-actions .btn { width: 100%; }

    .stat { padding: 1rem; }

    .contact-item {
        flex-wrap: wrap;
        gap: 0.35rem 0.75rem;
    }

    .contact-item .label { min-width: 100%; }

    footer {
        flex-direction: column;
        gap: 0.35rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
