/* ============================================================
   gatekeyp — Web UI design system
   Monochrome editorial minimalism (Phase 3.5, 2026-08): pure
   ink, one grayscale ramp, texture instead of color. Status is
   carried by shape, hatching, weight and glyphs — never hue
   alone. Webfonts are self-hosted (ABC Areal, no CDN, no trackers)
   so the UI stays as privacy-lean as the product. Single dark
   theme (2026-09-08): black paper, white ink; the light theme and
   its toggle were removed.
   ============================================================ */

/* ------------------------------------------------------------
   1a. Webfonts — ABC Areal (Dinamo), self-hosted, no CDN/tracker
   ------------------------------------------------------------ */
@font-face {
    font-family: "ABC Areal";
    src: url("/fonts/ABC-Areal/ABCAreal-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "ABC Areal";
    src: url("/fonts/ABC-Areal/ABCAreal-Medium.woff2") format("woff2");
    font-weight: 500 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "ABC Areal";
    src: url("/fonts/ABC-Areal/ABCAreal-Bold.woff2") format("woff2");
    font-weight: 700 800;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "ABC Areal Mono";
    src: url("/fonts/ABC-Areal/ABCArealMono-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "ABC Areal Mono";
    src: url("/fonts/ABC-Areal/ABCArealMono-Medium.woff2") format("woff2");
    font-weight: 500 600;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: "ABC Areal Mono";
    src: url("/fonts/ABC-Areal/ABCArealMono-Bold.woff2") format("woff2");
    font-weight: 700 800;
    font-style: normal;
    font-display: swap;
}

/* ------------------------------------------------------------
   1. Design tokens
   ------------------------------------------------------------ */
:root {
    /* Type — ABC Areal (self-hosted WOFF2, escaped by the server as /fonts/*) */
    --font-serif: "ABC Areal", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
                  "Times New Roman", serif;
    --font-sans: "ABC Areal", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    --font-mono: "ABC Areal Mono", ui-monospace, "SF Mono", "SFMono-Regular", Menlo, Consolas,
                 "Liberation Mono", monospace;

    /* Palette (pure ink on black paper) */
    --paper: #0b0b0b;
    --paper-deep: #080808;
    --surface: #131313;
    --surface-2: #1a1a1a;
    --ink: #f5f5f5;
    --ink-soft: #c0c0c0;
    --ink-faint: #9a9a9a;
    --line: #2a2a2a;
    --line-strong: #404040;

    /* Accent = ink. The "key moment" is white-on-black.
       No hue carries meaning. */
    --accent: #f5f5f5;
    --accent-deep: #ffffff;
    --accent-strong: #d9d9d9;
    --accent-soft: rgba(245, 245, 245, 0.10);

    /* Semantic — monochrome. Distinction comes from the motif set
       (solid / dashed / hatched) and glyphs, never hue alone. */
    --ok: #f5f5f5;
    --ok-soft: #1c1c1c;
    --warn: #c0c0c0;
    --warn-soft: #141414;
    --bad: #f5f5f5;
    --bad-soft: #1c1c1c;

    /* Ink for filled control surfaces (text/icon on accent & bad) — AA */
    --accent-contrast: #0b0b0b;
    --bad-contrast: #0b0b0b;

    /* Status ink for chip/badge text on soft washes — AA */
    --ok-deep: #f5f5f5;
    --warn-deep: #c0c0c0;
    --bad-deep: #f5f5f5;

    /* Motif fills (Phase 3.5 item 5) — texture does what color used to do.
       Theme-aware: built from --line / --surface tokens at use time. */
    --hatch-soft: repeating-linear-gradient(45deg,
                   transparent 0 9px, var(--line) 9px 10px);
    --hatch-fill: repeating-linear-gradient(45deg,
                   var(--surface) 0 9px, var(--surface-2) 9px 10px);
    --hatch-strong: repeating-linear-gradient(-45deg,
                   transparent 0 5px, var(--line-strong) 5px 6px);

    /* Faint dot grid on the page ground — the paper's tooth */
    --dot: rgba(255, 255, 255, 0.05);

    /* Elevation + shape */
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-2: 0 6px 22px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
    --radius-s: 6px;
    --radius-m: 10px;
    --radius-l: 16px;

    /* Layout */
    --container: 1080px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 72px;

    /* Type scale — editorial steps, 4px-aligned. Choose a step; don't free-type sizes. */
    --text-xs: 0.75rem;      /* 12 — meta, badges, timestamps */
    --text-sm: 0.875rem;     /* 14 — captions, hints, labels, nav */
    --text-base: 1rem;       /* 16 — body & running text */
    --text-md: 1.125rem;     /* 18 — ledes, section sub-heads */
    --text-lg: 1.375rem;     /* 22 — card / modal titles */
    --text-xl: 1.75rem;      /* 28 — reserved, panel titles */
    --text-2xl: 2.25rem;     /* 36 — view titles (fluid clamp) */
    --text-3xl: 3rem;        /* 48 — hero display (fluid clamp) */

    /* Leading + measure */
    --leading-display: 1.08;  /* tight, for large serif display */
    --leading-tight: 1.2;     /* headings */
    --leading-normal: 1.6;    /* body */
    --measure: 62ch;          /* body-copy width */
    --measure-display: 56ch;  /* ledes / intros */
    --measure-narrow: 42ch;   /* centered micro-copy */

    /* Layout grid — rhythm primitives */
    --grid-gap: var(--space-5);

    /* Motion — durations + easings (wired in the Phase 3.5 motion pass) */
    --dur-micro: 120ms;   /* hover, press */
    --dur-fast: 150ms;    /* small state changes */
    --dur-std: 180ms;     /* toast, modal */
    --dur-view: 250ms;    /* route / view entrances */
    --dur-slow: 400ms;    /* large or choreographed */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

    --focus-ring: 0 0 0 3px var(--accent-soft);

    color-scheme: dark;
}

/* ------------------------------------------------------------
   2. Reset + base
   ------------------------------------------------------------ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

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

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--ink);
    background:
        radial-gradient(var(--dot) 1px, transparent 1px) 0 0 / 24px 24px,
        var(--paper);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: background-color var(--dur-view) var(--ease-in-out), color var(--dur-view) var(--ease-in-out);
}

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

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

a:hover {
    text-decoration: underline;
}

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

h1, h2, h3, h4 {
    font-family: var(--font-serif);
    line-height: var(--leading-tight);
    margin: 0;
    font-weight: 600;
}

p {
    margin: 0;
}

[hidden] {
    display: none !important;
}

::selection {
    background: var(--accent-soft);
}

/* ------------------------------------------------------------
   3. Accessibility foundations
   ------------------------------------------------------------ */
:focus {
    outline: none;
}

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

.skip-link {
    position: absolute;
    left: -999px;
    top: 0;
    z-index: 100;
    background: var(--surface);
    color: var(--ink);
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
}

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

/* ------------------------------------------------------------
   4. App shell + top bar
   ------------------------------------------------------------ */
.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-5);
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--ink);
    margin-right: auto;
}

