/* MyThoughtBook — calm editorial design system.
   Clean sans (Inter) for UI, Source Serif 4 for post bodies, soft teal accent.
   Light and dark themes; focus rings are high-contrast in both. */

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

:root {
  --bg:            #fbfaf7;
  --bg-tint:       #f4f2ec;
  --surface:       #ffffff;
  --surface-2:     #faf9f5;
  --text:          #1b211f;
  --text-soft:     #3d4a46;
  --muted:         #66736e;
  --line:          #e5e2da;
  --line-strong:   #d3cfc4;

  --accent:        #2e6b5e;
  --accent-hover:  #245649;
  --accent-soft:   #e8f1ee;
  --accent-line:   #bcd6cd;
  --on-accent:     #ffffff;

  --journey:       #96573e;
  --journey-soft:  #f8ece6;
  --journey-line:  #e6cec1;

  /* Patient voice — deliberately a different hue from both the brand teal and
     the journey terracotta, so "who wrote this" is legible at a glance. */
  --patient:       #574d96;
  --patient-soft:  #eeecf8;
  --patient-line:  #cdc7e8;

  --danger:        #a33a33;
  --danger-soft:   #fbeceb;
  --warn-soft:     #fdf4e3;
  --warn-line:     #ecd9ae;
  --warn-text:     #74561c;
  --ok-soft:       #e8f1ee;

  --focus:         #1d4ed8;
  --focus-halo:    #ffffff;

  --radius:        14px;
  --radius-sm:     9px;
  --shadow-sm:     0 1px 2px rgba(27, 33, 31, .05), 0 1px 3px rgba(27, 33, 31, .04);
  --shadow-md:     0 4px 10px rgba(27, 33, 31, .06), 0 12px 28px rgba(27, 33, 31, .07);

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;

  --shell: 1200px;
  --shell-narrow: 760px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:            #14181a;
    --bg-tint:       #191e21;
    --surface:       #1c2225;
    --surface-2:     #20272a;
    --text:          #e9eeec;
    --text-soft:     #c4cfcb;
    --muted:         #93a19c;
    --line:          #2b3336;
    --line-strong:   #3a4448;

    --accent:        #6cc0ab;
    --accent-hover:  #86d4c0;
    --accent-soft:   #1d3630;
    --accent-line:   #2f5a4f;
    --on-accent:     #0d1a17;

    --journey:       #d79b7f;
    --journey-soft:  #37261f;
    --journey-line:  #5c4234;

    --patient:       #ada4ea;
    --patient-soft:  #262342;
    --patient-line:  #443c72;

    --danger:        #e88f87;
    --danger-soft:   #3a2320;
    --warn-soft:     #342a16;
    --warn-line:     #5a4a24;
    --warn-text:     #e6cf9c;
    --ok-soft:       #1d3630;

    --focus:         #8ab4ff;
    --focus-halo:    #0d1113;

    --shadow-sm:     0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md:     0 6px 14px rgba(0, 0, 0, .45), 0 16px 40px rgba(0, 0, 0, .35);
  }
}

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

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 90px; /* so anchor targets clear the sticky header */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3, h4 { line-height: 1.22; margin: 0; font-weight: 600; letter-spacing: -0.015em; }
p { margin: 0 0 1em; }
img { max-width: 100%; height: auto; display: block; }

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

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82em;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: .12em .45em;
  color: var(--text-soft);
  white-space: nowrap;
}

.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* Accessible-only text. */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- focus ---
   One visible, high-contrast ring everywhere. Never removed without a
   replacement; the halo keeps it legible over any background in both themes. */

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
  box-shadow: 0 0 0 5px var(--focus-halo);
}
/* Fallback for engines without :focus-visible. */
:focus:not(:focus-visible) { outline: none; }

.skip-link {
  position: absolute;
  left: 12px; top: -80px;
  z-index: 100;
  background: var(--accent);
  color: var(--on-accent);
  padding: 12px 18px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top .16s ease;
}
.skip-link:focus { top: 0; color: var(--on-accent); }

#main:focus { outline: none; }

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

