/*
 * Pixelated Dream - the design system.
 *
 * Written from scratch: no Tailwind, no CDN, no webfont. The previous build
 * loaded the Tailwind *play* CDN, which compiles CSS in the browser on every
 * page load - a third-party runtime dependency on every request, and a flash
 * of unstyled content before it finished. Nothing here needs a build step or a
 * network call.
 *
 * Layout: tokens, base, layout, chrome, components, utilities.
 * Everything is themed through the tokens at the top; no component hard-codes
 * a colour.
 */

/* ==================================================================
   Tokens
   ================================================================== */

:root {
    color-scheme: dark;

    /* Surfaces, darkest first. The hue is the brand purple, desaturated
       almost to grey, so accents read as colour against it. */
    --bg:            #0d0a11;
    --surface:       #16111d;
    --surface-2:     #1e1728;
    --surface-3:     #271f33;
    --border:        #322942;
    --border-strong: #453a5c;

    /* Text */
    --text:      #ece9f1;
    --text-dim:  #a99fba;
    --text-mute: #776d88;

    /* Brand. #341443 is the historical theme colour and stays the deep end. */
    --accent-deep: #341443;
    --accent:      #8b5cf6;
    --accent-lift: #a78bfa;
    --accent-fade: #2a1b47;

    /* Semantic */
    --ok:      #34d399;
    --ok-bg:   #10281f;
    --warn:    #fbbf24;
    --warn-bg: #2b2110;
    --bad:     #f87171;
    --bad-bg:  #2d1417;
    --info:    #60a5fa;
    --info-bg: #101d2e;

    /* Type. One scale, used everywhere. */
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
            Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
            "Liberation Mono", monospace;
    --t-xs: 0.75rem;
    --t-sm: 0.875rem;
    --t-md: 1rem;
    --t-lg: 1.125rem;
    --t-xl: 1.375rem;
    --t-2xl: 1.75rem;
    --t-3xl: 2.25rem;

    /* Space, on a 4px grid */
    --s-1: 0.25rem;
    --s-2: 0.5rem;
    --s-3: 0.75rem;
    --s-4: 1rem;
    --s-5: 1.5rem;
    --s-6: 2rem;
    --s-7: 3rem;
    --s-8: 4rem;

    --radius:    10px;
    --radius-sm: 6px;
    --radius-lg: 16px;

    --shadow:    0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.45);

    --page: 68rem;
    --prose: 44rem;
}

/* ==================================================================
   Base
   ================================================================== */

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

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: var(--t-md)/1.6 var(--font);
    /* A single wash of brand colour behind the masthead, so the top of every
       page is warmer than the bottom without needing a hero image. */
    background-image:
        radial-gradient(60rem 22rem at 50% -8rem, var(--accent-fade), transparent 70%);
    background-repeat: no-repeat;
    min-height: 100vh;
}

h1, h2, h3, h4 {
    margin: 0 0 var(--s-3);
    line-height: 1.25;
    font-weight: 650;
    letter-spacing: -0.015em;
}
h1 { font-size: var(--t-3xl); }
h2 { font-size: var(--t-2xl); }
h3 { font-size: var(--t-xl); }
h4 { font-size: var(--t-lg); }

p { margin: 0 0 var(--s-4); }
ul, ol { margin: 0 0 var(--s-4); padding-inline-start: var(--s-5); }
li { margin-bottom: var(--s-1); }

a {
    color: var(--accent-lift);
    text-decoration-color: color-mix(in srgb, var(--accent-lift) 40%, transparent);
    text-underline-offset: 2px;
}
a:hover { color: var(--text); text-decoration-color: currentColor; }

hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: var(--s-6) 0;
}

img { max-width: 100%; height: auto; }

code, kbd, samp, pre { font-family: var(--mono); font-size: 0.9em; }

code {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.1em 0.35em;
}

pre {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--s-4);
    overflow-x: auto;
    margin: 0 0 var(--s-4);
}
pre code { background: none; border: 0; padding: 0; }

small { font-size: var(--t-sm); color: var(--text-dim); }

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

::selection { background: var(--accent); color: #fff; }

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

.skip-link {
    position: absolute;
    left: -9999px;
    top: var(--s-2);
    background: var(--accent);
    color: #fff;
    padding: var(--s-2) var(--s-4);
    border-radius: var(--radius-sm);
    z-index: 100;
}
.skip-link:focus { left: var(--s-4); }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ==================================================================
   Layout
   ================================================================== */

.page {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.wrap {
    width: 100%;
    max-width: var(--page);
    margin-inline: auto;
    padding-inline: var(--s-4);
}

.main { flex: 1; padding-block: var(--s-6) var(--s-8); }

.stack > * + * { margin-top: var(--s-4); }
.stack-lg > * + * { margin-top: var(--s-6); }

.row {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    flex-wrap: wrap;
}
.row-between { justify-content: space-between; }

.grid {
    display: grid;
    gap: var(--s-4);
    grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}

.prose { max-width: var(--prose); }
.prose h2 { margin-top: var(--s-6); }
.prose h3 { margin-top: var(--s-5); }
.prose img { border-radius: var(--radius); border: 1px solid var(--border); }
.prose blockquote {
    margin: 0 0 var(--s-4);
    padding: var(--s-2) var(--s-4);
    border-left: 3px solid var(--accent);
    color: var(--text-dim);
}

/* ==================================================================
   Header and footer
   ================================================================== */

.masthead {
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.masthead-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-4);
    padding-block: var(--s-3);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--s-3);
    text-decoration: none;
    color: var(--text);
    font-weight: 650;
}
.brand:hover { color: var(--text); }
.brand img { width: 34px; height: 34px; display: block; }
.brand-name { font-size: var(--t-lg); letter-spacing: -0.02em; line-height: 1.1; }
.brand-tag {
    display: block;
    font-size: var(--t-xs);
    font-weight: 400;
    color: var(--text-mute);
}

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

