/* ==========================================================================
   design tokens
   everything visual (color, spacing, type, radius) is defined once here.
   change a value in :root and it propagates everywhere — that's the
   "consistent pattern" that makes future pages/components trivial to add.
   ========================================================================== */
:root {
    /* color — "cutesy baby blue" light theme (default) */
    --color-bg: #eaf6ff;
    --color-surface: #d9edfb;
    --color-text: #22314a;
    --color-text-muted: #5c7089;
    --color-border: #bfe0f5;
    --color-accent: #f2508a;
    --color-accent-hover: #d63f75;
    --color-accent-contrast: #ffffff;

    /* type — system font stacks only. no @font-face, no font files to
       download: each OS resolves these to whatever it already ships
       (San Francisco on macOS/iOS, Segoe UI on Windows, Roboto on
       Android, etc.), so text paints on the first frame instead of
       waiting on a network request. headings get a slightly different
       stack (Trebuchet/Verdana-leaning) so they still read as visually
       distinct from body copy, echoing the old two-font structure. */
    --font-heading: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif;
    --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-size-base: clamp(1rem, 0.94rem + 0.3vw, 1.2rem);
    --font-size-lg: clamp(1.25rem, 1.1rem + 0.6vw, 1.75rem);
    --font-size-xl: clamp(1.75rem, 1.5rem + 1vw, 2.5rem);
    --line-height-base: 1.6;

    /* spacing scale (multiples of 0.5rem) */
    --space-1: 0.5rem;
    --space-2: 1rem;
    --space-3: 1.5rem;
    --space-4: 2.5rem;
    --space-5: 4rem;

    /* layout */
    --sidebar-width: 260px;
    --content-max-width: 68ch;
    --avatar-size: 110px;
    --radius: 0.5rem;

    /* motion */
    --transition-fast: 150ms ease;
}

/* dark tokens, reused by both the "follow system" case and the explicit
   toggle override below, so there's exactly one place that defines them. */
:root {
    --dark-color-bg: #121014;
    --dark-color-surface: #1c1a20;
    --dark-color-text: #f1f0f5;
    --dark-color-text-muted: #a7a5b0;
    --dark-color-border: #2e2c34;
    --dark-color-accent: #9083f7;
    --dark-color-accent-hover: #a89bff;
    --dark-color-accent-contrast: #121014;
}

/* case 1: no explicit choice made (no [data-theme] attribute) — follow the
   OS/browser preference, same as before the toggle existed. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --color-bg: var(--dark-color-bg);
        --color-surface: var(--dark-color-surface);
        --color-text: var(--dark-color-text);
        --color-text-muted: var(--dark-color-text-muted);
        --color-border: var(--dark-color-border);
        --color-accent: var(--dark-color-accent);
        --color-accent-hover: var(--dark-color-accent-hover);
        --color-accent-contrast: var(--dark-color-accent-contrast);
    }
}

/* case 2: the toggle button set an explicit preference — this wins
   regardless of OS setting, and is what the theme.js script below writes
   to <html data-theme="..."> from localStorage. */
:root[data-theme="dark"] {
    --color-bg: var(--dark-color-bg);
    --color-surface: var(--dark-color-surface);
    --color-text: var(--dark-color-text);
    --color-text-muted: var(--dark-color-text-muted);
    --color-border: var(--dark-color-border);
    --color-accent: var(--dark-color-accent);
    --color-accent-hover: var(--dark-color-accent-hover);
    --color-accent-contrast: var(--dark-color-accent-contrast);
}

/* :root[data-theme="light"] needs no rules — the base :root block above
   already holds the light values, so it's the fallback the moment "dark"
   isn't explicitly set. */

/* ==========================================================================
   reset
   scoped and intentional, instead of a blanket `* { font-size: 1.5rem }`
   which fought with form controls and made overrides hard to reason about.
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

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

ul {
    list-style: none;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
    color: inherit;
}

/* ==========================================================================
   base
   ========================================================================== */
body {
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    background: var(--color-bg);
    color: var(--color-text);
    text-transform: lowercase;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    line-height: 1.25;
}

h1 {
    font-size: var(--font-size-xl);
}

h2,
h3 {
    font-size: var(--font-size-lg);
}

/* skip link: lets keyboard users jump past the sidebar nav on every page
   instead of tabbing through 4 links first. hidden until focused. */
.skip-link {
    position: absolute;
    top: -3rem;
    left: var(--space-2);
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius);
    z-index: 100;
    transition: top var(--transition-fast);
}

.skip-link:focus {
    top: var(--space-2);
}

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

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ==========================================================================
   page shell — the left/right split, rebuilt on grid
   previously: sidebar was `position:fixed; width:20%` and main was
   `position:absolute; width:70%; right:0`. that left an unaccounted-for
   10% gap between them, didn't respond to viewport size, and broke on
   narrow screens. grid-template-areas makes the relationship explicit and
   the single media query below is all it takes to reflow to one column.
   ========================================================================== */
.content {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-areas: "sidebar main" "sidebar footer";
    min-height: 100vh;
}

@media (max-width: 768px) {
    .content {
        grid-template-columns: 1fr;
        grid-template-areas: "sidebar" "main" "footer";
    }
}

/* ==========================================================================
   sidebar / header
   ========================================================================== */