.shell { width: 100%; max-width: var(--shell); margin-inline: auto; padding-inline: 24px; }
.shell--narrow { max-width: var(--shell-narrow); }
.shell--form { max-width: 520px; padding-block: 48px 72px; }

/* Signed-in working pages (editor, dashboard, moderation) get more room: the
   editor is two-column and the moderation tables are five columns wide. */
body.is-wide .shell { max-width: 1340px; }
body.is-wide .shell--narrow { max-width: var(--shell-narrow); }
body.is-wide .shell--form { max-width: 520px; }
.site-main { flex: 1 0 auto; padding-bottom: 72px; }

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.site-header__inner { display: flex; align-items: center; gap: 20px; min-height: 66px; }

.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-size: 1.06rem; }
.brand__mark {
  display: grid; place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-line);
}
.brand__text { letter-spacing: -0.02em; font-weight: 400; }
.brand__text strong { font-weight: 700; }

.nav { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.nav__spacer { width: 10px; }
.nav__form { margin: 0; }
.nav__link {
  display: inline-block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  text-decoration: none;
  font-size: .925rem;
  font-weight: 500;
}
.nav__link:hover { background: var(--bg-tint); color: var(--text); }
.nav__link.is-active { color: var(--accent); background: var(--accent-soft); }

.nav__toggle {
  display: none;
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
}

@media (max-width: 860px) {
  .nav__toggle { display: inline-flex; }
  .nav {
    display: none;
    width: 100%;
    order: 3;
    margin-left: 0;
    padding: 10px 0 16px;
    border-top: 1px solid var(--line);
    align-items: stretch;
    flex-direction: column;
    gap: 4px;
  }
  .nav.is-open { display: flex; }
  .nav__spacer { display: none; }
  .nav__form, .nav .btn { width: 100%; }
}

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

.site-footer { border-top: 1px solid var(--line); background: var(--bg-tint); padding: 36px 0; margin-top: auto; }
.site-footer__inner { display: grid; gap: 6px; }
.site-footer__brand { font-weight: 600; margin: 0 0 4px; }
.site-footer p { margin: 0; font-size: .9rem; max-width: 70ch; }

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

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--line-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  font: inherit;
  font-size: .925rem;
  font-weight: 550;
  font-family: var(--sans);
  line-height: 1.2;
  border-radius: var(--radius-sm);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: pointer;
  text-decoration: none;
  transition: background .14s ease, border-color .14s ease, transform .06s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-tint); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn[disabled]:active { transform: none; }

.btn--primary { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bd: var(--accent); }
.btn--primary:hover { --btn-bg: var(--accent-hover); --btn-bd: var(--accent-hover); color: var(--on-accent); }

.btn--ghost { --btn-bg: transparent; --btn-fg: var(--text-soft); --btn-bd: var(--line-strong); }
.btn--ghost:hover { --btn-fg: var(--text); background: var(--bg-tint); }

