/* =================================================================
   Bíločerný Ořechov — public-site stylesheet
   Inlines design tokens, then restyles the namespace's class contract
   (templates from common/) to deliver the brand visuals.
   ================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,wght@8..60,400;8..60,600;8..60,700&family=Inter+Tight:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* ---------- Ink scale (neutral black → grey) ---------- */
  --ink: #000000;
  --ink-90: #141414;
  --ink-70: #3D3D3D;
  --ink-50: #666666;
  --ink-30: #949494;
  --ink-15: #CFCFCF;
  --ink-5: rgba(0, 0, 0, 0.05);
  --ink-10: rgba(0, 0, 0, 0.10);

  /* ---------- Paper scale (white → light grey) ---------- */
  --paper: #FFFFFF;
  --paper-2: #F2F2F2;
  --rule: #E2E2E2;
  --white: #FFFFFF;

  /* ---------- Accent (green) — primary brand accent ---------- */
  --accent: #82C665;
  --accent-dark: #5FA046;
  --accent-light: #A8D88F;
  --accent-bg: #EAF4E3;

  /* ---------- Accent 2 (coral) — contrast accent ---------- */
  --accent-2: #E5523B;
  --accent-2-dark: #C23E2A;
  --accent-2-light: #F1907E;
  --accent-2-bg: #FBE6E1;

  /* ---------- Semantic ---------- */
  --fg-1: var(--ink);
  --fg-2: var(--ink-50);
  --fg-3: var(--ink-30);
  --fg-muted: var(--ink-15);
  --fg-link: var(--accent);
  --fg-link-hover: var(--accent-dark);
  --fg-on-accent: var(--white);

  --bg-page: var(--paper);
  --bg-surface: var(--white);
  --bg-surface-2: var(--paper-2);
  --bg-hover: var(--ink-5);
  --bg-active: var(--ink-10);
  --bg-accent: var(--accent);
  --bg-accent-soft: var(--accent-bg);

  --fg-accent-2: var(--accent-2);
  --bg-accent-2: var(--accent-2);
  --bg-accent-2-soft: var(--accent-2-bg);

  --border-1: var(--rule);
  --border-2: var(--ink);
  --border-accent: var(--accent);
  --border-accent-2: var(--accent-2);

  /* ---------- Typography ---------- */
  --font-serif: 'Source Serif 4', 'Georgia', 'Times New Roman', serif;
  --font-sans: 'Inter Tight', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-md: 18px;
  --font-size-lg: 22px;
  --font-size-xl: 28px;
  --font-size-2xl: 36px;
  --font-size-3xl: 48px;

  --line-tight: 1.15;
  --line-snug: 1.35;
  --line-normal: 1.55;
  --line-loose: 1.75;

  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.04em;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semi: 600;
  --weight-bold: 700;

  --type-display: var(--weight-bold) var(--font-size-3xl)/var(--line-tight) var(--font-serif);
  --type-h1: var(--weight-bold) var(--font-size-2xl)/var(--line-tight) var(--font-serif);
  --type-h2: var(--weight-semi) var(--font-size-xl)/var(--line-snug) var(--font-serif);
  --type-h3: var(--weight-semi) var(--font-size-lg)/var(--line-snug) var(--font-serif);
  --type-h4: var(--weight-semi) var(--font-size-md)/var(--line-snug) var(--font-sans);
  --type-body: var(--weight-regular) var(--font-size-md)/var(--line-loose) var(--font-sans);
  --type-body-sm: var(--weight-regular) var(--font-size-sm)/var(--line-normal) var(--font-sans);
  --type-ui: var(--weight-medium) var(--font-size-sm)/var(--line-snug) var(--font-sans);
  --type-caption: var(--weight-regular) var(--font-size-xs)/var(--line-snug) var(--font-sans);
  --type-mono: var(--weight-regular) var(--font-size-sm)/var(--line-normal) var(--font-mono);

  /* ---------- Spacing ---------- */
  --s-0: 0;
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --s-9: 96px;

  /* ---------- Radii ---------- */
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 8px;
  --radius-pill: 999px;

  /* ---------- Shadows ---------- */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);
  --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.14);

  /* ---------- Motion ---------- */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 150ms;
  --dur-normal: 220ms;

  /* ---------- Layout ---------- */
  --header-h: 64px;
  --content-max: 720px;
  --content-wide: 1080px;
  --board-size: min(480px, 70vw);

  /* ---------- Chess background (corner board) ---------- */
  --chess-square: rgba(0, 0, 0, 0.08);
  --chess-tile: 120px;        /* checker tile = two 60px squares */

  /* ---------- Icons (Lucide, MIT) as CSS masks ---------- */
  /* Used where the glyph is a pseudo-element (nav caret, download marker) and
     can't be inline SVG; `background-color` drives the color via the mask. */
  --icon-chevron-down: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  --icon-download: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 15V3'/%3E%3Cpath d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-family: var(--font-sans); color: var(--fg-1); background: var(--bg-page); overflow-x: hidden; }