.header__container {
    grid-area: sidebar;
    position: sticky;
    top: 0;
    height: 100vh;
    padding: var(--space-3);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

/* "owl" spacing: every direct child gets space above it except the first.
   avoids the old pattern's trailing margin under the last element. */
.header__container > * + * {
    margin-top: var(--space-2);
}

.header__identity {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

.header__controls {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.header__logo {
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    object-fit: cover;
    margin-inline: auto;
}

/* site identity is a heading visually, but semantically it repeats on
   every page — leaving it an <h1> meant every page shipped two <h1>s
   (this one, plus the page's own "# heading" from the markdown body).
   styled the same, but no longer competes with the real page heading. */
.header__brand {
    font-family: var(--font-heading);
    font-size: var(--font-size-lg);
}

.header__links {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.header__link {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: color var(--transition-fast), background var(--transition-fast);
}

.header__link:hover,
.header__link:focus-visible {
    background: var(--color-border);
}

.header__link[aria-current="page"] {
    color: var(--color-accent);
    font-weight: bold;
}

/* hamburger button — CSS-only icon (three <span> bars), no image asset.
   hidden on desktop by default; the mobile media query at the bottom of
   this section switches it on. open/close state (aria-expanded, the
   `.is-open` class on <nav>) is driven by js/theme.js, not CSS alone,
   so screen readers get an accurate expanded/collapsed announcement. */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    cursor: pointer;
}

.nav-toggle__bar {
    display: block;
    width: 1.1rem;
    height: 2px;
    background: var(--color-text);
    border-radius: 1px;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}

/* morphs the three bars into an "x" when open */
.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(2) {
    opacity: 0;
}

.nav-toggle[aria-expanded="true"] .nav-toggle__bar:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* theme toggle — a small icon button, always visible on desktop and
   mobile alike, so switching themes never requires opening the hamburger
   menu first. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border: 1px solid var(--color-border);
    border-radius: 50%;
    background: var(--color-bg);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    background: var(--color-border);
}

.theme-toggle:active {
    transform: scale(0.94);
}

/* mobile: collapses the centered sidebar into a compact top bar (avatar +
   name + theme toggle + hamburger), with the nav links flying open below
   it. this block is intentionally last in the section — CSS gives equal-
   specificity rules priority by source order regardless of @media
   nesting, so anything meant to win on small screens has to be defined
   after its desktop counterpart, not before it. */
@media (max-width: 768px) {
    .header__container {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-2);
        text-align: left;
    }

    /* the row layout uses flex `gap` instead, so the owl margin between
       top-level children (identity / controls / nav) would double up. */
    .header__container > * + * {
        margin-top: 0;
    }

    .header__identity {
        flex-direction: row;
    }

    .header__logo {
        width: 2.5rem;
        height: 2.5rem;
        margin-inline: 0;
    }

    .header__brand {
        font-size: 1.1rem;
    }

    .nav-toggle {
        display: inline-flex;
    }

    /* collapsed by default; js toggles `.is-open`. flex-basis: 100% forces
       the nav onto its own row, below the identity + controls top bar. */
    .nav {
        flex-basis: 100%;
        width: 100%;
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        transition: max-height var(--transition-fast), opacity var(--transition-fast);
    }

    .nav.is-open {
        max-height: 20rem;
        opacity: 1;
    }

    .header__links {
        padding-top: var(--space-2);
    }
}

/* ==========================================================================
   main content
   ========================================================================== */
.main__container {
    grid-area: main;
    padding: var(--space-4);
    max-width: var(--content-max-width);
}

.main__container > * + * {
    margin-top: var(--space-3);
}

.main__container ul,
.main__container ol {
    padding-left: var(--space-3);
    list-style: initial;
}

.main__container a {
    text-decoration: underline;
    text-decoration-color: var(--color-border);
    text-underline-offset: 0.2em;
}

.main__container a:hover,
.main__container a:focus-visible {
    text-decoration-color: currentColor;
}

/* ==========================================================================
   footer
   ========================================================================== */
.footer__container {
    grid-area: footer;
    padding: var(--space-2) var(--space-4);
    color: var(--color-text-muted);
    font-size: 0.875em;
}

/* ==========================================================================
   blog list
   ========================================================================== */
.blog__container {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.blog__container li {
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border);
}

.blog__container a {
    font-family: var(--font-heading);
    font-size: var(--font-size-lg);
}

.blog__container p {
    margin-top: var(--space-1);
    color: var(--color-text-muted);
    text-decoration: none;
}

/* ==========================================================================
   form
   ========================================================================== */
.form {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-width: 480px;
}

.form__section {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.form__label {
    font-size: 0.9em;
    color: var(--color-text-muted);
}

.form__input {
    /* form controls don't reliably inherit text-transform across browsers,
       so the old blanket `lowercase` on `*` risked showing a user's typed
       "Jordan" as "jordan" while they typed — the value would still submit
       correctly, but it *looked* broken. made explicit here either way. */
    text-transform: none;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color var(--transition-fast);
}

.form__input:focus-visible {
    border-color: var(--color-accent);
}

textarea.form__input {
    resize: vertical;
    min-height: 6rem;
}

.form__button {
    align-self: flex-start;
    padding: var(--space-1) var(--space-3);
    border: none;
    border-radius: var(--radius);
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    text-transform: lowercase;
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.form__button:hover,
.form__button:focus-visible {
    background: var(--color-accent-hover);
}

.form__button:active {
    transform: translateY(1px);
}
