/* ==========================================================
   cespana.com
   Laptops & desktops: a fixed left panel (name, menu, socials)
   and a scrolling right side for all sections.
   Phones & tablets: the panel sits on top; section titles pin
   to the top while you read each section.
   Within sections, a narrow margin column holds dates, tags
   and the photo when there's room.
   ========================================================== */

/* ---------- Design tokens ---------- */
:root {
    /* Colour */
    --bg: #F9F7F4;
    --text: #1A1A1A;
    --text-2: #545454;
    --text-3: #8A8A8A;
    --rule: #D9D5CE;
    --link: #333333;            /* links: a darker grey, bold, no underline */
    --accent: #B98700;          /* link hover; deep enough to read on cream */
    --placeholder: #ECE8E2;
    --selection: #F4C43055;
    --sticky-bg: rgba(249, 247, 244, 0.7);     /* pinned section titles on phones: page colour at 70% */

    /* Hover card ("glass") */
    --card-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.38));
    --card-border: rgba(255, 255, 255, 0.95);
    --card-shadow:
        0 1px 2px rgba(40, 32, 20, 0.04),
        0 12px 32px -12px rgba(60, 48, 25, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);

    /* Type */
    --serif: 'Newsreader', Georgia, serif;
    --sans: 'Work Sans', system-ui, sans-serif;

    --fs-lede: clamp(1.875rem, 1.35rem + 2.2vw, 3rem);
    --fs-prose: clamp(1.125rem, 1.07rem + 0.25vw, 1.25rem);
    --fs-body: 1.0625rem;
    --fs-ui: 0.9375rem;
    --fs-title: clamp(1.875rem, 1.5rem + 1.4vw, 2.5rem);

    /* Layout */
    --aside: 10rem;             /* left margin column */
    --gap: 3rem;                /* space between the two columns */
    --measure: 36rem;           /* reading width, ~70 characters */
    --gutter: clamp(1.25rem, 5vw, 3rem);
    --top: clamp(3rem, 9vh, 6rem);         /* top space of both panels on laptops */
}

[data-theme="dark"] {
    --bg: #0E1A2E;              /* deep blue */
    --text: #E2EBFA;            /* white with a cool blue hue */
    --text-2: #A8BBD8;
    --text-3: #7B8EAE;
    --rule: #26354F;
    --link: #EEF4FF;
    --accent: #00D2E9;
    --placeholder: #172640;
    --selection: #00D2E944;
    --sticky-bg: rgba(14, 26, 46, 0.7);

    --card-bg: linear-gradient(135deg, rgba(170, 200, 255, 0.09), rgba(170, 200, 255, 0.025));
    --card-border: rgba(190, 215, 255, 0.12);
    --card-shadow:
        0 14px 36px -14px rgba(0, 6, 20, 0.7),
        inset 0 1px 0 rgba(220, 235, 255, 0.07);
}

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

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

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    font-size: 1rem;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    transition: background-color 0.25s ease, color 0.25s ease;
}

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

/* Links: bold, darker grey, no underline. Hover turns them gold (cyan in dark mode). */
a {
    color: var(--link);
    font-weight: 600;
    text-decoration: none;
    transition: color 0.2s ease;
}

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

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

::selection {
    background: var(--selection);
}

/* ---------- Page container (used by the 404 page) ---------- */
.page {
    max-width: calc(var(--aside) + var(--gap) + var(--measure) + 2 * var(--gutter));
    margin-inline: auto;
    padding-inline: var(--gutter);
}

/* ---------- Layout ----------
   Phones & tablets: the panel (name, description, socials) sits on top, sections follow.
   Laptops & up:     the panel (with the menu) stays fixed on the left; the right side scrolls.
   There's no divider: the space between them does the separating.            */
.panel {
    position: relative;
    padding: clamp(3.5rem, 12vw, 5rem) var(--gutter) 0;
}

.content {
    container-type: inline-size;        /* lets rows adapt to the right panel's width */
    padding-inline: var(--gutter);
}

@media (min-width: 60rem) {
    .layout {
        display: grid;
        grid-template-columns: 2fr 3fr;     /* 40% / 60% */
    }

    .panel {
        gap: 2.5rem;                    /* minimum space between name, menu and socials */
        position: sticky;
        top: 0;
        height: 100vh;
        height: 100dvh;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        padding: var(--top) clamp(2rem, 3vw, 3rem) 2rem clamp(2rem, 4vw, 4rem);
    }

    .content {
        padding: var(--top) clamp(2rem, 5vw, 5rem) 0 0;
    }

    .content > * {
        max-width: calc(var(--aside) + var(--gap) + var(--measure));
    }
}