.brand:hover {
    text-decoration: none;
}

.brand-mark {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.brand-mark circle {
    fill: var(--accent);
    stroke: none;
}

.brand-name {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: var(--text-md);
    letter-spacing: -0.01em;
}

.topnav {
    display: flex;
    gap: var(--space-1);
}

.nav-link {
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-weight: 500;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-s);
    transition: color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.nav-link:hover {
    color: var(--ink);
    background: var(--surface-2);
    text-decoration: none;
}

.nav-link[aria-current="page"] {
    color: var(--accent);
    background: var(--accent-soft);
}

/* ------------------------------------------------------------
   5. Stage + landing
   ------------------------------------------------------------ */
.stage {
    flex: 1;
    width: 100%;
}

.stage-inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: var(--space-7) var(--space-5) var(--space-8);
}

.view {
    animation: view-in var(--dur-view) var(--ease-out) both;
}

@keyframes view-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.eyebrow {
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: var(--space-4);
}

.home-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-5);
}

.home-session {
    margin-top: var(--space-6);
    padding: var(--space-4) var(--space-5);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-1);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.home-session .session-msg {
    margin-right: auto;
    color: var(--ink-soft);
    font-size: var(--text-sm);
}

.home-session .session-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

/* ------------------------------------------------------------
   6. View headers, buttons, cards, forms
   ------------------------------------------------------------ */
