* {
    box-sizing: border-box;
}

/* ---------- Colour themes ---------- */
/* Dark is the default. The button in the nav bar switches to light by setting
   data-theme="light" on <html>, which swaps every colour below at once. */
:root {
    color-scheme: dark;
    --bg: #000000;
    --text: #ffffff;
    --text-muted: #aaaaaa;
    --text-dim: #888888;
    --card: #151515;
    --border: #2a2a2a;
    --border-mid: #333333;
    --border-strong: #444444;
    --accent: #7cc4ff;
    --bar-bg: rgba(0, 0, 0, 0.75);
    --backdrop: rgba(0, 0, 0, 0.75);
    --icon-filter: invert(1);
    --icon-filter-hover: none;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f6f6f4;
    --text: #111111;
    --text-muted: #555555;
    --text-dim: #666666;
    --card: #ffffff;
    --border: #e0e0e0;
    --border-mid: #d4d4d4;
    --border-strong: #c2c2c2;
    --accent: #1a6fc9;
    --bar-bg: rgba(246, 246, 244, 0.8);
    --backdrop: rgba(0, 0, 0, 0.45);
    --icon-filter: none;
    --icon-filter-hover: invert(1);
}

body {
    transition: background-color 0.3s, color 0.3s;
}

html {
    scroll-behavior: smooth;
    font-size: 20px;   /* base text size (browser default is 16px); all rem sizes scale from this */
}

body {
    margin: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
}

h1, h2, h3, p {
    color: var(--text);
}

p {
    overflow-wrap: anywhere;
}

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

h2 {
    font-size: 2.5rem;
    margin-top: 0;
    text-align: center;   /* centres the section headings */
    margin-bottom: 3rem;  /* space between the heading and the content below */
}

/* ---------- Top navigation bar + scroll progress ---------- */
:root {
    --nav-height: 3.5rem;
}

/* Clicking a nav link stops the section just below the bar, not underneath it */
section {
    scroll-margin-top: var(--nav-height);
}

.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bar-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Three columns: name on the left, links in the middle, empty space on the right
   (the empty column keeps the links centred on the page) */
.top-nav {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: var(--nav-height);
    padding: 0 1.5rem;
}

.top-nav .brand {
    justify-self: start;
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    padding: 0;
    background: none;
}

.top-nav ul {
    list-style: none;
    margin: 0;
    padding: 0 1rem;
    height: var(--nav-height);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(0.5rem, 3vw, 2.5rem);
}

.top-nav a {
    display: block;
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.2s, background-color 0.2s;
}

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

/* The section you're currently in */
.top-nav a.active {
    color: var(--bg);
    background-color: var(--text);
}

/* Light/dark mode button, top-right of the nav bar */
.theme-toggle {
    justify-self: end;
    display: grid;
    place-items: center;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
    background: var(--text);
    color: var(--bg);
}

.theme-toggle svg {
    width: 1.2rem;
    height: 1.2rem;
}

/* Show the sun in dark mode (click for light) and the moon in light mode */
.theme-toggle .icon-moon,
:root[data-theme="light"] .theme-toggle .icon-sun {
    display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
    display: block;
}

/* Grows from left to right as you scroll down the page (driven by main.js) */
.progress-bar {
    height: 3px;
    background: var(--accent);
    transform-origin: left;
    transform: scaleX(0);
}

/* ---------- 1. Intro ---------- */
.hero {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    min-height: 100vh;
    padding: calc(var(--nav-height) + 2rem) 2rem 2rem;   /* top padding clears the nav bar */
    overflow-x: hidden;
}

.hero img {
    flex: 0 0 auto;
    height: 80vh;          /* 80% of the window height */
    width: auto;           /* width follows from the photo's shape */
    max-width: 50vw;       /* stops it squeezing the text on narrow windows */
    object-fit: cover;
    margin: clamp(1rem, 4vw, 4rem);   /* space around the image, grows with the window */
    border-radius: 12px;
}

.hero .greeting {
    flex: 0 1 auto;        /* only as wide as the text needs, so the pair stays centred */
    max-width: 40rem;
    min-width: 0;
}

.hero .greeting p {
    line-height: 1.9;      /* more space between lines (the rest of the page uses 1.6) */
}

.button {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.75rem 1.75rem;
    border: 2px solid var(--text);
    border-radius: 999px;
    color: var(--text);
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s;
}

