/* ==========================================================================
   Chipd design system
   --------------------------------------------------------------------------
   Hand-rolled CSS, deliberately not Tailwind. The Play CDN compiled styles at
   runtime, which is why the CSP needed 'unsafe-eval'; owning the stylesheet
   lets that exception go away and removes a render-blocking round trip.

   Two token layers:
     1. Raw palette  — never changes, never referenced by components.
     2. Semantic     — flips per theme. Components only ever use these.
   ========================================================================== */

/* -------------------------------------------------------------- 1. tokens */

:root {
  /* Raw palette ---------------------------------------------------------- */
  --mulberry-50: #f6f1ff;
  --mulberry-100: #ebe0ff;
  --mulberry-200: #d8c4ff;
  --mulberry-300: #bf9dff;
  --mulberry-400: #a576f7;
  --mulberry-500: #8b55e8;
  --mulberry-600: #7340cb;
  --mulberry-700: #5c31a3;
  --mulberry-800: #46257c;
  --mulberry-900: #2f1954;

  --sunpaw-400: #ffb454;
  --sunpaw-500: #f59324;
  --sunpaw-600: #d4760f;

  --pinemint-400: #4fd1a8;
  --pinemint-500: #22b58c;
  --pinemint-600: #12906f;

  --rose-400: #e08aa0;
  --rose-600: #a83f5c;

  --cinnabar-400: #f26d70;
  --cinnabar-600: #d93036;

  /* Shape ---------------------------------------------------------------- */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Motion --------------------------------------------------------------- */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --dur-slow: 240ms;

  /* Type ----------------------------------------------------------------- */
  --font-display: "Bricolage Grotesque", "Outfit", system-ui, sans-serif;
  --font-body: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", monospace;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 0.9375rem; /* 15px — beats 16 for a dense feed */
  --text-lg: 1.0625rem;
  --text-xl: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
  --text-2xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);

  --leading-tight: 1.2;
  --leading-snug: 1.4;
  --leading-body: 1.6;

  /* Layout --------------------------------------------------------------- */
  --topbar-h: 56px;
  --bottombar-h: 56px;
  --nav-w: 240px;
  --rail-w: 320px;
  --feed-w: 640px;
}

/* Dark is the default. Warm-plum neutrals, luminance capped at both ends so
   nothing glares at 2am. Never #000, never #fff. */
:root,
[data-theme="dark"] {
  --canvas: #12101a;
  --surface: #1a1724;
  --surface-raised: #23202f;
  --surface-sunken: #0d0b14;
  --border: #2e2a3d;
  --border-strong: #413b54;

  --text: #edeaf5; /* 15.9:1 on canvas */
  --text-muted: #a7a1bc; /* 7.6:1 */
  /* 4.9:1. Was #7c7593, which measured 4.33:1 — under the 4.5 AA floor while
     being used at 12px for timestamps and handles. Lightened to pass. */
  --text-subtle: #857da0;

  --brand: var(--mulberry-400);
  --brand-hover: var(--mulberry-300);
  --brand-fill: var(--mulberry-500);
  --brand-on-fill: #fff;
  --brand-ghost: rgb(165 118 247 / 0.12);

  --accent: var(--sunpaw-400);
  --accent-ghost: rgb(255 180 84 / 0.12);
  --success: var(--pinemint-400);
  --danger: var(--cinnabar-400);
  --danger-ghost: rgb(242 109 112 / 0.12);
  --cw: #ffc978;
  --mature: var(--rose-400);

  --focus-ring: var(--mulberry-300);
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-2: 0 4px 16px -4px rgb(0 0 0 / 0.5);
  --shadow-3: 0 16px 48px -12px rgb(0 0 0 / 0.65);
  /* 4% white on the top edge only: makes a dark card read as lit from above.
     Does the job the old backdrop-blur glassmorphism was trying to do, for
     none of the GPU cost. */
  --hairline: inset 0 1px 0 rgb(255 255 255 / 0.04);
  color-scheme: dark;
}

