/* Agora — a quiet, typographic interface for research mathematics. */
:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f4f2ed;
  --ink: #1c1d21;
  --ink-2: #3d3f45;
  --muted: #6e6f73;
  --rule: #e4e1d9;
  --rule-strong: #cfcbc0;
  --accent: #2c4f8f;
  --accent-ink: #ffffff;
  --accent-soft: #e8eef9;
  --good: #2d7a4b;
  --good-soft: #e3f1e8;
  --danger: #a23a2f;
  --danger-soft: #f8e6e3;
  --warn-soft: #fbf3dc;
  --chip: #eef0f4;
  --chip-ink: #33415c;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 4px 16px rgba(20, 20, 30, .05);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 8px;
  --gutter: 20px;
  --page-max: 1180px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --surface: #1c1e23;
    --surface-2: #23262c;
    --ink: #e8e6e1;
    --ink-2: #c9c6bf;
    --muted: #9a9890;
    --rule: #2e3138;
    --rule-strong: #3d414a;
    --accent: #8fb0ef;
    --accent-ink: #0f1420;
    --accent-soft: #1e2a42;
    --good: #6cc48d;
    --good-soft: #1b3125;
    --danger: #ef8c80;
    --danger-soft: #3a201d;
    --warn-soft: #362f1a;
    --chip: #262a33;
    --chip-ink: #c3cde0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 var(--sans);
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.25; color: var(--ink); margin: 0 0 .5em; }
h1 { font-size: 1.85rem; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.12rem; }
h4 { font-size: .95rem; font-family: var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
p { margin: 0 0 1em; }
code, pre, kbd { font-family: var(--mono); font-size: .88em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.danger { color: var(--danger); }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: 6px 10px; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--gutter); height: 56px; display: flex; align-items: center; gap: 22px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); font-family: var(--serif); font-size: 1.3rem; font-weight: 600; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-mark rect { fill: var(--ink); }
.brand-mark path { fill: none; stroke: var(--bg); stroke-width: 6.5; stroke-linecap: round; stroke-linejoin: round; }
.footer .brand-mark { width: 20px; height: 20px; margin-right: 4px; vertical-align: -5px; }
.mainnav { display: flex; gap: 4px; }
.mainnav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
.mainnav a:hover { background: var(--surface-2); text-decoration: none; }
.mainnav a[aria-current] { color: var(--ink); background: var(--surface-2); }
.search { flex: 1; max-width: 380px; margin-left: auto; }
.search input { width: 100%; height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--rule); background: var(--surface-2); }
.search input:focus { background: var(--surface); }
.account { display: flex; align-items: center; gap: 8px; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 20px; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: var(--surface-2); }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 180px; padding: 6px; display: flex; flex-direction: column; }
.menu-pop a, .menu-pop .linklike { padding: 7px 10px; border-radius: 5px; color: var(--ink); text-align: left; font-size: .93rem; width: 100%; }
.menu-pop a:hover, .menu-pop .linklike:hover { background: var(--surface-2); text-decoration: none; }

.flash { max-width: var(--page-max); margin: 14px auto 0; padding: 10px 14px; background: var(--good-soft); color: var(--ink); border-radius: var(--radius); width: calc(100% - 2 * var(--gutter)); }

/* ---------- Page layout ---------- */
.page { flex: 1; width: 100%; max-width: var(--page-max); margin: 0 auto; padding: 28px var(--gutter) 64px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 40px; align-items: start; }
.cols-even { grid-template-columns: 1fr 1fr; gap: 32px; }
.col-side { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 76px; }
.narrow { max-width: 820px; margin: 0 auto; }
.narrow-wide { max-width: 1000px; margin: 0 auto; }
.footer { border-top: 1px solid var(--rule); background: var(--surface); }
.footer-inner { max-width: var(--page-max); margin: 0 auto; padding: 18px var(--gutter); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: .88rem; }
.footer nav { display: flex; gap: 18px; }
.footer a { color: var(--muted); }