.view-head {
    margin-bottom: var(--space-6);
    max-width: 640px;
}

.view-title {
    font-size: clamp(1.875rem, 3.5vw, 2.5rem);
    line-height: var(--leading-display);
    letter-spacing: -0.015em;
    margin-bottom: var(--space-3);
}

.split-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr));
    gap: var(--grid-gap);
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-1);
    padding: var(--space-5);
}

.form-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.card-title {
    font-size: var(--text-lg);
    margin-bottom: var(--space-1);
}

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

.field label {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink-soft);
}

.field .req {
    color: var(--accent);
}

.field .opt {
    color: var(--ink-faint);
    font-weight: 400;
}

.field input,
.field textarea,
.field select {
    font: inherit;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    padding: 0.6em 0.75em;
    width: 100%;
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.field textarea {
    resize: vertical;
    min-height: 96px;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
    outline: none;
}

.field .field-hint,
.field-hint {
    font-size: var(--text-sm);
    color: var(--ink-faint);
}

.field-hint {
    margin-top: var(--space-2);
}

.note,
.form-note {
    font-size: var(--text-sm);
    color: var(--ink-soft);
    margin-top: var(--space-1);
    white-space: pre-wrap;
}

.form-note.is-error,
.note.is-error {
    color: var(--bad);
    font-weight: 600;
}

.form-note.is-ok,
.note.is-ok {
    color: var(--ok);
}

.key-hint {
    font-size: var(--text-sm);
    color: var(--ink-faint);
    border-left: 2px solid var(--accent);
    padding-left: var(--space-3);
}

/* Invite-card drop zone (Phase 3.6) — the door's "ticket stub": dashed
   keyline + hatch fill, matching the empty-state motif (§12). */
.key-drop {
    display: block;
    border: 1.5px dashed var(--line-strong);
    border-radius: var(--radius-m);
    background: var(--hatch-fill);
    padding: var(--space-5);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}

.key-drop:hover,
.key-drop:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.key-drop.is-drag {
    border-color: var(--accent);
    border-style: solid;
    background: var(--surface-2);
}

.key-drop.is-busy .key-drop-title {
    font-weight: 700;
}

.key-drop.is-done {
    border-style: solid;
    border-color: var(--accent);
    background: var(--ok-soft);
}

.key-drop-icon {
    display: block;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--ink);
    margin-bottom: var(--space-2);
}

.key-drop-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--ink);
}

.key-drop-sub {
    font-size: var(--text-sm);
    color: var(--ink-faint);
    margin-top: var(--space-1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font: inherit;
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    padding: 0.62em 1.2em;
    cursor: pointer;
    text-decoration: none;
    transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out),
                color var(--dur-fast) var(--ease-out), transform var(--dur-micro) var(--ease-out);
}

.btn:hover {
    text-decoration: none;
}

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

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

.btn-primary:hover {
    background: var(--accent-deep);
    border-color: var(--accent-deep);
    color: var(--accent-contrast);
}

.btn-secondary {
    background: var(--surface);
    color: var(--ink);
}

.btn-secondary:hover {
    background: var(--surface-2);
    border-color: var(--ink-faint);
}

.btn-ghost {
    background: transparent;
    color: var(--accent);
    border-color: var(--accent);
}

.btn-ghost:hover {
    background: var(--accent-soft);
}

.btn-danger {
    background: var(--bad);
    border-color: var(--bad);
    color: var(--bad-contrast);
}

.btn-danger:hover {
    filter: brightness(1.08);
    color: var(--bad-contrast);
}

.btn-sm {
    font-size: var(--text-sm);
    padding: 0.5em 0.9em;
}

