/* =========================================================================
   Ennerd — design system
   Near-black canvas, spectral accents, instrument-panel typography.
   All fonts are system stacks: nothing is fetched from a third party.
   ========================================================================= */

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

:root {
    /* Structure */
    --width-page:  1140px;
    --width-prose: 68ch;
    --gutter: clamp(1.25rem, 4vw, 3rem);
    --radius: 14px;
    --radius-sm: 8px;

    /* Surfaces — a near-black that is slightly blue, not muddy grey */
    --bg:        #08090c;
    --bg-elev:   #0e1017;
    --bg-elev-2: #151824;
    --line:      #1d2130;
    --line-soft: #14171f;

    /* Ink */
    --text:       #e7e9f0;
    --text-dim:   #99a2b6;
    --text-faint: #5f6880;

    /* Spectral accents — sampled across a spectrum, violet → cyan → amber.
       Doubles as the palette for the particle field. */
    --violet: #7c5cff;
    --indigo: #4c6ef5;
    --cyan:   #22d3ee;
    --teal:   #2dd4a7;
    --amber:  #fbbf24;
    --rose:   #fb7185;

    --accent: var(--cyan);
    --spectrum: linear-gradient(100deg, var(--violet), var(--indigo), var(--cyan), var(--teal), var(--amber));

    /* Type */
    --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', Consolas, monospace;

    --step--1: clamp(0.80rem, 0.78rem + 0.10vw, 0.86rem);
    --step-0:  clamp(1.00rem, 0.96rem + 0.18vw, 1.09rem);
    --step-1:  clamp(1.25rem, 1.16rem + 0.42vw, 1.50rem);
    --step-2:  clamp(1.56rem, 1.38rem + 0.85vw, 2.07rem);
    --step-3:  clamp(1.95rem, 1.63rem + 1.55vw, 2.85rem);
    --step-4:  clamp(2.44rem, 1.88rem + 2.70vw, 3.92rem);

    --ease: cubic-bezier(.22, .61, .36, 1);
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    font-size: var(--step-0);
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: hidden;
}

/* A slow spectral wash behind everything — barely perceptible, but it stops
   the page from reading as flat black. */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background:
        radial-gradient(60rem 40rem at 12% -10%, rgba(124, 92, 255, .16), transparent 60%),
        radial-gradient(50rem 36rem at 88% 8%,  rgba(34, 211, 238, .11), transparent 60%),
        radial-gradient(46rem 34rem at 60% 100%, rgba(251, 191, 36, .07), transparent 60%);
}

/* -- Particle field ------------------------------------------------------ */

#field {
    position: fixed;
    inset: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    pointer-events: none;   /* never steals clicks or CMS long-press */
    opacity: .85;
}

/* -- Typography ---------------------------------------------------------- */

h1, h2, h3, h4 {
    line-height: 1.14;
    letter-spacing: -0.022em;
    font-weight: 640;
    text-wrap: balance;
}

h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p { text-wrap: pretty; }

a {
    color: var(--text);
    text-decoration-color: color-mix(in srgb, var(--accent) 55%, transparent);
    text-underline-offset: 4px;
    text-decoration-thickness: 1px;
    transition: color .18s var(--ease), text-decoration-color .18s var(--ease);
}

a:hover { color: var(--cyan); text-decoration-color: var(--cyan); }

code, pre, kbd, samp { font-family: var(--font-mono); font-size: .9em; }

code {
    background: var(--bg-elev-2);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: .12em .38em;
    color: var(--cyan);
}

pre {
    background: var(--bg-elev);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 1.15rem 1.35rem;
    overflow-x: auto;
    line-height: 1.55;
}

pre code { background: none; border: 0; padding: 0; color: var(--text-dim); }

::selection { background: color-mix(in srgb, var(--violet) 45%, transparent); color: #fff; }

/* Focus: visible, spectral, never removed. */
:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 3px;
    border-radius: 3px;
}

/* -- Layout primitives --------------------------------------------------- */