body { font: var(--type-body); color: var(--fg-1); background: var(--bg-page); min-height: 100vh; overflow-x: hidden; }

a {
  color: var(--fg-link);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
a:hover { color: var(--fg-link-hover); }

::selection { background: var(--accent); color: var(--white); }

/* ===== ICONS (Lucide inline SVG) ===== */
.icon {
  display: inline-block;
  vertical-align: middle;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
}

/* ===== HEADER (solid black masthead — no hero image) ===== */
header.hero {
  position: relative;
  background: var(--ink);
  color: var(--white);
  display: flex;
  flex-direction: column;
}

.hero-bar {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-4) var(--s-6);
  background: var(--ink);
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--white);
  border: 0;
  flex-shrink: 0;
}
.header-logo:hover { border: 0; }
.header-logo img {
  height: 56px;
  width: auto;
  display: block;
  transition: opacity var(--dur-fast) var(--ease);
}
.header-logo:hover img { opacity: 0.85; }
.header-logo .brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.header-logo .wordmark { font-family: var(--font-serif); font-weight: 700; font-size: 18px; }
.header-logo .sub {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--accent-light);
  margin-top: 2px;
  text-transform: uppercase;
}


/* ===== TOP NAVIGATION ===== */
.top-nav { flex: 1; min-width: 0; }
.top-nav > ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1);
}
.top-nav ul { list-style: none; margin: 0; padding: 0; }
.top-nav li { position: relative; }

.top-nav .nav-row {
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: background var(--dur-fast) var(--ease);
}
.top-nav .nav-row a {
  display: block;
  padding: 8px 14px;
  color: var(--white);
  font: var(--type-ui);
  border-bottom: 0;
  transition: color var(--dur-fast) var(--ease);
}
.top-nav .nav-row a:hover { border-bottom: 0; }
/* Hover surface spans the whole row so the dropdown caret sits inside the
   same hover background as its link. */
.top-nav > ul > li > .nav-row:hover { background: var(--bg-accent); }
.top-nav > ul > li > .nav-row:hover > a { color: var(--fg-1); }
.top-nav > ul > li > .nav-row:hover > .nav-caret { color: var(--fg-1); }

/* Carets (dropdown toggle) */
.top-nav .nav-toggle { display: none; }
.top-nav .nav-caret {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 2rem;
  color: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  user-select: none;
  margin-left: -8px;
  margin-right: 4px;
  transition: transform var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.top-nav .nav-caret::before {
  content: "";
  width: 0.9rem;
  height: 0.9rem;
  background-color: currentColor;
  -webkit-mask: var(--icon-chevron-down) center / contain no-repeat;
  mask: var(--icon-chevron-down) center / contain no-repeat;
}
.top-nav .nav-caret:hover { color: var(--accent); }

/* Submenu — dropdown panel on desktop */
.top-nav > ul > li.has-children > ul {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 12rem;
  background: var(--bg-surface);
  color: var(--fg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--s-2) 0;
  z-index: 60;
}
/* Invisible hover bridge across the 6px gap between the menu item and
   the dropdown panel — without this the dropdown closes the moment the
   cursor enters the gap. */
.top-nav > ul > li.has-children > ul::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 10px;
}
.top-nav > ul > li.has-children > .nav-row .nav-caret { color: rgba(255, 255, 255, 0.7); }
.top-nav > ul > li.has-children:hover > ul,
.top-nav > ul > li > .nav-toggle:checked ~ ul { display: block; }
.top-nav > ul > li > .nav-toggle:checked ~ .nav-row .nav-caret { transform: rotate(180deg); color: var(--accent); }

