/* ==========================================================================
   Ivan Padilla · Portfolio
   Design system: dark-first "mission control" aesthetic.
   ========================================================================== */

/* ---------- Tokens ---------- */

:root {
    --font-display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;

    --max-width: 68rem;
    --header-height: 4.25rem;
    --radius: 14px;
    --radius-sm: 9px;

    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

:root,
:root[data-theme='dark'] {
    color-scheme: dark;
    --bg: #0b0f14;
    --bg-raised: #10161d;
    --surface: rgba(255, 255, 255, 0.03);
    --surface-hover: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.18);
    --text: #e9eef4;
    --text-muted: #93a1b0;
    --accent: #3be0b0;
    --accent-strong: #6ceac6;
    --accent-contrast: #04241a;
    --accent-2: #5ba8ff;
    --life-cell: #2fc9a0;
    --canvas-opacity: 0.55;
    --glow: 0 0 32px rgba(59, 224, 176, 0.14);
    --header-bg: rgba(11, 15, 20, 0.82);
}

:root[data-theme='light'] {
    color-scheme: light;
    --bg: #f7f9fa;
    --bg-raised: #ffffff;
    --surface: rgba(11, 35, 51, 0.035);
    --surface-hover: rgba(11, 35, 51, 0.07);
    --border: rgba(11, 35, 51, 0.12);
    --border-strong: rgba(11, 35, 51, 0.26);
    --text: #15202b;
    --text-muted: #51606e;
    --accent: #0c8a6a;
    --accent-strong: #0a7257;
    --accent-contrast: #ffffff;
    --accent-2: #2563eb;
    --life-cell: #11a47e;
    --canvas-opacity: 0.4;
    --glow: 0 0 32px rgba(12, 138, 106, 0.12);
    --header-bg: rgba(247, 249, 250, 0.85);
}

/* ---------- Base ---------- */

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-height) + 1rem);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 1.0625rem;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.35s ease, color 0.35s ease;
}

::selection {
    background: var(--accent);
    color: var(--accent-contrast);
}

h1,
h2,
h3 {
    font-family: var(--font-display);
    line-height: 1.15;
    margin: 0 0 0.75em;
    text-wrap: balance;
}

p {
    margin: 0 0 1em;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-strong);
}

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

button {
    font: inherit;
    color: inherit;
}

.mono {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    letter-spacing: 0.02em;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

.skip-link {
    position: absolute;
    top: -3rem;
    left: 1rem;
    z-index: 100;
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: var(--accent-contrast);
    border-radius: var(--radius-sm);
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 1rem;
}

/* ---------- Header ---------- */

.site-header {
    position: fixed;
    inset: 0 0 auto;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    height: var(--header-height);
    padding: 0 clamp(1rem, 4vw, 2.5rem);
    border-bottom: 1px solid transparent;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.site-header.scrolled {
    background: var(--header-bg);
    border-bottom-color: var(--border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

.brand {
    margin-right: auto;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    padding: 0.35rem 0.6rem;
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.brand:hover .brand-mark {
    color: var(--accent);
    border-color: var(--accent);
    box-shadow: var(--glow);
}

.site-nav {
    display: flex;
    gap: 1.75rem;
}

.site-nav a {
    color: var(--text-muted);
    font-size: 0.9375rem;
    font-weight: 500;
    transition: color 0.2s ease;
}

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

.theme-toggle {
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.theme-toggle:hover {
    color: var(--accent);
    border-color: var(--accent);
    transform: rotate(15deg);
}

/* Show moon in light theme (action: go dark), sun in dark theme */
:root[data-theme='dark'] .icon-moon,
:root[data-theme='light'] .icon-sun {
    display: none;
}

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

.hero {
    position: relative;
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: calc(var(--header-height) + 2rem) clamp(1rem, 4vw, 2.5rem) 5rem;
    overflow: hidden;
}

#life-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: var(--canvas-opacity);
    mask-image: linear-gradient(to bottom, black 0%, black 62%, transparent 96%);
    -webkit-mask-image: linear-gradient(to bottom, black 0%, black 62%, transparent 96%);
}

/* The WebGL renderer paints its own background, so it can run brighter than
   the 2D fallback without washing out the hero copy. */
#life-canvas.is-3d {
    opacity: 0.92;
}

.hero-inner {
    position: relative;
    text-align: center;
    max-width: 52rem;
}

.hero-eyebrow {
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    margin-bottom: 1.25rem;
}

.hero-title {
    font-size: clamp(3.25rem, 10vw, 6.75rem);
    font-weight: 700;
    letter-spacing: -0.025em;
    margin-bottom: 1.25rem;
    text-shadow: 0 2px 24px var(--bg);
}

.hero-tagline {
    font-size: clamp(1.125rem, 2.2vw, 1.375rem);
    color: var(--text-muted);
    max-width: 38ch;
    margin: 0 auto 2rem;
    text-wrap: balance;
    text-shadow: 0 1px 12px var(--bg);
}

.hero-tagline strong {
    color: var(--text);
    font-weight: 600;
}

.status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--text-muted);
    margin-bottom: 2.25rem;
}

.status-chip #status-text,
.status-chip #uptime {
    color: var(--accent);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 0 rgba(59, 224, 176, 0.5);
    animation: pulse 2.4s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(59, 224, 176, 0.45); }
    70% { box-shadow: 0 0 0 9px rgba(59, 224, 176, 0); }
    100% { box-shadow: 0 0 0 0 rgba(59, 224, 176, 0); }
}