.btn--danger { --btn-bg: transparent; --btn-fg: var(--danger); --btn-bd: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn--danger:hover { background: var(--danger-soft); }

.btn--sm { padding: 6px 11px; font-size: .855rem; }
.btn--block { width: 100%; }
.btn--icon { padding: 8px; --btn-bg: transparent; --btn-bd: transparent; color: var(--muted); }
.btn--icon:hover { background: var(--bg-tint); color: var(--text); }

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

.hero { padding: 28px 0 14px; }
.hero__eyebrow {
  font-size: .8rem; letter-spacing: .09em; text-transform: uppercase;
  color: var(--accent); font-weight: 600; margin: 0 0 10px;
}
.hero__title { font-family: var(--serif); font-size: clamp(2rem, 4.2vw, 2.8rem); font-weight: 600; letter-spacing: -0.028em; margin: 0 0 10px; }
.hero__lede { font-size: 1.06rem; color: var(--text-soft); max-width: 62ch; margin: 0 0 10px; }
.hero__stats { font-size: .92rem; margin: 0; }

.page-head { padding: 32px 0 18px; }
.page-head--row { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.page-title { font-family: var(--serif); font-size: clamp(1.8rem, 3.4vw, 2.5rem); font-weight: 600; margin: 0 0 10px; }
.page-lede { font-size: 1.02rem; margin: 0; max-width: 64ch; }
.section-title { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; margin: 0 0 20px; }

/* ---------------------------------------------------------------- filters */

.filters-wrap { padding-bottom: 8px; }
.filters {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.filters__types { border: 0; margin: 0; padding: 0; min-width: 0; }
.filters__row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.segments { display: inline-flex; gap: 4px; background: var(--bg-tint); border: 1px solid var(--line); border-radius: 11px; padding: 4px; flex-wrap: wrap; }
.segment { margin: 0; }
.segment__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segment__face {
  display: inline-block;
  padding: 7px 15px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 550;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.segment__face:hover { color: var(--text); }
.segment__input:checked + .segment__face { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }
.segment__input:focus-visible + .segment__face {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-halo);
}

.field { display: grid; gap: 6px; min-width: 0; }
.field--search { position: relative; flex: 1 1 260px; }
.field__icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; display: grid; }
.label { font-size: .875rem; font-weight: 600; color: var(--text-soft); }
.field__hint { font-size: .82rem; color: var(--muted); margin: 0; }
.field__error { font-size: .85rem; color: var(--danger); margin: 0; font-weight: 500; }
.field__reveal { display: flex; gap: 8px; align-items: center; }
.field__reveal .input { flex: 1; }

.input {
  width: 100%;
  font: inherit;
  font-family: var(--sans);
  font-size: .95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.input::placeholder { color: var(--muted); opacity: .85; }
.input:hover { border-color: var(--muted); }
.input:focus { border-color: var(--accent); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input--search { padding-left: 40px; }
.select { appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% + 1px), calc(100% - 13px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.textarea { resize: vertical; min-height: 72px; line-height: 1.55; overflow-y: auto; }
.input--file { padding: 8px 10px; background: var(--surface-2); }
.input--file::file-selector-button {
  font: inherit; font-size: .85rem; font-weight: 550;
  margin-right: 10px; padding: 6px 11px;
  border-radius: 7px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); cursor: pointer;
}

.results { font-size: .9rem; color: var(--muted); margin: 10px 2px 0; }

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

.feed { padding-top: 16px; }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 26px;
}
@media (max-width: 1040px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; } }
@media (max-width: 680px)  { .grid { grid-template-columns: minmax(0, 1fr); gap: 20px; } }

/* Story grids flow down columns rather than across rows, so a short card
 * never leaves a hole under it.
 *
 * No-JS fallback: CSS multi-column. Cards never break across a column
 * boundary. Column *order* is then top-to-bottom-then-across, which reads
 * fine but does not balance heights — app.js replaces this with real
 * columns and shortest-column placement (.is-masonry below). */
.grid--masonry {
  display: block;
  columns: 3;
  column-gap: 26px;
}
.grid--masonry > .card {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  margin-bottom: 26px;
}
@media (max-width: 1040px) {
  .grid--masonry { columns: 2; column-gap: 22px; }
  .grid--masonry > .card { margin-bottom: 22px; }
}
@media (max-width: 680px) {
  .grid--masonry { columns: 1; }
  .grid--masonry > .card { margin-bottom: 20px; }
}

/* JS-enhanced: real flex columns, each filled independently. */
.grid--masonry.is-masonry {
  display: flex;
  align-items: flex-start;
  columns: auto;
  gap: 26px;
}
.grid--masonry.is-masonry > .card { margin-bottom: 0; }
.masonry__col {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 26px;
}
@media (max-width: 1040px) {
  .grid--masonry.is-masonry, .masonry__col { gap: 22px; }
}
@media (max-width: 680px) {
  .grid--masonry.is-masonry, .masonry__col { gap: 20px; }
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--line-strong); }

/* Stretched link: one tab stop per card, whole card clickable by mouse. */
.card__link { color: inherit; text-decoration: none; }
.card__link::after { content: ""; position: absolute; inset: 0; z-index: 1; }
.card__link:hover { color: var(--accent); }
.card:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-halo), var(--shadow-md);
}
.card__link:focus-visible { outline: none; box-shadow: none; }

