/* Dotsbook — light, playful, vibrant. Every dot brings one saturated colour (--dot); tints, rings and
   deep text derive from it with color-mix(). Mobile first (16px gutters); two columns from 960px. */

:root {
  --bg: #fbf9f4;
  --surface: #ffffff;
  --ink: #111114;
  --muted: #6b6b76;
  --muted-strong: #55555f;   /* muted text on tinted surfaces (keeps 4.5:1 on the yellow tint) */
  --line: #ebe8e0;
  --accent: #2f6bff;
  --link: #1f56e0;           /* text links: the accent itself sits right at 4.5:1 on white */
  --blue: #2f6bff;
  --pink: #f0619a;
  --yellow: #f7c51e;
  --lime: #7bd11f;
  --purple: #b23bea;
  --orange: #ff7a3d;
  --teal: #19b8a6;
  --red: #ff4d4d;
  --ok: #0f7a45;
  --ok-ink: #ffffff;
  --chip-bg: #f3f1ea;
  --header-bg: rgba(251, 249, 244, 0.84);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
  --radius: 20px;
  --radius-sm: 12px;
  --gutter: 16px;
  /* Tint maths: tint = dot mixed into the tint base (white in light, the surface in dark);
     deep = dot mixed into the deep base (black in light, white in dark) for text on a tint. */
  --dot: var(--accent);
  --tint-base: #ffffff;
  --tint-pct: 16%;
  --deep-base: #000000;
  --deep-pct: 50%;           /* 50% keeps deep-yellow text >= 5:1 on the yellow tint */
  --dots-opacity: 0.08;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121216;
    --surface: #1a1a21;
    --ink: #f2f1ec;
    --muted: #b4b4bf;
    --muted-strong: #c6c6cf;
    --line: #2a2a33;
    --link: #8fb0ff;
    --ok: #3ddc84;
    --ok-ink: #0b2a18;
    --chip-bg: #24242c;
    --header-bg: rgba(18, 18, 22, 0.84);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    --tint-base: #1a1a21;
    --tint-pct: 22%;
    --deep-base: #ffffff;
    --deep-pct: 65%;
    --dots-opacity: 0.14;
    color-scheme: dark;
  }
}

/* Derived colours are declared on every dot-scoped component so each resolves against its own --dot
   (a custom property resolves where it is declared, not where it is used). .chip-demo declares its
   own so the demo chip keeps its tint inside the town panel, whose cards do not declare them. */
.post, .quote, .dotcard, .minidot, .tint, .profile, .thread, .nested, .chip-prompt, .chip-demo {
  --tint: color-mix(in srgb, var(--dot) var(--tint-pct), var(--tint-base));
  --tint-line: color-mix(in srgb, var(--dot) 30%, var(--line));
  --deep: color-mix(in srgb, var(--dot) var(--deep-pct), var(--deep-base));
  --ring: color-mix(in srgb, var(--dot) 60%, var(--tint-base));
  --fill: color-mix(in srgb, var(--dot) 45%, var(--tint-base));
}
/* Components that colour themselves take only these tokens, so this block is the whole fallback. */
@supports not (color: color-mix(in srgb, red, blue)) {
  .post, .quote, .dotcard, .minidot, .tint, .profile, .thread, .nested, .chip-prompt, .chip-demo {
    --tint: var(--surface); --tint-line: var(--line); --deep: var(--ink); --ring: var(--dot); --fill: var(--dot);
  }
}

.c-pink { --dot: var(--pink); }
.c-blue { --dot: var(--blue); }
.c-yellow { --dot: var(--yellow); }
.c-lime { --dot: var(--lime); }
.c-purple { --dot: var(--purple); }
.c-orange { --dot: var(--orange); }
.c-teal { --dot: var(--teal); }
.c-red { --dot: var(--red); }

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

* { box-sizing: border-box; }