.btn-block {
    width: 100%;
}

/* ------------------------------------------------------------
   7. Workspace + organizer shell
   ------------------------------------------------------------ */
.ws-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}

.ws-head .ws-titles {
    margin-right: auto;
}

.ws-title {
    font-size: clamp(1.5rem, 3vw, 2rem);
    line-height: var(--leading-display);
    letter-spacing: -0.015em;
}

.ws-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

/* Tab bar inside the workspace */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    border-bottom: 1px solid var(--line);
    margin-bottom: var(--space-5);
    overflow-x: auto;
}

.tab {
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink-soft);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    white-space: nowrap;
    margin-bottom: -1px;
    transition: color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.tab:hover {
    color: var(--ink);
}

.tab[aria-selected="true"] {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.ws-main {
    display: grid;
    gap: var(--grid-gap);
    align-content: start;
    min-width: 0;
}

/* Organizer-key banner — a stamped notice: hairline hatch ground,
   bold keyline edge. Texture replaces the old amber wash. */
.organizer-banner {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
    background: var(--hatch-fill);
    border: 1px solid var(--line-strong);
    border-left: 4px solid var(--ink);
    border-radius: var(--radius-m);
    padding: var(--space-4) var(--space-5);
}

/* Key value display (organizer key, access key) */
.keycode {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    word-break: break-all;
    background: var(--paper-deep);
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    padding: var(--space-2) var(--space-3);
    color: var(--ink);
    user-select: all;
}

.keycode-full {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
}

.keycode-full .kc-value {
    flex: 1;
    min-width: 0;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-radius: 999px;
    padding: 3px 10px;
    border: 1px solid transparent;
}

.badge .badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

/* State badges — monochrome status by motif, not hue.
   active   = solid ink fill (the strongest signal)
   warn     = dashed keyline + soft wash (stamp in progress)
   revoked  = hatched + double keyline (voided/stamped-over)
   neutral  = plain chip (the quiet default) */
.badge-active {
    color: var(--accent-contrast);
    background: var(--accent);
    border-color: var(--accent);
}

.badge-revoked {
    color: var(--bad-deep);
    background: var(--hatch-soft);
    border: 1px solid var(--line-strong);
    border-style: double;
}

.badge-warn {
    color: var(--warn-deep);
    background: var(--warn-soft);
    border-color: var(--line-strong);
    border-style: dashed;
}

.badge-neutral {
    color: var(--ink-soft);
    background: var(--surface-2);
    border-color: var(--line);
}

/* ------------------------------------------------------------
   8. Content blocks, access keys
   ------------------------------------------------------------ */
.item {
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    background: var(--surface);
    padding: var(--space-4) var(--space-5);
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.item:hover {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-1);
}

.item-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.item-head .item-tag {
    flex: none;
}

.item-head .item-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-head .item-actions {
    margin-left: auto;
    display: flex;
    gap: var(--space-2);
}

.item-body {
    color: var(--ink-soft);
    font-size: var(--text-base);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-top: var(--space-2);
    color: var(--ink-faint);
    font-size: var(--text-xs);
    font-family: var(--font-mono);
}

.item-meta span:first-child {
    font-family: var(--font-sans);
}

/* Type tag for content blocks */
.tag {
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 3px 8px;
    border-radius: var(--radius-s);
}

/* Inline form rows (add block, generate key, revoke key) */
.inline-form {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: end;
}

.inline-form .field {
    flex: 1 1 180px;
    min-width: 160px;
    margin: 0;
}

.inline-form .btn {
    flex: none;
}

/* Access key detail rows */
.key-list {
    display: grid;
    gap: var(--space-3);
}

.key-detail-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: var(--radius-m);
    padding: var(--space-3) var(--space-4);
}

.key-detail-row .kd-badge {
    flex: none;
}

.key-detail-row .kd-info {
    min-width: 0;
    flex: 1;
}

.key-detail-row .kd-name {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    word-break: break-all;
    color: var(--ink);
}