[data-theme="light"] {
  --canvas: #faf7f5; /* warm paper, not clinical white */
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: #f2edea;
  --border: #e8e2de;
  --border-strong: #d4cbc5;

  --text: #1e1a26;
  --text-muted: #5c5468;
  --text-subtle: #6f6780; /* 5.0:1. Was #847b92 at 3.8:1 — failed AA. */

  --brand: var(--mulberry-600);
  --brand-hover: var(--mulberry-700);
  --brand-fill: var(--mulberry-500);
  --brand-on-fill: #fff;
  --brand-ghost: rgb(115 64 203 / 0.08);

  --accent: var(--sunpaw-600);
  --accent-ghost: rgb(212 118 15 / 0.1);
  --success: var(--pinemint-600);
  --danger: var(--cinnabar-600);
  --danger-ghost: rgb(217 48 54 / 0.08);
  --cw: #8a5200;
  --mature: var(--rose-600);

  --focus-ring: var(--mulberry-600);
  --shadow-1: 0 1px 2px rgb(30 26 38 / 0.06);
  --shadow-2: 0 4px 16px -4px rgb(30 26 38 / 0.1);
  --shadow-3: 0 16px 48px -12px rgb(30 26 38 / 0.18);
  --hairline: none;
  color-scheme: light;
}

/* Midnight: an overlay on dark for reading in bed, not a separate palette. */
[data-dim="true"] {
  --canvas: #0b0a0f;
  --surface: #131119;
  --surface-sunken: #08070c;
}
[data-dim="true"] img,
[data-dim="true"] video {
  filter: brightness(0.88);
}

/* A real high-contrast mode: heavier borders, brighter text, amber focus. */
[data-contrast="high"] {
  --text: #ffffff;
  --text-muted: #dcd7e8;
  --text-subtle: #bdb6cc;
  --border: #6b6383;
  --border-strong: #9a90b8;
  --brand: #c9a8ff;
  --focus-ring: #ffe58a;
}
[data-contrast="high"] .card,
[data-contrast="high"] .btn,
[data-contrast="high"] .input {
  border-width: 2px;
}

/* Body-font swap for low vision. Atkinson Hyperlegible disambiguates the
   letterforms that trip people up (I/l/1, O/0) and is genuinely warm, so it
   reads as a choice rather than a compromise. */
[data-font="hyperlegible"] {
  --font-body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --font-display: "Atkinson Hyperlegible", system-ui, sans-serif;
}

/* ---------------------------------------------------------------- 2. base */

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

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
  font-variant-numeric: tabular-nums; /* counters must not jitter as they tick */
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  letter-spacing: -0.02em; /* display sizes only; body stays at 0 */
  margin: 0;
}

p {
  margin: 0;
}

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

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

::selection {
  background: var(--brand-ghost);
  color: var(--text);
}

/* :focus-visible, not :focus — mouse users never see the ring, keyboard users
   always do. Never remove this without providing a replacement. */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--space-4);
  top: -100px;
  z-index: 200;
  padding: var(--space-3) var(--space-4);
  background: var(--brand-fill);
  color: var(--brand-on-fill);
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: top var(--dur-base) var(--ease-out);
}
.skip-link:focus {
  top: var(--space-3);
}

/* Reduced motion must also kill the like animation and any autoplay. */
@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;
  }
}

/* --------------------------------------------------------- 3. app shell */

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  max-width: 1280px;
  margin-inline: auto;
  padding-inline: var(--space-4);
  padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + var(--space-6));
}

@media (min-width: 1024px) {
  .app-shell {
    /* minmax(0, …) not a bare width: without the 0 minimum a wide media grid
       blows the column out and the whole page scrolls sideways. */
    grid-template-columns: var(--nav-w) minmax(0, var(--feed-w));
    padding-bottom: var(--space-7);
  }
}

@media (min-width: 1280px) {
  .app-shell {
    grid-template-columns: var(--nav-w) minmax(0, var(--feed-w)) var(--rail-w);
  }
}