/* Two-column row inside the right panel: margin column + reading column.
   Switches on when the right panel itself is wide enough. */
.row {
    display: grid;
    row-gap: 0.75rem;
}

.row > .aside:empty {
    display: none;
}

.main {
    min-width: 0;
    max-width: var(--measure);
}

@container (min-width: 44rem) {
    .row {
        grid-template-columns: var(--aside) minmax(0, 1fr);
        column-gap: var(--gap);
    }

    .row > .aside:empty {
        display: block;
    }
}

/* ---------- Panel: name & description ---------- */
.lede {
    font-family: var(--serif);
    font-size: var(--fs-lede);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: -0.015em;
    color: var(--text-2);
    max-width: 22ch;
    text-wrap: balance;
}

.lede-name {
    color: var(--text);
    font-weight: 500;           /* Newsreader Medium; 600 for semibold */
}

/* On the home page the name links to cespana.com: clickable, but no hover change */
a.lede-name:hover {
    color: var(--text);
}

/* The description sits below the name, a size smaller */
.lede-desc {
    display: block;
    margin-top: 0.6rem;
    font-size: clamp(1.375rem, 1.15rem + 0.65vw, 1.6875rem);
    line-height: 1.35;
    letter-spacing: 0;
}

.panel .lede {
    font-size: clamp(2.375rem, 1.9rem + 2.2vw, 3rem);    /* phones & tablets */
    padding-right: 2.5rem;              /* clears the theme icon on phones */
    margin-bottom: 2rem;
}

@media (max-width: 59.99rem) {
    .panel .lede-desc {
        font-size: clamp(1.5rem, 1.3rem + 0.8vw, 1.75rem);
    }
}

@media (min-width: 60rem) {
    .panel .lede {
        font-size: clamp(2.125rem, 1.35rem + 1.7vw, 2.875rem);
        padding-right: 0;
        margin-bottom: 0;
    }
}

/* ---------- Panel: menu (laptops & desktops only) ---------- */
.site-nav {
    display: none;                      /* phones & tablets: section titles pin instead */
}

@media (min-width: 60rem) {
    .site-nav {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        margin-block: auto;             /* centred between the name and the socials */
        font-size: 1rem;
    }

    .site-nav a {
        position: relative;
        padding-block: 0.3rem;
        font-weight: 400;
        color: var(--text-2);
        transition: color 0.2s ease;
    }

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

    /* Current section: a short line underneath */
    .site-nav a::after {
        content: '';
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0.2rem;
        height: 1px;
        background: currentColor;
        transform: scaleX(0);
        transform-origin: left;
        transition: transform 0.25s ease;
    }

    .site-nav a.is-current::after {
        transform: scaleX(1);
    }
}

/* ---------- Panel: social icons ----------
   Inline SVGs in index.html, coloured by the theme. Named "elsewhere"
   (not "social") because content blockers often hide "social" elements. */
.elsewhere {
    display: flex;
    gap: 0.25rem;
    margin: 1.25rem 0 0 -0.5625rem;     /* icons line up with the text above */
    list-style: none;
}

.elsewhere a {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    color: var(--text-2);
    transition: color 0.2s ease;
}

/* Hover/keyboard focus: just a colour change, gold in light mode, cyan in dark mode */
.elsewhere a:hover,
.elsewhere a:focus-visible {
    color: var(--accent);
}

.elsewhere a:focus-visible {
    outline: none;
}

.elsewhere-icon {
    width: 1.375rem;
    height: 1.375rem;
    fill: currentColor;
}

@media (min-width: 60rem) {
    .elsewhere {
        margin-top: 0;
        margin-bottom: 0.25rem;         /* sits just above the theme toggle */
    }
}

/* ---------- Panel: theme icon ---------- */
.theme-toggle {
    position: absolute;
    top: clamp(3.5rem, 12vw, 5rem);
    right: calc(var(--gutter) - 0.6rem);
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    color: var(--text-2);
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
}

@media (min-width: 60rem) {
    .theme-toggle {
        position: static;
        margin-left: -0.6rem;           /* icon lines up with the text above */
    }
}

/* Hover circle only on devices with a mouse (avoids a stuck circle after a tap) */
@media (hover: hover) {
    .theme-toggle:hover {
        color: var(--text);
        background: var(--placeholder);
    }
}

.theme-toggle svg {
    width: 1.125rem;
    height: 1.125rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-sun { display: none; }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }

/* ---------- Bio (top of the right panel) ---------- */
.hero {
    padding-top: clamp(5.5rem, 14vw, 7rem);     /* phones & tablets: clear break after the header */
}

