@layer base {
    html {
        scrollbar-gutter: stable both-edges;
        background: var(--page-bg);
        color: var(--page-text);
    }

    body {
        margin: 0;
        font-family: 'Merriweather', serif;
        font-weight: 500;
        font-variant-numeric: tabular-nums;
    }

    /* colors */
    :root {
        /* default (light theme) */
        --header-bg: #f7f4ed;
        --header-text: #2c2c2c;
        --page-bg: #f7f4ed;
        --page-text: #2c2c2c;
        --header-height: 3.25rem;
        --star-bright: rgba(29, 28, 26, 0.65);
        --star-dim: rgba(29, 28, 26, 0.55);
    }

    /* Follow system if no manual choice */
    @media (prefers-color-scheme: dark) {
        :root {
            --header-bg: #2c2c2c;
            --header-text: #f7f4ed;
            --page-bg: #2c2c2c;
            --page-text: #f7f4ed;
            --star-bright: rgba(247, 244, 237, 0.65);
            --star-dim: rgba(247, 244, 237, 0.55);
        }
    }

    /* starry background */
    body {
        background-image:
            /* big bright stars */
            radial-gradient(2px 2px at 10% 20%, var(--star-bright) 99%, transparent),
            radial-gradient(2px 2px at 80% 15%, var(--star-bright) 99%, transparent),

            /* medium stars */
            radial-gradient(1.5px 1.5px at 25% 40%, var(--star-dim) 99%, transparent),
            radial-gradient(1.5px 1.5px at 60% 10%, var(--star-dim) 99%, transparent),
            radial-gradient(1.5px 1.5px at 75% 80%, var(--star-dim) 99%, transparent),

            /* small base stars */
            radial-gradient(1px 1px at 5% 90%, var(--star-bright) 99%, transparent),
            radial-gradient(1px 1px at 95% 25%, var(--star-dim) 99%, transparent),
            radial-gradient(1px 1px at 35% 15%, var(--star-dim) 99%, transparent),
            radial-gradient(1px 1px at 70% 55%, var(--star-bright) 99%, transparent),
            radial-gradient(1px 1px at 20% 75%, var(--star-bright) 99%, transparent);
        background-repeat: no-repeat;
        background-attachment: fixed;
    }

    /* Layer A: slower, deeper twinkle */
    body::before {
        content: "";
        position: fixed;
        inset: 0;
        pointer-events: none;
        background-image:
            radial-gradient(2px 2px at 50% 70%, var(--star-bright) 99%, transparent),
            radial-gradient(1px 1px at 15% 50%, var(--star-dim) 99%, transparent),
            radial-gradient(1px 1px at 45% 85%, var(--star-dim) 99%, transparent),
            radial-gradient(1px 1px at 90% 45%, var(--star-bright) 99%, transparent),
            radial-gradient(1px 1px at 65% 25%, var(--star-dim) 99%, transparent);
        background-repeat: no-repeat;
        animation: twinkle-slow 10s ease-in-out infinite alternate;
        opacity: 0.6;
        /* base depth */
    }

    /* Layer B: faster, nearer twinkle (slight offset & different stars) */
    body::after {
        content: "";
        position: fixed;
        inset: 0;
        pointer-events: none;
        background-image:
            radial-gradient(1px 1px at 12% 78%, var(--star-bright) 99%, transparent),
            radial-gradient(1px 1px at 30% 55%, var(--star-bright) 99%, transparent),
            radial-gradient(1px 1px at 55% 40%, var(--star-dim) 99%, transparent),
            radial-gradient(1px 1px at 85% 65%, var(--star-bright) 99%, transparent);
        background-repeat: no-repeat;
        animation: twinkle-fast 6s ease-in-out infinite alternate;
        animation-delay: -2s;
        /* desync the rhythm */
        opacity: 0.8;
    }

    /* Keyframes: different ranges for subtle variety */
    @keyframes twinkle-slow {
        0% {
            opacity: 0.25;
        }

        50% {
            opacity: 0.9;
        }

        100% {
            opacity: 0.35;
        }
    }

    @keyframes twinkle-fast {
        0% {
            opacity: 0.4;
        }

        50% {
            opacity: 1;
        }

        100% {
            opacity: 0.5;
        }
    }

    /* Respect users who prefer less motion */
    @media (prefers-reduced-motion: reduce) {

        body::before,
        body::after {
            animation: none !important;
            opacity: 0.7 !important;
        }
    }

    li+li {
        margin-top: .5em;
    }
}