/* Topbar ----------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-inline: var(--space-4);
  background: color-mix(in srgb, var(--canvas) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

@media (prefers-reduced-transparency: reduce) {
  .topbar,
  .bottom-bar {
    background: var(--canvas);
    backdrop-filter: none;
  }
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--text-lg);
  color: var(--text);
  text-decoration: none;
  flex: none;
}
.brand:hover {
  text-decoration: none;
}

/* Logo mark is a CSS shape, not an image asset. */
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--mulberry-400), var(--sunpaw-400));
  display: grid;
  place-items: center;
  flex: none;
  position: relative;
}
.brand-mark::before {
  content: "";
  width: 11px;
  height: 9px;
  border-radius: 50% 50% 46% 46%;
  background: var(--canvas);
  opacity: 0.92;
  margin-top: 3px;
}
.brand-mark::after {
  content: "";
  position: absolute;
  top: 6px;
  width: 15px;
  height: 4px;
  background:
    radial-gradient(circle, var(--canvas) 55%, transparent 56%) 0 0 / 5px 4px no-repeat,
    radial-gradient(circle, var(--canvas) 55%, transparent 56%) 5px 0 / 5px 4px no-repeat,
    radial-gradient(circle, var(--canvas) 55%, transparent 56%) 10px 0 / 5px 4px no-repeat;
  opacity: 0.92;
}

.brand-tld {
  color: var(--brand);
}

.topbar-spacer {
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Sidebar nav ------------------------------------------------------------ */

.sidebar {
  display: none;
}

@media (min-width: 1024px) {
  .sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    position: sticky;
    top: calc(var(--topbar-h) + var(--space-5));
    align-self: start;
    max-height: calc(100dvh - var(--topbar-h) - var(--space-6));
    overflow-y: auto;
  }
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  background: none;
  border: 0;
  width: 100%;
  text-align: start;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}
.nav-item:hover {
  background: var(--brand-ghost);
  color: var(--text);
  text-decoration: none;
}
.nav-item[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  background: var(--brand-ghost);
}
/* Leading notch on the active item, scaling in from the centre. */
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 50%;
  translate: 0 -50%;
  width: 3px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--brand);
  animation: notch-in var(--dur-base) var(--ease-out);
}
@keyframes notch-in {
  from {
    transform: scaleY(0.3);
    opacity: 0;
  }
}

.nav-icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.nav-count {
  margin-inline-start: auto;
  min-width: 20px;
  height: 20px;
  padding-inline: 6px;
  border-radius: var(--radius-pill);
  background: var(--brand-fill);
  color: var(--brand-on-fill);
  font-size: var(--text-xs);
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* Bottom bar (mobile) ---------------------------------------------------- */

.bottom-bar {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 60;
  height: calc(var(--bottombar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  align-items: stretch;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

@media (min-width: 1024px) {
  .bottom-bar {
    display: none;
  }
}

.bottom-bar .nav-item {
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 48px; /* touch target floor, even though the icon is 24px */
  min-height: 48px;
  border-radius: 0;
  font-size: var(--text-xs);
  padding: 0;
}
.bottom-bar .nav-item[aria-current="page"] {
  background: none;
  color: var(--brand);
}
.bottom-bar .nav-item[aria-current="page"]::before {
  inset-inline: 30%;
  inset-inline-start: 30%;
  top: 0;
  translate: none;
  width: auto;
  height: 3px;
  border-radius: 0 0 var(--radius-pill) var(--radius-pill);
}
.bottom-bar .nav-count {
  position: absolute;
  top: 4px;
  inset-inline-end: 22%;
  margin: 0;
}

/* Compose FAB: the one action worth pulling out of the bar, in thumb reach. */
.fab {
  position: fixed;
  inset-inline-end: var(--space-4);
  bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + var(--space-4));
  z-index: 55;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-pill);
  border: 0;
  background: var(--brand-fill);
  color: var(--brand-on-fill);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-3);
  transition: transform var(--dur-fast) var(--ease-out);
}
.fab:active {
  transform: scale(0.94);
}

@media (min-width: 1024px) {
  .fab {
    display: none;
  }
}

/* Rail ------------------------------------------------------------------- */

.rail {
  display: none;
}

@media (min-width: 1280px) {
  .rail {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    position: sticky;
    top: calc(var(--topbar-h) + var(--space-5));
    align-self: start;
  }
}

.feed-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-width: 0; /* pairs with minmax(0,…) to stop media overflowing */
  padding-top: var(--space-5);
}

