/* Pixquilt base styles: design tokens, layout and the shared components.
   docs/DESIGN.md lists every class; /styleguide/ (DEBUG only) shows them.
   Feature apps put their own CSS in static/<app>/<app>.css and use the tokens
   below (var(--…)) instead of raw colours, so both themes keep working. */

/* ---------- tokens ---------- */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --surface-3: #e9e9eb;
  --ink: #141414;
  --ink-2: #5c5c63;
  --ink-3: #8c8c94;
  --line: #e4e4e7;
  --line-strong: #d0d0d5;
  --primary: #141414;
  --primary-ink: #ffffff;
  --primary-hover: #333336;
  --link: #1f5fbf;
  --focus: #2f6fdf;
  --success: #1d7a46;
  --success-bg: #e8f5ed;
  --danger: #c4281c;
  --danger-bg: #fdecea;
  --info-bg: #f4f4f5;
  --overlay: rgba(0, 0, 0, .55);
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --gutter: 16px;
  --max: 935px;
  --header-h: 56px;
  --show-light: inline-block;
  --show-dark: none;
  /* Old names, kept so templates written against the first design still work. */
  --stitch: var(--line);
  --font-display: var(--font);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e10;
    --surface: #17171a;
    --surface-2: #1f1f23;
    --surface-3: #2a2a2f;
    --ink: #ededef;
    --ink-2: #a8a8b0;
    --ink-3: #75757d;
    --line: #2a2a2f;
    --line-strong: #3a3a40;
    --primary: #ededef;
    --primary-ink: #111113;
    --primary-hover: #ffffff;
    --link: #7cb0ff;
    --focus: #6aa2ff;
    --success: #6fcf97;
    --success-bg: #14281d;
    --danger: #ff7b72;
    --danger-bg: #331a18;
    --info-bg: #1f1f23;
    --overlay: rgba(0, 0, 0, .7);
    --shadow: none;
    --show-light: none;
    --show-dark: inline-block;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e0e10;
  --surface: #17171a;
  --surface-2: #1f1f23;
  --surface-3: #2a2a2f;
  --ink: #ededef;
  --ink-2: #a8a8b0;
  --ink-3: #75757d;
  --line: #2a2a2f;
  --line-strong: #3a3a40;
  --primary: #ededef;
  --primary-ink: #111113;
  --primary-hover: #ffffff;
  --link: #7cb0ff;
  --focus: #6aa2ff;
  --success: #6fcf97;
  --success-bg: #14281d;
  --danger: #ff7b72;
  --danger-bg: #331a18;
  --info-bg: #1f1f23;
  --overlay: rgba(0, 0, 0, .7);
  --shadow: none;
  --show-light: none;
  --show-dark: inline-block;
  color-scheme: dark;
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
img, video { max-width: 100%; display: block; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-weight: 600; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--ink-2); }
.subtle { color: var(--ink-3); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
.mono { font-family: var(--font-mono); }
.ink, a.ink:hover { color: var(--ink); }
.center { text-align: center; }
.inline-form { display: inline; margin: 0; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.only-light { display: var(--show-light) !important; }
.only-dark { display: var(--show-dark) !important; }
/* Words beside header icons and captions under grid tiles: only the exhibition design (css/exhibition.css) shows them. */
.nav-word, .tile__label { display: none; }

/* ---------- layout ---------- */

.page { width: 100%; max-width: var(--max); margin: 0 auto; padding: 24px var(--gutter) 56px; flex: 1; }
.page--narrow { max-width: 400px; }
.page--medium { max-width: 640px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack--sm { gap: 8px; }
.stack--lg { gap: 32px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
input.grow { width: auto; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { margin: 0; }

/* ---------- header and nav ---------- */

.site-header { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); }
.site-header__inner { max-width: var(--max); height: var(--header-h); margin: 0 auto; padding: 0 var(--gutter); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); }
.brand:hover { color: var(--ink); text-decoration: none; }
.logo { fill: currentColor; flex: none; }
.wordmark { display: block; flex: none; width: auto; }
.brand .wordmark { height: 22px; }
.site-nav { display: flex; align-items: center; gap: 4px; }
.site-nav__link { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; color: var(--ink); padding: 6px 10px; border-radius: var(--radius-sm); font-size: .95rem; }
.site-nav__link:hover { background: var(--surface-2); text-decoration: none; }
.site-nav__link[aria-current="page"] { font-weight: 600; }
.link-button { background: none; border: 0; font: inherit; cursor: pointer; color: inherit; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon--sm { width: 16px; height: 16px; }
/* A small dropdown: <details class="menu"><summary class="icon-btn">…</summary><div class="menu__panel">a.menu__item…</div></details>. Used for the account menu. */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { background: var(--surface-2); }
.menu__panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 200px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0, 0, 0, .12); }
.menu__panel form { margin: 0; }
.menu__head { margin: 0; padding: 6px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu__item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 6px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--ink); font: inherit; font-size: .95rem; text-align: left; cursor: pointer; }
.menu__item:hover { background: var(--surface-2); text-decoration: none; }
.menu__item .icon { width: 18px; height: 18px; }
/* An unread count on a header icon: <a class="icon-btn nav-count">icon<span class="nav-count__badge">3</span></a>. Used by the notifications bell. */
.nav-count { position: relative; }
.nav-count__badge { position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--danger); color: var(--bg); box-shadow: 0 0 0 2px var(--bg); font-size: .68rem; font-weight: 700; line-height: 17px; text-align: center; pointer-events: none; }

