:root {
  --bg: #FBF9F5;
  --panel: #FFFFFF;
  --text: #1C1A17;
  --muted: #6E685E;
  --border: #E7E0D3;
  --soft: #F3EEE4;
  --accent: #9C7E4C;
  --topbar-h: 64px;
  --font-body: 'Jost', -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Playfair Display', Georgia, serif;
}
* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--topbar-h) + 16px); }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); font-size: 16px; line-height: 1.7; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
kbd { font-family: inherit; font-size: 0.7rem; border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; color: var(--muted); background: var(--panel); }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 40; background: rgba(251,249,245,0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar__inner { max-width: 1440px; margin: 0 auto; height: var(--topbar-h); display: flex; align-items: center; gap: 18px; padding: 0 clamp(16px, 3vw, 32px); }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--text); flex-shrink: 0; }
.brand__name { font-family: var(--font-head); font-size: 1.3rem; font-weight: 600; letter-spacing: 0.04em; }
.brand__logo { height: 34px; width: auto; align-self: center; }
.brand__sub { font-size: 0.85rem; color: var(--muted); }
.toplinks { margin-left: auto; display: flex; gap: 22px; }
.brand + .portal-link { margin-left: auto; }
.toplinks a { color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.toplinks a:hover { color: var(--text); }
.portal-link { color: var(--text); text-decoration: none; font-size: 0.92rem; font-weight: 500; border: 1px solid var(--border); border-radius: 10px; padding: 7px 14px; background: var(--panel); white-space: nowrap; }
.portal-link:hover { border-color: var(--accent); }
.search-btn { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 8px 10px 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); color: var(--muted); font: inherit; font-size: 0.9rem; cursor: pointer; }
.search-btn__label { flex: 1; text-align: left; }
.icon-btn { background: none; border: 0; padding: 6px; color: var(--text); cursor: pointer; }
.menu-btn { display: none; }

/* Layout */
.shell { max-width: 1440px; margin: 0 auto; display: grid; grid-template-columns: 260px minmax(0, 1fr) 220px; gap: 48px; padding: 0 clamp(16px, 3vw, 32px); }
.sidebar { position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 32px 8px 40px 0; }
.sidebar__group { margin-bottom: 26px; }
.sidebar__title { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text); margin-bottom: 6px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: 6px 10px; margin-left: -10px; border-radius: 7px; color: var(--muted); text-decoration: none; font-size: 0.94rem; line-height: 1.4; }
.sidebar a:hover { color: var(--text); background: var(--soft); }
.sidebar a.is-active { color: var(--accent); background: var(--soft); font-weight: 500; }
.sidebar-backdrop { display: none; }