.key-detail-row .kd-sub {
    font-size: var(--text-xs);
    color: var(--ink-faint);
}

.key-detail-row .kd-msg {
    font-style: italic;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.key-detail-row .kd-actions {
    flex: none;
    display: flex;
    gap: var(--space-2);
}

/* Empty states — a quiet "ticket stub": hatched fill + dashed keyline */
.empty {
    text-align: center;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-m);
    background: var(--hatch-fill);
    padding: var(--space-6) var(--space-5);
}

.empty-title {
    font-size: var(--text-md);
    margin-bottom: var(--space-1);
}

.empty-sub {
    color: var(--ink-soft);
    font-size: var(--text-sm);
    max-width: var(--measure-narrow);
    margin: 0 auto;
}

/* ------------------------------------------------------------
   9. Bulletin board + comments
   ------------------------------------------------------------ */
.bulletin-list {
    display: grid;
    gap: var(--space-3);
}

.bulletin-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    background: var(--surface);
    padding: var(--space-4) var(--space-5);
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.bulletin-card.bulletin-open {
    border-color: var(--line-strong);
    box-shadow: var(--shadow-1);
}

.bulletin-head {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    cursor: pointer;
}

.bulletin-head .b-title {
    font-family: var(--font-serif);
    font-size: var(--text-md);
    font-weight: 600;
    flex: 1;
    min-width: 0;
}

.bulletin-head .b-count {
    flex: none;
    font-size: var(--text-xs);
    color: var(--ink-faint);
    font-family: var(--font-mono);
}

.bulletin-head .b-toggle {
    flex: none;
    background: none;
    border: none;
    color: var(--ink-soft);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 var(--space-1);
    transition: transform var(--dur-fast) var(--ease-out);
}

.bulletin-card.bulletin-open .b-toggle {
    transform: rotate(180deg);
}

.bulletin-body {
    display: none;
    color: var(--ink-soft);
    font-size: var(--text-base);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    border-top: 1px solid var(--line);
    padding: var(--space-4) 0 0;
    margin-top: var(--space-3);
}

.bulletin-card.bulletin-open .bulletin-body {
    display: block;
    animation: bulletin-in var(--dur-fast) var(--ease-out) both;
}

.bulletin-meta {
    margin-top: var(--space-3);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.bulletin-foot {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    margin-top: var(--space-3);
}

.comment-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.comment-form .cf-author {
    grid-column: 1 / -1;
}

.comments {
    margin-top: var(--space-3);
    display: grid;
    gap: var(--space-2);
}

.comment {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-1) var(--space-2);
    background: var(--surface-2);
    border-radius: var(--radius-s);
    padding: var(--space-3) var(--space-4);
}

.comment .c-body {
    grid-column: 1 / -1;
    font-size: var(--text-sm);
    color: var(--ink);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.comment .c-meta {
    font-size: var(--text-xs);
    color: var(--ink-faint);
    font-family: var(--font-mono);
}

.comment .c-del {
    font-size: var(--text-xs);
    color: var(--ink-faint);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.comment .c-del:hover {
    color: var(--bad);
}

/* ------------------------------------------------------------
   10. Media
   ------------------------------------------------------------ */
.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-3);
}

.media-tile {
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    overflow: hidden;
    background: var(--surface-2);
    display: flex;
    flex-direction: column;
}

.media-tile .mt-preview {
    aspect-ratio: 4 / 3;
    object-fit: cover;
    width: 100%;
    background: var(--paper-deep);
}

.media-tile .mt-fallback {
    aspect-ratio: 4 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: var(--ink-faint);
    background: var(--paper-deep);
}

.media-tile .mt-info {
    padding: var(--space-2) var(--space-3);
    display: grid;
    gap: var(--space-1);
}

.media-tile .mt-name {
    font-size: var(--text-xs);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-tile .mt-size {
    font-size: var(--text-xs);
    color: var(--ink-faint);
    font-family: var(--font-mono);
}

.media-tile .mt-actions {
    padding: 0 var(--space-3) var(--space-3);
    display: flex;
    gap: var(--space-2);
}

.up-zone {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-m);
    padding: var(--space-5);
    background: var(--surface-2);
    text-align: center;
}