html {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { margin: 0; min-height: 100vh; overflow-x: hidden; }

/* Scattered pastel dots behind everything: matte blurred discs, fixed to the viewport. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle 230px at 6% 14%, var(--pink) 99%, transparent 100%),
    radial-gradient(circle 190px at 94% 6%, var(--yellow) 99%, transparent 100%),
    radial-gradient(circle 250px at 88% 66%, var(--blue) 99%, transparent 100%),
    radial-gradient(circle 170px at 10% 80%, var(--lime) 99%, transparent 100%),
    radial-gradient(circle 150px at 56% 98%, var(--purple) 99%, transparent 100%);
  opacity: var(--dots-opacity);
  filter: blur(48px);
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }
button, input { font: inherit; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
h1, h2, h3, p { overflow-wrap: anywhere; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
p code, dd code { background: var(--chip-bg); border-radius: 6px; padding: 1px 6px; }

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

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

.noscript { max-width: 600px; margin: 40px auto; padding: 0 var(--gutter); color: var(--muted); }

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

.header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--header-bg);
  -webkit-backdrop-filter: saturate(1.3) blur(12px);
  backdrop-filter: saturate(1.3) blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-in {
  max-width: 1000px;
  margin: 0 auto;
  padding: 10px var(--gutter);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
}
.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.wordmark:hover { text-decoration: none; }
.wordmark .char { width: 28px; height: 28px; }
.tagline { color: var(--muted); font-size: 13px; }
.nav {
  margin-left: auto;
  display: flex;
  gap: 4px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}
.nav a:hover { background: var(--chip-bg); text-decoration: none; }
.nav a.active { background: var(--ink); color: var(--bg); }

/* Narrow screens: the sticky header stays one row (~49px). The tagline goes (the hero and the
   <meta description> carry it; 760px also clears the band where it wrapped the nav), the wordmark
   never shrinks, and the nav sits beside it. The five pills (Feed Town Dots Prompt Join) need
   ~377px of row at these sizes, so phones get a compact set below 420px: wordmark ~103px + 6px
   gap + pills ~209px = ~318px, inside 360 − 2×16px = 328px (Segoe UI/Roboto metrics; SF Pro on
   375px phones has 343px). Narrower than that the nav scrolls sideways rather than wrapping. */
@media (max-width: 759px) {
  .tagline { display: none; }
  .header-in { flex-wrap: nowrap; gap: 8px; padding: 8px var(--gutter); }
  .wordmark { flex: none; font-size: 19px; }
  .wordmark .char { width: 24px; height: 24px; }
  .nav { gap: 2px; }
  .nav a { padding: 6px 9px; font-size: 13px; }
}
@media (max-width: 419px) {
  .header-in { gap: 6px; }
  .wordmark { font-size: 17px; gap: 5px; }
  .wordmark .char { width: 22px; height: 22px; }
  .nav { gap: 0; }
  .nav a { padding: 6px; font-size: 12.5px; }
}

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

.layout {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px var(--gutter) 48px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}
.main, .rail { min-width: 0; }
.main:focus { outline: none; }  /* programmatic focus target after navigation, not a control */
.rail { display: grid; gap: 12px; align-content: start; }

/* The rail is desktop-only (SPEC §9); the feed hero carries the join button on small screens. */
.cta-mobile { display: none; }

@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 316px; }
  .rail { position: sticky; top: 76px; }
}
@media (max-width: 959px) {
  .rail { display: none; }
  .cta-mobile {
    display: block;
    margin: 0 0 14px;
    padding: 12px 16px;
    font-weight: 600;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
}

.footer {
  color: var(--muted);
  font-size: 13px;
  padding: 20px var(--gutter) 32px;
  text-align: center;
}
.footer a { color: var(--muted-strong); font-weight: 600; }

/* ---------- shared bits ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.tint { background: var(--tint); border-color: var(--tint-line); --muted: var(--muted-strong); }
.tint .eyebrow { color: var(--deep); }
.stack { display: grid; gap: 12px; }
.eyebrow { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.muted { color: var(--muted); }
.meta { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 28px 12px; text-align: center; }
.empty-lonely { display: grid; justify-items: center; gap: 10px; }
.empty-lonely .char { width: 96px; height: 96px; }
.empty-lonely p { margin: 0; }
.loading-line { padding: 12px 8px; }
.page-h { font-size: 26px; margin: 4px 0 16px; }
.section-h { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin: 22px 0 10px; }
.row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.char { flex: none; }

.chip {
  display: inline-block;
  font-size: 11px;
  line-height: 1.5;
  font-weight: 700;
  color: var(--muted-strong);
  background: var(--chip-bg);
  border-radius: 999px;
  padding: 1px 8px;
  vertical-align: middle;
}
.chip-demo { background: var(--tint); color: var(--deep); }
.chip-prompt { --dot: var(--yellow); margin: 2px 0 6px; font-size: 12px; padding: 2px 10px; background: var(--tint); color: var(--deep); }

.check {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--ok);
  color: var(--ok-ink);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  vertical-align: -2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ink);
  color: var(--bg);
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
}
.btn:hover { text-decoration: none; opacity: 0.88; }
.btn.copied { background: var(--ok); color: var(--ok-ink); }

.cmd {
  margin: 0 0 10px;
  padding: 12px 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 2px;
  width: max-content;
  max-width: 100%;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--chip-bg);
  border-radius: 999px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 7px 14px; border-radius: 999px; color: var(--muted-strong); font-weight: 600; font-size: 14px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { background: var(--ink); color: var(--bg); }

.list.loading::after { content: "Loading…"; display: block; color: var(--muted); padding: 12px 8px; }
.sentinel { height: 1px; }

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

.hero-card { display: grid; gap: 12px; padding: 22px 22px 20px; margin-bottom: 16px; }
.hero-card h1 { font-size: 26px; margin: 0; }
.hero-card p { margin: 4px 0 0; color: var(--muted); }
.hero-card .btn { justify-self: start; }
.cast { display: flex; padding: 4px 0 2px 6px; }
.cast .char { width: 56px; height: 56px; margin-left: -10px; }
.cast .char:first-child { margin-left: 0; }
.cast .char:nth-child(odd) { transform: rotate(-7deg); }
.cast .char:nth-child(even) { transform: rotate(6deg) translateY(-3px); }
.cast-lg .char { width: 64px; height: 64px; }
@media (min-width: 640px) {
  .hero-card { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
  .cast { grid-column: 1 / -1; }
}

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

.avatar-img, .avatar-lg { border-radius: 50%; object-fit: cover; background: var(--chip-bg); flex: none; }
.avatar-img { width: 40px; height: 40px; }
.avatar { flex: none; margin: 4px 3px 0 3px; }

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

.post {
  display: flex;
  gap: 14px;
  padding: 16px 18px 14px;
  margin-bottom: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.post:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--tint-line); }
.post .avatar-img { width: 44px; height: 44px; box-shadow: 0 0 0 3px var(--ring), 0 0 0 7px var(--tint); }
.post-focus { cursor: default; }
.post-focus:hover { transform: none; box-shadow: none; }
.post-focus .text { font-size: 19px; line-height: 1.5; }
.post-focus .avatar-img { width: 52px; height: 52px; }
.post-body { flex: 1; min-width: 0; }
.post-head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: 14px; }
/* Names may be 40 unbroken characters: let heads wrap them instead of spilling past the card. */
.post-head, .quote-head, .dotcard-head, .minidot > span, .profile-body { overflow-wrap: anywhere; min-width: 0; }
.name { color: var(--ink); font-weight: 700; min-width: 0; }
.handle, .time { color: var(--muted); }
.reply-line { color: var(--muted); font-size: 13px; margin-top: 2px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 4px 0 6px; font-size: 16px; }
/* Post JSON carries no image dimensions, so a fixed box reserves the space before the lazy load
   (no layout shift in the infinite feed); other shapes letterbox on the chip background. */
.post-img { width: 100%; aspect-ratio: 4 / 3; border-radius: 14px; border: 1px solid var(--line); margin: 6px 0 4px; max-height: 480px; object-fit: contain; background: var(--chip-bg); }
.counts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.counts span { background: var(--chip-bg); color: var(--muted-strong); border-radius: 999px; padding: 3px 11px; font-size: 13px; font-weight: 600; }

.poll { display: grid; gap: 6px; margin: 6px 0 4px; }
.poll-row {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--chip-bg);
  overflow: hidden;
  font-size: 14px;
}
/* The bar length encodes the vote share, so its end gets an edge in --deep (the text-on-tint
   colour, >= 3:1 against the row for every palette colour in both schemes); the fill alone is
   below 3:1 for yellow and lime whatever the mix. A 0% bar has no width and draws nothing. */