.wrap {
    width: 100%;
    max-width: var(--width-page);
    margin-inline: auto;
    padding-inline: var(--gutter);
}

.prose { max-width: var(--width-prose); }
.prose > * + * { margin-top: 1.1em; }
.prose h2 { margin-top: 2.4em; }
.prose h3 { margin-top: 1.9em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: .4em; }

main { min-height: 60vh; }

section { padding-block: clamp(3.5rem, 9vw, 7rem); }

/* Eyebrow label — monospace, spaced, spectral. The instrument-panel voice. */
.eyebrow {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--text-faint);
    display: flex;
    align-items: center;
    gap: .8rem;
    margin-bottom: 1.4rem;
}

.eyebrow::before {
    content: '';
    width: 2rem;
    height: 2px;
    border-radius: 2px;
    background: var(--spectrum);
    flex: none;
}

.lead {
    font-size: var(--step-1);
    line-height: 1.55;
    color: var(--text-dim);
    max-width: 56ch;
}

.muted { color: var(--text-dim); }
.meta  { font-family: var(--font-mono); font-size: var(--step--1); color: var(--text-faint); }

/* Gradient text, used sparingly — one phrase per page at most. */
.spectral {
    background: var(--spectrum);
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
}

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

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    border-bottom: 1px solid var(--line-soft);
}

.site-header nav {
    display: flex;
    align-items: center;
    gap: 2rem;
    height: 68px;
}

.brand {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-right: auto;
}

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

/* The mark: a small spectral aperture. Reads as a lens or an iris — a nod to
   the camera work without being literal about it. */
.brand-mark {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--spectrum);
    position: relative;
    flex: none;
    transition: transform .4s var(--ease);
}

.brand-mark::after {
    content: '';
    position: absolute;
    inset: 5px;
    border-radius: 50%;
    background: var(--bg);
}

.brand:hover .brand-mark { transform: rotate(180deg) scale(1.08); }

.nav-links {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 1.9rem;
}

.nav-links a {
    font-size: .93rem;
    color: var(--text-dim);
    text-decoration: none;
    position: relative;
    padding-block: .4rem;
}

.nav-links a::after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 1.5px;
    border-radius: 2px;
    background: var(--spectrum);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .28s var(--ease);
}

.nav-links a:hover { color: var(--text); }
.nav-links a:hover::after,
.nav-links a.active::after { transform: scaleX(1); }
.nav-links a.active { color: var(--text); }

/* Dropdown submenu (e.g. Fun ▸ Tetris). CSS-only: hover/focus-within on
   desktop, expanded inline within the mobile menu. */
.has-submenu { position: relative; }

.submenu-parent { display: inline-flex; align-items: center; gap: .35rem; }

.caret {
    width: 0; height: 0;
    border-left: 3.5px solid transparent;
    border-right: 3.5px solid transparent;
    border-top: 4px solid currentColor;
    opacity: .6;
    transition: transform .2s var(--ease);
}

.has-submenu:hover .caret,
.has-submenu:focus-within .caret { transform: rotate(180deg); }

.submenu {
    list-style: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translate(-50%, 6px);
    min-width: 9rem;
    padding: .4rem;
    display: flex;
    flex-direction: column;
    gap: .1rem;
    background: color-mix(in srgb, var(--bg-elev) 96%, transparent);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .18s var(--ease), transform .18s var(--ease);
    z-index: 120;
}

/* A hover bridge so the menu doesn't vanish crossing the gap to it. */
.submenu::before {
    content: '';
    position: absolute;
    top: -8px; left: 0; right: 0; height: 8px;
}

.has-submenu:hover .submenu,
.has-submenu:focus-within .submenu {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}

.submenu a {
    display: block;
    padding: .5rem .7rem;
    border-radius: 6px;
    white-space: nowrap;
    font-size: .9rem;
    color: var(--text-dim);
}

.submenu a::after { display: none; }
.submenu a:hover,
.submenu a.active {
    color: var(--text);
    background: color-mix(in srgb, var(--cyan) 12%, transparent);
}