.top-nav > ul > li > ul .nav-row > a { flex: 1; }
.top-nav > ul > li > ul > li > .nav-row > a {
  color: var(--fg-1);
  padding: 8px var(--s-4);
  border-radius: 0;
}
.top-nav > ul > li > ul > li > .nav-row > .nav-caret { color: var(--fg-2); }
.top-nav > ul > li > ul > li > .nav-row:hover {
  background: var(--bg-accent);
  color: var(--fg-1);
}
.top-nav > ul > li > ul > li > .nav-row:hover > .nav-caret { color: var(--fg-1); }

/* Third-level — nested deeper inline */
.top-nav > ul > li > ul ul {
  padding-left: var(--s-3);
  border-left: 1px solid var(--border-1);
  margin: 4px 0 4px var(--s-4);
}
.top-nav > ul > li > ul ul .nav-row > a {
  color: var(--fg-2);
  font: var(--type-body-sm);
  padding: 6px var(--s-3);
}
.top-nav > ul > li > ul ul .nav-row > .nav-caret { color: var(--fg-2); }
.top-nav > ul > li > ul ul .nav-row:hover {
  background: var(--bg-accent);
  color: var(--fg-1);
}
.top-nav > ul > li > ul ul .nav-row:hover > .nav-caret { color: var(--fg-1); }

/* ===== SEARCH FORM IN TOP BAR ===== */
.top-search { flex-shrink: 0; position: relative; }
.top-search input[type="search"] {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--white);
  padding: 8px 32px 8px 14px;
  border-radius: var(--radius-md);
  font: var(--type-ui);
  outline: none;
  width: 14rem;
  max-width: 100%;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.top-search input[type="search"]::placeholder { color: rgba(255, 255, 255, 0.6); }
.top-search input[type="search"]:focus {
  background: rgba(255, 255, 255, 0.2);
  border-color: var(--accent);
}
.top-search input[type="search"]::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.top-search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.top-search-clear:hover { background: rgba(130, 198, 101, 0.2); color: var(--accent-light); }
.top-search input[type="search"]:placeholder-shown + .top-search-clear { display: none; }

.header-action {
  font: var(--type-ui);
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-md);
  color: var(--white);
  background: transparent;
  flex-shrink: 0;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.header-action:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  border-color: var(--accent);
}