h1 {
    text-align: center;

    &.welcome {
        font-size: 3rem;
        line-height: 1.2;
        margin-top: 8rem;
        margin-bottom: 7rem;
        font-weight: 600;
    }
}

main p.no-margin {
    margin: 0;
}

/* .text replacement in zola .md */
main:not(:has(.text-home)) p {
    text-align: justify;
    letter-spacing: normal;
    line-height: 1.4;
    text-indent: 3rem;
}

section {
    margin-top: 5rem;
    margin-bottom: 5rem;
}

main {
    margin: 0;
    max-width: 50rem;
    margin-inline: auto;
    /* center horizontally when viewport > max-width */
    padding-inline: 1rem;
    /* small side padding for narrow screens */
    min-height: 0;

    .page-content .center {
        text-align: center;
        text-indent: 0;
    }
}

@media (min-width: 60rem) {
    main {
        padding-inline: 2rem;
        /* more breathing room on big screens */
        margin-inline: auto;
    }
}


/* blog images */
.blog-image {
    margin: 1.5rem 0 0.5rem;

    summary {
        list-style: none;
        display: flex;
        justify-content: center;
        cursor: zoom-in;
    }

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

    img {
        display: block;
        width: auto;
        height: auto;
        max-width: min(100%, 36rem);
        transition: max-width 200ms ease;
    }

}

.blog-image[open] {
    summary {
        cursor: zoom-out;
    }

    img {
        max-width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .blog-image img {
        transition: none;
    }
}

.blog-image-description {
    text-align: center;
    font-style: italic;
    text-indent: 0;
    font-size: 0.85rem;
    line-height: 1.35;
    opacity: 0.75;
    margin: 0.25rem auto 1.5rem;
    max-width: 36rem;
}

/* ==================================================== */
/* underscore styles */
/* reset the default underline + basic look */
:where(p a, .nav a, .entry a, main a) {
    position: relative;
    text-decoration: none;
    /* remove default */
    color: var(--header-text);
    transition: color .2s ease;
    width: max-content;
}

/* the custom underline (hidden initially via scaleX(0)) */
:where(.nav a, .entry a, main a, .entry-title)::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -2px;
    width: 100%;
    /* underline position */
    height: 2px;
    background: var(--header-text);
    transform: scaleX(0);
    transform-origin: left center;
    border-radius: 999px;
}

a:not(.entry-title-no-link)::after {
    transition: transform 220ms cubic-bezier(.2, .8, .2, 1);
}

.entry-title::after {
    transition: transform 0.3s ease;
}

/* hover/focus shows the animated underline */
:where(a):not(.entry-title-no-link, .icon-link):is(:hover, :focus-visible)::after,
button:hover::after {
    transform: scaleX(1);
}


/* ==================================================== */
.header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--header-bg);
    color: var(--header-text);
    margin-bottom: 4rem;
}

.header::after {
    content: "";
    display: block;
    height: 2px;
    max-width: 52rem;
    /* match main +2rem */
    margin-inline: auto;
    /* center it */
    background: currentColor;
    border-radius: 999px;
    transform: scaleX(0);
    opacity: 0;
    transform-origin: center;
}