/* ------------------------------------------------------------ 4. surfaces */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1), var(--hairline);
  transition:
    border-color var(--dur-base) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}
.card-pad {
  padding: var(--space-4);
}
.card-hover:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2), var(--hairline);
}

@media (max-width: 479px) {
  /* Full-bleed cards on small phones: side gutters waste scarce width.
     Top-level cards only — :not(.card .card) spares anything nested inside
     another card, which would otherwise hang off the screen edge. */
  #view .card:not(.card .card) {
    border-radius: 0;
    border-inline: 0;
    margin-inline: calc(var(--space-4) * -1);
  }
}

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

.section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-subtle);
}

/* ------------------------------------------------------------- 5. buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding-inline: var(--space-4);
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: none;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition:
    background var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    transform var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-base) var(--ease-out);
}
.btn:hover {
  text-decoration: none;
}
.btn:active {
  transform: scale(0.97); /* tactile press, reads as responsive on touch */
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--brand-fill);
  color: var(--brand-on-fill);
  box-shadow: var(--shadow-1);
}
.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: var(--shadow-2);
}

/* --surface-sunken, not --surface-raised: in the light theme both the card and
   --surface-raised are pure white, which left this button invisible except for
   its 1px border. */
.btn-secondary {
  background: var(--surface-sunken);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-strong);
}

.btn-ghost {
  color: var(--text-muted);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--brand-ghost);
  color: var(--text);
}

.btn-danger {
  color: var(--danger);
  border-color: currentColor;
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-ghost);
}

.btn-sm {
  height: 32px;
  padding-inline: var(--space-3);
  font-size: var(--text-xs);
}
.btn-lg {
  height: 48px;
  padding-inline: var(--space-5);
  font-size: var(--text-base);
}
.btn-block {
  width: 100%;
}

/* Controls that are visually smaller than 44px get a centred, invisible hit
   rectangle that is at least 44×44. The control looks compact; the tap target
   is not. Applied to every sub-44px control in the shell. */
.btn-sm,
.icon-btn,
.brand,
.avatar-link {
  position: relative;
}
.btn-sm::after,
.icon-btn::after,
.brand::after,
.avatar-link::after {
  content: "";
  position: absolute;
  top: 50%;
  inset-inline-start: 50%;
  translate: -50% -50%;
  width: 100%;
  height: 100%;
  min-width: 44px;
  min-height: 44px;
}

/* Square icon button, still 44px of hit area at the smaller visual size. */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 0;
  background: none;
  color: var(--text-muted);
  position: relative;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}
.icon-btn:hover {
  background: var(--brand-ghost);
  color: var(--text);
}

/* --------------------------------------------------------------- 6. forms */

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

.label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
}

.input,
.textarea,
.select {
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  transition:
    border-color var(--dur-fast) var(--ease-out),
    background var(--dur-fast) var(--ease-out);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-subtle);
}
.input:hover,
.textarea:hover {
  border-color: var(--border-strong);
}
.textarea {
  resize: vertical;
  min-height: 84px;
  line-height: var(--leading-body);
}

.input-prefix {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding-inline-start: var(--space-3);
}
.input-prefix span {
  color: var(--text-subtle);
  font-weight: 700;
}
.input-prefix .input {
  border: 0;
  background: none;
  padding-inline-start: 0;
}
.input-prefix:focus-within {
  border-color: var(--focus-ring);
}

.hint {
  font-size: var(--text-xs);
  color: var(--text-subtle);
}
.error-text {
  font-size: var(--text-sm);
  color: var(--danger);
}

/* Switch ----------------------------------------------------------------- */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 44px;
  padding-block: var(--space-2);
}

