@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&family=IBM+Plex+Sans:ital,wght@0,100..700;1,100..700&display=swap");

/* ─── Tokens ─────────────────────────────────────────────── */
:root {
    --brand-base: oklch(0.4284 0.172 259.7);

    --ui-bg: #ffffff;
    --ui-bg-muted: oklch(from var(--brand-base) 0.97 0.015 h);
    --ui-bg-subtle: oklch(from var(--brand-base) 0.99 0.005 h);
    --ui-border: oklch(from var(--brand-base) 0.88 0.04 h);
    --ui-border-focus: oklch(from var(--brand-base) 0.55 0.16 h);

    --text-main: oklch(from var(--brand-base) 0.18 0.02 h);
    --text-muted: oklch(from var(--brand-base) 0.48 0.03 h);
    --text-on-brand: #ffffff;

    --ui-hover: oklch(from var(--brand-base) calc(l - 0.06) c h);
    --ui-active: oklch(from var(--brand-base) calc(l - 0.1) c h);

    --space-2: 0.5rem;
    --space-4: 1rem;
    --space-5: 1.5rem;

    --radius-md: 8px;
    --shadow-md: 0 4px 12px oklch(from var(--brand-base) 0.15 0.1 h / 0.14);

    --font-sans: "IBM Plex Sans", sans-serif;
    --font-mono: "IBM Plex Mono", monospace;
    --text-sm: 0.875rem;
    --text-base: 1rem;

    --transition-base: 200ms ease;

    interpolate-size: allow-keywords;
    color-scheme: light;
}

/* ─── Dark Mode ──────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --ui-bg: oklch(0.14 0.02 259.7);
        --ui-bg-muted: oklch(from var(--brand-base) 0.18 0.02 h);
        --ui-bg-subtle: oklch(from var(--brand-base) 0.12 0.015 h);
        --ui-border: oklch(from var(--brand-base) 0.3 0.04 h);
        --ui-border-focus: oklch(from var(--brand-base) 0.65 0.16 h);

        --text-main: oklch(from var(--brand-base) 0.93 0.01 h);
        --text-muted: oklch(from var(--brand-base) 0.65 0.025 h);

        /* In dark mode, hover = lighter, not darker */
        --ui-hover: oklch(from var(--brand-base) calc(l + 0.08) c h);
        --ui-active: oklch(from var(--brand-base) calc(l + 0.14) c h);

        --shadow-md: 0 4px 12px oklch(0 0 0 / 0.4);
    }
}

/* ─── Reset ──────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
}

/* ─── Base ───────────────────────────────────────────────── */
body {
    font-family: var(--font-mono);
    line-height: 1.6;
    background: var(--ui-bg-subtle);
    color: var(--text-main);
}

h1,
h2,
h3 {
    font-family: var(--font-sans);
    text-wrap: balance;
    margin-bottom: 0.5em;
}

p {
    text-wrap: pretty;
    color: var(--text-muted);
    max-width: 65ch;
    margin-bottom: 1.5lh;
}

a {
    color: var(--ui-active);

    &:hover {
        color: var(--ui-hover);
    }
}

/* ─── Forms ──────────────────────────────────────────────── */
input,
textarea,
select {
    font: inherit;
    font-size: var(--text-sm);
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--ui-bg);
    color: var(--text-main);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-base);
    outline: none;

    &:focus {
        border-color: var(--ui-border-focus);
    }
}

label {
    display: block;
    font-size: var(--text-sm);
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-bottom: var(--space-4);
}

/* ─── Buttons ────────────────────────────────────────────── */
button,
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 0.55rem 1.1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: var(--brand-base);
    color: var(--text-on-brand);
    transition:
        background var(--transition-base),
        transform 100ms ease;
    user-select: none;

    &:hover {
        background: var(--ui-hover);
    }
    &:active {
        transform: translateY(1px);
        background: var(--ui-active);
    }
}

.btn-ghost {
    background: transparent;
    color: var(--text-main);
    border-color: var(--ui-border);

    &:hover {
        background: var(--ui-bg-muted);
    }
    &:active {
        background: var(--ui-bg-muted);
    }
}

/* ─── Nav ────────────────────────────────────────────────── */
nav {
    ul {
        list-style: none;
        padding: 0;
        line-height: 2.4;
    }

    a {
        text-decoration: none;
        color: var(--text-main);
    }
}

/* ─── Layout — default: header + sidebar + main ──────────── */
body {
    display: grid;
    grid-template-areas:
        "header header"
        "sidebar main";
    grid-template-columns: 320px 1fr;
    grid-template-rows: 80px 1fr;
    height: 100dvh;
    overflow: hidden;
}