/* Center the header contents like main */
.header-inner {
    max-width: 50rem;
    /* match main’s max-width */
    margin-inline: auto;
    /* center */
    padding: 0.5rem 1rem;
    align-items: center;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    /* left | center | right */

    .header-left {
        justify-self: start;
    }

    .header-center {
        justify-self: center;
    }

    .header-right {
        justify-self: end;
    }

    .nav {
        margin-block-start: 1em;
    }
}

/* current page: underline is always visible */
.nav a[aria-current="page"]::after {
    transform: scaleX(1);
}


footer {
    text-align: center;
    padding: 1rem;
    position: sticky;
    top: 100dvh;
    /* stick to the bottom edge of the viewport */
}

.page {
    min-height: 100dvh;
    /* full height, mobile-safe */

    flex-direction: column;
}

/* header underline animation */
/* animate the line as the page scrolls */
@keyframes header-underline {
    from {
        transform: scaleX(0);
        opacity: 0;
    }

    to {
        transform: scaleX(1);
        opacity: 1;
    }
}

/* modern browsers: ties the animation to the document scroll */
@supports (animation-timeline: scroll(root block)) {
    .header::after {
        animation-name: header-underline;
        animation-timeline: scroll(root block);
        /* grow from 0→1 over the first 80px of scroll */
        animation-range: 0 80px;
        animation-fill-mode: both;
        /* keep the end state */
    }
}

/* fallback: if scroll-driven animations aren’t supported, just shows the line */
@supports not (animation-timeline: scroll(root block)) {
    .header::after {
        transform: scaleX(1);
        opacity: 1;
    }
}

/* ==================================================== */
/* text rotator */
.text-rotator {
    display: inline-block;
    overflow: hidden;
    height: 1em;
    /* one line tall so only one word shows */
    vertical-align: baseline;

    /* Stacks the two words vertically and animate the TRACK, not each word */
    .track {
        display: block;
        will-change: transform;
        animation: swap 30s ease-in-out infinite;
    }

    .track>span {
        display: block;
        /* “Welcome” (line 1), “Fáilte” (line 2) */
    }
}

/* Even timing:
   - 0–40%: show Welcome
   - 40–50%: slide up to Fáilte
   - 50–90%: hold on Fáilte
   - 90–100%: slide back to Welcome
*/
@keyframes swap {

    0%,
    45% {
        transform: translateY(-0%);
    }

    50%,
    95% {
        transform: translateY(-50%);
    }

    100% {
        transform: translateY(0%);
    }
}

/* Motion safety */
@media (prefers-reduced-motion: reduce) {
    .text-rotator .track {
        animation: none;
        transform: translateY(0%);
    }
}

