/* psfp5 docs — dark design system shared with landing.html and the admin panel. */
:root {
  color-scheme: dark;
  --bg: #0A0B0D;
  --bg2: #0D0F13;
  --panel: #131519;
  --panel2: #171A20;
  --ink: #EDEFF2;
  --muted: #9AA0A8;
  --dim: #7A818B;
  --border: rgba(255, 255, 255, 0.08);
  --line2: rgba(255, 255, 255, 0.12);
  --accent: #8F7BFF;
  --accent-hi: #B3A6FF;
  --accent-soft: rgba(143, 123, 255, 0.16);
  --success: #3EDBB6;
  --warn: #D8B25E;
  --danger: #F0736A;
  --code-bg: #0D0F13;
  --code-fg: #C9CED6;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.8);
  --radius-card: 14px;
  --radius-btn: 9px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  /* Neutral surface tints used for chips/hover/inline-code. Broken out as
     variables so the light theme can flip them from white-alpha to black-alpha. */
  --inline-code-bg: rgba(255, 255, 255, 0.07);
  --chip-bg: rgba(255, 255, 255, 0.06);
  --chip-bg-hi: rgba(255, 255, 255, 0.10);
  --chip-line-hi: rgba(255, 255, 255, 0.24);
  --surface-hover: rgba(255, 255, 255, 0.05);
  --surface-hover-soft: rgba(255, 255, 255, 0.03);
  --select-bg: rgba(143, 123, 255, 0.35);
  --topbar-bg: rgba(9, 10, 12, 0.6);
  --field-bg: #1B1F27;
  --notice-fg: #D6D0F5;
  --notice-warn-fg: #EAD9AE;
  /* Bottom stop of the section-card gradient. Kept as a variable so light theme
     can flip it off the hardcoded dark value (which otherwise faded every card
     to near-black on white). */
  --panel-grad-b: #101216;
}

/* Light theme — stamped as data-theme="light" on <html> (pre-paint by theme.js,
   toggled from app.js). Warm off-white palette matching the admin panel and
   landing page; the violet brand accent is darkened for contrast on white. */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #FAF9F5;
  --bg2: #F2F1EC;
  --panel: #FFFFFF;
  --panel2: #F6F5F1;
  --ink: #1A1B1E;
  --muted: #5C616B;
  --dim: #868C95;
  --border: rgba(0, 0, 0, 0.10);
  --line2: rgba(0, 0, 0, 0.16);
  --accent: #6B54E0;
  --accent-hi: #5B44D0;
  --accent-soft: rgba(143, 123, 255, 0.16);
  --success: #12A594;
  --warn: #B5852B;
  --danger: #D64545;
  --code-bg: #F6F5F1;
  --code-fg: #2A2E35;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.18);
  --inline-code-bg: rgba(0, 0, 0, 0.05);
  --chip-bg: rgba(0, 0, 0, 0.04);
  --chip-bg-hi: rgba(0, 0, 0, 0.07);
  --chip-line-hi: rgba(0, 0, 0, 0.22);
  --surface-hover: rgba(0, 0, 0, 0.05);
  --surface-hover-soft: rgba(0, 0, 0, 0.035);
  --select-bg: rgba(143, 123, 255, 0.30);
  --topbar-bg: rgba(250, 249, 245, 0.72);
  --field-bg: #FFFFFF;
  --notice-fg: #4A3E9E;
  --notice-warn-fg: #6B4F16;
  /* Warm off-white bottom stop so section cards read as clean white surfaces
     (like the admin panel) instead of fading to a dark gradient. */
  --panel-grad-b: #F6F5F1;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .18s ease, color .18s ease;
}
::selection { background: var(--select-bg); }

a { color: var(--accent-hi); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid rgba(143, 123, 255, 0.65);
  outline-offset: 2px;
  border-radius: 6px;
}