/* Lets <button> elements use the same look as link buttons */
button.button {
    background: transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.button.small {
    margin-top: 0.75rem;
    padding: 0.4rem 1.1rem;
    font-size: 0.9rem;
}

.button:hover {
    background-color: var(--text);
    color: var(--bg);
}

/* ---------- Shared section layout (About, Contact) ---------- */
.content {
    min-height: 100vh;
    max-width: 1000px;
    margin: 0 auto;
    padding: 6rem 2rem;
}

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

.card h3 {
    margin-top: 0;
}

/* ---------- 2. About ---------- */
.about-grid {
    display: grid;
    grid-template-columns: 1fr;   /* one column: cards stack, all the same width */
    gap: 1.5rem;
    margin-top: 2rem;
}

.timeline {
    list-style: none;
    padding: 0;
    margin: 0;
}

.timeline > li {
    padding-left: 1rem;
    border-left: 2px solid var(--accent);
    margin-bottom: 1rem;
}

.timeline span {
    display: block;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Education entries: university logo on top, details underneath */
.timeline > li.edu {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.edu-logo {
    flex: 0 0 auto;
    width: 180px;
    height: auto;
    padding: 0.4rem;
    background: white;      /* the logos are dark on transparent, so they need a light tile */
    border: 1px solid var(--border);   /* keeps the tile visible on white cards in light mode */
    border-radius: 8px;
}

/* Experience entries: organisation icon on the left, details on the right */
.timeline > li.exp {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.exp-icon {
    flex: 0 0 auto;
    width: 56px;
    height: 56px;
    object-fit: contain;    /* fits both the tall EUFS logo and the round UoE crest */
    padding: 0.3rem;
    background: white;      /* the icons have black parts, so they need a light tile */
    border: 1px solid var(--border);   /* keeps the tile visible on white cards in light mode */
    border-radius: 8px;
}

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

.skills li {
    padding: 0.35rem 0.9rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-size: 0.9rem;
}

.card h4 {
    margin: 1rem 0 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.points {
    margin: 0.5rem 0 0;
    padding-left: 1.2rem;
}

.points li {
    margin-bottom: 0.35rem;
}

.interests {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.interests li {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.interests span {
    display: block;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* ---------- 3. Projects (horizontal scroll) ---------- */
.projects {
    padding-top: 6rem;
}

.projects h2 {
    padding: 0 2rem;
    margin-bottom: 2rem;   /* space between the heading and the cards */
    font-size: 2rem;
}

/* Tall wrapper: its height (set in main.js) controls how long you scroll
   before the cards finish sliding. */
.projects-scroller {
    position: relative;
}

/* Pinned just below the nav bar, using the full remaining window height */
.projects-sticky {
    position: sticky;
    top: var(--nav-height);
    height: calc(100vh - var(--nav-height));
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: safe center;   /* heading + cards centred together (never pushed under the nav bar) */
    padding: 0.75rem 0;
}

.projects-track {
    display: flex;
    flex: 0 1 auto;            /* may shrink to the space left under the heading... */
    min-height: 0;             /* ...which makes the card pictures shrink to fit */
    gap: 2rem;                 /* space between project cards */
    list-style: none;
    margin: 0;
    padding: 0 2rem;
    width: max-content;        /* lets main.js measure the full row of cards */
}

/* Vertical line separating the current project from past projects */
.project-divider {
    flex: 0 0 auto;
    width: 2px;
    align-self: stretch;
    margin: 1.5rem 0.5rem;
    border-radius: 2px;
    background: var(--border-strong);
}

/* Small "Current" label on the current project's card */
.badge-current {
    display: inline-block;
    margin-right: 0.4rem;
    padding: 0.05rem 0.6rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--bg);
    font-size: 0.8rem;
    font-weight: 700;
    vertical-align: 0.1em;
}

.project {
    flex: 0 0 auto;
    display: flex;
}

.project-card h3 {
    font-size: 1.6rem;
    text-align: center;
    margin: 0 0 0.75rem;
    line-height: 1.3;
    /* main.js gives every title the height of the tallest one;
       shorter titles sit centred in that space */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Picture under each project title; swap the src in index.html for a real photo or GIF */
.project-media {
    display: block;
    width: 100%;
    /* 24% of the window height (max 320px). On short windows it shrinks
       (down to 60px) by however much is needed for the whole card to fit. */
    height: min(24vh, 320px);
    flex: 0 1 auto;
    min-height: 60px;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.project-card .project-meta {
    color: var(--text-muted);
}

.project-card .skills {
    margin-top: 1rem;
}

.project-card {
    width: min(600px, 80vw);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.25rem 2rem;
}

.project-card .button {
    margin-top: 0.5rem;
}

.project-card p {
    margin: 0.5rem 0;
}

/* Cards are columns so the footer (line + button) always sits at the bottom */
.project-card {
    display: flex;
    flex-direction: column;
}

/* Only the picture shrinks when space is short; everything else keeps its size */
.project-card > * {
    flex-shrink: 0;
}

.project-card > .project-media {
    flex-shrink: 1;
}

.project-footer {
    margin-top: auto;
    padding-top: 0.75rem;
}

.project-footer hr {
    border: none;
    border-top: 1px solid var(--border-mid);
    margin: 0 0 0.75rem;
}

.project-footer .button {
    margin-top: 0;
}

/* On the card, the description is cut to 3 lines ("..."); the pop-up shows it in full */
.project-card > p:not(.project-meta) {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

/* Only visible inside the pop-up */
.project-details {
    display: none;
}

/* ---------- Project pop-up ---------- */
/* Stop the page behind from scrolling while the pop-up is open */
html:has(.project-modal[open]) {
    overflow: hidden;
}

.project-modal {
    width: min(760px, 92vw);
    max-height: 88vh;
    padding: 0;
    border: 1px solid var(--border-mid);
    border-radius: 16px;
    background: var(--card);
    color: var(--text);
    overflow: auto;
}

.project-modal::backdrop {
    background: var(--backdrop);
    backdrop-filter: blur(4px);
}

.project-modal[open]::backdrop {
    animation: backdrop-fade 0.3s ease;
}

@keyframes backdrop-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-inner {
    position: relative;
    padding: 2.5rem 2rem 2rem;
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--border-strong);
    border-radius: 50%;
    background: transparent;
    color: var(--text);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    background: var(--text);
    color: var(--bg);
}

.project-modal h3 {
    font-size: 1.9rem;
    text-align: center;
    line-height: 1.3;
    margin: 0 2rem 1rem;
}

.project-modal .project-media {
    /* Full width at the media's own shape: nothing is cropped or stretched.
       If it's taller than the pop-up, the pop-up scrolls. */
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: auto;    /* overrides the 16:9 card shape used on phones */
    object-fit: contain;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.project-modal .project-meta {
    color: var(--text-muted);
}

.project-modal .skills {
    margin-top: 1rem;
}

.project-modal .project-details {
    display: block;
    margin-top: 1rem;
}

/* ---------- 4. Contact ---------- */
/* Only as tall as its content, so there's no empty space at the end of the page */
#contact {
    min-height: auto;
    padding-bottom: 25%;
}

.contact-list {
    list-style: none;
    padding: 0;
    font-size: 1.2rem;
}

.contact-list {
    display: flex;
    flex-direction: column;
    align-items: center;      /* capsules centred on the page */
    gap: 1rem;
    margin: 1.5rem 0 0;
}

/* Capsule around each contact method */
.contact-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1.4rem 0.6rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: var(--card);
    color: var(--text);
    text-decoration: none;
}

/* LinkedIn and GitHub capsules are buttons */
.contact-pill.is-button {
    border: 2px solid var(--text);
    font-weight: 600;
    transition: background-color 0.2s, color 0.2s, transform 0.2s;
}

.contact-pill.is-button:hover {
    background: var(--text);
    color: var(--bg);
    transform: translateY(-2px);
}

.contact-pill.is-button:hover .contact-icon {
    filter: var(--icon-filter-hover);   /* keep the icon visible on the filled button */
}

/* Drawn icons (like the download arrow) use the text colour, so no filter is needed */
.contact-icon.svg-icon,
.contact-pill.is-button:hover .contact-icon.svg-icon {
    filter: none;
}

.pill-arrow {
    font-size: 0.9em;
    opacity: 0.7;
}

.contact-icon {
    width: 28px;
    height: 28px;
    filter: var(--icon-filter);   /* black icons: turned white in dark mode, left black in light mode */
}

/* ---------- Phones ---------- */
@media (max-width: 700px) {
    .hero {
        flex-direction: column;
        text-align: center;
        padding: calc(var(--nav-height) + 1rem) 1rem 2rem;
    }


    .hero img {
        max-width: 100%;
        margin: 1.5rem auto;
    }

    h2 {
        font-size: 2rem;
    }

    /* On phones the projects stack vertically instead of sliding sideways
       (main.js turns the horizontal scroll off at this width) */
    .projects {
        padding-top: 4rem;
    }

    .projects-scroller {
        height: auto !important;
    }

    .projects-sticky {
        position: static;
        height: auto;
        overflow: visible;
        padding: 0 0 2rem;
    }

    .projects-track {
        flex-direction: column;
        width: auto;
        padding: 0 1rem;
        transform: none !important;
    }

    .project-divider {
        width: auto;
        height: 2px;
        margin: 0.5rem 1.5rem;
    }

    .project-card {
        width: 100%;
        padding: 1.25rem;
    }

    .project-card h3 {
        font-size: 1.35rem;
    }

    .project-media {
        height: auto;
        aspect-ratio: 16 / 9;
    }

    .modal-inner {
        padding: 2.5rem 1.25rem 1.5rem;
    }

    .project-modal h3 {
        font-size: 1.4rem;
        margin: 0 1.5rem 0.75rem;
    }

    /* Not enough room for the name and the links on phones */
    .top-nav {
        display: block;
        padding: 0;
    }

    .top-nav .brand {
        display: none;
    }

    /* The blur would trap the floating button inside the bar, so use a solid bar on phones */
    .top-bar {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--bg);
    }

    /* On phones the button floats in the bottom-right corner instead */
    .theme-toggle {
        position: fixed;
        right: 1rem;
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
        width: 2.8rem;
        height: 2.8rem;
        background: var(--card);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    }

    .top-nav a {
        padding: 0.35rem 0.6rem;
        font-size: 0.85rem;
    }
}