.poll-bar { position: absolute; top: 0; bottom: 0; left: 0; background: var(--fill); border-radius: var(--radius-sm); box-shadow: inset -3px 0 0 var(--deep); }
.poll-label, .poll-pct { position: relative; }
.poll-pct { color: var(--ink); flex: none; font-weight: 600; }  /* ink: sits on the fill, not the row */
.poll-row.win .poll-label { font-weight: 700; }
.poll .meta { margin-top: 2px; }

.quote {
  display: block;
  margin: 8px 0 4px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--tint);
  border: 1px solid var(--tint-line);
  color: var(--ink);
  font-size: 14px;
  --muted: var(--muted-strong);
}
.quote:hover { text-decoration: none; border-color: var(--ring); }
.quote-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.quote-head .avatar-img { width: 22px; height: 22px; box-shadow: 0 0 0 2px var(--ring); }
.quote-text { display: block; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- thread ---------- */

.ancestors .post { margin-bottom: 6px; }
.thread-replies { margin-left: 24px; padding-left: 16px; border-left: 3px solid var(--dot); }
.nested { margin: -6px 0 14px 24px; padding-left: 14px; border-left: 3px solid var(--dot); }
.nested .post { margin-bottom: 8px; }

/* ---------- dot cards ---------- */

.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.grid > .empty, .grid.loading::after { grid-column: 1 / -1; }

.dotcard {
  display: flex;
  gap: 14px;
  padding: 16px;
  background: var(--tint);
  border: 1px solid var(--tint-line);
  border-radius: var(--radius);
  color: var(--ink);
  --muted: var(--muted-strong);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.dotcard:hover { text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); }
.dotcard .avatar-img { width: 64px; height: 64px; box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--ring); margin: 3px; }
.dotcard-main { display: grid; gap: 2px; min-width: 0; align-content: start; }
.dotcard-head b { font-size: 16px; }
.dotcard-bio { color: var(--ink); font-size: 14px; overflow-wrap: anywhere; }

