:root {
  /* Aligned with Next.js article-guide palette */
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --text: #171717;
  --text-muted: #525252;
  --border: #e5e5e5;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  /* Set precisely from JS (navbar offsetHeight); fallback before script runs */
  --site-header-height: 3.5rem;
  --sidebar-width: 280px;
  /* Content width: comfortable on laptop; scales up on large / external monitors */
  --layout-max: 1280px;
  --layout-pad-x: 1.25rem;
}

@media (min-width: 1360px) {
  :root {
    --layout-max: 1520px;
    --layout-pad-x: 1.75rem;
  }
}

@media (min-width: 1600px) {
  :root {
    --layout-max: 1720px;
    --layout-pad-x: 2.25rem;
  }
}

@media (min-width: 1920px) {
  :root {
    --layout-max: min(1840px, calc(100vw - 5rem));
  }
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-elevated: #171717;
  --text: #fafafa;
  --text-muted: #a3a3a3;
  --border: #404040;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 40px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Public site only — admin uses its own shell (see admin/css/admin.css) */
body:not(.admin-body) {
  padding-top: var(--site-header-height);
  transition: padding-top 0.25s ease;
}

body:not(.admin-body).nav-header-hidden {
  padding-top: 0;
}

@media (prefers-reduced-motion: reduce) {
  body:not(.admin-body) {
    transition: none;
  }
}

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

a:hover {
  color: var(--accent-hover);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.muted {
  color: var(--text-muted);
}

.error {
  color: #b91c1c;
}

[data-theme="dark"] .error {
  color: #fca5a5;
}

/* Doc layout: fixed-width sidebar (desktop) is position:fixed in components.css; main offsets here. */
.layout {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 0 3rem 0;
}

@media (min-width: 961px) {
  .layout {
    display: block;
  }

  .layout > .main {
    margin-left: var(--sidebar-width);
    min-width: 0;
    padding: 1rem var(--layout-pad-x) 0;
    max-width: var(--layout-max);
  }

  /* Home: center readable column in the area to the right of the fixed sidebar */
  body[data-page="home"] .layout > .main {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: calc(100% - var(--sidebar-width));
    max-width: none;
    margin-left: var(--sidebar-width);
    margin-right: 0;
    padding: 1rem var(--layout-pad-x) 0;
    box-sizing: border-box;
  }

  body[data-page="home"] .layout > .main > * {
    width: 100%;
    max-width: min(52rem, 100%);
  }
}

@media (max-width: 960px) {
  .layout {
    display: block;
  }

  .layout > .main {
    min-width: 0;
    padding: 1rem var(--layout-pad-x) 0;
    max-width: none;
  }

  body[data-page="home"] .layout > .main {
    display: block;
    width: 100%;
    margin-left: 0;
  }

  body[data-page="home"] .layout > .main > * {
    max-width: none;
  }
}

.main {
  min-width: 0;
}

.page-header {
  margin-bottom: 2rem;
}

.page-title {
  font-size: clamp(1.75rem, 2.5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}

.page-lead {
  margin: 0;
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: min(56ch, 100%);
}

@media (min-width: 1360px) {
  .page-lead {
    max-width: min(62ch, 100%);
  }
}

.reading-progress {
  position: fixed;
  top: var(--site-header-height);
  left: 0;
  height: 3px;
  width: 0;
  z-index: 1048;
  background: linear-gradient(90deg, var(--accent), #22d3ee);
  transition: top 0.25s ease;
}

body.nav-header-hidden .reading-progress {
  top: 0;
}

@media (prefers-reduced-motion: reduce) {
  .reading-progress {
    transition: none;
  }
}

.prose {
  font-size: 1.05rem;
}

/* Long lines are hard to read — cap article width; main column can still be wide for code & layout */
.article-body.prose {
  max-width: min(72ch, 100%);
}

@media (min-width: 1600px) {
  .article-body.prose {
    max-width: min(76ch, 100%);
    font-size: 1.0625rem;
  }
}

.prose h2,
.prose h3,
.prose h4 {
  margin-top: 2rem;
  letter-spacing: -0.02em;
}

.prose pre {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1rem 1rem 1rem;
  overflow-x: auto;
}

.prose code {
  font-family: var(--mono);
  font-size: 0.92em;
}

.prose p code,
.prose li code {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.1em 0.35em;
  border-radius: 6px;
}

.code-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}

.code-copy-btn:hover {
  border-color: var(--accent);
}

.blog-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

/* Two cards per row when the main column is wide enough (typical 15–17" + external displays) */
@media (min-width: 1400px) {
  .blog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.75rem;
  }
}

@media (min-width: 1800px) {
  .blog-grid {
    gap: 2rem;
  }
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  text-align: center;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.empty-state--compact {
  padding: 1.35rem 1.25rem;
  text-align: left;
}

.empty-state__title {
  margin: 0 0 0.35rem;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
}

.empty-state__hint {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.section-title {
  font-size: 1.25rem;
  margin: 2.5rem 0 1rem;
  letter-spacing: -0.02em;
}

.hero + section .section-title {
  margin-top: 1.75rem;
}

.related-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

@media (min-width: 1360px) {
  .related-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
  }
}

.related-card {
  display: block;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  color: inherit;
}

.related-card:hover {
  border-color: var(--accent);
}

.related-card__title {
  font-weight: 600;
}

.form {
  display: grid;
  gap: 1rem;
  max-width: 480px;
}

.form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form input,
.form textarea {
  font: inherit;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
}

.form-msg {
  margin: 0;
  min-height: 1.25em;
}

.form-msg.success {
  color: #15803d;
}

.form-msg.error {
  color: #b91c1c;
}

[data-theme="dark"] .form-msg.success {
  color: #86efac;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 2rem 0;
}

.tag {
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.comments-section {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.sidebar-overlay {
  position: fixed;
  top: var(--site-header-height);
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 1030;
  transition: top 0.25s ease;
}

body.nav-header-hidden .sidebar-overlay {
  top: 0;
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-overlay {
    transition: none;
  }
}

body.sidebar-open {
  overflow: hidden;
}