code {
  border-radius: 5px;
  background: var(--inline-code-bg);
  color: var(--code-fg);
  font-family: var(--mono);
  font-size: 0.9em;
  padding: 0.1rem 0.3rem;
}
pre {
  position: relative;
  overflow: auto;
  margin: 12px 0 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  color: var(--code-fg);
}
pre code {
  display: block;
  min-width: max-content;
  padding: 16px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  line-height: 1.6;
}
pre::-webkit-scrollbar { height: 8px; }
pre::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 4px; }
pre::-webkit-scrollbar-track { background: transparent; }

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--line2);
  border-radius: 6px;
  background: var(--chip-bg);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 9px;
  transition: color .15s, border-color .15s, background .15s;
}
.copy-btn:hover { color: var(--ink); border-color: var(--chip-line-hi); background: var(--chip-bg-hi); }

/* ============ Topbar ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 62px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-bg);
  backdrop-filter: blur(14px) saturate(1.3);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  padding: 0 28px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  font-family: var(--mono);
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.04em;
  line-height: 1;
  transform: translateY(1px);
}
.brand strong, .brand small { display: block; line-height: 1.2; }
.brand strong { font-size: 15px; font-weight: 650; letter-spacing: -0.015em; }
.brand small { color: var(--dim); font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; margin-top: 3px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.top-actions a {
  border: 1px solid var(--line2);
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--ink);
  font-size: 13.5px;
  padding: 7px 13px;
  transition: border-color .15s, background .15s;
}
.top-actions a:hover { text-decoration: none; border-color: var(--chip-line-hi); background: var(--surface-hover-soft); }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 34px;
  border: 1px solid var(--line2); border-radius: var(--radius-btn);
  background: transparent; color: var(--muted);
  cursor: pointer; padding: 0;
  transition: color .15s, border-color .15s, background .15s;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--chip-line-hi); background: var(--surface-hover-soft); }
.theme-toggle svg { width: 17px; height: 17px; }
/* Show the sun in dark mode (click → light), the moon in light mode. */
.theme-toggle .icon-moon { display: none; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: inline; }

/* ============ Layout ============ */
.layout {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  gap: 36px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 30px 28px 60px;
}
.sidebar {
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 112px);
  overflow: auto;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 4px; }
.search { display: block; margin-bottom: 16px; }
.search span {
  display: block;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  margin-bottom: 7px;
}
.search input {
  width: 100%;
  border: 1px solid var(--line2);
  border-radius: var(--radius-btn);
  background: var(--field-bg);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  padding: 9px 11px;
}
.search input::placeholder { color: var(--dim); }
.search input:focus { border-color: var(--accent); outline: none; }
#toc { display: grid; gap: 2px; }
#toc a {
  border-radius: 8px;
  color: var(--muted);
  font-size: 13.5px;
  padding: 7px 10px;
  transition: color .15s, background .15s;
}
#toc a:hover { background: var(--surface-hover); color: var(--ink); text-decoration: none; }
#toc a.active { background: var(--accent-soft); color: var(--accent-hi); }

main { min-width: 0; }