/* Hamburger (mobile only) */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  padding: 4px;
  background: none;
  border: 0;
  margin-left: auto;
}
.hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--white);
  border-radius: 1px;
  transition: transform 0.25s, opacity 0.25s;
}
header:has(#menu-toggle:checked) .hamburger span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
header:has(#menu-toggle:checked) .hamburger span:nth-child(2) { opacity: 0; }
header:has(#menu-toggle:checked) .hamburger span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ===== CONTENT ===== */
.content {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-page);
}

/* Subtle full-width chessboard motif at the top that dissolves downward. */
.content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: min(80vh, 760px);
  z-index: 0;
  pointer-events: none;
  background-image:
    conic-gradient(var(--chess-square) 90deg, transparent 90deg 180deg,
                   var(--chess-square) 180deg 270deg, transparent 270deg);
  background-size: var(--chess-tile) var(--chess-tile);
  background-position: top left;
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 22%, transparent 92%);
          mask-image: linear-gradient(to bottom, #000 0%, #000 22%, transparent 92%);
}
/* Queen + king (slightly rotated) on the corner board. Absolute; hidden on small
   screens. main/footer sit above (z-index 1) so text stays crisp. */
.content::after {
  content: "";
  position: absolute;
  left: 28px;
  top: 28px;
  width: 240px;
  height: 130px;
  z-index: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  background-image:
    url("/assets/img/queen-white.svg"),
    url("/assets/img/king-black.svg");
  background-position: left 0 top 0, left 112px top 0;
  background-size: 112px 112px, 118px 118px;
  opacity: 0.95;
}
.content > main,
.content > footer { position: relative; z-index: 1; }

main {
  flex: 1;
  width: 100%;
  max-width: var(--content-wide);
  margin-inline: auto;
  padding: var(--s-7) var(--s-6);
  min-width: 0;
}

/* Reading column — narrower than the wide component gallery, for a comfortable
   line length. Centered within the (already centered) main. */
.article-detail,
.page-search,
main > .article-body { max-width: var(--content-max); margin-inline: auto; }

/* ===== FOOTER ===== */
footer {
  border-top: 1px solid var(--border-1);
  padding: var(--s-5) var(--s-7);
  font: var(--type-caption);
  color: var(--fg-2);
  margin-top: var(--s-8);
}
footer a { color: var(--fg-2); }
footer a:hover { color: var(--accent); }

/* ===== ARTICLE DETAIL — page masthead ===== */
.article-detail h1 {
  font: var(--type-display);
  font-size: 44px;
  margin: 0 0 var(--s-3);
  letter-spacing: var(--tracking-tight);
  color: var(--ink);
}
.article-detail .meta {
  font: var(--type-caption);
  color: var(--fg-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: var(--s-4);
}

/* ===== TAGS ===== */
.tag-list { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s-2); margin: var(--s-3) 0 var(--s-5); }
.tag {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-surface-2);
  border-radius: var(--radius-sm);
  font: var(--type-caption);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-2);
  border: 0;
}
.tag:hover, .tag.active {
  background: var(--accent);
  color: var(--white);
  border: 0;
}

/* ===== EDIT AFFORDANCES ===== */
.edit-link {
  font: var(--type-caption);
  color: var(--fg-3);
  vertical-align: middle;
  margin-left: var(--s-2);
  border: 0;
}
.edit-link:hover { color: var(--accent); border: 0; }
.edit-bar { text-align: right; margin-bottom: var(--s-3); }

/* =================================================================
   ARTICLE BODY — markdown rich text
   Mirrors the .bn-rich block from the design system.
   ================================================================= */

.article-body { font: var(--type-body); color: var(--fg-1); margin-top: var(--s-4); }

/* Headings */
.article-body h1 {
  font: var(--type-display);
  font-size: 38px;
  margin: var(--s-7) 0 var(--s-4);
  letter-spacing: var(--tracking-tight);
}
.article-body h2 {
  font: var(--type-h2);
  margin: var(--s-7) 0 var(--s-3);
}
.article-body h3 { font: var(--type-h3); margin: var(--s-6) 0 var(--s-3); }
.article-body h4 { font: var(--type-h4); margin: var(--s-5) 0 var(--s-2); }
.article-body h5 {
  font: var(--type-h4);
  font-size: 16px;
  margin: var(--s-5) 0 var(--s-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-2);
}
.article-body h6 {
  font: var(--type-caption);
  font-size: 12px;
  margin: var(--s-5) 0 var(--s-2);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-3);
}

/* Headings in the secondary accent colour (coral) */
.article-detail h1,
.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4,
.article-body h5,
.article-body h6,
.page-search h1 { color: var(--accent-2); }

/* Paragraph + inline */
.article-body p { font: var(--type-body); margin: 0; padding: 0; text-wrap: pretty; }
.article-body a { color: var(--accent); }
.article-body a:hover { color: var(--accent-dark); }
.article-body strong { color: var(--ink); font-weight: 700; }
.article-body em { font-style: italic; }
.article-body del { color: var(--fg-3); }