/* Hamburger */
.nav-toggle {
    display: none;
    background: none;
    border: 0;
    cursor: pointer;
    padding: 8px;
    flex-direction: column;
    gap: 5px;
}

.nav-toggle span {
    display: block;
    width: 22px;
    height: 1.5px;
    border-radius: 2px;
    background: var(--text);
    transition: transform .25s var(--ease), opacity .25s var(--ease);
}

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

.hero {
    padding-block: clamp(5rem, 15vw, 10.5rem) clamp(3.5rem, 9vw, 7rem);
}

.hero h1 { max-width: 18ch; }
.hero .lead { margin-top: 1.8rem; }

.hero-actions {
    margin-top: 2.6rem;
    display: flex;
    flex-wrap: wrap;
    gap: .9rem;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    padding: .72rem 1.35rem;
    border-radius: 100px;
    border: 1px solid var(--line);
    background: var(--bg-elev);
    color: var(--text);
    font-size: .94rem;
    font-weight: 520;
    text-decoration: none;
    cursor: pointer;
    transition: border-color .2s var(--ease), background .2s var(--ease), transform .2s var(--ease);
}

.btn:hover {
    color: var(--text);
    border-color: color-mix(in srgb, var(--cyan) 50%, var(--line));
    background: var(--bg-elev-2);
    transform: translateY(-1px);
}

.btn-primary {
    border: 0;
    background: var(--spectrum);
    color: #06070a;
    font-weight: 640;
}

.btn-primary:hover { color: #06070a; filter: brightness(1.08); }

/* -- Cards --------------------------------------------------------------- */

.grid {
    display: grid;
    gap: 1.15rem;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr));
}

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: .7rem;
    padding: 1.7rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
    text-decoration: none;
    overflow: hidden;
    transition: border-color .28s var(--ease), transform .28s var(--ease), background .28s var(--ease);
}

/* A spectral hairline that wipes in along the top edge on hover. */
.card::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    top: 0;
    height: 1.5px;
    background: var(--spectrum);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .45s var(--ease);
}

.card:hover {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--cyan) 26%, var(--line));
    background: color-mix(in srgb, var(--bg-elev-2) 82%, transparent);
}

.card:hover::before { transform: scaleX(1); }

.card h3 { font-size: var(--step-1); }
.card p  { color: var(--text-dim); font-size: .96rem; }

.card-index {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    color: var(--text-faint);
}

/* Tag pills */
.tags { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: auto; padding-top: .9rem; }

.tag {
    font-family: var(--font-mono);
    font-size: .72rem;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-dim);
    border: 1px solid var(--line);
    border-radius: 100px;
    padding: .22rem .6rem;
}

/* -- Entry list (writing / projects index) ------------------------------- */

.entries { border-top: 1px solid var(--line-soft); }

.entry {
    display: grid;
    grid-template-columns: 9rem 1fr;
    gap: 1.5rem;
    padding-block: 1.6rem;
    border-bottom: 1px solid var(--line-soft);
    text-decoration: none;
    transition: background .25s var(--ease);
}

.entry:hover { background: color-mix(in srgb, var(--bg-elev) 60%, transparent); }
.entry:hover h3 { color: var(--cyan); }
.entry h3 { font-size: var(--step-1); transition: color .2s var(--ease); }
.entry p  { color: var(--text-dim); font-size: .96rem; margin-top: .35rem; }

/* -- Callout (used for the gated thesis section) ------------------------- */

.callout {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--bg-elev) 80%, transparent);
    padding: clamp(1.5rem, 4vw, 2.4rem);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
}

.callout .eyebrow { margin-bottom: 0; }

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

.site-footer {
    margin-top: clamp(4rem, 10vw, 8rem);
    border-top: 1px solid var(--line-soft);
    padding-block: 3rem 3.5rem;
    color: var(--text-faint);
    font-size: .9rem;
}

.site-footer .wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem 2.5rem;
    align-items: center;
}

.site-footer a { color: var(--text-dim); text-decoration: none; }
.site-footer a:hover { color: var(--cyan); }
.site-footer .spacer { margin-left: auto; }

