:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f6f5f4;
  --surface-strong: #ebe9e7;
  --text: #191918;
  --muted: #615d59;
  --border: rgba(0, 0, 0, 0.11);
  --accent: #0877d1;
  --accent-soft: #edf7ff;
  --code-bg: #f5f4f2;
  --shadow: 0 4px 18px rgba(0,0,0,.04), 0 1px 4px rgba(0,0,0,.03);
  --content: 760px;
  --radius: 12px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #191919;
  --surface: #242424;
  --surface-strong: #30302f;
  --text: #f2f1ef;
  --muted: #aaa6a1;
  --border: rgba(255,255,255,.12);
  --accent: #62aef0;
  --accent-soft: #1c3142;
  --code-bg: #232322;
  --shadow: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration-thickness: .08em; text-underline-offset: .15em; }
a:hover { text-decoration: underline; }
button, input { font: inherit; }
button, .button {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover, .button:hover { background: var(--surface-strong); text-decoration: none; }
button:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 2px;
}

.site-header {
  height: 60px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { color: var(--text); font-weight: 700; letter-spacing: -.025em; text-decoration: none; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.icon-button { width: 42px; padding: 0; display: grid; place-items: center; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--surface); }
.login-card {
  width: min(100%, 420px);
  padding: clamp(24px, 7vw, 42px);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: -.04em; }
.login-card > p { margin: 0 0 30px; color: var(--muted); }
.login-card label { display: grid; gap: 7px; margin: 16px 0; font-weight: 600; font-size: 14px; }
.login-card input, .search-form input {
  width: 100%; min-width: 0; border: 1px solid var(--border); border-radius: 8px;
  padding: 11px 12px; background: var(--bg); color: var(--text);
}
.login-card button { width: 100%; margin-top: 10px; background: var(--accent); color: white; border-color: transparent; }
.error { padding: 10px 12px; color: #a1262e; background: #fff0f1; border-radius: 8px; }

.library-shell { width: min(100% - 32px, 980px); margin: 0 auto; padding: 56px 0 88px; min-width: 0; }
.library-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 30px; }
.library-heading h1 { margin: 0; font-size: clamp(34px, 7vw, 54px); line-height: 1; letter-spacing: -.055em; }
.library-heading p { margin: 9px 0 0; color: var(--muted); }
.search-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-bottom: 28px; }
.document-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; min-width: 0; }
.document-card { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); box-shadow: var(--shadow); }
.document-card a { display: block; height: 100%; padding: 22px; color: var(--text); text-decoration: none; }
.document-card:hover { border-color: color-mix(in srgb, var(--accent) 42%, var(--border)); }
.document-card h2 { margin: 0 0 24px; font-size: 20px; line-height: 1.3; letter-spacing: -.025em; overflow-wrap: anywhere; }
.document-card p { margin: 0; color: var(--muted); font-size: 13px; }
.empty-state { color: var(--muted); padding: 32px 0; }

.reading-progress { position: fixed; top: 0; left: 0; z-index: 40; height: 2px; width: 0; background: var(--accent); }
.reader-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: clamp(38px, 6vw, 84px);
  width: min(100% - 40px, 1120px);
  margin: 0 auto;
  padding: 64px 0 110px;
  min-width: 0;
}
.reader-main { width: 100%; max-width: var(--content); justify-self: end; min-width: 0; }
.article-kicker { color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.article-title { margin: 12px 0 18px; font-size: clamp(38px, 7vw, 62px); line-height: 1.04; letter-spacing: -.055em; overflow-wrap: anywhere; }
.article-meta { color: var(--muted); font-size: 14px; margin-bottom: 52px; }
.markdown-body { min-width: 0; overflow-wrap: anywhere; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { line-height: 1.22; letter-spacing: -.025em; scroll-margin-top: 82px; }
.markdown-body h1 { font-size: 34px; margin: 2.3em 0 .65em; }
.markdown-body h2 { font-size: 27px; margin: 2.25em 0 .65em; padding-top: .15em; }
.markdown-body h3 { font-size: 21px; margin: 1.9em 0 .55em; }
.markdown-body p, .markdown-body ul, .markdown-body ol { margin: 0 0 1.25em; }
.markdown-body li + li { margin-top: .35em; }
.markdown-body blockquote { margin: 1.7em 0; padding: 3px 0 3px 20px; border-left: 3px solid var(--accent); color: var(--muted); }
.markdown-body hr { margin: 3em 0; border: 0; border-top: 1px solid var(--border); }
.markdown-body img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
.markdown-body pre {
  position: relative; max-width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-inline: contain;
  padding: 20px; margin: 1.5em 0; border: 1px solid var(--border); border-radius: 10px; background: var(--code-bg);
  font: 13px/1.65 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.markdown-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.markdown-body :not(pre) > code { padding: .18em .38em; border-radius: 5px; background: var(--code-bg); font-size: .88em; }
.table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; margin: 1.5em 0; }
.markdown-body table { width: 100%; min-width: 520px; border-collapse: collapse; font-size: 14px; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 10px 12px; text-align: left; }
.markdown-body th { background: var(--surface); }
.copy-code { position: absolute; top: 8px; right: 8px; min-height: 32px; padding: 4px 9px; font-size: 12px; opacity: 0; }
pre:hover .copy-code, .copy-code:focus { opacity: 1; }

.toc { position: sticky; top: 94px; align-self: start; min-width: 0; }
.toc-title { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.toc ol { list-style: none; margin: 13px 0 0; padding: 0; border-left: 1px solid var(--border); }
.toc li { margin: 0; }
.toc li.level-3 a { padding-left: 24px; }
.toc a { display: block; padding: 6px 12px; color: var(--muted); font-size: 13px; line-height: 1.35; text-decoration: none; overflow-wrap: anywhere; }
.toc a:hover { color: var(--text); }
.toc-mobile { display: none; }

@media (max-width: 760px) {
  .site-header { height: 54px; padding-inline: 14px; }
  .library-shell { width: min(100% - 28px, 980px); padding-top: 38px; }
  .library-heading { align-items: start; }
  .document-grid { grid-template-columns: minmax(0, 1fr); }
  .reader-layout { display: block; width: min(100% - 30px, var(--content)); padding: 34px 0 72px; }
  .reader-main { min-width: 0; }
  .article-title { font-size: clamp(34px, 11vw, 48px); }
  .article-meta { margin-bottom: 32px; }
  .toc { display: none; }
  .toc-mobile { display: block; margin: 0 0 34px; border: 1px solid var(--border); border-radius: 9px; padding: 10px 13px; }
  .toc-mobile summary { cursor: pointer; font-weight: 600; }
  .toc-mobile ol { margin: 12px 0 4px; padding-left: 22px; }
  .toc-mobile a { display: block; padding: 4px 0; overflow-wrap: anywhere; }
  .markdown-body h2 { font-size: 24px; }
  .copy-code { opacity: 1; }
}

@media (max-width: 390px) {
  .search-form { grid-template-columns: minmax(0, 1fr); }
  .search-form button { width: 100%; }
  .reader-layout { width: min(100% - 24px, var(--content)); }
  .markdown-body pre { margin-inline: 0; padding: 16px 14px; }
}