.nav a {
    display: inline-block;
    padding: var(--s-2) var(--s-3);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    text-decoration: none;
    font-size: var(--t-sm);
    font-weight: 500;
    white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.is-active { color: var(--text); background: var(--surface-2); }
.nav a.is-account {
    border: 1px solid var(--border-strong);
    color: var(--text);
}
.nav a.is-account:hover { border-color: var(--accent); }

.nav-toggle {
    display: none;
    align-items: center;
    gap: var(--s-2);
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--s-2) var(--s-3);
    font: 500 var(--t-sm) var(--font);
    cursor: pointer;
}

.nav-mobile {
    display: none;
    flex-direction: column;
    gap: var(--s-1);
    padding-bottom: var(--s-3);
}
.nav-mobile a { padding: var(--s-3); }

@media (max-width: 800px) {
    .nav-desktop { display: none; }
    .nav-toggle { display: inline-flex; }
    .nav-mobile { display: flex; }
    .nav-mobile[hidden] { display: none; }
}

.footer {
    border-top: 1px solid var(--border);
    padding-block: var(--s-6);
    color: var(--text-mute);
    font-size: var(--t-sm);
}
.footer nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-4);
    margin-bottom: var(--s-3);
}
.footer a { color: var(--text-dim); text-decoration: none; }
.footer a:hover { color: var(--text); }
.footer p { margin: 0 0 var(--s-1); }

/* ==================================================================
   Components
   ================================================================== */

/* --- card ------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--s-5);
}
.card-tight { padding: var(--s-4); }
.card > :last-child { margin-bottom: 0; }

.card-link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, transform .15s;
}
.card-link:hover {
    border-color: var(--border-strong);
    color: inherit;
    transform: translateY(-2px);
}

.card-title { margin-bottom: var(--s-2); font-size: var(--t-lg); }
.card-meta { color: var(--text-mute); font-size: var(--t-sm); }

/* --- section heading -------------------------------------------- */

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-4);
    margin-bottom: var(--s-4);
    padding-bottom: var(--s-3);
    border-bottom: 1px solid var(--border);
}
.section-head h2, .section-head h1 { margin: 0; }

.lede { font-size: var(--t-lg); color: var(--text-dim); max-width: var(--prose); }

/* --- buttons ----------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    padding: var(--s-3) var(--s-5);
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    font: 600 var(--t-sm)/1 var(--font);
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--accent-lift); color: #fff; }
.btn:disabled, .btn[aria-disabled="true"] {
    opacity: .55;
    cursor: not-allowed;
}

.btn-quiet {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}
.btn-quiet:hover { background: var(--surface-3); color: var(--text); }

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--bad); color: #2d1417; }
.btn-danger:hover { background: #fca5a5; color: #2d1417; }

.btn-sm { padding: var(--s-2) var(--s-3); font-size: var(--t-xs); }
.btn-block { width: 100%; }

/* --- forms ------------------------------------------------------- */

.field { margin-bottom: var(--s-4); }
.field:last-child { margin-bottom: 0; }

.label {
    display: block;
    margin-bottom: var(--s-2);
    font-size: var(--t-sm);
    font-weight: 600;
    color: var(--text-dim);
}

.input, .textarea, .select {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: var(--s-3);
    font: var(--t-sm)/1.5 var(--font);
}
.input:hover, .textarea:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .textarea:focus, .select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-fade);
}
.input::placeholder, .textarea::placeholder { color: var(--text-mute); }
.textarea { min-height: 8rem; resize: vertical; }
.input[type="file"] { padding: var(--s-2); }

.hint { margin: var(--s-2) 0 0; font-size: var(--t-xs); color: var(--text-mute); }
.field-error { margin: var(--s-2) 0 0; font-size: var(--t-xs); color: var(--bad); }

.check {
    display: flex;
    align-items: flex-start;
    gap: var(--s-3);
    font-size: var(--t-sm);
}
.check input { margin-top: 0.2em; accent-color: var(--accent); }

.form-actions {
    display: flex;
    gap: var(--s-3);
    align-items: center;
    flex-wrap: wrap;
    margin-top: var(--s-5);
}

/* --- alerts ------------------------------------------------------ */