/* Lists — diamond bullet, mono numerals */
.article-body ul, .article-body ol { padding-left: 26px; margin: 0 0 var(--s-4); }
.article-body ul { list-style: none; }
.article-body ul > li { position: relative; font: var(--type-body); margin-bottom: 6px; padding-left: 4px; }
.article-body ul > li::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 14px;
  width: 6px;
  height: 6px;
  background: var(--accent);
  transform: rotate(45deg);
}
.article-body ol { list-style: none; counter-reset: bn-ol; }
.article-body ol > li { counter-increment: bn-ol; position: relative; font: var(--type-body); margin-bottom: 6px; padding-left: 4px; }
.article-body ol > li::before {
  content: counter(bn-ol) ".";
  position: absolute;
  left: -26px;
  top: 0;
  font-family: var(--font-mono);
  color: var(--accent);
  font-weight: 500;
}
.article-body li > ul, .article-body li > ol { margin-top: 6px; margin-bottom: 0; }
.article-body li > p { margin: 0 0 6px; }

/* Task lists (GFM) */
.article-body ul.task-list, .article-body ul li.task-list-item { list-style: none; }
.article-body li.task-list-item::before { display: none; }
.article-body li.task-list-item input[type=checkbox] { margin-right: 8px; accent-color: var(--accent); }

/* Blockquote */
.article-body blockquote {
  margin: var(--s-5) 0;
  padding: var(--s-3) var(--s-5);
  border-left: 3px solid var(--accent);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 19px;
  line-height: 1.55;
  color: var(--fg-1);
  background: var(--bg-accent-soft);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.article-body blockquote p:last-child { margin: 0; }
.article-body blockquote cite {
  display: block;
  font: var(--type-caption);
  font-style: normal;
  color: var(--fg-2);
  margin-top: 8px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Code: inline + fenced block */
.article-body code {
  font: var(--type-mono);
  font-size: 0.92em;
  background: var(--bg-surface-2);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: var(--ink-90);
  border: 1px solid var(--border-1);
}
.article-body pre {
  font: var(--type-mono);
  font-size: 14px;
  background: var(--ink);
  color: var(--paper);
  padding: var(--s-4) var(--s-5);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 0 0 var(--s-5);
  border-left: 3px solid var(--accent);
}
.article-body pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* Tables */
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--s-5) 0;
  font: var(--type-body-sm);
}
.article-body thead th {
  text-align: left;
  font: var(--type-ui);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-2);
  padding: 10px 12px;
  border-bottom: 2px solid var(--ink);
  background: var(--bg-surface-2);
}
.article-body tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-1);
  vertical-align: top;
}
.article-body tbody tr:hover td { background: var(--ink-5); }

/* Horizontal rule — chessboard texture */
.article-body hr {
  border: 0;
  height: 14px;
  margin: var(--s-7) 0;
  background-image:
    linear-gradient(45deg, var(--ink-10) 25%, transparent 25%),
    linear-gradient(-45deg, var(--ink-10) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--ink-10) 75%),
    linear-gradient(-45deg, transparent 75%, var(--ink-10) 75%);
  background-size: 7px 7px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  opacity: 0.4;
}

/* Inline images in markdown */
.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: var(--s-5) 0;
  filter: grayscale(0.35) sepia(0.12);
  transition: filter var(--dur-normal) var(--ease);
}
.article-body img:hover { filter: none; }

/* Footnotes (GFM) */
.article-body .footnotes {
  font: var(--type-body-sm);
  color: var(--fg-2);
  border-top: 1px solid var(--border-1);
  margin-top: var(--s-7);
  padding-top: var(--s-4);
}
.article-body sup a { font: var(--type-mono); font-size: 11px; color: var(--accent); }

/* Definition lists */
.article-body dl { margin: 0 0 var(--s-4); }
.article-body dt { font-weight: 700; color: var(--ink); margin-top: var(--s-3); }
.article-body dd { margin: 4px 0 0 var(--s-4); color: var(--fg-2); font: var(--type-body-sm); }

/* =================================================================
   MARKDOWN DIRECTIVES — surfaces emitted by markdown.rs
   ================================================================= */

