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

:root {
    --bg-deep: #0f1624;
    --bg-base: #141c2e;
    --bg-raised: #1b253c;
    --bg-card: #212c45;

    --green: #34d9b0;
    --blue: #5ba8e6;
    --red: #e8606b;
    --accent: #6bb8f0;

    --text: #cdd5e0;
    --text-muted: #94a3b8;
    --text-heading: #ffffff;

    --content-width: 72ch;
    --page-width: 68.75rem;
    --header-height: calc(2.5rem + 49px);

    --gutter: max(5%, calc(50% - var(--page-width) / 2));
    --ease: 0.2s ease;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family:
        system-ui,
        -apple-system,
        sans-serif;
    font-size: 1.0625rem;
    line-height: 1.75;
    color: var(--text);
    background-color: var(--bg-base);
    -webkit-font-smoothing: antialiased;
}

/* --- Layout --- */

.prose {
    max-width: var(--content-width);
    margin: 0 auto;
}

section {
    padding: 5rem var(--gutter);
}

/* --- Typography --- */

h1,
h2,
h3 {
    font-weight: 600;
    color: var(--text-heading);
    line-height: 1.3;
}

h1 {
    font-size: 2.75rem;
    letter-spacing: -0.5px;
}

h2 {
    font-size: 1.75rem;
    margin-bottom: 2rem;
}

h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
}

p {
    margin-bottom: 1.25rem;
}

p:last-child {
    margin-bottom: 0;
}

a {
    color: var(--blue);
    text-decoration: none;
    transition: color var(--ease);
}

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

/* --- Header --- */

body > header {
    position: sticky;
    top: 0;
    z-index: 200;
    padding: 1.25rem var(--gutter);
    background: var(--bg-deep);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
}

.logo img {
    display: block;
    border-radius: 8px;
}

.site-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-heading);
    margin-left: 1rem;
    margin-right: auto;
    white-space: nowrap;
}

.site-name:hover {
    color: var(--accent);
}

nav ul {
    display: flex;
    gap: 2rem;
    list-style: none;
}

nav a {
    color: var(--text-muted);
    font-size: 0.9375rem;
    font-weight: 500;
    padding: 0.25rem 0;
    border-bottom: 2px solid transparent;
    transition:
        color var(--ease),
        border-color var(--ease);
}

nav a:hover {
    color: var(--text-heading);
    border-bottom-color: var(--accent);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    margin-left: 1rem;
}

.hamburger {
    display: block;
    position: relative;
    width: 22px;
    height: 2px;
    background: var(--text-muted);
    transition: all 0.2s;
}

.hamburger::before,
.hamburger::after {
    content: "";
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--text-muted);
    transition: all 0.2s;
}

.hamburger::before {
    top: -7px;
}

.hamburger::after {
    bottom: -7px;
}

.nav-toggle[aria-expanded="true"] .hamburger {
    background: transparent;
}

.nav-toggle[aria-expanded="true"] .hamburger::before {
    transform: translateY(7px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .hamburger::after {
    transform: translateY(-7px) rotate(-45deg);
}

/* --- Sub-navigation --- */

.subnav-wrap {
    position: sticky;
    top: var(--header-height);
    z-index: 150;
    background: var(--bg-raised);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    /* anchor for fade overlays */
    isolation: isolate;
}

.subnav {
    overflow-x: auto;
    scrollbar-width: none;
    padding-inline: var(--gutter);
    -webkit-overflow-scrolling: touch;
}

.subnav-fade-right,
.subnav-fade-left {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2.5rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--ease);
    z-index: 1;
}

.subnav-fade-left {
    left: 0;
    background: linear-gradient(to right, var(--bg-raised), transparent);
}

.subnav-fade-right {
    right: 0;
    background: linear-gradient(to left, var(--bg-raised), transparent);
}

.subnav-wrap.can-scroll-left .subnav-fade-left,
.subnav-wrap.can-scroll-right .subnav-fade-right {
    opacity: 1;
}

.subnav::-webkit-scrollbar {
    display: none;
}

.subnav ul {
    display: flex;
    gap: 0.25rem;
    list-style: none;
    padding: 0;
    min-width: max-content;
}

.subnav a {
    display: block;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.75rem 1rem;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition:
        color var(--ease),
        border-color var(--ease),
        background-color var(--ease);
}

.subnav a:hover,
.subnav a.active {
    color: var(--text-heading);
    border-bottom-color: var(--accent);
}

/* --- Page header --- */

main > header {
    background: var(--bg-raised);
    text-align: center;
    padding: 4rem var(--gutter) 5rem;
}

main > header h1 {
    margin-bottom: 1rem;
}

main > header .lead {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin-bottom: 0;
    max-width: var(--content-width);
    margin-left: auto;
    margin-right: auto;
}

/* --- Section variants --- */

.section-base {
    background: var(--bg-base);
}

.section-deep {
    background: var(--bg-deep);
}

/* --- Article --- */

article {
    margin-bottom: 3rem;
}

article:last-child {
    margin-bottom: 0;
}

article header h3 a {
    color: var(--text-heading);
}

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

.article-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0;
}

