:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #1d2430;
  --muted: #6b7280;
  --line: #d9ddd6;
  --accent: #0f766e;
  --accent-2: #9f1239;
  --focus: #2563eb;
  --code: #111827;
  --shadow: 0 18px 45px rgba(28, 35, 45, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

button.primary,
.button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.danger,
.button.danger {
  background: var(--accent-2);
  color: white;
  border-color: var(--accent-2);
}

.inline-form {
  margin: 0;
  display: inline-flex;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.topbar {
  height: 64px;
  padding: 0 clamp(18px, 5vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 247, 244, 0.92);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  font-weight: 800;
  letter-spacing: 0;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar form {
  margin: 0;
}

.home-shell,
.admin-shell,
.auth-shell,
.editor-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
}

.library-head,
.admin-head {
  min-height: 160px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 42px 0 28px;
}

.eyebrow,
.post-kicker {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

.library-head h1,
.admin-head h1 {
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 1.02;
}

.search-box {
  width: min(340px, 100%);
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.search-box input,
.auth-panel input,
.editor-meta input,
.editor-meta select,
.toolbar select,
.toolbar input[type="color"] {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 6px;
  min-height: 40px;
  padding: 8px 10px;
}

.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
  padding-bottom: 64px;
}

.post-card {
  min-height: 250px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

.post-card h2 {
  font-size: 1.5rem;
  line-height: 1.18;
  margin-bottom: 10px;
}

.post-card p,
.subtitle,
.lead {
  color: var(--muted);
  line-height: 1.75;
}

.meta,
.tag-row,
.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.tag-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 9px;
}

.empty-state {
  min-height: calc(100vh - 64px);
  display: grid;
  place-content: center;
  text-align: center;
  gap: 16px;
  padding: 32px;
}

.auth-shell {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
}

.auth-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 16px;
}

.auth-panel label,
.editor-meta label,
.reader-tools label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.table-wrap.stacked {
  margin-top: 18px;
}

.table-wrap h2 {
  padding: 18px 18px 0;
  font-size: 1.1rem;
}

.security-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.admin-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
  display: grid;
  gap: 14px;
}

.admin-panel h2 {
  margin: 0;
  font-size: 1.15rem;
}

.admin-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.admin-panel input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 6px;
  min-height: 40px;
  padding: 8px 10px;
}

.check-list {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.8;
}

.recovery-codes {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel), var(--bg) 45%);
  padding: 12px;
  line-height: 1.7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.reader-shell {
  width: min(1280px, calc(100vw - 28px));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 36px;
  padding: 38px 0 86px;
}

.reader-tools {
  position: sticky;
  top: 86px;
  align-self: start;
  display: grid;
  gap: 16px;
  color: var(--muted);
}

.reader-tools input {
  width: 100%;
}

#toc {
  display: grid;
  gap: 8px;
  font-size: 0.92rem;
}

#toc a {
  color: var(--muted);
}

.reader-main {
  width: min(calc(var(--measure, 78) * 1ch), 100%);
  font-size: calc(var(--font-scale, 100) * 1%);
}

.reader-main > h1 {
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: clamp(2.4rem, 6vw, 5.6rem);
  line-height: 1.02;
  margin-bottom: 18px;
}

.article-body {
  margin-top: 34px;
  font-family: Georgia, "Noto Serif SC", serif;
  line-height: 1.86;
  font-size: 1.12rem;
}

.article-body h1,
.article-body h2,
.article-body h3 {
  margin: 2em 0 0.7em;
  line-height: 1.18;
}

.article-body p,
.article-body ul,
.article-body ol,
.article-body blockquote,
.article-body table,
.article-body pre {
  margin: 1.05em 0;
}

.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.article-cover {
  width: 100%;
  max-height: 440px;
  object-fit: cover;
  border-radius: 8px;
  margin-top: 28px;
  border: 1px solid var(--line);
}

.article-body blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 18px;
  color: var(--muted);
}

.article-body pre {
  overflow: auto;
  background: var(--code);
  color: #f8fafc;
  border-radius: 8px;
  padding: 16px;
}

.drop-cap::first-letter {
  float: left;
  font-size: 4.8em;
  line-height: 0.82;
  padding: 0.08em 0.12em 0 0;
  color: var(--accent-2);
}

body.reader-dark {
  --bg: #101214;
  --panel: #171a1d;
  --ink: #e5e7eb;
  --muted: #a1a8b3;
  --line: #2e3338;
  --accent: #2dd4bf;
  --accent-2: #fb7185;
  --code: #050608;
  color-scheme: dark;
}

.editor-shell {
  padding: 24px 0 48px;
}

.editor-meta {
  display: grid;
  gap: 14px;
}

.title-input {
  font-size: clamp(2rem, 5vw, 4.6rem);
  font-weight: 800;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  border-radius: 0;
}

.subtitle-input {
  font-size: 1.1rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.editor-workbench {
  margin-top: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.toolbar button {
  min-width: 38px;
  flex: 0 0 auto;
}

.toolbar select {
  width: auto;
  min-width: 92px;
}

.toolbar input[type="color"] {
  width: 42px;
  padding: 2px;
}

.split-editor {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 62vh;
}

.version-panel {
  border-top: 1px solid var(--line);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: start;
}

.version-panel h2 {
  font-size: 1.05rem;
}

.version-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}

.version-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.version-item p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

#markdownEditor,
.rich-editor,
#previewPane {
  min-height: 62vh;
  border: 0;
  border-right: 1px solid var(--line);
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
  overflow: auto;
}

#markdownEditor {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.7;
}

.rich-editor {
  display: none;
  outline: none;
  font-family: Georgia, "Noto Serif SC", serif;
  line-height: 1.8;
}

.editor-html #markdownEditor {
  display: none;
}

.editor-html .rich-editor {
  display: block;
}

.editor-page.immersive .topbar,
.editor-page.immersive .editor-meta {
  display: none;
}

.editor-page.immersive .editor-shell {
  width: 100vw;
  padding: 0;
}

.editor-page.immersive .editor-workbench {
  border-radius: 0;
  border: 0;
}

@media (max-width: 860px) {
  .library-head,
  .admin-head,
  .reader-shell {
    display: block;
  }

  .reader-tools {
    position: static;
    margin-bottom: 28px;
  }

  .reader-main {
    width: 100%;
  }

	  .meta-grid,
	  .split-editor,
	  .security-grid,
	  .version-item {
	    grid-template-columns: 1fr;
	  }

  #markdownEditor,
  .rich-editor,
  #previewPane {
    min-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