/* ---------- messages ---------- */

.messages { width: 100%; max-width: var(--max); margin: 16px auto 0; padding: 0 var(--gutter); display: grid; gap: 8px; }
.message { padding: 10px 14px; border-radius: var(--radius-sm); background: var(--info-bg); color: var(--ink); font-size: .95rem; }
.message--success { background: var(--success-bg); color: var(--success); }
.message--error, .message--warning { background: var(--danger-bg); color: var(--danger); }

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

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: 600 .9rem/1.2 var(--font); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--primary-ink); }
.btn--danger { color: var(--danger); }
.btn--danger:hover { background: var(--danger-bg); color: var(--danger); }
.btn--ghost { border-color: transparent; background: none; }
.btn--sm { min-height: 32px; padding: 5px 12px; font-size: .85rem; }
.btn--lg { min-height: 46px; padding: 12px 22px; font-size: 1rem; }
.btn--block { width: 100%; }

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

.field { margin-bottom: 16px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; font-size: .9rem; }
.field__help { color: var(--ink-3); font-size: .82rem; margin-top: 6px; }
.field__help ul { margin: 4px 0 0; padding-left: 18px; }
.field__error, .form-errors p { color: var(--danger); font-size: .85rem; margin: 6px 0 0; }
.form-errors { background: var(--danger-bg); border-radius: var(--radius-sm); padding: 8px 12px 10px; margin-bottom: 16px; }
.form-errors p:first-child { margin-top: 0; }
.field--error input, .field--error textarea, .field--error select { border-color: var(--danger); }
input[type="text"], input[type="password"], input[type="email"], input[type="search"], input[type="url"], input[type="number"], textarea, select {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font: inherit;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; }
input[type="file"] { display: block; width: 100%; padding: 10px; border: 1px dashed var(--line-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink-2); font: inherit; font-size: .9rem; }
input[type="file"]::file-selector-button { margin-right: 12px; padding: 6px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: 600 .85rem var(--font); cursor: pointer; }
/* A checkbox or radio with its label to the right: <label class="check"><input type="checkbox"> Text</label> */
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 400; cursor: pointer; }
.check input { margin-top: 2px; }
.field > .check { display: flex; font-weight: 400; margin-bottom: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }

/* ---------- cards and lists ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.card--flat { box-shadow: none; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
/* Avatar (or any thumbnail) next to a block of text. Used for comments and member lists. */
.media { display: flex; align-items: flex-start; gap: 12px; }
.media__body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.media__meta { color: var(--ink-3); font-size: .82rem; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: .75rem; font-weight: 600; line-height: 1.5; vertical-align: middle; }
.badge--danger { background: var(--danger-bg); color: var(--danger); }
.badge--success { background: var(--success-bg); color: var(--success); }
.empty { text-align: center; padding: 48px 16px; color: var(--ink-2); }
.empty .icon { width: 40px; height: 40px; margin: 0 auto 12px; stroke-width: 1.25; color: var(--ink-3); }
.empty h2 { color: var(--ink); }

/* ---------- avatars ---------- */

/* <img class="avatar avatar--lg" src="…" alt="">, or a <span class="avatar"> with an initial when there is no picture. */
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 50%; object-fit: cover; background: var(--surface-3); color: var(--ink-2); font-weight: 600; text-transform: uppercase; overflow: hidden; }
.avatar--xs { width: 24px; height: 24px; font-size: .7rem; }
.avatar--sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar--md { width: 56px; height: 56px; font-size: 1.2rem; }
.avatar--lg { width: 88px; height: 88px; font-size: 2rem; }
.avatar--xl { width: 150px; height: 150px; font-size: 3.5rem; }

/* ---------- profile header ---------- */