article img {
    width: 100%;
    max-height: min(280px, 40vw);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    object-fit: cover;
    margin-bottom: 1rem;
}

article p {
    line-height: 1.7;
}

.article-link {
    display: inline-block;
    font-weight: 500;
    font-size: 0.9375rem;
}

.article-link::after {
    content: " →";
}

/* --- Data table --- */

.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Monaco, Consolas, monospace;
    font-size: 0.9375rem;
}

.nowrap {
    white-space: nowrap;
}

thead {
    background: var(--bg-card);
}

thead th {
    color: var(--text-heading);
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.875rem 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background-color var(--ease);
}

tbody tr:hover {
    background: var(--bg-raised);
}

tbody td {
    padding: 0.75rem 1rem;
    color: var(--text);
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

.text-green {
    color: var(--green);
}

.text-red {
    color: var(--red);
}

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

.mb-2 {
    margin-bottom: 2rem;
}

/* --- Footer --- */

footer {
    background: var(--bg-deep);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding: 2rem var(--gutter);
    text-align: center;
}

footer p {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0;
}

footer .disclaimer {
    max-width: var(--content-width);
    margin: 0 auto 1.5rem;
    line-height: 1.7;
}

footer a {
    color: var(--text-muted);
}

footer a:hover {
    color: var(--text-heading);
}

/* --- Skip link --- */

.skip-link {
    position: absolute;
    top: -100%;
    left: 0.5rem;
    z-index: 999;
    background: var(--accent);
    color: var(--bg-deep);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.875rem;
}

.skip-link:focus {
    top: 0.5rem;
    color: var(--bg-deep);
}

/* --- Focus --- */

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

/* --- Prose content (markdown) --- */

.prose h2 {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    scroll-margin-top: calc(var(--header-height) + 3rem);
}

.prose h2:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.prose h3 {
    margin-top: 2rem;
}

.prose ul,
.prose ol {
    padding-left: 1.5rem;
    margin-bottom: 1.25rem;
}

.prose li {
    margin-bottom: 0.5rem;
}

.prose li p {
    margin-bottom: 0.5rem;
}

.prose hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin: 2.5rem 0;
}

.prose pre {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 1.25rem;
    overflow-x: auto;
    margin-bottom: 1.25rem;
    font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre;
    word-wrap: normal;
}

.prose code {
    background: var(--bg-card);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Monaco, Consolas, monospace;
    font-size: 0.9em;
}

.prose pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

.prose strong {
    color: var(--text-heading);
}

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

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* --- Responsive --- */

@media (max-width: 720px) {
    h1 {
        font-size: 2rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    main > header {
        padding: 3rem var(--gutter) 3.5rem;
    }

    main > header .lead {
        font-size: 1.1rem;
    }

    section {
        padding: 3.5rem var(--gutter);
    }

    /* Main nav mobile */
    #main-nav {
        position: fixed;
        top: var(--header-height);
        left: 0;
        width: 100%;
        background: var(--bg-deep);
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease-out;
        z-index: 100;
    }

    #main-nav.nav-active {
        max-height: 80vh;
    }

    #main-nav ul {
        flex-direction: column;
        align-items: center;
        gap: 0;
        padding: 1rem 0;
    }

    #main-nav a {
        display: block;
        padding: 0.75rem 1.5rem;
        border-bottom: none;
    }

    .nav-toggle {
        display: block;
    }

    /* Sub-nav: tighter on mobile */
    .subnav-wrap {
        top: var(--header-height);
    }

    .subnav {
        padding-inline: 1rem;
    }

    .subnav a {
        font-size: 0.8125rem;
        padding: 0.625rem 0.75rem;
    }

    article img {
        max-height: min(200px, 40vw);
    }
}