.hero-actions {
    display: flex;
    gap: 0.9rem;
    justify-content: center;
    flex-wrap: wrap;
}

.hero-caption {
    position: absolute;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100vw - 2rem);
    display: flex;
    align-items: center;
    gap: 0.9rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin: 0;
}

.reseed-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.2rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}

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

/* ---------- Buttons ---------- */

.btn {
    display: inline-block;
    padding: 0.72rem 1.4rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9375rem;
    line-height: 1.4;
    border: 1px solid transparent;
    transition: transform 0.2s var(--ease), box-shadow 0.2s ease,
        background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.btn:hover {
    transform: translateY(-2px);
}

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

.btn-primary:hover {
    background: var(--accent-strong);
    color: var(--accent-contrast);
    box-shadow: var(--glow);
}

.btn-ghost {
    border-color: var(--border-strong);
    color: var(--text);
    background: var(--surface);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

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

/* ---------- Metrics ---------- */

.metrics {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0;
}

.metric {
    padding: 2.25rem 1.5rem;
    text-align: center;
}

.metric + .metric {
    border-left: 1px solid var(--border);
}

.metric dt {
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.metric dd {
    margin: 0 0 0.35rem;
    font-size: clamp(1.9rem, 3.5vw, 2.6rem);
    font-weight: 500;
    color: var(--text);
    line-height: 1;
}

.metric-suffix {
    font-size: 0.6em;
    color: var(--accent);
}

/* ---------- Sections ---------- */

.section {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: clamp(4rem, 9vw, 7rem) clamp(1rem, 4vw, 2.5rem) 0;
}

.section h2 {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    font-size: clamp(1.75rem, 4vw, 2.4rem);
    letter-spacing: -0.02em;
}

.section-num {
    color: var(--accent);
    font-size: 0.9rem;
}

.section-sub {
    color: var(--text-muted);
    margin-top: -0.5rem;
    margin-bottom: 2.5rem;
}

/* ---------- About ---------- */

.about-layout {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 3rem;
    align-items: start;
}

.about-text p {
    max-width: 62ch;
}

.about-education {
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
    margin-top: 1.75rem;
}

.about-photo {
    margin: 0;
    position: relative;
}

.about-photo img {
    width: 100%;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
}

.about-photo::after {
    content: '';
    position: absolute;
    inset: 0.75rem -0.75rem -0.75rem 0.75rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    opacity: 0.35;
    z-index: -1;
}

/* ---------- Timeline ---------- */

.timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 1.75rem;
    border-left: 1px solid var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 3rem;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: calc(-1.75rem - 5.5px);
    top: 0.45rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--bg), var(--glow);
}

.timeline-date {
    color: var(--accent);
    margin-bottom: 0.4rem;
}

.timeline-item h3 {
    font-size: 1.3rem;
    margin-bottom: 0.2rem;
}

.timeline-org {
    color: var(--text-muted);
    font-size: 0.9375rem;
    margin-bottom: 1rem;
}

.timeline-item ul {
    margin: 0 0 1.1rem;
    padding-left: 1.2rem;
    color: var(--text-muted);
}

.timeline-item ul li {
    margin-bottom: 0.45rem;
}

.timeline-item ul li::marker {
    color: var(--accent);
}

.timeline-tags {
    color: var(--text-muted);
    opacity: 0.85;
}

/* ---------- Projects ---------- */

.projects-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.4rem;
}