/* ==================================================== */
/* the culture */
@layer the-culture {
    .entry {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 1rem;
        /* breathing room between left/right */
        margin-bottom: 1.5rem;
        /* space between entries */
        padding: 0.75rem 0;
        border-bottom: 1px solid currentColor;
    }

    /* Left column: title + meta stacked */
    .entry-info {
        display: flex;
        flex-direction: column;
        gap: .35rem;
        /* space between title and meta */
        min-width: 0;
        /* allow long titles to wrap nicely */
    }

    .entry-title {
        width: max-content;
    }

    /* The extra line(s) under the title */
    .entry-meta {
        font-size: .9rem;
        line-height: 1.6;
        opacity: .8;
        /* softer than title without needing a new color var */
    }

    /* Keeps the links on the right from shrinking */
    .entry-links {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* On very narrow screens, the right column drops under */
    @media (max-width: 34rem) {
        .entry {
            flex-wrap: wrap;
        }

        .entry-links {
            margin-top: .5rem;
        }
    }

    .entry-links a {
        margin-left: 1rem;
    }

    .culture-essays,
    .culture-interviews,
    .other {
        content-visibility: auto;
        contain-intrinsic-size: 800px;
    }

    ul.entries {
        padding-inline-start: 0;
    }

    /* sticky titles */
    h2 {
        position: sticky;
        top: calc(var(--header-height) + 0rem);
        /* sits just under header */
        z-index: 5;
        /* above entries */
        background: var(--page-bg);
        /* so text doesn’t overlap content behind */
        padding-block: .25rem;
        /* small breathing room */
        /* optional: a soft underline on the sticky title itself */
        box-shadow: 0 1px 0 0 color-mix(in oklab, currentColor 35%, transparent);
        /* When you jump via anchors, don’t hide the title under the sticky header */
        scroll-margin-top: calc(var(--header-height) + 0.75rem);
        margin-top: 2em;
    }

    .h2-offset {
        margin-top: 6em;
    }


    h3 {
        text-align: center;
        margin-block-end: 3em;
    }

    h4 {
        margin-block-start: 3em;
    }

    .marain-images {
        text-align: center;
        background-color: #f7f4ed;
        margin-bottom: 1em;
        margin-top: 1em;
    }
}

/* ==================================================== */
/* tooltips */
@layer tooltips {

    /* Wrapper ensures the tooltip positions relative to the trigger */
    .tip-wrap {
        position: relative;
        display: inline-block;
    }

    /* Hide by default (keep screen-reader accessible via aria) */
    .tooltip {
        position: absolute;
        inset-inline-start: 50%;
        inset-block-end: calc(100% + .5rem);
        /* place above the link */
        transform: translateX(-50%) translateY(.25rem);
        min-width: 12rem;
        max-width: 50rem;
        text-align: center;
        padding: .5rem .75rem;
        background: var(--page-bg);
        color: var(--page-text);
        border-radius: .5rem;
        box-shadow: 0 4px 20px var(--page-text);
        font-size: .9rem;
        line-height: 1.35;

        opacity: 0;
        pointer-events: none;
        transition: opacity .18s ease, transform .18s ease;
        z-index: 5;
        white-space: normal;
        /* allow wrapping */
    }

    /* Little arrow */
    .tooltip::after {
        content: "";
        position: absolute;
        inset-inline-start: 50%;
        inset-block-start: 100%;
        transform: translateX(-50%);
        border: 6px solid transparent;
        border-block-start-color: currentColor;
        opacity: .15;
        /* soft arrow via color bleed */
    }

    .tooltip {
        color: inherit;
    }

    /* for the arrow color trick */
    .tooltip>* {
        color: var(--page-text);
    }

    /* real text color */

    /* Show on hover/focus of the trigger */
    .has-tip:focus+.tooltip,
    .has-tip:hover+.tooltip {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
        pointer-events: auto;
    }

    /* Keyboard focus ring for accessibility (if you don’t already have one) */
    .has-tip:focus {
        outline: 2px solid currentColor;
        outline-offset: 2px;
    }

    /* Motion safety */
    @media (prefers-reduced-motion: reduce) {
        .tooltip {
            transition: none;
            transform: translateX(-50%) translateY(0);
        }
    }
}

/* ================================*/
/* logos */
@layer logos {
    .icon-link {
        display: inline-flex;
        align-items: center;
        color: inherit;
        text-decoration: none;
        transition: transform 0.2s ease;

        &:hover {
            transform: scale(1.1);
        }

        svg {
            margin-left: 0.25rem;
        }
    }
}

/* ==================================== */
/* projects */
.project-image {
    max-height: 5.5rem;
    border-radius: .3rem;
    border: solid 1px var(--page-text);
    filter: grayscale(75%);
}

/* ==================================== */
/* blog */
.post-item {
    display: grid;
    grid-template-columns: 7rem 1fr;
    column-gap: 1rem;
    align-items: start;
}

.post-text a {
    display: inline-block;
}

.post-subtitle {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-top: 0.15rem;
}

/* Epigraph */
.epigraph {
    margin: 1.5rem 0;
    font-style: italic;
    text-align: right;
    font-size: 0.95rem;

    blockquote { margin: 0; }
    figcaption {
        margin-top: 0.35rem;
        font-weight: 600;
        font-size: 0.9rem;
        opacity: 0.85;
    }
}