.card__cover { background: var(--bg-tint); aspect-ratio: 1200 / 630; overflow: hidden; }
.card__cover img { width: 100%; height: 100%; object-fit: cover; }

.card__body { padding: 18px 20px 4px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card__tags { display: flex; gap: 6px; flex-wrap: wrap; }
.card__title { font-family: var(--serif); font-size: 1.32rem; font-weight: 600; letter-spacing: -0.018em; margin: 0; }
.card__excerpt { color: var(--muted); font-size: .935rem; line-height: 1.6; margin: 0 0 14px; }
.card__role { color: var(--accent); font-size: .875rem; font-weight: 550; margin: 0; }

.card__foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  margin-top: auto;
  flex-wrap: wrap;
}
.card__author { display: grid; min-width: 0; flex: 1 1 auto; }
.card__author-name { font-size: .885rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card__author-meta { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card__meta { font-size: .8rem; color: var(--muted); display: flex; gap: 5px; white-space: nowrap; }

.card--person .card__body { padding: 22px 20px 12px; align-items: flex-start; }
.card__title--person { font-size: 1.16rem; }
.card__foot--person { font-size: .85rem; }

/* ------------------------------------------------------------------- tags */

.tag {
  display: inline-block;
  font-size: .715rem;
  font-weight: 650;
  letter-spacing: .055em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.tag--thought { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.tag--journey { background: var(--journey-soft); color: var(--journey); border-color: var(--journey-line); }
.tag--draft   { background: var(--bg-tint); color: var(--muted); border-color: var(--line-strong); }
.tag--live    { background: var(--ok-soft); color: var(--accent); border-color: var(--accent-line); }
.tag--blocked { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.tag--consent { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); text-transform: none; letter-spacing: 0; font-size: .75rem; }
.tag--admin   { background: var(--warn-soft); color: var(--warn-text); border-color: var(--warn-line); }
.tag--pending { background: var(--warn-soft); color: var(--warn-text); border-color: var(--warn-line); }

/* Voice badges. The patient badge is filled and coloured because it is the
   thing a reader most needs to notice; the doctor badge is the quiet default. */
.tag--patient { background: var(--patient-soft); color: var(--patient); border-color: var(--patient-line); }
.tag--doctor  { background: transparent; color: var(--muted); border-color: var(--line-strong); }

.taglist { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 34px 0 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--bg-tint);
  border: 1px solid var(--line);
  color: var(--text-soft);
  text-decoration: none;
}
.chip:hover { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.chip--diagnosis { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.chip--procedure { background: var(--journey-soft); border-color: var(--journey-line); color: var(--journey); }
.chip--topic     { background: var(--bg-tint); border-color: var(--line); color: var(--text-soft); }
.chip--diagnosis:hover,
.chip--procedure:hover { filter: brightness(.97); }
.chip--more { background: transparent; color: var(--muted); border-style: dashed; }
.chip__count {
  font-size: .74rem;
  font-weight: 650;
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 14%, transparent);
}

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

.avatar { border-radius: 50%; background: var(--bg-tint); flex: none; object-fit: cover; }
.avatar--sm { width: 36px; height: 36px; }
.avatar--lg { width: 72px; height: 72px; }
.avatar--xl { width: 96px; height: 96px; }

/* ------------------------------------------------------------- post page */

.post { padding-top: 34px; }
.backlink { margin-bottom: 26px; }
.backlink--foot { margin: 48px 0 0; padding-top: 26px; border-top: 1px solid var(--line); }
.backlink__a { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; font-weight: 550; text-decoration: none; }
.backlink__a:hover { text-decoration: underline; }

.post__head { margin-bottom: 30px; }
.post__tags { margin-bottom: 16px; }
.post__title { font-family: var(--serif); font-size: clamp(2rem, 4.6vw, 3rem); font-weight: 600; letter-spacing: -0.028em; margin: 0 0 16px; }
.post__standfirst { font-family: var(--serif); font-size: 1.24rem; line-height: 1.6; color: var(--text-soft); margin: 0 0 26px; }

.byline { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.byline__author { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.byline__author:hover .byline__name { color: var(--accent); text-decoration: underline; }
.byline__names { display: grid; }
.byline__name { font-weight: 600; font-size: .97rem; }
.byline__role { font-size: .86rem; color: var(--muted); }
.byline__meta { margin: 0 0 0 auto; font-size: .875rem; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.post__cover { margin: 30px 0 36px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); background: var(--bg-tint); }
.post__cover img { width: 100%; aspect-ratio: 1200 / 630; object-fit: cover; }

/* ----------------------------------------------------------- privacy note */

.notice {
  display: flex;
  gap: 14px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background: var(--journey-soft);
  border: 1px solid var(--journey-line);
  margin: 26px 0 0;
}
.notice--consent { color: var(--text-soft); }
.notice__icon { color: var(--journey); flex: none; display: grid; padding-top: 2px; }
.notice__title { font-weight: 650; color: var(--journey); margin: 0 0 4px; font-size: .95rem; }
.notice__text { margin: 0; font-size: .92rem; line-height: 1.6; }

/* ------------------------------------------------------------------ prose */

.prose {
  font-family: var(--serif);
  font-size: 1.185rem;
  line-height: 1.78;
  color: var(--text);
  max-width: 68ch;
}
.prose > * + * { margin-top: 1.35em; }
.prose p { margin: 0; }
.prose h2 { font-family: var(--serif); font-size: 1.6rem; font-weight: 600; margin-top: 2.1em; letter-spacing: -0.02em; }
.prose h3 { font-family: var(--serif); font-size: 1.32rem; font-weight: 600; margin-top: 1.8em; }
.prose h4 { font-size: 1.1rem; margin-top: 1.6em; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0; }
.prose li + li { margin-top: .55em; }
.prose li::marker { color: var(--muted); }
.prose blockquote {
  margin: 1.8em 0;
  padding: 4px 0 4px 24px;
  border-left: 3px solid var(--accent-line);
  color: var(--text-soft);
  font-style: italic;
  font-size: 1.14em;
}
.prose blockquote p { margin: 0; }
.prose a { text-decoration: underline; }
.prose img { border-radius: var(--radius-sm); margin-inline: auto; }
.prose figure { margin: 1.8em 0; }
.prose figcaption { font-family: var(--sans); font-size: .87rem; color: var(--muted); text-align: center; margin-top: 10px; }
.prose code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: var(--bg-tint); padding: .12em .38em; border-radius: 5px; }
.prose pre { background: var(--bg-tint); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 16px; overflow-x: auto; font-size: .92rem; }
.prose pre code { background: none; padding: 0; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 2.4em 0; }

/* -------------------------------------------------------------- authorbox */

.authorbox {
  display: flex;
  gap: 20px;
  margin-top: 44px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.authorbox__body { flex: 1 1 260px; }
.authorbox__eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; margin: 0 0 4px; }
.authorbox__name { font-family: var(--serif); font-size: 1.28rem; margin: 0 0 3px; }
.authorbox__name a { text-decoration: none; color: var(--text); }
.authorbox__name a:hover { color: var(--accent); text-decoration: underline; }
.authorbox__role { color: var(--accent); font-size: .88rem; font-weight: 550; margin: 0 0 10px; }
.authorbox__bio { font-size: .94rem; color: var(--text-soft); margin: 0 0 16px; }

.related { padding-top: 62px; }

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

.profile { padding-top: 34px; }
.profile__head { display: flex; gap: 24px; align-items: flex-start; padding: 8px 0 30px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.profile__name { font-family: var(--serif); font-size: clamp(1.8rem, 3.6vw, 2.5rem); margin: 0 0 6px; }
.profile__role { color: var(--accent); font-weight: 600; margin: 0 0 4px; }
.profile__creds { font-size: .9rem; margin: 0 0 12px; }
.profile__bio { max-width: 62ch; color: var(--text-soft); margin: 0 0 12px; }
.profile__counts { font-size: .88rem; margin: 0; }

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

.authcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow-sm); }
.form { display: grid; gap: 18px; margin-top: 24px; }
.authcard__alt { margin: 20px 0 0; font-size: .9rem; text-align: center; }

.flash { padding: 13px 17px; border-radius: var(--radius-sm); margin: 18px 0; font-size: .93rem; border: 1px solid transparent; }
.flash--ok    { background: var(--ok-soft); color: var(--accent); border-color: var(--accent-line); }
.flash--warn  { background: var(--warn-soft); color: var(--warn-text); border-color: var(--warn-line); }
.flash--error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

.check { display: flex; gap: 10px; align-items: flex-start; font-size: .93rem; cursor: pointer; line-height: 1.5; }
.check input { margin: 3px 0 0; width: 17px; height: 17px; accent-color: var(--accent); flex: none; cursor: pointer; }

.radiogroup { display: grid; gap: 10px; }
.radio { display: flex; gap: 11px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface); transition: border-color .14s ease, background .14s ease; }
.radio:hover { border-color: var(--muted); }
.radio input { margin: 3px 0 0; width: 17px; height: 17px; accent-color: var(--accent); flex: none; cursor: pointer; }
.radio:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio__body { display: grid; gap: 3px; }
.radio__label { font-weight: 600; font-size: .93rem; }
.radio__hint { font-size: .84rem; color: var(--muted); line-height: 1.45; }

/* ----------------------------------------------------------------- editor */

.editor-head { padding: 30px 0 18px; }
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 28px;
  align-items: start;
  padding-bottom: 60px;
}
@media (max-width: 960px) { .editor { grid-template-columns: minmax(0, 1fr); } }

.editor__main { display: grid; gap: 22px; min-width: 0; }
.editor__side { display: grid; gap: 18px; position: sticky; top: 86px; max-height: calc(100vh - 106px); overflow-y: auto; padding-right: 2px; }
@media (max-width: 960px) { .editor__side { position: static; max-height: none; overflow: visible; } }

.input--title { font-family: var(--serif); font-size: 1.5rem; font-weight: 600; padding: 14px 16px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; }
.panel__title { font-size: .95rem; font-weight: 650; margin: 0; display: flex; align-items: center; gap: 8px; }
.panel__title--warn { color: var(--journey); }
.panel__text { font-size: .875rem; color: var(--text-soft); margin: 0; line-height: 1.55; }
.panel__foot { font-size: .82rem; margin: 0; }
.panel--privacy { background: var(--journey-soft); border-color: var(--journey-line); }
.panel--privacy .notice__icon { color: var(--journey); }
.panel--actions { position: relative; }

.checklist { margin: 0; padding-left: 20px; font-size: .865rem; color: var(--text-soft); display: grid; gap: 5px; line-height: 1.5; }
.checklist li::marker { color: var(--journey); }

.consent {
  background: var(--surface);
  border: 1px solid var(--journey-line);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  display: grid;
  gap: 6px;
}

.cover-preview { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-tint); }
.cover-preview img { width: 100%; aspect-ratio: 1200 / 630; object-fit: cover; }

/* Rich-text editor */
.rte { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); overflow: hidden; }
.rte:focus-within { border-color: var(--accent); }