@media (min-width: 60rem) {
    .hero {
        padding-top: 0.35rem;           /* first line sits level with the name */
    }
}

/* Phones & tablets (panel on top) vs laptops & desktops (panel on the left) */
@media (min-width: 60rem) {
    .mobile-only { display: none; }
}

@media (max-width: 59.99rem) {
    .desktop-only { display: none; }
}

/* ---------- Sticky section titles (phones & tablets) ----------
   Each section's own title sticks to the top while you scroll through that
   section, then the next section's title takes its place. Plain CSS, no
   separate bar and no JavaScript, so content blockers leave it alone.        */
@media (max-width: 59.99rem) {
    .content .section-title {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 10;
        margin-inline: calc(-1 * var(--gutter));    /* background runs edge to edge */
        margin-bottom: 1.75rem;
        padding: 0.9rem var(--gutter);
        font-family: var(--serif);
        font-size: 1.625rem;
        font-weight: 400;
        line-height: 1.15;
        letter-spacing: -0.01em;
        background-color: var(--sticky-bg);         /* 70% see-through */
        -webkit-backdrop-filter: blur(10px);         /* softens text passing underneath */
                backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--rule);        /* solid edge */
    }
}

/* ---------- Sections ---------- */
.section {
    padding-top: clamp(6.5rem, 12vw, 8rem);
    scroll-margin-top: 1rem;
}

.section-title {
    font-family: var(--serif);
    font-size: var(--fs-title);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin-bottom: clamp(2rem, 4vw, 3rem);
}

/* ---------- Long-form text ---------- */
.prose > * + * {
    margin-top: 1.1em;
}

.prose p,
.prose li {
    font-family: var(--serif);
    font-size: var(--fs-prose);
    line-height: 1.6;
    color: var(--text-2);       /* softer grey (light) / soft blue (dark) */
    text-wrap: pretty;
}

.prose h3 {
    font-family: var(--sans);
    font-size: var(--fs-ui);
    font-weight: 500;
    color: var(--text);
    margin-top: 2.75rem;
}

.prose h3 + * {
    margin-top: 0.75rem;
}

.plain-list {
    list-style: none;
}

.plain-list li + li {
    margin-top: 0.6em;
}

/* Run-in lead word, e.g. "Growth." */
.plain-list strong {
    font-family: var(--sans);
    font-size: 0.85em;
    font-weight: 500;
    color: var(--text);
}

/* ---------- Entries (projects & experience) ---------- */
.entries {
    list-style: none;
    display: grid;
    gap: clamp(2.5rem, 5vw, 3.5rem);
}

.entry {
    align-items: baseline;      /* dates line up with the role title */
    row-gap: 0.25rem;
}

.meta {
    font-size: var(--fs-ui);
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

.entry-title {
    font-family: var(--sans);
    font-size: 1.0625rem;
    font-weight: 500;
    line-height: 1.4;
}

.entry-sub {
    font-size: var(--fs-ui);
    color: var(--text-2);
}

.entry-body,
.entry-summary {
    font-family: var(--serif);
    font-size: var(--fs-body);
    line-height: 1.6;
    color: var(--text-2);
    text-wrap: pretty;
}

.entry-body {
    margin-top: 0.75rem;
}

.entry-summary {
    display: block;
    margin-top: 0.35rem;
}

/* ---------- Hover cards ----------
   Projects and experience entries have no visible box until you hover them.
   The card is drawn just outside the text, so nothing moves when it appears.
   Only in the laptop/desktop layout with a mouse; phones and tablets stay clean. */
@media (hover: hover) and (min-width: 60rem) {
    .entry {
        position: relative;
        isolation: isolate;
    }

    .entry::before {
        content: '';
        position: absolute;
        inset: -1.25rem -1.5rem;
        z-index: -1;
        border-radius: 16px;
        background: var(--card-bg);
        border: 1px solid var(--card-border);
        box-shadow: var(--card-shadow);
        -webkit-backdrop-filter: blur(14px) saturate(1.3);
                backdrop-filter: blur(14px) saturate(1.3);
        opacity: 0;
        transform: scale(0.985);
        transition: opacity 0.3s ease, transform 0.3s ease;
        pointer-events: none;
    }

    .entry:hover::before,
    .entry:focus-within::before {
        opacity: 1;
        transform: scale(1);
    }
}

@media (hover: hover) and (min-width: 60rem) and (prefers-reduced-motion: reduce) {
    .entry::before { transition: opacity 0.2s ease; transform: none; }
}

/* ---------- Projects: expand in place ---------- */
.project summary {
    list-style: none;
    cursor: pointer;
}

.project summary::-webkit-details-marker {
    display: none;
}

.project summary:hover .entry-title {
    color: var(--accent);
}

.more {
    display: inline-block;
    margin-top: 0.6rem;
    font-size: var(--fs-ui);
    font-weight: 500;
    color: var(--link);
    transition: color 0.2s ease;
}

.project summary:hover .more {
    color: var(--accent);
}

.more::after         { content: "Read more"; }
.project[open] .more::after { content: "Show less"; }

/* Phones: projects open as their own page, so the cue says so */
@media (max-width: 47.99rem) {
    .more::after,
    .project[open] .more::after { content: "View project  →"; white-space: pre; }
}

.project-detail {
    padding-top: 1.75rem;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 9rem), 1fr));
    gap: 0.75rem;
    margin-bottom: 1.75rem;
}