.up-zone .field {
    max-width: 460px;
    margin: 0 auto var(--space-3);
}

/* ------------------------------------------------------------
   11. Attendee event page
   ------------------------------------------------------------ */
.ep-head {
    margin-bottom: var(--space-6);
}

.ep-eyebrow {
    margin-bottom: var(--space-3);
}

.ep-title {
    font-size: clamp(1.875rem, 3.5vw, 2.5rem);
    line-height: var(--leading-display);
    letter-spacing: -0.015em;
    margin: 0 0 var(--space-3);
}

.ep-lede {
    color: var(--ink-soft);
    font-size: var(--text-md);
    max-width: var(--measure);
    white-space: pre-wrap;
}

.ep-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin-top: var(--space-4);
    color: var(--ink-soft);
    font-size: var(--text-sm);
    border-top: 1px solid var(--line);
    padding-top: var(--space-4);
}

.ep-meta .ep-meta-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

.ep-main {
    display: grid;
    gap: var(--grid-gap);
    align-content: start;
    min-width: 0;
}

.fact-list {
    display: grid;
    gap: var(--space-2);
}

.fact-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--line);
    font-size: var(--text-sm);
}

.fact-row:last-child {
    border-bottom: none;
}

.fact-row .f-key {
    color: var(--ink-faint);
    flex: none;
}

.fact-row .f-val {
    text-align: right;
    overflow-wrap: anywhere;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
}

/* ------------------------------------------------------------
   12. Toasts
   ------------------------------------------------------------ */
.toast-region {
    position: fixed;
    right: var(--space-4);
    bottom: var(--space-4);
    z-index: 90;
    display: grid;
    gap: var(--space-2);
    width: min(360px, calc(100vw - 2 * var(--space-4)));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-2);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    animation: toast-in var(--dur-std) var(--ease-out) both;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.toast.toast-ok {
    border-left-color: var(--ok);
}

.toast.toast-error {
    border-left-color: var(--bad);
    background: var(--bad-soft);
}

.toast .toast-icon {
    flex: none;
    font-weight: 700;
}

.toast .toast-body {
    flex: 1;
    min-width: 0;
    white-space: pre-wrap;
}

.toast .toast-close {
    flex: none;
    background: none;
    border: none;
    color: var(--ink-faint);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 var(--space-1);
}

.toast .toast-close:hover {
    color: var(--ink);
}

.toast.is-leaving {
    animation: toast-out var(--dur-fast) var(--ease-out) both;
}

@keyframes toast-out {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(8px); }
}

@keyframes bulletin-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------
   13. Modals
   ------------------------------------------------------------ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 80;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    animation: fade-in var(--dur-fast) var(--ease-out) both;
}

@keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-2);
    width: min(480px, 100%);
    max-height: calc(100vh - 2 * var(--space-5));
    overflow: auto;
    padding: var(--space-5);
    animation: modal-in var(--dur-std) var(--ease-out) both;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.modal-title {
    font-size: var(--text-lg);
    margin-right: auto;
}

.modal-close {
    flex: none;
    background: none;
    border: none;
    color: var(--ink-faint);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 var(--space-1);
}

.modal-close:hover {
    color: var(--ink);
}

.modal-body {
    color: var(--ink-soft);
    font-size: var(--text-sm);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin-bottom: var(--space-5);
}

.modal-body .keycode {
    margin-top: var(--space-3);
}

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
}

/* ------------------------------------------------------------
   14. Responsive
   ------------------------------------------------------------ */
