/* Shared design system for pub.s1d.me and explorer.s1d.me */
:root {
  --bg: #f7f6f3; --panel: #ffffff; --sunken: #f1efea; --hover: #ecebe6; --sel: #e4e8fd;
  --line: #e6e3dc; --line-2: #d6d2c8; --text: #1c1b19; --text-2: #3d3a35; --muted: #6c675e; --faint: #9b958b;
  --accent: #3f56d9; --accent-2: #2f43b8; --accent-soft: #e9ecfd; --on-accent: #fff;
  --green: #1d7a46; --green-soft: #e3f3e9; --amber: #a3620a; --amber-soft: #fbf0dc; --red: #b4232c; --red-soft: #fbe5e6;
  --violet: #7044c4; --violet-soft: #efe8fb; --teal: #0f7a83; --teal-soft: #ddf2f3;
  --shadow: 0 1px 2px rgba(28, 27, 25, .06), 0 4px 16px rgba(28, 27, 25, .05);
  --shadow-lg: 0 10px 40px rgba(28, 27, 25, .14), 0 2px 6px rgba(28, 27, 25, .06);
  --r: 10px; --r-sm: 7px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Bitstream Charter", "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111215; --panel: #17181c; --sunken: #1d1f24; --hover: #23252b; --sel: #262d4d;
    --line: #2a2c33; --line-2: #383b44; --text: #ebe9e5; --text-2: #d0cdc7; --muted: #a29d94; --faint: #757068;
    --accent: #8597ff; --accent-2: #a3b1ff; --accent-soft: #232a4c; --on-accent: #0d1020;
    --green: #5fcf8e; --green-soft: #173325; --amber: #f0b45a; --amber-soft: #352710; --red: #ff8087; --red-soft: #3a1a1d;
    --violet: #b89cff; --violet-soft: #2a2140; --teal: #5cd0d8; --teal-soft: #13302f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 48px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111215; --panel: #17181c; --sunken: #1d1f24; --hover: #23252b; --sel: #262d4d;
  --line: #2a2c33; --line-2: #383b44; --text: #ebe9e5; --text-2: #d0cdc7; --muted: #a29d94; --faint: #757068;
  --accent: #8597ff; --accent-2: #a3b1ff; --accent-soft: #232a4c; --on-accent: #0d1020;
  --green: #5fcf8e; --green-soft: #173325; --amber: #f0b45a; --amber-soft: #352710; --red: #ff8087; --red-soft: #3a1a1d;
  --violet: #b89cff; --violet-soft: #2a2140; --teal: #5cd0d8; --teal-soft: #13302f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 12px 48px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, kbd, pre, samp { font-family: var(--mono); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .dim { color: var(--faint); }
.small { font-size: 13px; } .mono { font-family: var(--mono); font-size: .92em; }
.i { flex: none; vertical-align: -3px; }

/* buttons + inputs */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--panel); color: var(--text); font: 500 14px var(--sans); cursor: pointer;
  text-decoration: none !important; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; gap: 5px; }