/* ::img / ::file (image)  — figure with link + caption */
.article-image {
  margin: var(--s-5) 0;
  text-align: center;
}
.article-image img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 0;
  filter: grayscale(0.35) sepia(0.12);
  transition: filter var(--dur-normal) var(--ease);
}
.article-image a:hover img { filter: none; }
.article-image figcaption {
  margin-top: var(--s-2);
  font: var(--type-caption);
  color: var(--fg-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ::file (non-image) — burgundy download link */
.file-download {
  display: inline-block;
  color: var(--accent);
}
.file-download:hover { color: var(--accent-dark); }
.file-download::before {
  content: "";
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.35em;
  vertical-align: -0.15em;
  background-color: var(--accent);
  -webkit-mask: var(--icon-download) center / contain no-repeat;
  mask: var(--icon-download) center / contain no-repeat;
}

/* ::gallery */
.gallery { margin: var(--s-6) 0; }
.gallery h3 {
  font: var(--type-h3);
  margin: 0 0 var(--s-3);
  color: var(--ink);
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--s-3);
  margin-top: var(--s-4);
}
.gallery-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-decoration: none;
  color: var(--fg-1);
  background: var(--bg-surface-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 0;
}
.gallery-item:hover { border: 0; }
.gallery-item img {
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  border-radius: 0;
  filter: grayscale(0.45) sepia(0.18);
  transition: filter var(--dur-normal) var(--ease), transform var(--dur-normal) var(--ease);
}
.gallery-item:hover img { filter: none; transform: scale(1.03); }
.gallery-item span {
  padding: var(--s-2) var(--s-3);
  font: var(--type-caption);
  color: var(--fg-2);
  text-align: center;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-1);
}

/* ::fen / ::pgn — chess viewers */
.pgn-viewer, .fen-viewer {
  --board-size: min(480px, 70vw);
  margin: var(--s-6) auto;
  max-width: var(--board-size);
}
.pgn-viewer.size-sm, .fen-viewer.size-sm { --board-size: min(280px, 60vw); }
.pgn-viewer.size-lg, .fen-viewer.size-lg { --board-size: min(560px, 85vw); }
.fen-viewer { width: var(--board-size); height: var(--board-size); }
.pgn-viewer .board { width: var(--board-size); height: var(--board-size); }

/* Reset article-body img styling for chess pieces rendered by chessboard.js */
.pgn-viewer img, .fen-viewer img {
  margin: 0;
  filter: none;
  border-radius: 0;
  max-width: none;
  transition: none;
}
.pgn-viewer img:hover, .fen-viewer img:hover { filter: none; }
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: var(--s-2);
  margin-top: var(--s-3);
}
.controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border: 1px solid var(--border-1);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font: var(--type-ui);
  line-height: 1;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.controls button:hover { background: var(--ink-5); border-color: var(--ink); }