@media (max-width: 640px) {
    .stage-inner {
        padding-top: var(--space-5);
    }

    .topbar {
        flex-wrap: wrap;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
    }

    .topnav {
        order: 3;
        width: 100%;
        border-top: 1px solid var(--line);
        padding-top: var(--space-2);
    }

    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-form .btn {
        width: 100%;
    }

    .comment-form {
        grid-template-columns: 1fr;
    }

    .comment-form .btn {
        width: 100%;
    }

    .key-detail-row {
        flex-wrap: wrap;
    }

    .key-detail-row .kd-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .organizer-banner .btn {
        width: 100%;
    }

    .modal-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .modal-actions .btn {
        width: 100%;
    }

    .fact-row {
        flex-direction: column;
        gap: var(--space-1);
    }

    .fact-row .f-val {
        text-align: left;
    }
}

@media (max-width: 420px) {
    .card {
        padding: var(--space-4);
    }

    .split-cards {
        grid-template-columns: 1fr;
    }
}

/* ------------------------------------------------------------
   15. Reduced motion + print
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media print {
    .topbar,
    .toast-region,
    .modal-backdrop {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .card,
    .item,
    .bulletin-card,
    .media-tile {
        box-shadow: none;
        break-inside: avoid;
    }
}

/* ------------------------------------------------------------
   16. JS-rendered components (driven by app.js)
   ------------------------------------------------------------ */

/* Ghost badge — subdued metadata chips */
.badge-ghost {
    color: var(--ink-faint);
    background: transparent;
    border-color: var(--line);
}

/* Section support text, used inside cards on the tab panels */
.section-text {
    color: var(--ink-soft);
    font-size: var(--text-base);
    white-space: pre-wrap;
    margin: 0 0 var(--space-3);
}

/* Bulletin body text node (nested in the already-styled .bulletin-body) */
.b-body-text {
    margin: 0 0 var(--space-3);
}

/* ------------------------------------------------------------
   17. Motif set (Phase 3.5 item 5)
   The in-house texture language that replaced hue as the carrier
   of meaning: hatches (wells, voided surfaces) and stamps (dashed /
   double keylines). These primitives are the vocabulary the Phase 3.6
   invite cards build on.
   ------------------------------------------------------------ */

/* Hatch utilities — apply to any surface for a "printed" texture.
   Theme-aware via --line / --surface tokens at use time. */
.hatch-soft {
    background: var(--hatch-soft);
}

.hatch-fill {
    background: var(--hatch-fill);
}

.hatch-strong {
    background: var(--hatch-strong);
}

/* "Voided" composite — hatched ground + double keyline. Reserved
   for revoked / destructive surfaces (badges, danger zone). */
.voided {
    background: var(--hatch-soft);
    border-style: double;
    border-color: var(--line-strong);
}

/* ------------------------------------------------------------
   18. Invite card cover picker (Phase 3.7)
   The make-card modal's cover chooser: preset swatches + own
   image upload + a live card preview. Monochrome, token-driven.
   ------------------------------------------------------------ */

.cover-picker {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: var(--space-2) 0 var(--space-2);
}

.cover-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    min-width: 96px;
    padding: var(--space-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    background: var(--paper);
    color: var(--ink-soft);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    cursor: pointer;
    transition:
        border-color var(--dur-fast) var(--ease-out),
        box-shadow var(--dur-fast) var(--ease-out);
}

.cover-chip canvas {
    width: 88px;
    height: 30px;
    display: block;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    background: var(--paper-deep);
}

.cover-chip:hover {
    border-color: var(--line-strong);
}

.cover-chip.is-selected {
    border-color: var(--ink);
    box-shadow: 0 0 0 1px var(--ink);
}

.cover-upload {
    justify-content: center;
    min-height: 78px;
}

.cover-upload-icon {
    font-size: var(--text-lg);
    line-height: 1;
    color: var(--ink-soft);
}

.card-preview-wrap {
    margin-top: var(--space-3);
    text-align: center;
}

#card-preview {
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-1);
    width: 200px;
    height: 300px;
    background: var(--paper-deep);
}

/* ------------------------------------------------------------------
 * Honeypot field (attendee RSVP form) — rendered into the DOM but
 * invisible and un-tabbable for humans (aria-hidden + tabindex=-1 in
 * the markup); bots that blindly autofill `website` are caught app-side.
 * ------------------------------------------------------------------ */
.field-hp {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
    visibility: hidden;
}