.switch {
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-sunken);
  position: relative;
  transition: background var(--dur-base) var(--ease-out);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text-muted);
  transition:
    translate var(--dur-base) var(--ease-out),
    background var(--dur-base) var(--ease-out);
}
.switch[aria-checked="true"] {
  background: var(--brand-fill);
  border-color: var(--brand-fill);
}
.switch[aria-checked="true"]::after {
  translate: 18px 0;
  background: #fff;
}

/* -------------------------------------------------------------- 7. avatar */

.avatar {
  position: relative;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* No stock photo, no generated art: an empty avatar is a tinted disc with the
   first glyph of the handle set in the display face. */
.avatar-initial {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--brand);
  background: var(--brand-ghost);
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 0.5em;
  text-transform: uppercase;
  user-select: none;
}
.avatar-lg {
  width: 96px;
  height: 96px;
  font-size: 96px;
}
.avatar-md {
  width: 56px;
  height: 56px;
  font-size: 56px;
}
.avatar {
  font-size: 40px;
}

/* Status collar: a ring with a gap, warmer than the usual corner dot.
   Always paired with a visible or sr-only label — never colour alone. */
.avatar-collar {
  box-shadow:
    0 0 0 3px var(--canvas),
    0 0 0 5px var(--status, var(--success));
}
.avatar-collar-online {
  --status: var(--success);
}
.avatar-collar-con {
  --status: var(--accent);
}

/* -------------------------------------------------------------- 8. badges */

/* Three shapes so the tiers are distinguishable without reading colour. */
.badge-role {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--brand) 28%, transparent);
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1.5;
}
.badge-earned {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--accent);
}
.badge-mod {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--danger) 26%, transparent);
  color: var(--danger);
}

/* Content badges are rectangular on purpose: shape alone separates a safety
   label from a decorative role pill, which matters for colourblind users. */
.badge-content {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--cw) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--cw) 32%, transparent);
  color: var(--cw);
  font-size: var(--text-xs);
  font-weight: 700;
}
.badge-mature {
  background: color-mix(in srgb, var(--mature) 14%, transparent);
  border-color: color-mix(in srgb, var(--mature) 32%, transparent);
  color: var(--mature);
}

.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
}
.badge-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--status, var(--text-subtle));
  flex: none;
}

.chip-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-ghost);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 700;
}

/* ---------------------------------------------------------------- 9. tabs */

.tablist {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}
.tablist::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  flex: none;
  scroll-snap-align: start;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border: 0;
  background: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: var(--text-sm);
  transition: color var(--dur-fast) var(--ease-out);
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
}
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-3);
  bottom: -1px;
  height: 3px;
  border-radius: var(--radius-pill) var(--radius-pill) 0 0;
  background: var(--brand);
  animation: tab-in var(--dur-base) var(--ease-out);
}
@keyframes tab-in {
  from {
    transform: scaleX(0.4);
    opacity: 0;
  }
}

/* --------------------------------------------------------------- 10. post */

.post {
  display: flex;
  flex-direction: column;
  content-visibility: auto;
  contain-intrinsic-size: auto 320px; /* keeps the scrollbar honest off-screen */
}

.post-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-3);
}

.post-ident {
  min-width: 0;
  flex: 1;
}

.post-name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  font-weight: 700;
  font-size: var(--text-sm);
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-subtle);
  font-size: var(--text-xs);
  margin-top: 2px;
}
.post-handle {
  font-family: var(--font-mono);
}

.post-body {
  padding: 0 var(--space-4) var(--space-3);
  max-width: 68ch; /* measure cap — never justify */
  font-size: var(--text-base);
  line-height: var(--leading-body);
  overflow-wrap: anywhere; /* a pasted URL must not blow the column out */
  white-space: pre-wrap;
}

.post-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2) var(--space-2);
  border-top: 1px solid var(--border);
  margin-top: var(--space-1);
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding-inline: var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-subtle);
  font-size: var(--text-xs);
  font-weight: 600;
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out);
}
.action-btn:hover {
  background: var(--brand-ghost);
  color: var(--text);
}
.action-btn[data-danger]:hover {
  background: var(--danger-ghost);
  color: var(--danger);
}
.action-btn[aria-pressed="true"] {
  color: var(--mature);
}
.action-btn[aria-pressed="true"] svg {
  fill: currentColor;
  animation: pop var(--dur-slow) var(--ease-spring);
}
/* The one celebratory spring in the system. Anywhere else and the UI feels
   bouncy and cheap. */