.move-info {
  flex: 1 1 auto;
  min-width: 0;
  text-align: center;
  font: var(--type-mono);
  color: var(--fg-1);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.controls button { flex: 0 0 auto; }

/* ::page — transcluded inline (no extra chrome) */
.transclude { margin: 0; }

/* =================================================================
   PAGE SEARCH / LIST
   ================================================================= */

.page-search h1 {
  font: var(--type-display);
  font-size: 44px;
  margin: 0 0 var(--s-3);
  letter-spacing: var(--tracking-tight);
}
.page-search > .meta {
  font: var(--type-caption);
  color: var(--fg-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: var(--s-5);
}

.search-form {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  align-items: stretch;
  margin: var(--s-5) 0 var(--s-6);
  padding: var(--s-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.search-form input[type="search"],
.search-form input[type="text"] {
  flex: 1 1 12rem;
  min-width: 0;
  padding: 10px 12px;
  background: var(--white);
  color: var(--fg-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  font: var(--type-body-sm);
  outline: none;
}
.search-form input[type="search"] { flex-grow: 2; }
.search-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--bg-accent-soft);
}
.search-form input::placeholder { color: var(--fg-3); }
.search-form button {
  padding: 10px 22px;
  background: var(--accent);
  color: var(--white);
  border: 0;
  border-radius: var(--radius-md);
  cursor: pointer;
  font: var(--type-ui);
  transition: background var(--dur-fast) var(--ease);
}
.search-form button:hover { background: var(--accent-dark); }

/* Results — burgundy-rail cards */
.page-list { list-style: none; margin: var(--s-5) 0; padding: 0; display: flex; flex-direction: column; gap: var(--s-4); }
.page-list li {
  background: var(--bg-surface);
  border-left: 3px solid var(--accent);
  padding: var(--s-4) var(--s-5);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border-bottom: 0;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.page-list li:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.page-list li a {
  font: var(--type-h3);
  font-size: 18px;
  color: var(--ink);
  border: 0;
}
.page-list li a:hover { color: var(--accent); border: 0; }
.page-list .summary {
  display: block;
  color: var(--fg-2);
  font: var(--type-body-sm);
  margin-top: 4px;
}
.page-list .meta {
  display: block;
  color: var(--fg-3);
  font: var(--type-caption);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 6px;
}

/* Pagination */
.pagination { display: flex; gap: var(--s-2); align-items: center; margin: var(--s-6) 0; flex-wrap: wrap; }
.pagination a, .pagination .current {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  font: var(--type-ui);
  background: var(--bg-surface);
}
.pagination a { color: var(--accent); }
.pagination a.page-link { display: inline-flex; align-items: center; gap: 4px; }
.pagination a:hover { background: var(--accent); color: var(--white); border-color: var(--accent); }
.pagination .current {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
}
.pagination .meta {
  font: var(--type-caption);
  color: var(--fg-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0 var(--s-2);
}

/* =================================================================
   LIGHTBOX — dark overlay; keeps lightbox.js's class contract
   ================================================================= */

.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(17, 17, 17, 0.92);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
}
.lightbox-overlay.active { display: flex; }

.lb-content {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  max-width: 90vw;
  max-height: 90vh;
}
.lb-img {
  display: block;
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  user-select: none;
  background: var(--ink);
}
.lb-bottom {
  margin-top: var(--s-2);
  text-align: center;
  color: var(--white);
  font: var(--type-body-sm);
  display: flex;
  gap: var(--s-4);
  justify-content: space-between;
  width: 100%;
  min-height: 1.2em;
}
.lb-caption { flex: 1; text-align: left; }
.lb-counter {
  color: var(--ink-15);
  font: var(--type-mono);
  font-size: 12px;
}

.lb-close, .lb-prev, .lb-next {
  position: fixed;
  background: rgba(17, 17, 17, 0.6);
  border: 0;
  color: var(--white);
  cursor: pointer;
  z-index: 10000;
  border-radius: var(--radius-pill);
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--dur-fast) var(--ease);
}
.lb-close:hover, .lb-prev:hover, .lb-next:hover { background: var(--accent); }

.lb-close { top: 1rem; right: 1.5rem; font-size: 1.6rem; line-height: 1; }
.lb-prev, .lb-next { top: 50%; transform: translateY(-50%); font-size: 1.8rem; line-height: 1; }
.lb-prev { left: 1rem; }
.lb-next { right: 1rem; }

/* =================================================================
   CHESSBOARD DIVIDER UTILITY
   ================================================================= */

.chessboard-divider {
  height: 14px;
  background-image:
    linear-gradient(45deg, var(--ink-10) 25%, transparent 25%),
    linear-gradient(-45deg, var(--ink-10) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--ink-10) 75%),
    linear-gradient(-45deg, transparent 75%, var(--ink-10) 75%);
  background-size: 7px 7px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  opacity: 0.4;
  margin: var(--s-6) 0;
}

/* =================================================================
   STYLE GUIDE — component & token gallery (preview surface)
   Layout-only helpers; every visual value is pulled from the tokens
   in :root so the gallery stays a faithful mirror of the system.
   ================================================================= */

.styleguide { max-width: var(--content-wide); margin: 0 auto; }
.styleguide > .meta {
  font: var(--type-caption);
  color: var(--fg-3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: var(--s-6);
}

.sg-section { margin: var(--s-8) 0; }
.sg-section > h2 {
  font: var(--type-h2);
  margin: 0 0 var(--s-2);
}
.sg-section > .sg-note {
  font: var(--type-body-sm);
  color: var(--fg-2);
  margin: 0 0 var(--s-5);
}
.sg-subhead {
  font: var(--type-caption);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin: var(--s-5) 0 var(--s-3);
}

/* Generic responsive card grid */
.sg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--s-3);
}

/* Color swatches */
.sg-swatch {
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}
.sg-swatch .chip { height: 64px; }
.sg-swatch .body { padding: var(--s-2) var(--s-3); }
.sg-swatch .name { font: var(--type-ui); color: var(--fg-1); display: block; }
.sg-swatch .var { font: var(--type-mono); font-size: 11px; color: var(--fg-3); display: block; margin-top: 2px; }

/* Type specimens */
.sg-type-row {
  display: flex;
  align-items: baseline;
  gap: var(--s-5);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border-1);
}
.sg-type-row .label {
  flex: 0 0 7rem;
  font: var(--type-mono);
  font-size: 12px;
  color: var(--fg-3);
}
.sg-type-row .specimen { flex: 1; min-width: 0; color: var(--fg-1); }