/* ============ Sections ============ */
.doc-section {
  scroll-margin-top: 84px;
  margin: 0 0 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: linear-gradient(180deg, var(--panel), var(--panel-grad-b));
  box-shadow: var(--shadow);
  padding: 30px;
}
.doc-section.hidden { display: none; }
.eyebrow {
  margin: 0 0 12px;
  color: var(--dim);
  font-family: var(--mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .18em;
  font-size: 11px;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.15; letter-spacing: -0.02em; }
h1 { font-size: 40px; font-weight: 650; max-width: 780px; text-wrap: balance; }
h2 {
  border-bottom: 1px solid var(--border);
  font-size: 24px;
  font-weight: 650;
  margin-bottom: 18px;
  padding-bottom: 14px;
}
h3 { font-size: 17px; font-weight: 650; margin: 24px 0 10px; }
h4 { font-size: 14.5px; font-weight: 650; margin: 18px 0 8px; }
.lead { max-width: 860px; color: var(--muted); font-size: 17px; text-wrap: pretty; }
p { margin: 10px 0 14px; }
ul, ol { padding-left: 22px; }
li { margin: 7px 0; }

/* ============ Fact cards / grids ============ */
.facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 24px 0;
}
.facts div,
.grid article {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel2);
  padding: 15px;
}
.facts span {
  display: block;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.facts strong { display: block; margin-top: 6px; font-size: 14.5px; overflow-wrap: anywhere; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid article h3 { margin-top: 0; }
.grid article h3:first-child { margin-top: 2px; }

/* ============ Flow visual ============ */
.flow-visual {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto minmax(130px, 1fr) auto minmax(130px, 1fr) auto minmax(130px, 1fr);
  align-items: center;
  gap: 8px;
  margin: 26px 0;
}
.flow-visual div {
  border: 1px solid var(--line2);
  border-radius: 10px;
  background: var(--panel2);
  font-size: 13.5px;
  font-weight: 600;
  padding: 13px 10px;
  text-align: center;
}
.flow-visual span {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10.5px;
  text-align: center;
}

/* ============ Notices ============ */
.notice {
  border: 1px solid rgba(143, 123, 255, 0.3);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: rgba(143, 123, 255, 0.08);
  color: var(--notice-fg);
  padding: 14px 16px;
}
.notice a { color: var(--accent-hi); }
.notice.compact { margin-top: 14px; }
.notice.warn {
  border-color: rgba(216, 178, 94, 0.35);
  border-left-color: var(--warn);
  background: rgba(216, 178, 94, 0.08);
  color: var(--notice-warn-fg);
}

/* ============ Tables ============ */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 12px 0 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
th, td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}
th {
  background: var(--panel2);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
}
tr:last-child td { border-bottom: 0; }

/* ============ Endpoint chips ============ */
.endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 8px;
  border: 1px solid var(--line2);
  border-radius: 10px;
  background: var(--panel2);
  padding: 10px 12px;
}
.endpoint span {
  min-width: 48px;
  border-radius: 6px;
  background: var(--accent);
  color: #FFFFFF;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  text-align: center;
}
.endpoint code { background: transparent; color: var(--ink); font-size: 13.5px; padding: 0; }
.endpoint.public span { background: rgba(62, 219, 182, 0.16); color: var(--success); }
.endpoint em {
  margin-left: auto;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10.5px;
  font-style: normal;
  letter-spacing: .12em;
  text-transform: uppercase;
  border: 1px solid var(--line2);
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}

/* ============ Code tabs ============ */
.code-tabs {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel2);
  padding: 10px;
}
.tab-list { display: flex; gap: 8px; margin-bottom: 10px; }
.tab-list button {
  border: 1px solid var(--line2);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  transition: color .15s, border-color .15s, background .15s;
}
.tab-list button:hover { color: var(--ink); border-color: var(--chip-line-hi); }
.tab-list button.active {
  border-color: rgba(143, 123, 255, 0.5);
  background: var(--accent-soft);
  color: var(--accent-hi);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel pre { margin-bottom: 0; }

/* ============ Numbered steps ============ */
.steps { counter-reset: item; list-style: none; padding-left: 0; }
.steps li {
  position: relative;
  min-height: 40px;
  border-left: 1px solid var(--line2);
  margin: 0;
  padding: 0 0 20px 42px;
}
.steps li::before {
  position: absolute;
  left: -16px;
  top: 0;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border: 1px solid var(--line2);
  border-radius: 50%;
  background: var(--panel2);
  color: var(--accent-hi);
  content: counter(item);
  counter-increment: item;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
}
.steps li:last-child { border-left-color: transparent; padding-bottom: 4px; }

/* ============ Back to top ============ */
.to-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line2);
  border-radius: 10px;
  background: var(--panel2);
  color: var(--ink);
  cursor: pointer;
  font-size: 17px;
  transition: border-color .15s, background .15s;
}
.to-top:hover { border-color: var(--accent); background: var(--accent-soft); }
.to-top.visible { display: block; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; padding: 18px; }
  .sidebar { position: static; max-height: none; }
  #toc { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .facts, .grid.two, .flow-visual { grid-template-columns: 1fr; }
  .flow-visual span { display: none; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; padding: 12px 16px; }
  .top-actions { width: 100%; }
  .top-actions a { flex: 1; text-align: center; }
  .doc-section { padding: 20px; }
  h1 { font-size: 30px; }
  #toc { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; }
}
