/* ===========================================================================
   System Design Notes — shared styles
   =========================================================================== */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2128;
  --text-dim: #5b6470;
  --border: #e2e6ea;
  --accent: #4f46e5;
  --accent-weak: #eef0fe;
  --accent-text: #ffffff;
  --good: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.06);
  --maxw: 940px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans:
    system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Dark palette — applied when the user explicitly picks "dark"... */
:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232d;
  --text: #e6edf3;
  --text-dim: #9aa6b2;
  --border: #2a313c;
  --accent: #7c83ff;
  --accent-weak: #1d2233;
  --accent-text: #0d1117;
  --good: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* ...or when the OS prefers dark and the user hasn't forced light/dark ("system"). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #1c232d;
    --text: #e6edf3;
    --text-dim: #9aa6b2;
    --border: #2a313c;
    --accent: #7c83ff;
    --accent-weak: #1d2233;
    --accent-text: #0d1117;
    --good: #4ade80;
    --warn: #fbbf24;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.7rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
}
.brand {
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.brand:hover {
  text-decoration: none;
}
.brand .logo {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--accent-text);
  border-radius: 8px;
  font-size: 15px;
  font-weight: 800;
}
.topbar .spacer {
  flex: 1;
}
.topbar .home-link {
  font-size: 0.92rem;
  color: var(--text-dim);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.topbar .home-link:hover {
  color: var(--text);
  text-decoration: none;
  background: var(--surface-2);
}

/* ---------- Theme toggle (system / light / dark) ---------- */
.theme-seg {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.theme-seg button {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}
.theme-seg button svg {
  width: 18px;
  height: 18px;
  display: block;
  flex: none;
}
.theme-seg button:hover {
  color: var(--text);
}
.theme-seg button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}
.theme-seg button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Layout ---------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.4rem 1.1rem 4rem;
}

.page-head {
  margin: 1rem 0 1.4rem;
}
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}
h1 {
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  line-height: 1.15;
  margin: 0.3rem 0 0.5rem;
  letter-spacing: -0.02em;
}
.lede {
  color: var(--text-dim);
  font-size: 1.05rem;
  margin: 0;
}

h2 {
  font-size: 1.4rem;
  margin: 2.4rem 0 0.8rem;
  letter-spacing: -0.01em;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--border);
  scroll-margin-top: 70px;
}
h3 {
  font-size: 1.12rem;
  margin: 1.5rem 0 0.5rem;
}
p {
  margin: 0.6rem 0;
}
ul,
ol {
  padding-left: 1.3rem;
}
li {
  margin: 0.3rem 0;
}
strong {
  color: var(--text);
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ---------- Callouts / tags ---------- */
.tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.callout {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
  margin: 1rem 0;
  box-shadow: var(--shadow);
}
.callout.good {
  border-left-color: var(--good);
}
.callout.warn {
  border-left-color: var(--warn);
}
.callout .callout-title {
  font-weight: 700;
  margin: 0 0 0.25rem;
}

/* ---------- Tables ---------- */
.table-scroll {
  overflow-x: auto;
  margin: 1rem 0;
  border-radius: var(--radius-sm);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
th,
td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: var(--surface-2);
  font-weight: 700;
}
tr:last-child td {
  border-bottom: none;
}

/* ---------- Code & Mermaid ---------- */
code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}
pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
}
pre code {
  background: none;
  border: none;
  padding: 0;
}
.api-block {
  font-family: var(--mono);
  font-size: 0.9rem;
}

pre.mermaid {
  background: var(--surface);
  text-align: center;
  padding: 1.1rem;
  line-height: 1.3;
}
pre.mermaid svg {
  max-width: 100%;
  height: auto;
}
.diagram-caption {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: -0.4rem 0 1.4rem;
}

/* ---------- Pager (prev/next) ---------- */
.pager {
  display: flex;
  gap: 0.7rem;
  align-items: stretch;
  margin: 1.4rem 0;
}
.pager.pager-top {
  margin-top: 0.4rem;
}
.pager a,
.pager span.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.7rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  min-width: 0;
}
.pager a:hover {
  text-decoration: none;
  border-color: var(--accent);
}
.pager span.empty {
  visibility: hidden;
}
.pager .dir {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 700;
}
.pager .ttl {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pager .next {
  text-align: right;
}

/* ---------- Home index ---------- */
.intro-card {
  background: linear-gradient(135deg, var(--accent-weak), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  margin-bottom: 1.6rem;
  box-shadow: var(--shadow);
}
.intro-card h1 {
  margin-top: 0;
}
.stats {
  display: flex;
  gap: 1.4rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
  color: var(--text-dim);
  font-size: 0.92rem;
}
.stats b {
  color: var(--text);
  font-size: 1.15rem;
}

.cat-group {
  margin: 1.8rem 0;
}
.cat-group h2 {
  border: none;
  margin-bottom: 0.8rem;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 0.9rem;
}
.card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  transition:
    transform 0.12s ease,
    border-color 0.12s ease;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  text-decoration: none;
}
.card .num {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
}
.card .card-title {
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.card .card-blurb {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin: 0;
}

/* ---------- Notes ---------- */
.notes {
  margin: 3rem 0 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow);
}
.notes h2 {
  border: none;
  margin: 0 0 0.2rem;
  font-size: 1.25rem;
}
.notes .notes-sub {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}
.note-form {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: flex-start;
}
.note-form .field {
  flex: 1;
  min-width: 200px;
}
.note-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 44px;
  max-height: 140px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
}
.note-form textarea:focus {
  outline: 2px solid var(--accent);
  border-color: var(--accent);
}
.note-form .row2 {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.4rem;
}
.btn {
  appearance: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-text);
  border: 1px solid var(--accent);
}
.btn:hover {
  filter: brightness(1.05);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.counter {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.counter.over {
  color: var(--danger);
  font-weight: 700;
}

.note-verify {
  margin: 0.25rem 0 0.1rem;
}
.human-check {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.human-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.cf-box {
  min-height: 65px;
}

.note-list {
  list-style: none;
  padding: 0;
  margin: 1.2rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}
.note-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  word-break: break-word;
}
.note-item .meta {
  display: block;
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}
.notes-status {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 0.8rem;
}
.notes-status.error {
  color: var(--danger);
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--border);
  margin-top: 2rem;
  padding: 1.6rem 1.1rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.88rem;
}
.footer a {
  color: var(--text-dim);
  text-decoration: underline;
}

/* ---------- TOC chips ---------- */
.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1.2rem 0 0;
}
.toc a {
  font-size: 0.82rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.toc a:hover {
  color: var(--text);
  border-color: var(--accent);
  text-decoration: none;
}

@media (max-width: 560px) {
  body {
    font-size: 16px;
  }
  .pager {
    flex-direction: row;
  }
  .pager .ttl {
    font-size: 0.9rem;
  }
}