.content { min-width: 0; padding: 36px 0 60px; max-width: 780px; }
.cover { margin: 0 0 32px; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); background: var(--soft); }
.cover img { display: block; width: 100%; height: auto; max-height: 360px; object-fit: cover; }
.crumb { font-size: 0.82rem; color: var(--accent); font-weight: 500; margin-bottom: 4px; }
.page-title { font-family: var(--font-head); font-weight: 600; font-size: clamp(1.9rem, 3.4vw, 2.6rem); line-height: 1.2; margin: 0 0 24px; }
.draft-banner { background: #FFF4DB; border: 1px solid #EBD39B; color: #7A5A12; padding: 10px 14px; border-radius: 10px; font-size: 0.9rem; margin-bottom: 20px; }

/* Article typography */
.prose > :first-child { margin-top: 0; }
.prose h2 { font-family: var(--font-head); font-weight: 600; font-size: 1.55rem; line-height: 1.3; margin: 2.2em 0 0.6em; }
.prose h3 { font-size: 1.15rem; font-weight: 600; margin: 1.8em 0 0.4em; }
.prose h2 .anchor, .prose h3 .anchor { margin-left: 8px; color: var(--border); text-decoration: none; opacity: 0; transition: opacity .15s; }
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.prose p, .prose ul, .prose ol { margin: 0 0 1.1em; }
.prose li { margin-bottom: 0.35em; }
.prose img { display: block; max-width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--border); margin: 1.4em 0; box-shadow: 0 8px 28px rgba(28,26,23,0.07); cursor: zoom-in; }
.prose code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.86em; background: var(--soft); padding: 0.15em 0.45em; border-radius: 5px; }
.prose pre { background: #1F1C18; color: #F3EEE4; padding: 16px 18px; border-radius: 10px; overflow-x: auto; font-size: 0.88rem; }
.prose pre code { background: none; padding: 0; color: inherit; }
.prose blockquote { margin: 1.4em 0; padding: 4px 0 4px 20px; border-left: 3px solid var(--border); color: var(--muted); }
.prose table { width: 100%; border-collapse: collapse; margin: 1.4em 0; font-size: 0.93rem; display: block; overflow-x: auto; }
.prose th, .prose td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.prose th { font-weight: 600; font-size: 0.82rem; color: var(--muted); background: var(--soft); }
.prose iframe { width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 12px; margin: 1.4em 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 2.4em 0; }

.callout { border: 1px solid var(--border); border-left-width: 4px; border-radius: 10px; padding: 14px 18px; margin: 1.5em 0; background: var(--panel); }
.callout > :last-child { margin-bottom: 0; }
.callout__label { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 4px; }
.callout--note { border-left-color: #6C8EBF; } .callout--note .callout__label { color: #4C6E9F; }
.callout--tip { border-left-color: #5E9C76; } .callout--tip .callout__label { color: #3E7C56; }
.callout--warning { border-left-color: #C9812E; } .callout--warning .callout__label { color: #A9610E; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 56px; }
.pager__link { display: flex; flex-direction: column; gap: 2px; border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; text-decoration: none; color: var(--text); background: var(--panel); transition: border-color .15s; }
.pager__link:hover { border-color: var(--accent); }
.pager__link span { font-size: 0.8rem; color: var(--muted); }
.pager__link--next { text-align: right; grid-column: 2; }
.updated { font-size: 0.85rem; color: var(--muted); margin-top: 24px; }
.site-footer { margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--border); font-size: 0.85rem; color: var(--muted); }

/* On this page */
.toc { position: sticky; top: var(--topbar-h); align-self: start; max-height: calc(100vh - var(--topbar-h)); overflow-y: auto; padding: 40px 0; }
.toc__title { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 10px; }
.toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.toc a { display: block; padding: 4px 0 4px 14px; margin-left: -1px; border-left: 2px solid transparent; font-size: 0.86rem; color: var(--muted); text-decoration: none; line-height: 1.4; }
.toc .toc__l3 a { padding-left: 26px; font-size: 0.82rem; }
.toc a:hover { color: var(--text); }
.toc a.is-active { color: var(--accent); border-left-color: var(--accent); }

/* Search modal */
.search-modal[hidden] { display: none; }
.search-modal { position: fixed; inset: 0; z-index: 60; }
.search-modal__backdrop { position: absolute; inset: 0; background: rgba(28,26,23,0.35); }
.search-modal__panel { position: relative; max-width: 620px; margin: 10vh auto 0; background: var(--panel); border-radius: 14px; box-shadow: 0 24px 60px rgba(0,0,0,0.2); overflow: hidden; }
.search-modal__field { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--muted); }
.search-modal__field input { flex: 1; border: 0; outline: 0; font: inherit; font-size: 1.05rem; background: none; color: var(--text); }
.search-modal__results { list-style: none; margin: 0; padding: 8px; max-height: 60vh; overflow-y: auto; }
.search-modal__results a { display: block; padding: 10px 12px; border-radius: 9px; text-decoration: none; color: var(--text); }
.search-modal__results a:hover, .search-modal__results a.is-focus { background: var(--soft); }
.search-modal__results .g { font-size: 0.75rem; color: var(--accent); }
.search-modal__results .t { font-weight: 500; }
.search-modal__results .x { font-size: 0.85rem; color: var(--muted); display: block; margin-top: 2px; }
.search-modal__results mark { background: #F4E4BE; color: inherit; border-radius: 3px; }
.search-modal__empty { padding: 20px 12px; color: var(--muted); text-align: center; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(20,18,15,0.88); display: flex; align-items: center; justify-content: center; padding: 24px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

@media (max-width: 1180px) {
  .shell { grid-template-columns: 240px minmax(0, 1fr); }
  .toc { display: none; }
}
@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .toplinks { display: none; }
  .search-btn { min-width: 0; }
  .portal-link { margin-left: auto; padding: 6px 12px; }
  .search-btn__label, .search-btn kbd { display: none; }
  .brand__sub { display: none; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: var(--topbar-h); left: 0; bottom: 0; height: auto; width: min(300px, 85vw); background: var(--bg); z-index: 35; padding: 24px 20px; border-right: 1px solid var(--border); transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.is-open { transform: none; }
  .sidebar-backdrop.is-open { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(28,26,23,0.3); z-index: 30; }
  .pager { grid-template-columns: 1fr; }
  .pager__link--next { grid-column: auto; }
}