/* -- Reveal on scroll ---------------------------------------------------- */

[data-reveal] {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity .7s var(--ease), transform .7s var(--ease);
}

[data-reveal].is-visible { opacity: 1; transform: none; }

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

@media (max-width: 720px) {
    .nav-toggle { display: flex; }

    .nav-links {
        position: absolute;
        top: 68px;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: .5rem var(--gutter) 1.5rem;
        background: color-mix(in srgb, var(--bg) 96%, transparent);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
        border-bottom: 1px solid var(--line-soft);
        display: none;
    }

    nav.open .nav-links { display: flex; }
    .nav-links a { padding-block: .85rem; font-size: 1.02rem; }
    .nav-links a::after { display: none; }

    /* In the mobile menu the dropdown flattens into an indented sublist —
       hover has no meaning on touch, so the children are simply always shown. */
    .submenu {
        position: static;
        transform: none;
        opacity: 1;
        visibility: visible;
        min-width: 0;
        padding: 0 0 .3rem 1rem;
        background: none;
        border: none;
        box-shadow: none;
    }
    .caret { display: none; }
    .submenu a { font-size: .95rem; padding-block: .55rem; }

    nav.open .nav-toggle span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
    nav.open .nav-toggle span:nth-child(2) { opacity: 0; }
    nav.open .nav-toggle span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

    .entry { grid-template-columns: 1fr; gap: .4rem; }
}

/* -- Motion and contrast preferences ------------------------------------- */

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

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

    [data-reveal] { opacity: 1; transform: none; }
    #field { display: none; }   /* the simulation also self-disables in JS */
}

/* The CMS injects a light-ish editing chrome; keep our own surfaces stable
   when the admin preview iframe adds .cms-edit-mode to <body>. */
.cms-edit-mode [data-cms-type] { border-radius: 4px; }

/* -- Tetris -------------------------------------------------------------- */

.tetris {
    display: flex;
    flex-wrap: wrap;
    gap: 1.75rem;
    align-items: flex-start;
}

.tetris-stage {
    position: relative;
    flex: none;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-elev) 85%, transparent);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}

#tetris-board {
    display: block;
    height: min(72vh, 600px);
    width: auto;
    touch-action: none;   /* our own buttons handle input; don't scroll */
}

.tetris-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .9rem;
    padding: 1.5rem;
    text-align: center;
    background: color-mix(in srgb, var(--bg) 72%, transparent);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.tetris-overlay[hidden] { display: none; }
.tetris-overlay h2 { font-size: var(--step-2); }
.tetris-overlay p { color: var(--text-dim); font-size: .95rem; }

.tetris-side {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-width: 12rem;
}

.tetris-stat { display: flex; flex-direction: column; gap: .15rem; }
.tetris-stat .label {
    font-family: var(--font-mono);
    font-size: var(--step--1);
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--text-faint);
}
.tetris-stat .value { font-size: var(--step-2); font-variant-numeric: tabular-nums; }

.tetris-next {
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--bg-elev) 60%, transparent);
}

.tetris-keys {
    font-size: .82rem;
    color: var(--text-dim);
    line-height: 1.9;
}
.tetris-keys kbd {
    font-family: var(--font-mono);
    font-size: .78rem;
    background: var(--bg-elev-2);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: .08em .45em;
    color: var(--text);
}

/* On-screen controls — shown only where a fine pointer is absent. */
.tetris-touch { display: none; }

@media (pointer: coarse) {
    .tetris-touch {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: .5rem;
        width: 100%;
        max-width: 20rem;
        margin-top: .5rem;
    }
    .tetris-touch button {
        padding: .9rem 0;
        font-size: 1.1rem;
        border-radius: var(--radius-sm);
        border: 1px solid var(--line);
        background: var(--bg-elev);
        color: var(--text);
        cursor: pointer;
    }
    .tetris-touch button:active { background: var(--bg-elev-2); }
    .tetris-touch .wide { grid-column: span 3; }
}