.gallery img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    background: var(--placeholder);
    border-radius: 2px;
}

/* ---------- About: text with the photo beside it ----------
   Phones & narrow screens: photo above the text.
   Wider right panel: text on the left, photo in a narrow column on the right,
   staying in view while you scroll through the About text.                    */
.about {
    display: grid;
}

.portrait {
    order: -1;                  /* above the text when stacked */
    max-width: 12rem;
    margin-bottom: 2rem;
}

.portrait img {
    width: 100%;
    border-radius: 2px;
    filter: grayscale(100%);
    transition: filter 0.3s ease;
}

.portrait img:hover {
    filter: grayscale(70%);
}

@container (min-width: 44rem) {
    .about {
        grid-template-columns: minmax(0, var(--measure)) var(--aside);
        column-gap: var(--gap);
        align-items: start;
    }

    .portrait {
        order: 0;               /* back to the right of the text */
        max-width: none;
        margin: 0;
        padding-top: 0.45rem;   /* top of the photo sits level with the first line */
        position: sticky;
        top: 2.5rem;
    }
}

/* ---------- "View full résumé" link under Experience ---------- */
.section-more {
    margin-top: clamp(2.5rem, 5vw, 3.5rem);
}

.section-more a {
    font-size: var(--fs-ui);
    font-weight: 500;
}

/* ---------- Footer ---------- */
.site-footer {
    padding-block: clamp(6rem, 14vw, 9rem) 3rem;
    font-size: 0.8125rem;
    color: var(--text-3);
}

.site-footer a {
    font-weight: 500;
}

/* ---------- Project page (phones only) ---------- */
.sheet {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: var(--bg);
    color: var(--text);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sheet::backdrop {
    background: var(--bg);
}

.sheet[open] {
    animation: sheetIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes sheetIn {
    from { transform: translateX(100%); }
    to   { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .sheet[open] { animation: none; }
}

/* Stop the page behind from scrolling */
body:has(.sheet[open]) {
    overflow: hidden;
}

.sheet-head {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 0.5rem var(--gutter);
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
}

.sheet-back {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: -0.35rem;
    padding: 0.6rem 0.35rem;
    font: inherit;
    font-size: var(--fs-ui);
    color: var(--text);
    background: none;
    border: 0;
    cursor: pointer;
}

.sheet-back svg {
    width: 1.125rem;
    height: 1.125rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sheet-body {
    padding: 2.25rem var(--gutter) 4rem;
}

.sheet-title {
    font-family: var(--serif);
    font-size: var(--fs-title);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin-top: 0.5rem;
}

.sheet-summary {
    font-family: var(--serif);
    font-size: var(--fs-prose);
    line-height: 1.6;
    color: var(--text-2);
    margin-top: 1rem;
}

/* ---------- Button (used on the 404 page) ---------- */
.button {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.7rem 1.25rem 0.7rem 1rem;
    font-family: var(--sans);
    font-size: var(--fs-ui);
    font-weight: 500;
    color: var(--bg);
    background: var(--text);
    border-radius: 999px;
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.button:hover {
    color: var(--bg);
    opacity: 0.85;
}

.button svg {
    width: 1rem;
    height: 1rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------- 404 page ---------- */
.not-found-page {
    display: flex;
    flex-direction: column;
    justify-content: center;            /* content sits in the middle of the screen */
    min-height: 100vh;
    min-height: 100dvh;
}

.not-found {
    width: 100%;
    padding-block: 4rem;
}

.not-found-code {
    font-family: var(--serif);
    font-size: clamp(5rem, 3rem + 10vw, 10rem);
    font-weight: 300;
    line-height: 0.9;
    letter-spacing: -0.03em;
    color: var(--text-3);
    margin-bottom: clamp(1.5rem, 4vw, 2.5rem);
}

.not-found .lede {
    max-width: 26ch;
    margin-bottom: 2.5rem;
}