.profile-head { display: grid; grid-template-columns: auto 1fr; gap: 14px 28px; align-items: center; align-content: center; padding: 8px 0 28px; }
.profile-head__avatar { grid-row: 1 / span 3; }
.profile-head__name { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.profile-head__name h1 { margin: 0; font-size: 1.35rem; font-weight: 500; }
.profile-head__stats { display: flex; gap: 24px; margin: 0; padding: 0; list-style: none; }
.profile-head__stats strong { font-weight: 600; }
.profile-head__bio { grid-column: 2; white-space: pre-line; overflow-wrap: anywhere; }
.profile-head__bio .strong { display: block; }

/* ---------- tabs ---------- */

.tabs { display: flex; justify-content: center; gap: 32px; border-top: 1px solid var(--line); margin-bottom: 4px; }
.tabs__link { display: inline-flex; align-items: center; gap: 6px; padding: 14px 0; margin-top: -1px; border-top: 1px solid transparent; color: var(--ink-3); font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.tabs__link:hover { color: var(--ink); text-decoration: none; }
.tabs__link[aria-current="page"] { color: var(--ink); border-top-color: var(--ink); }

/* ---------- image grid ---------- */

/* <div class="grid"><a class="tile" href="…"><img src="…" alt="…"></a>…</div> */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.tile { position: relative; display: block; aspect-ratio: 1; overflow: hidden; background: var(--surface-2); color: #fff; }
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; }
.tile::after { content: ""; position: absolute; inset: 0; background: rgba(0, 0, 0, 0); transition: background .15s; }
.tile:hover::after { background: rgba(0, 0, 0, .15); }
/* Small icons in the corner of a tile: video, private, several items. */
.tile__marks { position: absolute; top: 8px; right: 8px; z-index: 1; display: flex; gap: 6px; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }
.tile__marks .icon { width: 18px; height: 18px; stroke: #fff; }

/* ---------- single post ---------- */

/* Picture or video on the left, details and comments on the right; stacked on phones. */
.post { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.post__media { background: #000; display: grid; place-items: center; min-height: 300px; }
.post__media img, .post__media video { width: 100%; max-height: 80vh; object-fit: contain; }
.post__side { display: flex; flex-direction: column; border-left: 1px solid var(--line); min-width: 0; }
.post__head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.post__body { flex: 1; padding: 16px; overflow-y: auto; }
.post__foot { padding: 12px 16px; border-top: 1px solid var(--line); }

/* ---------- landing ---------- */

.landing { flex: 1; display: grid; place-items: center; padding: 40px var(--gutter); }
.landing__inner { width: min(320px, 100%); text-align: center; }
.landing__word { display: flex; justify-content: center; margin: 0 0 40px; }
.landing__word .wordmark { height: 44px; }
.landing__actions { display: grid; gap: 10px; }
.corner { position: fixed; top: 12px; right: 12px; }

/* ---------- auth ---------- */

.auth { padding: 32px 28px; }
.auth__head { text-align: center; margin-bottom: 24px; }
.auth__head .logo { display: block; margin: 0 auto 12px; }
.auth__head h1 { font-size: 1.3rem; }
.auth__head p { margin: 0; }
.auth__alt { text-align: center; margin: 16px 0 0; color: var(--ink-2); font-size: .95rem; }
.auth__terms { margin: 12px 0 0; color: var(--ink-3); font-size: .82rem; text-align: center; }

/* ---------- footer ---------- */

.site-footer { border-top: 1px solid var(--line); }
.site-footer__inner { max-width: var(--max); margin: 0 auto; padding: 14px var(--gutter); display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; font-size: .82rem; }
.site-footer a { color: var(--ink-3); }
.site-footer a:hover { color: var(--ink); }

/* ---------- legal pages (terms, privacy) ---------- */

.legal { overflow-wrap: anywhere; }
.legal__head { margin-bottom: 24px; }
.legal__head p { margin: 0; }
.legal h2 { margin-top: 32px; scroll-margin-top: calc(var(--header-h) + 12px); }
.legal h3 { margin-top: 20px; }
.legal ul, .legal ol { margin: 0 0 1em; padding-left: 20px; }
.legal li { margin-bottom: 6px; }
.legal__toc { margin: 0 0 24px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); }
.legal__toc ol { margin: 0; }
.legal__toc li { margin-bottom: 2px; }
.legal__note { margin: 0 0 24px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--danger-bg); color: var(--ink); font-size: .9rem; }
.legal__note p:last-child { margin-bottom: 0; }
.legal__note p:first-child { margin-bottom: 4px; }
.legal-blank { padding: 0 3px; border-radius: 3px; background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.legal__table { margin: 0 0 1em; overflow-x: auto; }
.legal table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.legal th, .legal td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.legal th { color: var(--ink-2); font-weight: 600; }

/* ---------- errors ---------- */

.error-page { text-align: center; padding: 64px 0; }
.error-page__code { font-size: 3rem; font-weight: 650; letter-spacing: -.03em; color: var(--ink-3); margin: 0 0 8px; }

/* ---------- phones ---------- */

@media (max-width: 735px) {
  .post { grid-template-columns: 1fr; }
  .post__side { border-left: 0; border-top: 1px solid var(--line); }
  .profile-head { gap: 12px 20px; padding-bottom: 20px; }
  .profile-head__avatar.avatar--xl { width: 80px; height: 80px; font-size: 2rem; }
  .profile-head__avatar { grid-row: 1 / span 2; }
  .profile-head__bio { grid-column: 1 / -1; }
  .profile-head__stats { gap: 16px; font-size: .9rem; }
}

@media (max-width: 480px) {
  .page { padding-top: 16px; }
  .card, .auth { padding: 20px 16px; }
  .grid { gap: 2px; }
  .site-nav__link { padding: 6px 8px; }
  .site-nav__label { display: none; }
  .site-header__inner { gap: 8px; }
  .site-nav { gap: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