.tb {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.tb__btn {
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}
.tb__btn:hover { background: var(--bg-tint); color: var(--text); }
.tb__btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.tb__sep { width: 1px; height: 20px; background: var(--line-strong); margin: 0 5px; }

.rte__surface {
  font-family: var(--serif);
  font-size: 1.1rem;
  line-height: 1.75;
  padding: 20px 22px;
  min-height: 320px;
  max-height: 60vh;   /* auto-grows to here, then scrolls — see policy §6 */
  overflow-y: auto;
  outline: none;
}
.rte__surface:focus-visible { outline: none; box-shadow: none; }
.rte__surface:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}
.rte__surface > * + * { margin-top: 1.1em; }
.rte__surface p { margin: 0; }
.rte__surface h2 { font-size: 1.45rem; font-family: var(--serif); }
.rte__surface h3 { font-size: 1.22rem; font-family: var(--serif); }
.rte__surface blockquote {
  margin: 1.3em 0; padding-left: 18px;
  border-left: 3px solid var(--accent-line);
  color: var(--text-soft); font-style: italic;
}
.rte__surface ul, .rte__surface ol { padding-left: 1.4em; margin: 0; }

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

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 620px; }
.table th, .table td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; background: var(--surface-2); }
.table tbody tr:last-child th, .table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }

/* NB: do NOT use display:grid here — it takes the <th> out of table layout,
   which makes the row borders stagger across columns. Block children instead. */
.rowtitle { font-weight: 600; max-width: 420px; }
.rowtitle > a, .rowtitle__name, .rowtitle__meta { display: block; }
.rowtitle__name { font-weight: 600; }
.rowtitle a { text-decoration: none; color: var(--text); }
.rowtitle a:hover { color: var(--accent); text-decoration: underline; }
.rowtitle__meta { font-size: .8rem; font-weight: 400; margin-top: 3px; }
/* Same rule as .rowtitle: the <td> itself must stay a table-cell, so the flex
   row lives in an inner wrapper created by the cell's own box. */
.rowactions { white-space: nowrap; }
.rowactions > * { display: inline-flex; vertical-align: middle; margin: 2px 5px 2px 0; }
.rowactions form { margin: 2px 5px 2px 0; }

.admin-section { padding-bottom: 44px; }

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

.empty { text-align: center; padding: 64px 24px; border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface); display: grid; gap: 10px; justify-items: center; }
.empty__title { font-family: var(--serif); font-size: 1.4rem; margin: 0; }
.empty p { margin: 0; max-width: 46ch; }

.errorpage { padding: 80px 0; text-align: center; }
.errorpage__code { font-family: var(--serif); font-size: 4rem; color: var(--accent); margin: 0 0 6px; font-weight: 600; }