.btn.icon { width: 32px; padding: 0; justify-content: center; }
.btn.icon.sm { width: 28px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=search], input[type=password], textarea, select {
  font: 14px var(--sans); color: var(--text); background: var(--panel); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 7px 10px; outline: none; min-width: 0; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
label.field { display: grid; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg { display: inline-flex; background: var(--sunken); border: 1px solid var(--line); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--muted);
  font: 500 13px var(--sans); padding: 5px 10px; border-radius: 7px; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

.badge { display: inline-flex; align-items: center; gap: 4px; font: 600 11.5px/1 var(--sans); padding: 4px 7px; border-radius: 999px;
  background: var(--sunken); color: var(--muted); white-space: nowrap; letter-spacing: .01em; }
.badge.pub-b, .badge.green { background: var(--green-soft); color: var(--green); }
.badge.pw-b, .badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.priv-b, .badge.violet { background: var(--violet-soft); color: var(--violet); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }
.badge.teal { background: var(--teal-soft); color: var(--teal); }

.note { padding: 10px 14px; border-radius: var(--r-sm); background: var(--sunken); border: 1px solid var(--line); font-size: 13.5px; margin: 0 0 14px; }
.note.warn { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.note.err { background: var(--red-soft); border-color: transparent; color: var(--red); }

.theme-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  display: inline-grid; place-items: center; }
.theme-btn:hover { background: var(--hover); color: var(--text); }
.theme-btn::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 1.7px solid currentColor;
  background: linear-gradient(90deg, currentColor 50%, transparent 50%); }

/* ---------- rendered Markdown ---------- */
.md-body { font-size: 15px; line-height: 1.65; color: var(--text); overflow-wrap: break-word; min-width: 0; }
.md-body > :first-child { margin-top: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5 { line-height: 1.25; font-weight: 650; letter-spacing: -.012em; margin: 1.7em 0 .6em; scroll-margin-top: 80px; }
.md-body h1 { font-size: 1.85em; letter-spacing: -.02em; }
.md-body h2 { font-size: 1.4em; padding-bottom: .3em; border-bottom: 1px solid var(--line); }
.md-body h3 { font-size: 1.15em; } .md-body h4 { font-size: 1em; } .md-body h5 { font-size: .9em; color: var(--muted); }
.md-body p, .md-body ul, .md-body ol, .md-body blockquote, .md-body pre, .md-body .table-wrap { margin: 0 0 1em; }
.md-body ul, .md-body ol { padding-left: 1.6em; }
.md-body li { margin: .25em 0; } .md-body li > ul, .md-body li > ol { margin: .2em 0; }
.md-body li.task { list-style: none; margin-left: -1.4em; display: flex; gap: .55em; align-items: baseline; }
.md-body li.task .box { flex: none; width: 15px; height: 15px; border: 1.5px solid var(--line-2); border-radius: 4px; display: inline-grid;
  place-items: center; font-size: 11px; transform: translateY(2px); color: var(--on-accent); }
.md-body li.task.done .box { background: var(--accent); border-color: var(--accent); }
.md-body li.task.done { color: var(--muted); }
.md-body a { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 2px; }
.md-body a:hover { text-decoration-color: var(--accent); }
.md-body blockquote { border-left: 3px solid var(--line-2); padding: .1em 0 .1em 1em; color: var(--text-2); }
.md-body hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
.md-body img { max-width: 100%; height: auto; border-radius: 6px; }
.md-body :not(pre) > code { font-size: .86em; background: var(--sunken); border: 1px solid var(--line); border-radius: 5px; padding: .1em .38em; }
.md-body pre.code { font-size: 13px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-sm); }
.table-wrap table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.table-wrap th, .table-wrap td { padding: 7px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table-wrap th { background: var(--sunken); font-weight: 600; white-space: nowrap; }
.table-wrap tr:last-child td { border-bottom: 0; }
.table-wrap.data td { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.table-wrap.data { max-height: 70vh; }
.table-wrap.data th { position: sticky; top: 0; }

/* code blocks */
pre.code { margin: 0; background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; overflow: auto;
  font: 12.8px/1.55 var(--mono); tab-size: 4; color: var(--text); }
pre.code code { font: inherit; }
.viewer pre.code { counter-reset: ln; padding-left: 0; border: 0; border-radius: 0; background: transparent; }
.viewer pre.code .ln { display: block; padding-left: 4.2em; position: relative; min-height: 1.55em; }
.viewer pre.code .ln::before { counter-increment: ln; content: counter(ln); position: absolute; left: 0; width: 3.2em; text-align: right;
  color: var(--faint); user-select: none; font-size: .92em; }
.viewer pre.code .ln:hover { background: var(--hover); }
pre.plain { white-space: pre-wrap; font: 12.5px/1.5 var(--mono); margin: 0; }

/* TOC */
.toc { font-size: 13px; position: sticky; top: 84px; align-self: start; max-height: calc(100vh - 110px); overflow: auto; padding-left: 14px; border-left: 1px solid var(--line); }
.toc-h { font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.toc a { display: block; color: var(--muted); padding: 3px 0; line-height: 1.35; text-decoration: none; }
.toc a:hover, .toc a.on { color: var(--text); }
.toc a.on { font-weight: 550; }
.toc .toc-l1 { padding-left: 12px; } .toc .toc-l2 { padding-left: 24px; font-size: 12.5px; }
.reader-grid { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 48px; }
@media (max-width: 1000px) { .reader-grid { grid-template-columns: minmax(0, 1fr); } .reader-grid .toc { display: none; } }

/* simple pages (sign-in errors etc.) */
.plain-page main.narrow { max-width: 520px; margin: 12vh auto; padding: 0 16px; }
.brand-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; margin-bottom: 18px; }
.logo-dot { width: 12px; height: 12px; border-radius: 4px; background: var(--accent); display: inline-block; }

@media print {
  .top, .foot, .doc-tools, .toc, .theme-btn { display: none !important; }
  body { background: #fff; color: #000; }
}