.project-card,
.teaching-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.85rem;
    /* --rx/--ry/--mx/--my are driven by js/tilt.js on fine pointers. */
    transform: perspective(900px) rotateX(var(--rx, 0deg))
        rotateY(var(--ry, 0deg)) translateY(var(--lift, 0));
    transition: transform 0.25s var(--ease), border-color 0.3s ease,
        background-color 0.3s ease, box-shadow 0.3s ease;
}

.project-card::after,
.teaching-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(
        260px circle at var(--mx, 50%) var(--my, 50%),
        rgba(59, 224, 176, 0.08),
        transparent 70%
    );
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.project-card:hover::after,
.teaching-card:hover::after {
    opacity: 1;
}

.project-card:hover {
    --lift: -4px;
    border-color: var(--accent);
    background: var(--surface-hover);
    box-shadow: var(--glow);
}

.project-featured {
    grid-column: 1 / -1;
    background:
        linear-gradient(var(--bg-raised), var(--bg-raised)) padding-box,
        linear-gradient(120deg, var(--accent), var(--accent-2)) border-box;
    border: 1px solid transparent;
}

.project-featured:hover {
    background:
        linear-gradient(var(--bg-raised), var(--bg-raised)) padding-box,
        linear-gradient(120deg, var(--accent-strong), var(--accent-2)) border-box;
}

.project-featured p:not(.project-meta):not(.project-tags) {
    max-width: 68ch;
}

.project-meta {
    color: var(--accent);
    margin-bottom: 0.8rem;
}

.project-card h3,
.teaching-card h3 {
    font-size: 1.25rem;
    margin-bottom: 0.6rem;
}

.project-featured h3 {
    font-size: 1.55rem;
}

.project-card p,
.teaching-card p {
    color: var(--text-muted);
    font-size: 0.9688rem;
}

.project-tags {
    color: var(--text-muted);
    opacity: 0.8;
    margin-bottom: 0;
}

.project-tags + .project-link {
    margin-top: 1rem;
}

.project-link {
    display: inline-block;
    margin-top: 0.4rem;
    font-weight: 600;
    font-size: 0.9375rem;
}

.project-link:hover span {
    margin-left: 0.25rem;
}

.project-link span {
    transition: margin-left 0.2s var(--ease);
    display: inline-block;
}

/* ---------- Teaching ---------- */

.teaching-card {
    background: var(--surface);
}

.teaching-card p:not(.project-meta) {
    max-width: 72ch;
}

/* ---------- Skills ---------- */

.skills-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2.25rem 3rem;
}

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

.chip-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.chip-list li {
    padding: 0.32rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.875rem;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.chip-list li:hover {
    border-color: var(--accent);
    color: var(--text);
}

/* ---------- Contact ---------- */

.section-contact {
    text-align: center;
    padding-bottom: clamp(4rem, 9vw, 7rem);
}

.section-contact h2 {
    justify-content: center;
}

.contact-lead {
    color: var(--text-muted);
    font-size: 1.15rem;
    max-width: 42ch;
    margin: 0 auto 2.25rem;
}

.contact-links {
    display: flex;
    gap: 0.9rem;
    justify-content: center;
    flex-wrap: wrap;
}

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

.site-footer {
    border-top: 1px solid var(--border);
    padding: 2rem clamp(1rem, 4vw, 2.5rem);
    text-align: center;
    color: var(--text-muted);
}

.site-footer p {
    margin: 0;
    font-size: 0.78rem;
}

/* ---------- Reveal animations (JS-gated) ---------- */

html.js .reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.7s var(--ease), transform 0.7s var(--ease);
}

html.js .reveal.is-visible {
    opacity: 1;
    transform: none;
}

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

@media (max-width: 880px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .metric:nth-child(3) {
        border-left: none;
    }

    .metric:nth-child(n + 3) {
        border-top: 1px solid var(--border);
    }

    .about-layout {
        grid-template-columns: 1fr;
    }

    .about-photo {
        max-width: 240px;
        order: -1;
    }

    .projects-grid,
    .skills-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 660px) {
    .site-nav {
        display: none;
    }

    .hero-caption span:first-child {
        display: none;
    }
}

/* ---------- Reduced motion ---------- */

@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;
    }

    html.js .reveal {
        opacity: 1;
        transform: none;
    }
}