header {
    grid-area: header;
    display: flex;
    align-items: center;
    padding: 0 2rem;
    background: var(--ui-bg);
    box-shadow: var(--shadow-md);
    z-index: 2;
    justify-content: space-between;

    a {
        color: var(--text-base);
        text-decoration: none;
    }

    a:first-of-type {
        font-weight: 700;
    }
}

aside {
    grid-area: sidebar;
    border-right: 1px solid var(--ui-border);
    background: var(--ui-bg-muted);
    padding: 2rem;
    overflow-y: auto;

    nav {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: 100%;
    }
}

main {
    grid-area: main;
    padding: 2rem;
    overflow-y: auto;
    height: 100%;
}

/* ─── Layout variants ────────────────────────────────────── */
body[data-auth="false"],
body[data-layout="center-card"] {
    grid-template-areas: "main";
    grid-template-columns: 1fr;
    grid-template-rows: 100dvh;
    place-items: center;

    > main {
        width: 100%;
        max-width: 60ch;
        padding: 1rem;
        box-sizing: border-box;
    }
}

body[data-auth="false"] :where(header, aside),
body[data-layout="center-card"] :where(header, aside) {
    display: none;
}

body[data-layout="no-sidebar"] {
    grid-template-areas: "header" "main";
    grid-template-columns: 1fr;
    grid-template-rows: 80px 1fr;
}

body[data-layout="no-sidebar"] aside {
    display: none;
}

/* ─── Responsive — tablet (sidebar becomes top nav strip) ── */
@media (max-width: 900px) {
    body {
        grid-template-columns: 1fr;
        grid-template-rows: 80px auto 1fr;
        grid-template-areas:
            "header"
            "sidebar"
            "main";

        height: auto;
        overflow: visible;
    }

    aside {
        border-right: none;
        border-bottom: 1px solid var(--ui-border);
        padding: 0.75rem 1.5rem;

        nav {
            flex-direction: row;
            align-items: center;
            height: auto;

            ul {
                display: flex;
                flex-wrap: wrap;
                gap: 0.25rem 1.5rem;
                line-height: 2;
            }
        }
    }

    main {
        overflow-y: visible;
    }

    /* Keep centered layouts correct on tablet */
    body[data-auth="false"],
    body[data-layout="center-card"] {
        grid-template-rows: 100dvh;
        grid-template-areas: "main";
    }

    body[data-layout="no-sidebar"] {
        grid-template-areas: "header" "main";
        grid-template-rows: 80px 1fr;
    }
}

/* ─── Responsive — mobile ────────────────────────────────── */
@media (max-width: 560px) {
    header {
        padding: 0 1rem;
    }

    aside {
        padding: 0.5rem 1rem;

        nav ul {
            gap: 0.25rem 1rem;
            font-size: var(--text-sm);
        }
    }

    main {
        padding: 1.25rem 1rem;
    }

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

    p {
        max-width: 100%;
    }
}

/* ─── Semantic Card Grid ─────────────────────────────────── */

/* Any list or section marked with data-layout="cards" */
[data-layout="cards"] {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-5);
    padding: 0;
    list-style: none;
}

[data-layout="cards"] > * {
    background: var(--ui-bg);
    border: 1px solid var(--ui-border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition:
        transform var(--transition-base),
        box-shadow var(--transition-base);
    box-shadow: var(--shadow-md);
    text-decoration: none;
}

[data-layout="cards"] > *:hover {
    border-color: var(--ui-border-focus);
}

[data-layout="cards"] > * :is(img, header):first-child {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: var(--ui-bg-muted);
    border-bottom: 1px solid var(--ui-border);
}

[data-layout="cards"] > * :is(div, section) {
    padding: var(--space-4);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

[data-layout="cards"] > * :is(h2, h3, h4) {
    margin: 0;
    font-size: 1.15rem;
    color: var(--text-main);
}

[data-layout="cards"] > * footer {
    padding: var(--space-2);
    background: var(--ui-bg-subtle);
    border-top: 1px solid var(--ui-border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}

main h1 {
    font-family: var(--font-sans);
    font-size: 2.75rem;
    font-weight: 800;
    line-height: 1.05;
    color: var(--text-main);

    margin-top: var(--space-5);
    margin-bottom: calc(var(--space-5) * 3);
}

main > a:first-child:has(+ h1) {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0;
    transition: all var(--transition-base);

    &:hover {
        color: var(--brand-base);
    }
}

main > a:first-child:has(+ h1) + h1 {
    margin-top: var(--space-2);
}