.minidot {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  margin: 0 -10px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 14px;
}
.minidot:hover { text-decoration: none; background: var(--tint); }
.minidot .avatar-img { width: 32px; height: 32px; box-shadow: 0 0 0 2px var(--ring); }
.minidot > span { display: grid; min-width: 0; }
.minidot b { font-weight: 700; }
.minidot .muted { font-size: 12px; }

/* ---------- rail ---------- */

.prompt-text { margin: 0 0 8px; font-size: 16px; font-weight: 600; line-height: 1.4; }
.stats { display: flex; gap: 28px; }
.stat { display: grid; }
.stat b { font-size: 30px; line-height: 1.1; letter-spacing: -0.03em; }
.stat span { color: var(--muted); font-size: 13px; }

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

.profile { margin-bottom: 14px; }
.profile-banner {
  height: 132px;
  border-radius: var(--radius);
  border: 1px solid var(--tint-line);
  background: radial-gradient(circle 84px at 86% 54%, var(--ring) 99%, transparent 100%), var(--tint);
}
.profile-body { position: relative; padding: 0 20px; }
.avatar-lg {
  width: 96px;
  height: 96px;
  margin-top: -48px;
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--surface), 0 0 0 8px var(--ring);
}
.profile-name { font-size: 24px; margin: 12px 0 0; }
.profile-handle { font-size: 15px; }
.bio { margin: 8px 0 0; white-space: pre-wrap; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 8px; }
.pill { background: var(--chip-bg); border-radius: 999px; padding: 4px 12px; font-size: 13px; color: var(--muted-strong); }
.pill b { color: var(--ink); }

/* ---------- directory ---------- */

.toolbar { display: grid; gap: 10px; margin-bottom: 14px; }
.search {
  width: 100%;
  padding: 12px 18px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.search::placeholder { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  color: var(--muted-strong);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
}
.chip-btn:hover { color: var(--ink); text-decoration: none; }
.chip-btn.active { color: var(--bg); background: var(--ink); border-color: var(--ink); }

/* ---------- prompt, join, about ---------- */

.prompt-hero { display: block; padding: 24px 24px 22px; }
.prompt-big { font-size: 28px; line-height: 1.25; margin: 6px 0 10px; }
.prompt-hero p { margin: 0; }

.lead { font-size: 17px; margin: 6px 0 0; }
.step { display: flex; gap: 16px; }
.step-n {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--deep);
  border: 2px solid var(--dot);
  font-weight: 800;
  font-size: 15px;
}
.step-main { flex: 1; min-width: 0; }
.step h2 { font-size: 18px; margin: 0 0 8px; }
.step p { margin: 0; }
.faq dl { margin: 0; display: grid; gap: 10px; }
.faq dt { font-weight: 700; }
.faq dd { margin: 2px 0 0; color: var(--muted); }

.prose h2 { font-size: 18px; margin: 0 0 6px; }
.prose p { margin: 0 0 8px; }
.prose p:last-child { margin-bottom: 0; }
.prose ul { margin: 0 0 8px; padding-left: 20px; }
.prose li { margin-bottom: 4px; }

@media (max-width: 480px) {
  .thread-replies { margin-left: 10px; padding-left: 10px; }
  .nested { margin-left: 10px; padding-left: 10px; }
  .post { gap: 12px; padding: 14px 14px 12px; }
  .card, .hero-card { padding: 16px; }
  .profile-body { padding: 0 12px; }
}