@keyframes pop {
  0% {
    transform: scale(0.8);
  }
  60% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

/* -------------------------------------------------------------- 11. media */

.media-grid {
  display: grid;
  gap: 4px;
  padding-inline: var(--space-4);
  padding-bottom: var(--space-3);
}
.media-grid[data-count="1"] {
  grid-template-columns: 1fr;
}
.media-grid[data-count="2"] {
  grid-template-columns: 1fr 1fr;
}
.media-grid[data-count="3"] {
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.media-grid[data-count="3"] > :first-child {
  grid-row: span 2;
}
.media-grid[data-count="4"] {
  grid-template-columns: 1fr 1fr;
}

.media-slot {
  position: relative;
  margin: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-sunken);
  aspect-ratio: 1;
}
.media-grid[data-count="1"] .media-slot {
  aspect-ratio: 4 / 3;
  max-height: 70vh;
}
/* Traditional art posted as a tall photo must not be centre-cropped —
   the composition is the work. Letterbox it into the well instead. */
.media-slot[data-fit="contain"] img {
  object-fit: contain;
}
.media-slot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The ALT badge is a real button: showing the author's description on tap is
   what makes people write it. Platforms that hide alt text get single-digit
   coverage. */
.alt-badge {
  position: absolute;
  inset-inline-start: var(--space-2);
  bottom: var(--space-2);
  padding: 3px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: rgb(0 0 0 / 0.7);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
}
.alt-badge:hover {
  background: rgb(0 0 0 / 0.85);
}

/* Content veil ----------------------------------------------------------- */

/* Opaque element ABOVE the media, not filter:blur() on the <img>. A CSS blur
   samples the real pixels — it can be undone in devtools or caught in a
   screenshot mid-transition. This never paints the content until revealed. */
.media-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
  text-align: center;
  background: var(--surface-sunken);
  background-image: repeating-linear-gradient(
    45deg,
    color-mix(in srgb, var(--mature) 7%, transparent) 0 10px,
    transparent 10px 20px
  );
  transition: opacity var(--dur-slow) var(--ease-out);
}
.media-slot[data-revealed="true"] .media-veil {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}
.media-veil p {
  font-size: var(--text-xs);
  color: var(--text-muted);
  max-width: 34ch;
}

/* The warning itself lives outside the veil and is always readable — the
   point of a warning is to be read before you decide. */
.cw-strip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: 0 var(--space-4) var(--space-3);
}

/* ------------------------------------------------------- 12. feed states */

.skeleton {
  background: var(--surface-raised);
  border-radius: var(--radius-sm);
  animation: pulse 1.6s var(--ease-out) infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

/* Pawpad loader: four CSS discs in an arc. Reads as a paw at a glance,
   stays abstract, ships no image. */
.pawpad {
  display: inline-grid;
  grid-template-columns: repeat(3, 6px);
  gap: 3px;
  align-items: end;
  justify-items: center;
  width: 24px;
}
.pawpad i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
  animation: pad 1.1s var(--ease-out) infinite;
}
.pawpad i:nth-child(2) {
  animation-delay: 0.12s;
  margin-bottom: 3px;
}
.pawpad i:nth-child(3) {
  animation-delay: 0.24s;
}
.pawpad i:nth-child(4) {
  grid-column: 1 / -1;
  width: 13px;
  height: 10px;
  border-radius: 50% 50% 46% 46%;
  animation-delay: 0.36s;
}
@keyframes pad {
  0%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-5);
  text-align: center;
}
.empty-state h3 {
  font-size: var(--text-xl);
}
.empty-state p {
  color: var(--text-muted);
  max-width: 44ch;
  line-height: var(--leading-body);
}

.load-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* An explicit terminus. Endless scroll with no floor is hostile to the
   late-night browsing this palette is tuned for. */