/* ---------------------------------------------------------------- dialog */

.dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  max-width: 460px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow-md);
  max-height: 80vh;
  overflow-y: auto;
}
.dialog::backdrop { background: rgba(20, 24, 26, .45); backdrop-filter: blur(2px); }
.dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.dialog__title { font-family: var(--serif); font-size: 1.3rem; margin: 0; }
.dialog__foot { font-size: .82rem; margin: 16px 0 0; }

.shortcuts { margin: 0; display: grid; gap: 9px; }
.shortcuts__row { display: flex; align-items: baseline; gap: 14px; }
.shortcuts dt { flex: none; min-width: 124px; }
.shortcuts dd { margin: 0; font-size: .91rem; color: var(--text-soft); }

/* Generated cover art is light by design; dim it slightly in dark mode so a
   grid of cards does not glare against the dark surface. */
@media (prefers-color-scheme: dark) {
  .card__cover img,
  .post__cover img,
  .cover-preview img { filter: brightness(.84) saturate(.92); }
}

/* ------------------------------------------------------------- motion --- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover { transform: none; }
}

/* High-contrast / forced-colors: keep the focus ring visible. */
@media (forced-colors: active) {
  :focus-visible { outline: 3px solid Highlight; box-shadow: none; }
  .card:focus-within { outline: 3px solid Highlight; }
}

/* ==========================================================================
   v2 — patient voices, tag collections
   ========================================================================== */

/* -------------------------------------------------- chips inside a card ---
   Cards use a stretched link (.card__link::after covers the card), so anything
   else interactive has to be lifted above it. Tag chips are real navigation, so
   they get lifted, and they take their own focus ring rather than lighting up
   the whole card — otherwise focusing a chip looks identical to focusing the
   card title. */

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0;
  margin: 0;
}
.card .chips { position: relative; z-index: 2; margin-bottom: 14px; }
.card .chip { font-size: .78rem; padding: 3px 10px; }
.card:has(.chip:focus-visible) { outline: none; box-shadow: var(--shadow-md); }
.chip:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-halo);
}

/* --------------------------------------------------- browse by condition */

.browse { padding-top: 2px; padding-bottom: 2px; }
.browse__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.browse__head .section-title { font-size: 1.32rem; margin-bottom: 8px; }
.browse__all { font-size: .9rem; color: var(--accent); }
.chips--browse { gap: 8px; }
.chips--browse .chip { font-size: .9rem; padding: 6px 13px; }