.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px 18px; }
.card h4 { margin-bottom: 10px; }
.card + .card { margin-top: 0; }
section.card { margin-bottom: 20px; }
.notice { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; background: var(--warn-soft); }
.notice-danger { background: var(--danger-soft); }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 7px; border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink); font: 500 .92rem var(--sans); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-sm { height: 30px; padding: 0 11px; font-size: .86rem; }
.btn-xs { height: 24px; padding: 0 8px; font-size: .78rem; border-radius: 5px; }
.btn-block { width: 100%; height: 40px; }
.btn[disabled] { opacity: .55; cursor: default; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.linklike:hover { text-decoration: underline; }
form.inline { display: inline; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 7px; padding: 8px 11px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { font-family: var(--mono); font-size: .9rem; line-height: 1.5; resize: vertical; }
label { font-weight: 600; font-size: .92rem; display: block; }
label.check { font-weight: 400; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack > label { margin-top: 6px; margin-bottom: -4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 200px; }
.row-end { display: flex; gap: 10px; justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.grid2 label { margin-bottom: 4px; }
.hint { font-size: .84rem; color: var(--muted); margin: -4px 0 4px; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .92rem; margin-bottom: 6px; }

/* ---------- Hero & lists ---------- */
.hero { padding: 10px 0 26px; border-bottom: 1px solid var(--rule); margin-bottom: 22px; }
.hero h1 { font-size: 2.05rem; max-width: 720px; }
.hero p { color: var(--ink-2); max-width: 680px; font-size: 1.03rem; }
.hero-cta { display: flex; gap: 10px; flex-wrap: wrap; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.list-head h1, .list-head h2 { margin: 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin: 8px 0 0; align-items: flex-end; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; font-size: .92rem; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a[aria-current] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs-fill { flex: 1; }
.tabs-sm a { padding: 4px 10px; font-size: .86rem; }
.kind-filter { width: auto; height: 30px; padding: 0 8px; font-size: .86rem; margin-bottom: 5px; }
.tlist { list-style: none; margin: 0; padding: 0; }
.titem { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 18px; padding: 16px 2px; border-bottom: 1px solid var(--rule); }
.titem.is-deleted { opacity: .55; }
.tstats { display: flex; flex-direction: column; gap: 5px; align-items: flex-end; font-size: .82rem; color: var(--ink-2); padding-top: 2px; }
.tstats b { font-weight: 600; }
.stat { white-space: nowrap; padding: 1px 6px; border-radius: 4px; }
.stat.answered { border: 1px solid var(--good); color: var(--good); }
.stat.accepted { background: var(--good); color: #fff; }
.ttitle { font-size: 1.1rem; margin: 0 0 4px; font-weight: 600; }
.ttitle a { color: var(--ink); }
.ttitle a:hover { color: var(--accent); text-decoration: none; }
.texcerpt { color: var(--ink-2); font-size: .92rem; margin: 0 0 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tfoot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.tmeta { font-size: .84rem; color: var(--muted); margin-left: auto; }
.who { font-weight: 500; }
.rep { font-weight: 600; color: var(--ink-2); font-size: .85em; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 4px; background: var(--chip); color: var(--chip-ink); font-size: .8rem; font-weight: 500; line-height: 1.7; }
.chip:hover { text-decoration: none; filter: brightness(.96); }
.chip-area { background: transparent; border: 1px solid var(--rule-strong); color: var(--ink-2); font-family: var(--mono); font-size: .75rem; }
.kind { display: inline-block; font: 600 .68rem/1.6 var(--sans); text-transform: uppercase; letter-spacing: .06em; padding: 0 6px; border-radius: 3px; vertical-align: 2px; background: var(--surface-2); color: var(--ink-2); }
.kind-paper { background: #efe7f7; color: #5b3b86; }
.kind-discussion { background: #e5f0f2; color: #2a5f69; }
.kind-announcement { background: #f8ecd9; color: #7a5212; }
.kind-question { background: var(--accent-soft); color: var(--accent); }
@media (prefers-color-scheme: dark) {
  .kind-paper { background: #2d2340; color: #cdb6ef; }
  .kind-discussion { background: #1d3236; color: #9fd0d9; }
  .kind-announcement { background: #3a2e17; color: #edc98a; }
}
.badge { display: inline-block; font: 600 .7rem/1.6 var(--sans); padding: 0 6px; border-radius: 3px; background: var(--surface-2); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; vertical-align: 2px; }
.badge-bot { background: var(--chip); color: var(--chip-ink); }
.pager { display: flex; gap: 4px; margin: 22px 0 8px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 6px; border: 1px solid var(--rule); padding: 0 8px; font-size: .9rem; }
.pager .cur { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pager .gap { border: 0; }
.count { margin-top: 8px; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }
.search-big { display: flex; gap: 8px; margin: 10px 0 14px; }

/* Sidebar */
.stats-card { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; padding: 14px 8px; }
.stats-card b { display: block; font-size: 1.3rem; font-family: var(--serif); }
.stats-card span { font-size: .78rem; color: var(--muted); }
.stats-wide { grid-template-columns: repeat(5, 1fr); margin-bottom: 10px; }
.stats-wide a { color: inherit; }
.arealist { list-style: none; margin: 0; padding: 0; columns: 1; font-size: .88rem; max-height: 340px; overflow: auto; }
.arealist a { display: block; padding: 3px 6px; color: var(--ink-2); border-radius: 4px; }
.arealist a:hover, .arealist a[aria-current] { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.code { font-family: var(--mono); font-size: .76rem; color: var(--muted); display: inline-block; min-width: 58px; }
.related, .mini { list-style: none; margin: 0; padding: 0; }
.related li, .mini li { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--rule); font-size: .9rem; align-items: baseline; }
.mini li { grid-template-columns: auto 1fr auto; }
.related li:last-child { border-bottom: 0; }
.score-pill { min-width: 30px; text-align: center; font-size: .78rem; font-weight: 600; padding: 0 5px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); }
.score-pill.accepted { background: var(--good); color: #fff; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* ---------- Thread ---------- */
.thread-head { border-bottom: 1px solid var(--rule); padding-bottom: 14px; margin-bottom: 20px; }
.thread-head h1 { font-size: 1.75rem; margin: 6px 0 8px; }
.kicker { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.thread-meta { display: flex; gap: 18px; flex-wrap: wrap; }
.post { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 16px; padding: 4px 0 22px; }
.reply { border-top: 1px solid var(--rule); padding-top: 22px; }
.reply.is-accepted { }
.is-deleted .post-body { opacity: .55; }
.votes { display: flex; flex-direction: column; align-items: center; gap: 2px; padding-top: 2px; }
.vote { width: 38px; height: 32px; border-radius: 50%; border: 1px solid var(--rule-strong); background: var(--surface); color: var(--muted); cursor: pointer; font-size: .85rem; line-height: 1; }
.vote:hover { color: var(--accent); border-color: var(--accent); }
.vote.on.up { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.vote.on.down { background: var(--danger); color: #fff; border-color: var(--danger); }
.score { font: 600 1.2rem var(--serif); padding: 4px 0; }
.accept-mark { color: var(--good); font-size: 1.6rem; line-height: 1; margin-top: 6px; }
.post-main { min-width: 0; }
.post-tags { margin: 14px 0 6px; }
.source { margin: 4px 0; overflow-wrap: anywhere; }
.post-foot { display: flex; justify-content: space-between; gap: 16px; margin-top: 14px; flex-wrap: wrap; align-items: flex-start; }
.post-actions { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); padding-top: 4px; }
.post-actions a, .post-actions .linklike { color: var(--muted); }
.post-actions a:hover, .post-actions .linklike:hover { color: var(--accent); }
.accept-btn { color: var(--good) !important; font-weight: 600; }
.usercard { background: var(--surface-2); border-radius: 6px; padding: 8px 12px; min-width: 210px; }
.reply .usercard { background: transparent; border: 1px solid var(--rule); }
#q .usercard { background: var(--accent-soft); }
.usercard-row { display: flex; gap: 9px; align-items: center; margin-top: 4px; font-size: .9rem; line-height: 1.35; }
.avatar { --h: 210; display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; flex: none; background: hsl(var(--h) 45% 88%); color: hsl(var(--h) 45% 28%); font: 600 .82rem var(--sans); letter-spacing: .02em; }
@media (prefers-color-scheme: dark) { .avatar { background: hsl(var(--h) 30% 26%); color: hsl(var(--h) 60% 85%); } }
.avatar-sm { width: 28px; height: 28px; font-size: .72rem; border-radius: 50%; }
.avatar-lg { width: 76px; height: 76px; font-size: 1.6rem; border-radius: 12px; }
img.avatar { display: inline-block; object-fit: cover; background: var(--surface-2); }
.avatar-edit { display: flex; gap: 18px; align-items: flex-start; }
.avatar-edit .stack { gap: 8px; min-width: 0; }
.avatar-edit p { margin: 0; }
.avatar-upload { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.avatar-upload input[type=file] { max-width: 100%; font-size: .86rem; }
.replies-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; border-bottom: 1px solid var(--rule); padding-bottom: 6px; margin: 18px 0 0; }
.replies-head h2 { margin: 0; }
.replies-head .tabs { border: 0; margin: 0; }
.reply-form { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--rule); }
.join-prompt p:last-child { margin: 0; }

/* Attachments */
.attachments { margin: 18px 0 6px; border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 14px; background: var(--surface); }
.attachments h4 { margin: 0 0 6px; }
.attachments ul { list-style: none; margin: 0; padding: 0; }
.pdf { display: flex; align-items: center; gap: 10px; padding: 6px 0; flex-wrap: wrap; border-top: 1px solid var(--rule); }
.pdf:first-child { border-top: 0; }
.pdf a:not(.btn) { overflow-wrap: anywhere; flex: 1; min-width: 160px; }
.pdf-icon { font: 700 .62rem var(--sans); color: #fff; background: #b8432f; border-radius: 3px; padding: 2px 4px; letter-spacing: .04em; }
.pdf-inline { width: 100%; height: 78vh; border: 1px solid var(--rule); border-radius: 6px; margin-top: 6px; background: var(--surface-2); }

/* ---------- Rendered post bodies ---------- */
.post-body { font-family: var(--serif); font-size: 1.06rem; line-height: 1.62; color: var(--ink); overflow-wrap: break-word; }
.post-body > :first-child { margin-top: 0; }
.post-body p, .post-body ul, .post-body ol, .post-body blockquote, .post-body pre, .post-body table { margin: 0 0 .9em; }
.post-body h1, .post-body h2, .post-body h3, .post-body h4 { margin: 1.3em 0 .5em; font-family: var(--serif); text-transform: none; letter-spacing: 0; color: var(--ink); }
.post-body h1 { font-size: 1.4rem; } .post-body h2 { font-size: 1.25rem; } .post-body h3 { font-size: 1.1rem; } .post-body h4 { font-size: 1rem; }
.post-body ul, .post-body ol { padding-left: 1.5em; }
.post-body li + li { margin-top: .25em; }
.post-body blockquote { background: var(--accent-soft); border-radius: 8px; padding: .55em 1em; color: var(--ink-2); }
.post-body code { background: var(--surface-2); padding: .1em .35em; border-radius: 4px; font-size: .84em; }
.post-body pre { background: var(--surface-2); padding: 12px 14px; border-radius: 6px; overflow-x: auto; line-height: 1.45; }
.post-body pre code { background: none; padding: 0; font-size: .84rem; }
.post-body img { max-width: 100%; height: auto; border-radius: 4px; }
.post-body table { border-collapse: collapse; display: block; overflow-x: auto; font-size: .95rem; }
.post-body th, .post-body td { border: 1px solid var(--rule); padding: 5px 10px; }
.post-body th { background: var(--surface-2); }
.post-body hr { border: 0; border-top: 1px solid var(--rule); margin: 1.5em 0; }
.post-body a { overflow-wrap: anywhere; }
.math.display { display: block; overflow-x: auto; overflow-y: hidden; margin: .8em 0; padding: 2px 0; text-align: center; }
.math.inline { white-space: normal; }
.katex { font-size: 1.08em; }
.katex-display { margin: 0; }
.katex-error { color: var(--danger) !important; font-family: var(--mono); font-size: .85em; }
.env { margin: 1em 0; padding: .7em 1em; border-radius: 10px; background: var(--accent-soft); }
.env > :last-child { margin-bottom: 0; }
.env-head { font-weight: 700; font-style: normal; margin-right: .3em; }
.env-theorem, .env-lemma, .env-proposition, .env-corollary, .env-conjecture, .env-claim { font-style: italic; }
.env-theorem .env-head, .env-lemma .env-head, .env-proposition .env-head, .env-corollary .env-head, .env-conjecture .env-head, .env-claim .env-head { font-style: normal; }
.env-definition, .env-remark, .env-example, .env-notation, .env-question, .env-problem { background: var(--good-soft); }
.env-proof { background: none; padding: 0; border-radius: 0; }
.env-proof .env-head { font-style: italic; font-weight: 600; }
.qed { float: right; }
.citation { white-space: nowrap; }
.cite { font-weight: 500; }
.cite.pending { color: var(--muted); font-family: var(--mono); font-size: .85em; }
.cite.missing { color: var(--danger); border-bottom: 1px dotted var(--danger); }
.references { margin-top: 1.4em; padding-top: .8em; border-top: 1px solid var(--rule); font-size: .92rem; }
.references h4 { font-family: var(--sans); font-size: .78rem; margin-bottom: .4em; }
.references ol { padding-left: 1.8em; margin: 0; }
.references li { margin: .3em 0; }
.references li:target { background: var(--warn-soft); }
.references cite { font-style: italic; }
.footnotes { font-size: .9rem; color: var(--ink-2); border-top: 1px solid var(--rule); margin-top: 1.4em; padding-top: .6em; }

/* ---------- Editor ---------- */
.editor { border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--surface); overflow: hidden; }
.editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.editor.dragging { border-color: var(--accent); border-style: dashed; }
.toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 5px 6px; border-bottom: 1px solid var(--rule); background: var(--surface-2); align-items: center; }
.toolbar button { height: 28px; min-width: 30px; padding: 0 8px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--ink-2); font: 500 .84rem var(--sans); cursor: pointer; }
.toolbar button:hover { background: var(--surface); border-color: var(--rule); }
.toolbar .sep { width: 1px; height: 18px; background: var(--rule-strong); margin: 0 4px; }
.toolbar .help { margin-left: auto; font-size: .8rem; padding: 0 6px; }
.editor textarea { border: 0; border-radius: 0; box-shadow: none !important; min-height: 180px; padding: 12px 14px; background: var(--surface); }
.upload-status { padding: 6px 14px; font-size: .84rem; background: var(--accent-soft); border-top: 1px solid var(--rule); }
.preview-label { font: 600 .7rem var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 8px 14px 0; border-top: 1px dashed var(--rule-strong); background: var(--bg); }
.preview { padding: 6px 14px 14px; min-height: 60px; background: var(--bg); font-size: 1rem; }
.kinds { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.kindopt { display: flex; gap: 8px; padding: 10px 12px; border: 1px solid var(--rule-strong); border-radius: 8px; cursor: pointer; font-weight: 400; background: var(--surface); }
.kindopt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.kindopt input { margin-top: 3px; }
.kindopt span { display: flex; flex-direction: column; }
.kindopt small { color: var(--muted); font-size: .8rem; line-height: 1.35; }
.import-box { background: var(--accent-soft); border-color: transparent; }
.import-box .row { margin-top: 8px; }

/* Dialogs */
.dialog { border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); color: var(--ink); padding: 20px 22px; width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(10, 12, 18, .45); }
.dialog h3 { margin: 0; }
.cite-result .ref { padding: 6px 0; border-top: 1px solid var(--rule); font-size: .9rem; }
.cite-result .err { color: var(--danger); font-size: .9rem; }
.dialog-pdf { width: min(1100px, calc(100vw - 24px)); height: calc(100vh - 40px); padding: 0; display: none; flex-direction: column; overflow: hidden; }
.dialog-pdf[open] { display: flex; }
.dialog-pdf iframe { flex: 1; border: 0; width: 100%; background: #525659; }
.pdf-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--rule); font-size: .9rem; gap: 10px; }
.pdf-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Auth & misc pages ---------- */
.authbox { max-width: 440px; margin: 30px auto; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 28px 30px; box-shadow: var(--shadow); }
.authbox h1 { font-size: 1.6rem; }
.errorbox { text-align: center; }
.err-code { font: 600 3rem var(--serif); color: var(--rule-strong); margin: 0; }
.prose { font-family: var(--serif); font-size: 1.05rem; line-height: 1.65; }
.prose h2 { margin-top: 1.4em; }
.prose code, .prose pre { font-size: .85rem; }
.prose pre { background: var(--surface-2); padding: 12px 14px; border-radius: 6px; overflow-x: auto; font-family: var(--mono); }
.formatting td { vertical-align: top; }
.formatting td pre { margin: 0; background: none; padding: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.table select { width: auto; padding: 3px 6px; font-size: .86rem; }
.admin details summary { cursor: pointer; }
.admin .row select { width: auto; }
.log { max-height: 320px; overflow: auto; background: var(--surface-2); padding: 10px; border-radius: 6px; }
.domains { list-style: none; padding: 0; columns: 2; font-size: .9rem; margin-top: 14px; }
.domains li { break-inside: avoid; padding: 2px 0; }
pre.source { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .82rem; background: var(--surface-2); padding: 10px 12px; border-radius: 6px; max-height: 480px; overflow: auto; }
.flag blockquote { margin: 8px 0; padding: 8px 12px; border-radius: 8px; background: var(--danger-soft); }

/* Profile & people */
.profile-head { display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center; padding-bottom: 18px; border-bottom: 1px solid var(--rule); margin-bottom: 18px; }
.profile-head h1 { margin: 0 0 2px; }
.affil { font-family: var(--serif); font-size: 1.1rem; color: var(--ink-2); margin: 0 0 4px; }
.repbox { text-align: center; padding: 10px 18px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
.repbox b { display: block; font: 600 1.5rem var(--serif); }
.repbox span { font-size: .78rem; color: var(--muted); }
.bio { margin-bottom: 18px; }
.people { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 16px 0; }
.people li { display: flex; gap: 12px; padding: 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); align-items: flex-start; }
.taggrid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.taggrid li { padding: 10px 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
.taggrid p { margin: 6px 0 0; }
.taginfo { margin: 4px 0 6px; color: var(--ink-2); }
.areagrid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.areagrid a { display: flex; flex-direction: column; padding: 12px 14px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); color: var(--ink); height: 100%; }
.areagrid a:hover { border-color: var(--accent); text-decoration: none; }
.areagrid b { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
  .col-side { position: static; }
  .topbar-inner { flex-wrap: wrap; height: auto; min-height: 56px; padding-top: 10px; padding-bottom: 0; row-gap: 4px; }
  .mainnav { order: 10; width: 100%; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter) 6px; width: calc(100% + 2 * var(--gutter)); }
  .mainnav a { padding: 4px 10px; font-size: .9rem; white-space: nowrap; }
}
@media (max-width: 640px) {
  :root { --gutter: 14px; }
  body { font-size: 15px; }
  .topbar-inner { gap: 10px; }
  .brand-name { display: none; }
  .search { max-width: none; }
  .titem { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .tstats { flex-direction: row; align-items: center; gap: 10px; }
  .post { grid-template-columns: 40px minmax(0, 1fr); gap: 10px; }
  .vote { width: 32px; height: 28px; }
  .grid2, .cols-even { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.55rem; }
  .thread-head h1 { font-size: 1.4rem; }
  .profile-head { grid-template-columns: auto 1fr; }
  .repbox { grid-column: 1 / -1; }
  .stats-wide { grid-template-columns: repeat(3, 1fr); row-gap: 10px; }
  .domains { columns: 1; }
  .usercard { min-width: 0; width: 100%; }
  .authbox { padding: 22px 18px; margin: 10px auto; }
}

/* ---------- Comments, notifications ---------- */
.comments { margin-top: 12px; border-top: 1px solid var(--rule); font-size: .9rem; }
.comment { padding: 6px 0 6px 2px; border-bottom: 1px solid var(--rule); line-height: 1.5; color: var(--ink-2); }
.comment:target { background: var(--warn-soft); }
.comment-body p { display: inline; margin: 0; }
.comment-body .math.display { display: inline-block; margin: 0; }
.comment-meta { color: var(--muted); white-space: nowrap; }
.comment-meta form button { font-size: 1rem; line-height: 1; padding: 0 4px; color: var(--muted); }
.add-comment { padding-top: 6px; }
.add-comment summary { list-style: none; cursor: pointer; color: var(--muted); }
.add-comment summary::-webkit-details-marker { display: none; }
.comment-form { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; }
.comment-form textarea { min-height: 54px; font-family: var(--sans); font-size: .9rem; }
.inline-details { display: inline; position: relative; }
.inline-details summary { list-style: none; display: inline; cursor: pointer; }
.inline-details summary::-webkit-details-marker { display: none; }
.close-form { position: absolute; z-index: 5; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; padding: 12px; box-shadow: var(--shadow); width: min(420px, 80vw); margin-top: 6px; }
.bell { position: relative; display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--muted); }
.bell:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.bell.has-unread { color: var(--ink); }
.bell-count { position: absolute; top: 0; right: -2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font: 700 .66rem/17px var(--sans); text-align: center; }
.notes { list-style: none; padding: 0; margin: 0; }
.notes li { display: grid; grid-template-columns: 90px 1fr; gap: 12px; padding: 12px 6px; border-bottom: 1px solid var(--rule); }
.notes li.unread { background: var(--accent-soft); }
.note-kind { font: 600 .68rem/1.8 var(--sans); text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

/* ---------- Reputation: bounties, badges, revisions ---------- */
.bounty-pill { display: inline-block; background: #1f6fb2; color: #fff; font: 700 .72rem/1.6 var(--sans); padding: 0 6px; border-radius: 3px; vertical-align: 2px; }
.bounty-notice { background: var(--accent-soft); }
.bounty-btn { color: #1f6fb2 !important; font-weight: 600; }
/* Badges: metallic chips with a glossy medal. Each level sets its own palette. */
.badge-chip {
  --b-bg1: #f4f4f6; --b-bg2: #e6e7eb; --b-ink: #33363d; --b-edge: #c9ccd3;
  --b-m1: #ffffff; --b-m2: #b9bec7; --b-m3: #7d8592; --b-glow: rgba(125, 133, 146, .35);
  display: inline-flex; align-items: center; gap: 7px; padding: 3px 11px 3px 6px; border-radius: 999px;
  background: linear-gradient(135deg, var(--b-bg1), var(--b-bg2)); color: var(--b-ink);
  border: 1px solid var(--b-edge); font: 600 .84rem/1.5 var(--sans); letter-spacing: .01em;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset, 0 1px 3px var(--b-glow);
  transition: transform .15s ease, box-shadow .15s ease;
}
.badge-chip:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255, 255, 255, .6) inset, 0 4px 12px var(--b-glow); }
.badge-chip .dot {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 32% 30%, var(--b-m1) 0 18%, var(--b-m2) 45%, var(--b-m3) 100%);
  box-shadow: 0 0 0 1.5px var(--b-m3), 0 0 6px var(--b-glow);
}
.badge-novice {
  --b-bg1: #effbe9; --b-bg2: #c9efc0; --b-ink: #1f5a2b; --b-edge: #9bd79a;
  --b-m1: #f3fff0; --b-m2: #7fd38a; --b-m3: #2f8a45; --b-glow: rgba(70, 180, 100, .4);
}
.badge-bronze {
  --b-bg1: #e3fbf6; --b-bg2: #a9eadb; --b-ink: #0d5548; --b-edge: #6fd0bb;
  --b-m1: #e8fffa; --b-m2: #3cc4a6; --b-m3: #11806b; --b-glow: rgba(30, 170, 140, .42);
}
.badge-silver {
  --b-bg1: #e8f1ff; --b-bg2: #b5d0ff; --b-ink: #123e8a; --b-edge: #7fa8f0;
  --b-m1: #f0f6ff; --b-m2: #4f8ef0; --b-m3: #1d4fb8; --b-glow: rgba(60, 120, 230, .45);
}
.badge-gold {
  --b-bg1: #fff6c9; --b-bg2: #ffd54a; --b-ink: #5c3d00; --b-edge: #e9b415;
  --b-m1: #fffbe0; --b-m2: #f7c21b; --b-m3: #a86f00; --b-glow: rgba(240, 180, 0, .55);
}
@media (prefers-color-scheme: dark) {
  .badge-chip { box-shadow: 0 1px 0 rgba(255, 255, 255, .08) inset, 0 1px 4px var(--b-glow); }
  .badge-novice { --b-bg1: #1f4a2a; --b-bg2: #14311c; --b-ink: #b6f0bd; --b-edge: #3f8a52; --b-glow: rgba(110, 210, 130, .35); }
  .badge-bronze { --b-bg1: #12443c; --b-bg2: #0b2e28; --b-ink: #9ff0dc; --b-edge: #2f9a83; --b-glow: rgba(60, 200, 170, .35); }
  .badge-silver { --b-bg1: #1b3566; --b-bg2: #112347; --b-ink: #b9d3ff; --b-edge: #3d6cc4; --b-glow: rgba(90, 150, 255, .38); }
  .badge-gold { --b-bg1: #5c4500; --b-bg2: #3b2c00; --b-ink: #ffe27a; --b-edge: #b68a00; --b-glow: rgba(255, 200, 30, .4); }
}
.profile-badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; }
.badgegrid { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.badgegrid li { padding: 12px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); }
.badgegrid p { margin: 6px 0 0; }
.revision .rev-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: .9rem; }
.rev-num { font: 700 .8rem var(--sans); background: var(--ink); color: var(--bg); border-radius: 4px; padding: 1px 7px; }
.diff ins { background: var(--good-soft); color: var(--ink); text-decoration: none; }
.diff del { background: var(--danger-soft); color: var(--ink); text-decoration: line-through; }
.privileges .ok { color: var(--good); font-weight: 600; }
/* Badge cards: a soft wash of the tier's colour (no side bars). */
.badgegrid li.lvl-novice { background: linear-gradient(135deg, #f2fcef, var(--surface) 70%); border-color: #c9ecc4; }
.badgegrid li.lvl-bronze { background: linear-gradient(135deg, #e9faf6, var(--surface) 70%); border-color: #b5e8dc; }
.badgegrid li.lvl-silver { background: linear-gradient(135deg, #ecf3ff, var(--surface) 70%); border-color: #c3d6fb; }
.badgegrid li.lvl-gold { background: linear-gradient(135deg, #fff8dc, var(--surface) 70%); border-color: #f3dc8a; }
@media (prefers-color-scheme: dark) {
  .badgegrid li.lvl-novice { background: linear-gradient(135deg, #16301b, var(--surface) 70%); border-color: #2b5a33; }
  .badgegrid li.lvl-bronze { background: linear-gradient(135deg, #10302b, var(--surface) 70%); border-color: #22594f; }
  .badgegrid li.lvl-silver { background: linear-gradient(135deg, #16284a, var(--surface) 70%); border-color: #2b4a85; }
  .badgegrid li.lvl-gold { background: linear-gradient(135deg, #352a07, var(--surface) 70%); border-color: #6b5410; }
}

/* ---------- Semantic colours for areas and tags ----------
   Each family sets --f-bg (fill), --f-ink (text), --f-edge (border) and --f-dot (marker). */
.fam-algebra     { --f-bg: #f1ebff; --f-ink: #4a2a96; --f-edge: #cdbdf6; --f-dot: #7c4ddb; }
.fam-geometry    { --f-bg: #e2f6f3; --f-ink: #0d5c54; --f-edge: #a3dcd3; --f-dot: #17a594; }
.fam-analysis    { --f-bg: #e6f0ff; --f-ink: #1b4a9b; --f-edge: #b0c9f3; --f-dot: #3b7be0; }
.fam-probability { --f-bg: #fff1dc; --f-ink: #874a00; --f-edge: #f3c88a; --f-dot: #ef9a1a; }
.fam-discrete    { --f-bg: #e6f6e9; --f-ink: #1f6133; --f-edge: #ace0b6; --f-dot: #36ad55; }
.fam-logic       { --f-bg: #eaedf7; --f-ink: #34406e; --f-edge: #bcc4e2; --f-dot: #5b6aa8; }
.fam-physics     { --f-bg: #fde9ef; --f-ink: #8c1f45; --f-edge: #f2b5c7; --f-dot: #e0487a; }
.fam-general     { --f-bg: #f1f1ef; --f-ink: #4a4a46; --f-edge: #d6d5cf; --f-dot: #9a9990; }
@media (prefers-color-scheme: dark) {
  .fam-algebra     { --f-bg: #2b2148; --f-ink: #d3c3ff; --f-edge: #4d3c86; --f-dot: #a07cff; }
  .fam-geometry    { --f-bg: #12352f; --f-ink: #a6eadf; --f-edge: #23695d; --f-dot: #3cc9b4; }
  .fam-analysis    { --f-bg: #172c4f; --f-ink: #b9d2ff; --f-edge: #2e5596; --f-dot: #6b9cf0; }
  .fam-probability { --f-bg: #3a2a10; --f-ink: #ffd49a; --f-edge: #7a561c; --f-dot: #f3ac3c; }
  .fam-discrete    { --f-bg: #15341d; --f-ink: #b2ecbe; --f-edge: #2c6b3b; --f-dot: #55c873; }
  .fam-logic       { --f-bg: #232a45; --f-ink: #c5ceef; --f-edge: #46518a; --f-dot: #8592d0; }
  .fam-physics     { --f-bg: #3d1724; --f-ink: #ffbfd2; --f-edge: #7e2c48; --f-dot: #f06f9a; }
  .fam-general     { --f-bg: #2a2a28; --f-ink: #d0cfc8; --f-edge: #4a4a45; --f-dot: #a5a49b; }
}
.chip[class*="fam-"] { background: var(--f-bg); color: var(--f-ink); border: 1px solid var(--f-edge); }
.chip[class*="fam-"]:hover { filter: none; border-color: var(--f-dot); }
.chip-area[class*="fam-"] { font-weight: 600; }
.chip { border: 1px solid transparent; }
.chip-count { opacity: .65; font-weight: 500; }
/* Special tags */
.chip.tag-verified { background: #e3f7e8; color: #17602f; border: 1px solid #8fd6a2; font-weight: 600; }
.chip.tag-verified::before { content: "✓"; font-weight: 700; color: #22a04b; }
.chip.tag-source { background: transparent; color: var(--ink-2); border: 1px dashed var(--rule-strong); }
@media (prefers-color-scheme: dark) {
  .chip.tag-verified { background: #15361f; color: #a9ebb9; border-color: #2f7a46; }
  .chip.tag-verified::before { color: #5fd685; }
}
/* Area markers in lists and the Areas page */
.fam-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--f-dot, var(--rule-strong)); margin-right: 7px; vertical-align: 1px; flex: none; }
.arealist a[aria-current] { background: var(--f-bg); color: var(--f-ink); }



/* ---------- Wide screens ----------
   The frame grows with the viewport; list pages gain a left rail, and threads with
   PDFs dock a reader beside the discussion. Prose keeps a readable measure. */
.cols-3 { grid-template-columns: 270px minmax(0, 1fr); grid-template-rows: auto 1fr; grid-template-areas: "left main" "side main"; } /* areas always on the left */
.cols-3 > .col-main { grid-area: main; }
.cols-3 > .col-left { grid-area: left; }
.cols-3 > .col-side { grid-area: side; position: static; }
.arealist-group + .arealist-group { margin-top: 10px; }
.arealist-family { display: flex; align-items: center; font: 600 .74rem var(--sans); text-transform: uppercase; letter-spacing: .05em; color: var(--f-ink); margin: 0 0 3px 6px; }
.arealist-family .fam-dot { width: 8px; height: 8px; }
.arealist { max-height: none; }
.pdf-dock { display: none; padding: 0; overflow: hidden; }
@media (min-width: 1440px) {
  :root { --page-max: 1360px; }
  .narrow-wide { max-width: 1100px; }
}
@media (min-width: 1600px) {
  :root { --page-max: 1680px; --gutter: 28px; }
  .cols { gap: 36px; }
  .cols-3 { grid-template-columns: 250px minmax(0, 1fr) 310px; grid-template-rows: auto; grid-template-areas: "left main side"; }
  .cols-3 > .col-left, .cols-3 > .col-side { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; scrollbar-width: thin; }
  .thread-cols:not(.dock-open) { max-width: 1400px; margin: 0 auto; grid-template-columns: minmax(0, 1fr) 340px; }
  .dock-open { grid-template-columns: minmax(0, 1fr) minmax(480px, 44%); }
  .dock-open > .col-side { top: 72px; }
  .dock-open .pdf-dock { display: flex; flex-direction: column; height: calc(100vh - 92px); }
  .pdf-dock iframe { flex: 1; width: 100%; border: 0; background: #525659; }
  .pdf-dock-bar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--rule); font-size: .86rem; }
  .pdf-dock-bar select { flex: 1; padding: 4px 8px; font-size: .84rem; }
  .pdf-dock-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
  .dock-open > .col-side > .card:not(.pdf-dock) { display: none; } /* facts/related give way to the reader */
  .narrow-wide { max-width: 1240px; }
  .post-body { font-size: 1.1rem; }
}
@media (min-width: 1800px) {
  body { font-size: 16px; }
}
@media (min-width: 2200px) {
  :root { --page-max: 1880px; }
  .cols-3 { grid-template-columns: 280px minmax(0, 1fr) 340px; }
}
@media (max-width: 980px) {
  .cols-3 { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "side" "left"; grid-template-rows: auto; }
}

/* ---------- No greys: every chip and label carries a hue ----------
   Hues are spread around the wheel so families stay distinguishable. */
.fam-algebra     { --f-bg: #f3ebff; --f-ink: #5b21b6; --f-edge: #cfb5fb; --f-dot: #7c3aed; }   /* purple 270 */
.fam-logic       { --f-bg: #fce8fd; --f-ink: #86198f; --f-edge: #f0abfc; --f-dot: #c026d3; }   /* fuchsia 300 */
.fam-physics     { --f-bg: #ffe6ee; --f-ink: #9f1239; --f-edge: #fda4c0; --f-dot: #e11d48; }   /* rose 345 */
.fam-probability { --f-bg: #ffedd9; --f-ink: #9a3412; --f-edge: #fdba8c; --f-dot: #ea580c; }   /* orange 25 */
.fam-general     { --f-bg: #f1f9d6; --f-ink: #3f6212; --f-edge: #c5e286; --f-dot: #65a30d; }   /* lime 80 */
.fam-discrete    { --f-bg: #e3f8e8; --f-ink: #166534; --f-edge: #9ee0b0; --f-dot: #16a34a; }   /* green 140 */
.fam-geometry    { --f-bg: #ddf7f3; --f-ink: #115e59; --f-edge: #93ddd2; --f-dot: #0d9488; }   /* teal 175 */
.fam-analysis    { --f-bg: #e3edff; --f-ink: #1e40af; --f-edge: #a9c3fb; --f-dot: #2563eb; }   /* blue 220 */
@media (prefers-color-scheme: dark) {
  .fam-algebra     { --f-bg: #2e1a52; --f-ink: #d8c4ff; --f-edge: #5b3a9e; --f-dot: #a78bfa; }
  .fam-logic       { --f-bg: #3d1442; --f-ink: #f5c2f9; --f-edge: #86288f; --f-dot: #e879f9; }
  .fam-physics     { --f-bg: #43121f; --f-ink: #ffc1d1; --f-edge: #8f2442; --f-dot: #fb7194; }
  .fam-probability { --f-bg: #42200c; --f-ink: #ffcfa6; --f-edge: #92451a; --f-dot: #fb923c; }
  .fam-general     { --f-bg: #263510; --f-ink: #d4f09a; --f-edge: #4d6b1c; --f-dot: #a3e635; }
  .fam-discrete    { --f-bg: #12351f; --f-ink: #aef0c0; --f-edge: #23733d; --f-dot: #4ade80; }
  .fam-geometry    { --f-bg: #0f3632; --f-ink: #a1efe3; --f-edge: #1d7068; --f-dot: #2dd4bf; }
  .fam-analysis    { --f-bg: #172a57; --f-ink: #bcd0ff; --f-edge: #2f53a8; --f-dot: #60a5fa; }
}
/* Tags without an area yet: sky. Imported-source tag and labels: indigo. */
.chip { background: #e2f3fc; color: #075985; border-color: #9fd3f0; }
.chip.tag-source { background: #e8e9ff; color: #3730a3; border: 1px solid #b4b8fb; font-weight: 600; }
.chip.tag-source::before { content: "⤓"; font-weight: 700; color: #4f46e5; }
.badge-bot, .badge { background: #e8e9ff; color: #3730a3; }
.score-pill { background: #e3edff; color: #1e40af; }
.chip-area:not([class*="fam-"]) { background: #e2f3fc; color: #075985; }
@media (prefers-color-scheme: dark) {
  .chip { background: #0d2f45; color: #b5e3fb; border-color: #1f5a7d; }
  .chip.tag-source { background: #22234f; color: #c7caff; border-color: #3f43a3; }
  .chip.tag-source::before { color: #a5b4fc; }
  .badge-bot, .badge { background: #22234f; color: #c7caff; }
  .score-pill { background: #172a57; color: #bcd0ff; }
}


/* ---------- Areas page: panels (default) and map views ---------- */
.areas-head { align-items: center; }
.view-toggle { display: inline-flex; background: var(--surface); border: 1px solid var(--rule); border-radius: 999px; padding: 3px; }
.view-toggle a { padding: 4px 14px; border-radius: 999px; color: var(--ink-2); font-weight: 500; font-size: .9rem; }
.view-toggle a:hover { text-decoration: none; color: var(--ink); }
.view-toggle a[aria-current] { background: var(--accent); color: var(--accent-ink); }
.area-panels { column-width: 430px; column-gap: 16px; margin-top: 18px; } /* masonry flow: panels keep their natural heights */
.area-panel { background: var(--f-bg); border-radius: 16px; padding: 18px 20px 14px; break-inside: avoid; margin-bottom: 16px; }
.area-panel h2 { font-size: 1.08rem; color: var(--f-ink); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 0; }
.area-panel-total { font: 600 .8rem var(--sans); opacity: .8; }
.area-panel ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 2px 18px; }
.area-panel li a { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; color: var(--ink); }
.area-panel li a:hover { text-decoration: none; }
.area-panel li a:hover .area-name { text-decoration: underline; text-decoration-color: var(--f-dot); text-underline-offset: 3px; }
.area-name { font-family: var(--serif); }
.area-count { color: var(--f-ink); font-weight: 600; font-size: .85rem; font-variant-numeric: tabular-nums; }
.area-panel li.is-empty .area-count { opacity: .45; }
.area-map { display: grid; gap: 20px; margin-top: 18px; }
.area-map-head { font-size: 1rem; color: var(--f-ink); margin: 0 0 8px; display: flex; align-items: center; }
.area-map ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.area-map li { flex: 0 1 var(--tile-w); min-width: 0; } /* same scale on every row, so sizes compare across families */
.area-map li a { display: flex; flex-direction: column; justify-content: space-between; height: 88px; padding: 10px 12px; border-radius: 12px;
  background: color-mix(in srgb, var(--f-dot) var(--strength), var(--f-bg)); color: var(--f-ink); }
.area-map li a.tile-dark { color: #fff; }
.area-map li a:hover { text-decoration: none; outline: 2px solid var(--f-dot); outline-offset: 2px; }
.tile-name { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
.tile-meta { display: flex; justify-content: space-between; gap: 8px; font-size: .8rem; opacity: .92; font-variant-numeric: tabular-nums; }
.tile-meta .code { font-family: var(--mono); font-size: .76rem; min-width: 0; color: inherit; }


/* Settings: account identity at the top of the Profile panel */
.account-row { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 4px 0 18px; padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); }
.account-row div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.account-row dt { font: 600 .72rem var(--sans); text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.account-row dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.private-pill { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; background: var(--surface); color: var(--accent); font: 600 .7rem/1.7 var(--sans); vertical-align: 1px; }

/* ---------- Security settings & two-step sign-in ---------- */
.settings-tabs { margin-bottom: 18px; }
.sec-section { margin-bottom: 16px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sec-head h2 { margin: 0; }
.status-pill { font: 600 .74rem/1.8 var(--sans); padding: 0 10px; border-radius: 999px; background: var(--danger-soft); color: var(--danger); }
.status-pill.on { background: var(--good-soft); color: var(--good); }
.passkeys { list-style: none; padding: 0; margin: 12px 0; }
.passkeys li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--rule); }
.pk-main { flex: 1; min-width: 0; }
.pk-icon { font-size: 1.2rem; }
.add-passkey summary { list-style: none; display: inline-flex; }
.add-passkey summary::-webkit-details-marker { display: none; }
.add-passkey[open] summary { margin-bottom: 10px; }
.totp-setup { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.totp-setup img { border-radius: 8px; background: #fff; padding: 8px; image-rendering: pixelated; }
.totp-setup .stack { flex: 1; min-width: 240px; }
.secret { font: 600 1rem var(--mono); letter-spacing: .06em; background: var(--accent-soft); padding: 6px 10px; border-radius: 6px; overflow-wrap: anywhere; }
.codes { font: 600 1rem/1.9 var(--mono); background: var(--accent-soft); border-radius: 8px; padding: 12px 16px; columns: 2; margin: 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; margin: 14px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--rule); }
.upload-hint { padding: 6px 14px; font-size: .8rem; color: var(--muted); border-top: 1px solid var(--rule); background: var(--surface); }

/* ---------- Post composer ----------
   Narrow screens: one column. Wide screens: write and preview side by side,
   with the post's settings in a sticky sidebar. */
.composer { max-width: 820px; margin: 0 auto; }
.composer-form { display: flex; flex-direction: column; gap: 16px; }
.composer-side .card { padding: 14px 16px; }
.composer-side label { margin-bottom: 4px; }
.composer-tips h4 { margin-bottom: 8px; }
.composer-tips dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0 0 10px; }
.composer-tips dt code { font-size: .78rem; }
.composer-tips dd { margin: 0; color: var(--muted); }
@media (min-width: 1400px) {
  .composer { max-width: min(1560px, 100%); }
  .composer-form { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }
  .composer-side { position: sticky; top: 76px; }
  .composer .kinds { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .composer .editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "tb tb" "in pl" "in pv" "st pv" "hn pv"; grid-template-rows: auto auto 1fr auto auto; }
  .composer .editor > .toolbar { grid-area: tb; }
  .composer .editor > textarea { grid-area: in; min-height: 62vh; border-right: 1px solid var(--rule); resize: none; }
  .composer .editor > .upload-status { grid-area: st; }
  .composer .editor > .upload-hint { grid-area: hn; }
  .composer .editor > .preview-label { grid-area: pl; border-top: 0; }
  .composer .editor > .preview { grid-area: pv; max-height: 62vh; overflow-y: auto; }
}

/* ---------- Area filters ---------- */
.filterbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.filter-search input { width: 220px; height: 32px; padding: 0 12px; border-radius: 16px; font-size: .88rem; }
.filter-tags { flex: 1; min-width: 0; }
.chip.is-picked { outline: 2px solid var(--f-dot, var(--accent)); outline-offset: 1px; font-weight: 600; }
.clear-filters { white-space: nowrap; }