.alert {
    display: flex;
    gap: var(--s-3);
    padding: var(--s-3) var(--s-4);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    font-size: var(--t-sm);
    margin-bottom: var(--s-4);
}
.alert-success { background: var(--ok-bg);   border-color: var(--ok);   color: var(--ok); }
.alert-error   { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }
.alert-warning { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.alert-info    { background: var(--info-bg); border-color: var(--info); color: var(--info); }

/* --- badges ------------------------------------------------------ */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    padding: 0.15rem var(--s-2);
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text-dim);
    font-size: var(--t-xs);
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}
.badge-accent  { background: var(--accent-fade); border-color: var(--accent); color: var(--accent-lift); }
.badge-success { background: var(--ok-bg);   border-color: var(--ok);   color: var(--ok); }
.badge-warning { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.badge-danger  { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }

/* --- tables ------------------------------------------------------ */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table th, .table td {
    padding: var(--s-3) var(--s-4);
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.table th {
    background: var(--surface-2);
    color: var(--text-dim);
    font-weight: 600;
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: .06em;
    white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface); }
.table td.num { font-variant-numeric: tabular-nums; text-align: right; }

/* --- description list -------------------------------------------- */

.facts { display: grid; grid-template-columns: auto 1fr; gap: var(--s-2) var(--s-4); margin: 0; }
.facts dt { color: var(--text-mute); font-size: var(--t-sm); }
.facts dd { margin: 0; font-size: var(--t-sm); }

/* --- empty state -------------------------------------------------- */

.empty {
    text-align: center;
    padding: var(--s-7) var(--s-4);
    color: var(--text-mute);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}
.empty h3 { color: var(--text-dim); }

/* --- breadcrumb --------------------------------------------------- */

.crumbs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--s-2);
    align-items: center;
    font-size: var(--t-sm);
    color: var(--text-mute);
    margin-bottom: var(--s-4);
}
.crumbs a { color: var(--text-dim); text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.crumbs span[aria-hidden] { color: var(--text-mute); }

/* --- avatar ------------------------------------------------------- */

.avatar {
    width: 4rem; height: 4rem;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-2);
    border: 1px solid var(--border);
}
.avatar-lg { width: 6rem; height: 6rem; }
.avatar-sm { width: 2rem; height: 2rem; }

/* --- hero --------------------------------------------------------- */

.hero { padding-block: var(--s-7) var(--s-6); }
.hero h1 { max-width: 20ch; }
.hero .lede { margin-bottom: var(--s-5); }

/* --- sidebar layout (admin, account) ------------------------------- */

.with-side {
    display: grid;
    gap: var(--s-6);
    grid-template-columns: 15rem 1fr;
    align-items: start;
}
@media (max-width: 860px) {
    .with-side { grid-template-columns: 1fr; }
}

.side-nav { display: flex; flex-direction: column; gap: var(--s-1); }
.side-nav a {
    padding: var(--s-2) var(--s-3);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    text-decoration: none;
    font-size: var(--t-sm);
}
.side-nav a:hover { background: var(--surface-2); color: var(--text); }
.side-nav a.is-active {
    background: var(--accent-fade);
    color: var(--accent-lift);
    font-weight: 600;
}
.side-title {
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-mute);
    margin: var(--s-4) 0 var(--s-2);
}

/* --- error page ---------------------------------------------------- */

.error-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 55vh;
    gap: var(--s-3);
}
.error-code {
    font-size: clamp(4rem, 18vw, 8rem);
    font-weight: 800;
    line-height: 1;
    margin: 0;
    color: var(--surface-3);
    letter-spacing: -0.04em;
}
.error-page h1 { margin: 0; font-size: var(--t-2xl); }
.error-page p { color: var(--text-dim); margin: 0; }
.error-page .btn { margin-top: var(--s-4); }
.error-facts { margin: var(--s-2) 0 0; font-size: var(--t-sm); color: var(--text-dim); }
.error-facts dt { font-weight: 650; color: var(--text); display: inline; }
.error-facts dd { display: inline; margin: 0 0 0 var(--s-1); }
.error-facts div { margin-bottom: var(--s-1); }

/* ==================================================================
   Utilities - deliberately few
   ================================================================== */

.muted { color: var(--text-mute); }
.dim   { color: var(--text-dim); }
.mono  { font-family: var(--mono); font-size: 0.9em; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }

/* --- narrow single-purpose pages (sign in, register, verify) -------- */

.auth {
    max-width: 26rem;
    margin-inline: auto;
    padding-block: var(--s-6);
}
.auth h1 { font-size: var(--t-2xl); text-align: center; }
.auth .lede { text-align: center; font-size: var(--t-md); margin-bottom: var(--s-5); }
.auth-alt {
    margin-top: var(--s-5);
    text-align: center;
    font-size: var(--t-sm);
    color: var(--text-dim);
}
.auth-methods {
    display: flex;
    flex-direction: column;
    gap: var(--s-3);
    margin-top: var(--s-4);
    padding-top: var(--s-4);
    border-top: 1px solid var(--border);
}