/* Inline component cluster (buttons, tags, etc.) */
.sg-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }

/* Card panel for grouping a component demo */
.sg-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}

/* Spacing scale bars */
.sg-space-row { display: flex; align-items: center; gap: var(--s-4); margin-bottom: var(--s-2); }
.sg-space-row .label { flex: 0 0 4rem; font: var(--type-mono); font-size: 12px; color: var(--fg-3); }
.sg-space-row .bar { height: 14px; background: var(--accent); border-radius: var(--radius-sm); }

/* Icon gallery cells */
.sg-icon-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-2);
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-md);
  color: var(--ink);
}

/* Radius / shadow tiles */
.sg-tile {
  height: 88px;
  display: flex;
  align-items: flex-end;
  padding: var(--s-2) var(--s-3);
  background: var(--bg-surface);
  border: 1px solid var(--border-1);
  font: var(--type-mono);
  font-size: 11px;
  color: var(--fg-3);
}

/* =================================================================
   RESPONSIVE
   ================================================================= */

@media (max-width: 900px) {
  .hamburger { display: flex; order: 3; }

  .hero-bar {
    flex-wrap: wrap;
    padding: var(--s-3) var(--s-4);
    gap: var(--s-3);
  }

  .top-nav {
    order: 5;
    flex-basis: 100%;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s var(--ease);
  }
  .top-nav.open { max-height: 70vh; overflow-y: auto; }
  .top-nav > ul {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding-top: var(--s-3);
  }
  .top-nav > ul > li.has-children > ul {
    position: static;
    display: block;
    background: rgba(0, 0, 0, 0.2);
    border: 0;
    box-shadow: none;
    color: var(--white);
    margin-top: 4px;
  }
  .top-nav > ul > li > ul > li > .nav-row > a {
    color: rgba(255, 255, 255, 0.85);
  }
  .top-nav > ul > li > ul > li > .nav-row > a:hover {
    background: rgba(255, 255, 255, 0.1);
  }

  .top-search { order: 4; flex-basis: 100%; }
  .top-search input[type="search"] { width: 100%; }

  .header-action { order: 2; }

  main { padding: var(--s-5) var(--s-4); }

  .article-detail h1 { font-size: 32px; }
  .article-body h1 { font-size: 28px; }
}

@media (max-width: 600px) {
  .lb-prev, .lb-next { width: 2.5rem; height: 2.5rem; font-size: 1.4rem; }
  .lb-close { width: 2.5rem; height: 2.5rem; font-size: 1.4rem; }

  /* Small devices: hide the corner chess emblem. */
  .content::before,
  .content::after { display: none; }
}