/* --------------------------------------------------------- feed filters */

.filters__segments { display: flex; gap: 22px; flex-wrap: wrap; }
.filters__group { border: 0; margin: 0; padding: 0; min-width: 0; }
.filters__legend {
  font-size: .74rem;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0 7px;
}
.matched {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 16px 2px 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.matched__label { font-size: .88rem; color: var(--muted); }

/* ------------------------------------------------------------ tag pages */

.tagpage__head .backlink { margin-bottom: 18px; }
.tagpage__kind {
  font-size: .76rem;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 6px;
}
.tagpage__counts { margin-bottom: 16px; }
.tagpage__pair { font-size: .9rem; margin: 12px 0 0; max-width: 60ch; }

.segment-links { display: inline-flex; gap: 4px; background: var(--bg-tint); border: 1px solid var(--line); border-radius: 11px; padding: 4px; flex-wrap: wrap; }
.segment-link {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 550;
  color: var(--muted);
  text-decoration: none;
}
.segment-link:hover { color: var(--text); }
.segment-link.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow-sm); }

.taggrid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.taggrid__link {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  height: 100%;
}
.taggrid__link:hover { border-color: var(--accent-line); background: var(--surface-2); }
.taggrid__label { font-weight: 600; }
.taggrid__count { font-size: .85rem; }

/* "Read more like this" under a story */
.tagblock {
  margin: 38px 0 0;
  padding: 22px 24px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.tagblock__title { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; margin: 0 0 16px; }
.tagblock__groups { margin: 0; display: grid; gap: 14px; }
.tagblock__group dt {
  font-size: .74rem;
  font-weight: 650;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}
.tagblock__group dd { margin: 0; }

/* --------------------------------------------------------- notices etc. */

.notice--patient { background: var(--patient-soft); border-color: var(--patient-line); }
.notice--patient .notice__icon { color: var(--patient); }
.notice--patient .notice__title { color: var(--patient); }

.profile__voice { margin: 0 0 8px; }

/* ----------------------------------------------------- signup type choice */

.authcard--wide { max-width: 720px; }
.choices { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin: 6px 0 22px; }
.choice {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}
.choice:hover { border-color: var(--accent-line); background: var(--accent-soft); }
.choice__title { font-family: var(--serif); font-size: 1.24rem; font-weight: 600; }
.choice__blurb { color: var(--muted); font-size: .92rem; line-height: 1.55; }
.choice__points { margin: 4px 0 0; padding-left: 20px; color: var(--text-soft); font-size: .88rem; line-height: 1.7; }
.choice__go { margin-top: auto; padding-top: 10px; color: var(--accent); font-weight: 600; font-size: .9rem; }

/* ------------------------------------------------------------ form bits */

.fieldset { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; margin: 0; }
.fieldset > .label { padding: 0 4px; }
.label--sub { font-size: .85rem; font-weight: 550; }
.radiogroup--tight { gap: 7px; }
.panel__foot--error { color: var(--danger); font-weight: 600; }

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

.tagfield { position: relative; }
.tokens { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 0 0 8px; }
.tokens[hidden] { display: none; }
.token {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  padding: 3px 4px 3px 11px;
  font-size: .85rem;
  color: var(--accent);
  max-width: 100%;
}
.token__text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.token__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
  flex: none;
}
.token__remove:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.token__remove:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
  box-shadow: 0 0 0 4px var(--focus-halo);
}
.token__add { margin-top: 8px; }

/* -------------------------------------------------------------- admin --- */

.row--flagged > * { background: var(--warn-soft); }
.row--flagged .rowtitle a { color: var(--warn-text); }

/* --------------------------------------------------------- dark tweaks */

@media (prefers-color-scheme: dark) {
  .tag--doctor { border-color: var(--line-strong); }
  .choice:hover { background: var(--surface); }
}

@media (forced-colors: active) {
  .chip:focus-visible,
  .token__remove:focus-visible { outline: 3px solid Highlight; box-shadow: none; }
  .token { border: 1px solid ButtonBorder; }
}