.feed-end {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-4);
  color: var(--text-subtle);
  font-size: var(--text-sm);
}
.feed-end::before,
.feed-end::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ------------------------------------------------------------- 13. modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgb(0 0 0 / 0.66);
  animation: fade-in var(--dur-base) var(--ease-out);
}
.modal[hidden] {
  display: none;
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.modal-panel {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - var(--space-6));
  overflow-y: auto;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
  padding: var(--space-5);
  animation: rise var(--dur-slow) var(--ease-out);
}
@keyframes rise {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.modal-title {
  font-size: var(--text-xl);
  font-weight: 800;
}

/* Bottom sheet on phones: a centred dialog wastes thumb reach. */
@media (max-width: 599px) {
  .modal {
    place-items: end stretch;
    padding: 0;
  }
  .modal-panel {
    max-width: none;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
    animation: sheet-up var(--dur-slow) var(--ease-out);
  }
  @keyframes sheet-up {
    from {
      transform: translateY(100%);
    }
  }
}

/* --------------------------------------------------------------- 14. toast */

.toast-region {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-3));
  inset-inline-end: var(--space-4);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  max-width: 380px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-3);
  font-size: var(--text-sm);
  font-weight: 500;
  animation: toast-in var(--dur-slow) var(--ease-out);
}
.toast::before {
  content: "";
  width: 3px;
  align-self: stretch;
  border-radius: var(--radius-pill);
  background: var(--success);
  flex: none;
}
.toast[data-kind="error"]::before {
  background: var(--danger);
}
.toast[data-kind="warn"]::before {
  background: var(--accent);
}
@keyframes toast-in {
  from {
    transform: translateY(-8px);
    opacity: 0;
  }
}

@media (max-width: 599px) {
  .toast-region {
    inset-inline: var(--space-3);
    top: calc(var(--topbar-h) + var(--space-2));
  }
  .toast {
    max-width: none;
  }
}

/* ------------------------------------------------------------- 15. profile */

.profile-banner {
  aspect-ratio: 3 / 1;
  background: var(--surface-sunken);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
}
.profile-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* Empty banner is a brand wash, not a stock photograph. */
.profile-banner:not(:has(img)) {
  background-image: linear-gradient(
    135deg,
    color-mix(in srgb, var(--brand) 16%, var(--surface)),
    color-mix(in srgb, var(--accent) 16%, var(--surface))
  );
}

.profile-head {
  padding: 0 var(--space-4) var(--space-4);
}

/* Half-overlap welds the two upload slots into one identity block. The 4px
   canvas ring is a knockout, not a shadow — it holds up over ANY banner. */
.profile-avatar {
  width: clamp(88px, 12vw, 120px);
  height: clamp(88px, 12vw, 120px);
  font-size: clamp(88px, 12vw, 120px);
  margin-top: calc(clamp(88px, 12vw, 120px) / -2);
  border: 4px solid var(--canvas);
  background: var(--canvas);
  border-radius: var(--radius-pill);
  position: relative;
  z-index: 1;
}

.profile-name {
  font-size: var(--text-2xl);
  font-weight: 800;
}

.profile-stats {
  display: flex;
  gap: var(--space-5);
  flex-wrap: wrap;
  padding-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.profile-stats b {
  color: var(--text);
  font-weight: 700;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-top: var(--space-2);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding-top: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-sm);
}
.meta-row span,
.meta-row a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* --------------------------------------------------------------- 16. util */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.row-between {
  justify-content: space-between;
}
.wrap {
  flex-wrap: wrap;
}
.grow {
  flex: 1;
  min-width: 0;
}
.muted {
  color: var(--text-muted);
}
.subtle {
  color: var(--text-subtle);
  font-size: var(--text-xs);
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mono {
  font-family: var(--font-mono);
}
[hidden] {
  display: none !important;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: var(--space-3);
}
.metric {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  text-align: center;
}
.metric b {
  display: block;
  font-family: var(--font-display);
  font-size: var(--text-xl);
  color: var(--brand);
}
.metric span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-subtle);
}
