/* ============================================================
   ai-readable-gazette-kr — design system
   Philosophy: archive over campaign, document first, low chrome.
   Tone: editorial / institutional / restrained — leans into
   brutalist/archive territory because this project is the records
   layer for an official gazette corpus.
   ============================================================ */

:root {
  /* palette — paper / ink */
  --paper:    #F7F5F1;   /* main page background */
  --canvas:   #FFFFFF;   /* content surfaces */
  --ink:      #111318;   /* primary text */
  --muted:    #5A6270;   /* secondary text */
  --hush:     #7A808C;   /* tertiary text */
  --line:     #E3E0D8;   /* main dividers */
  --line-2:   #EFEDE6;   /* subtle dividers */
  --slate:    #D7DDE5;   /* quiet UI surface */

  /* accents — use at most two in one view */
  --civic:    #193A6B;   /* primary link / active state */
  --civic-bg: #E8EEF7;
  --archive:  #2E5E4E;   /* readable/final layer */
  --source:   #8A5A18;   /* raw / source / pdf */
  --seal:     #8B1A1A;   /* correction seal / index mark (archive-specific) */
  --alert:    #8B2E2E;

  /* typography */
  --sans:
    "Pretendard", "Pretendard Variable", -apple-system, BlinkMacSystemFont,
    "Noto Sans KR", "Apple SD Gothic Neo", system-ui, sans-serif;
  --serif:
    "Noto Serif KR", "Noto Serif CJK KR", "Nanum Myeongjo", "AppleMyungjo",
    "Batang", serif;
  --mono:
    "JetBrains Mono", "IBM Plex Mono", "SF Mono", ui-monospace,
    Menlo, Consolas, monospace;

  /* scale */
  --rad: 2px;          /* archive-y, not rounded */
  --shadow: none;
  --ring: inset 0 0 0 1px var(--line);

  /* spacing */
  --pad-xs: 4px;
  --pad-s:  8px;
  --pad-m:  16px;
  --pad-l:  24px;
  --pad-xl: 40px;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* optional dark mode — keep archive paper feel, invert with warmth */
    --paper:    #14151A;
    --canvas:   #1B1D23;
    --ink:      #F0EEE6;
    --muted:    #B8BCC6;
    --hush:     #8A8E98;
    --line:     #2E3038;
    --line-2:   #25272E;
    --slate:    #2A2D35;
    --civic:    #7FA3D4;
    --civic-bg: #1E2A3D;
    --source:   #C88A3E;
    --seal:     #D85C5C;
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
}

a { color: var(--civic); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

button { font: inherit; cursor: pointer; }

/* ============================================================
   Layout frame
   ============================================================ */
.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 28px;
}

/* ============================================================
   Header
   ============================================================ */
header.site {
  background: var(--canvas);
  border-bottom: 1px solid var(--line);
  padding: 32px 0 0;
}
header.site .brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
header.site h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.015em;
  color: var(--ink);
}
header.site .brand .slash {
  color: var(--line);
  font-family: var(--mono);
  font-weight: 400;
}
header.site .version {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--seal);
  border: 1px solid var(--seal);
  padding: 1px 6px;
  border-radius: var(--rad);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
header.site .tag {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}
header.site .stats {
  margin: 10px 0 0;
  color: var(--hush);
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
header.site nav.top {
  margin-top: 18px;
  display: flex;
  gap: 0;
  border-top: 1px solid var(--line);
}
header.site nav.top a {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 14px 0;
  margin-right: 28px;
  border-top: 2px solid transparent;
  margin-top: -1px;
  transition: color 0.1s;
}
header.site nav.top a:hover {
  color: var(--ink);
  text-decoration: none;
}
header.site nav.top a.active {
  color: var(--ink);
  border-top-color: var(--ink);
  font-weight: 700;
}
header.site nav.top a.ext {
  margin-left: auto;
  margin-right: 0;
  color: var(--hush);
  font-family: var(--mono);
  font-size: 11px;
}

/* ============================================================
   Views (route containers)
   ============================================================ */
main { padding: 40px 0 60px; }
.view { display: none; }
.view.active { display: block; }

section.block {
  margin-bottom: 48px;
}
section.block > h2 {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
  font-family: var(--mono);
}
section.block > .sub {
  margin: 0 0 18px;
  color: var(--hush);
  font-size: 12px;
  font-family: var(--mono);
}

/* ============================================================
   Home — intro strip
   ============================================================ */
.home-intro {
  display: grid;
  grid-template-columns: minmax(0, 2fr) 1fr;
  gap: 48px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 48px;
}
.home-intro .lede {
  font-size: 17px;
  line-height: 1.65;
  color: var(--ink);
  max-width: 64ch;
}
.home-intro .lede strong { font-weight: 700; }
.home-intro .meta-box {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 16px;
}
.home-intro .meta-box dl { margin: 0; }
.home-intro .meta-box dt {
  color: var(--hush);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 10px;
  margin-top: 8px;
}
.home-intro .meta-box dt:first-child { margin-top: 0; }
.home-intro .meta-box dd {
  margin: 2px 0 0;
  color: var(--ink);
  font-size: 13px;
}

/* ============================================================
   Timeline heatmap
   ============================================================ */
.heatmap {
  width: 100%;
  background: var(--canvas);
  border: 1px solid var(--line);
  padding: 20px 24px 14px;
}
.heatmap .hm-row {
  display: flex;
  align-items: end;
  gap: 1px;
  height: 72px;
  margin-bottom: 8px;
}
.heatmap .hm-bar {
  flex: 1;
  background: var(--slate);
  min-width: 1px;
  position: relative;
  cursor: pointer;
  transition: background 0.1s;
}
.heatmap .hm-bar:hover {
  background: var(--civic);
}
.heatmap .hm-scale {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--hush);
  letter-spacing: 0.04em;
}
.heatmap .hm-caption {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  margin-top: 6px;
  min-height: 16px;
}

/* ============================================================
   Institution tree
   ============================================================ */
.inst-tree {
  background: var(--canvas);
  border: 1px solid var(--line);
}
.inst-tree .cat {
  border-bottom: 1px solid var(--line-2);
}
.inst-tree .cat:last-child { border-bottom: 0; }
.inst-tree .cat-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--canvas);
  border: 0;
  width: 100%;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.inst-tree .cat-head:hover {
  background: var(--line-2);
}
.inst-tree .cat-head .name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.01em;
}
.inst-tree .cat-head .count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--hush);
}
.inst-tree .cat-head .disclose {
  font-family: var(--mono);
  color: var(--hush);
  margin-right: 10px;
  transition: transform 0.15s;
  display: inline-block;
  width: 10px;
}
.inst-tree .cat.open .cat-head .disclose { transform: rotate(90deg); }
.inst-tree .cat-items {
  display: none;
  padding: 0 20px 16px 40px;
}
.inst-tree .cat.open .cat-items { display: block; }
.inst-tree .cat-items .inst-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 1px solid var(--line-2);
}
.inst-tree .cat-items .inst-row:last-child { border-bottom: 0; }
.inst-tree .cat-items .inst-row:hover {
  color: var(--civic);
}
.inst-tree .cat-items .inst-row .cnt {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--hush);
}

/* ============================================================
   Recent dates
   ============================================================ */
.recent-list {
  background: var(--canvas);
  border: 1px solid var(--line);
}
.recent-list .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
}
.recent-list .row:last-child { border-bottom: 0; }
.recent-list .row:hover { background: var(--line-2); text-decoration: none; }
.recent-list .row .date {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.recent-list .row .label {
  color: var(--hush);
  font-size: 12px;
  font-family: var(--mono);
}

/* ============================================================
   Browse view
   ============================================================ */
.browse-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}
.browse-layout .sidebar {
  position: sticky;
  top: 24px;
  background: var(--canvas);
  border: 1px solid var(--line);
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
}
.sidebar .tabs {
  display: flex;
  gap: 6px;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--line-2);
}
.sidebar .tabs button,
.year-jumper button,
.cat-pills button,
.sidebar .list .item {
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.sidebar .tabs button:active,
.year-jumper button:active,
.cat-pills button:active,
.sidebar .list .item:active {
  transform: translateY(1px);
}
.sidebar .tabs button {
  flex: 1;
  border: 1px solid transparent;
  background: transparent;
  padding: 11px 0;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--hush);
  border-radius: calc(var(--rad) - 2px);
}
.sidebar .tabs button.active {
  color: var(--ink);
  border-color: var(--line);
  background: var(--canvas);
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}
/* Legacy standalone .filter — kept as fallback if filter-row wrapper missing.
   Active filter styling now lives under .filter-row in the section below. */
.sidebar .list {
  display: none;
  overflow-y: auto;
  flex: 1;
  min-height: 320px;
}
.sidebar .list.active { display: block; }
.sidebar .list .item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink);
}
.sidebar .list .item:hover { background: var(--line-2); }
.sidebar .list .item.selected {
  background: var(--civic-bg);
  color: var(--civic);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--civic);
}
.sidebar .list .item.pulse {
  background: var(--civic-bg);
  animation: pulsefade 0.7s ease-out;
}
@keyframes pulsefade {
  from { background: var(--civic); }
  to   { background: var(--civic-bg); }
}

/* search result highlight */
.sidebar .list mark {
  background: #fff3a0;
  color: var(--ink);
  padding: 0 2px;
  border-radius: 1px;
}
@media (prefers-color-scheme: dark) {
  .sidebar .list mark { background: #5c4a08; color: var(--ink); }
}
.sidebar .list .item .count {
  color: var(--hush);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--canvas);
}
.sidebar .list .item.selected .count {
  color: var(--civic);
  border-color: color-mix(in srgb, var(--civic) 28%, var(--line));
  background: color-mix(in srgb, var(--civic-bg) 80%, var(--canvas));
}

/* search results in sidebar */
.sidebar .search-results .item {
  display: block;
}
.sidebar .search-results .item .hit-title {
  font-size: 13px;
  color: var(--ink);
  line-height: 1.35;
  margin-bottom: 2px;
}
.sidebar .search-results .item .hit-meta {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--hush);
}
.sidebar .search-results .search-hint {
  padding: 20px 16px;
  font-size: 12px;
  color: var(--hush);
  font-family: var(--mono);
  text-align: center;
}

/* ============================================================
   Docs list (main pane in browse view)
   ============================================================ */
.main-pane { min-height: 420px; }
.browse-back {
  display: none;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  background: var(--canvas);
  padding: 6px 12px;
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-radius: var(--rad);
}
.browse-back:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.browse-back:focus-visible {
  outline: 2px solid var(--civic);
  outline-offset: 2px;
}
.main-head {
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.main-head h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.015em;
  color: var(--ink);
}
.main-head .sub {
  color: var(--hush);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
}

.docs-list .hint {
  color: var(--hush);
  font-family: var(--mono);
  font-size: 12px;
  padding: 30px 0;
}
.doc-row {
  display: block;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}
.doc-row:hover {
  text-decoration: none;
  background: var(--line-2);
}
.doc-row .meta {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 4px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--hush);
  letter-spacing: 0.02em;
}
.doc-row .meta .inst {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  color: var(--civic);
  letter-spacing: 0;
}
.doc-row .meta .n {
  color: var(--hush);
}
.doc-row .title {
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  font-weight: 500;
  padding: 0 14px;
}
.doc-row .meta { padding: 0 14px; }

/* ============================================================
   Reader
   ============================================================ */
.reader {
  background: var(--canvas);
  border: 1px solid var(--line);
  padding: 32px 44px 44px;
}
.reader .reader-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.reader .reader-head button.back {
  border: 1px solid var(--line);
  background: var(--canvas);
  padding: 6px 12px;
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  border-radius: var(--rad);
}
.reader .reader-head button.back:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.reader .reader-head .meta {
  flex: 1;
  min-width: 0;
  color: var(--hush);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
}
.reader .reader-head .meta .inst {
  color: var(--civic);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 12px;
}
.reader .reader-head a.raw {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--source);
  border: 1px solid var(--source);
  padding: 4px 10px;
  border-radius: var(--rad);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.reader .reader-head a.raw:hover {
  background: var(--source);
  color: var(--canvas);
  text-decoration: none;
}

.reader h2.doc-title {
  margin: 0 0 24px;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--ink);
  max-width: 62ch;
}

.markdown {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.85;
  color: var(--ink);
  max-width: 70ch;
  overflow-wrap: anywhere;
}
.markdown p { margin: 0 0 1.15em; overflow-wrap: anywhere; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
  font-family: var(--sans);
  margin-top: 1.8em;
  margin-bottom: 0.55em;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.markdown h1 { font-size: 19px; }
.markdown h2 { font-size: 17px; }
.markdown h3 { font-size: 15px; }
.markdown code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--line-2);
  padding: 1px 5px;
  border-radius: var(--rad);
}
.markdown pre {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--line-2);
  padding: 14px 16px;
  border-left: 2px solid var(--line);
  overflow-x: auto;
  line-height: 1.6;
  margin: 0 0 1.2em;
}
.markdown table {
  border-collapse: collapse;
  margin: 1.2em 0;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
  max-width: 100%;
  display: block;
  overflow-x: auto;
}
.markdown th, .markdown td {
  border: 1px solid var(--line);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}
.markdown th {
  background: var(--line-2);
  font-weight: 700;
  font-family: var(--sans);
}
.markdown ul, .markdown ol { margin: 0 0 1.2em; padding-left: 1.6em; }
.markdown li { margin-bottom: 0.45em; overflow-wrap: anywhere; }
.markdown a { overflow-wrap: anywhere; word-break: break-word; }
.markdown blockquote {
  border-left: 3px solid var(--line);
  margin: 0 0 1.2em;
  padding: 0.4em 1.2em;
  color: var(--muted);
  font-style: italic;
}
.markdown hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 2em 0;
}

/* ============================================================
   About view — editorial prose
   ============================================================ */
.prose {
  max-width: 760px;
  margin: 0 auto;
}
.prose h1 {
  font-size: 32px;
  font-weight: 800;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}
.prose .prose-lede {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}
.prose h2 {
  margin-top: 2em;
  margin-bottom: 0.6em;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.prose h3 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-size: 14px;
  font-weight: 700;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.prose p, .prose li { line-height: 1.75; }
.prose p { margin: 0 0 1.1em; }
.prose pre {
  background: var(--canvas);
  border: 1px solid var(--line);
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  border-radius: var(--rad);
  overflow-x: auto;
  margin: 0.8em 0 1.4em;
}
.prose code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--line-2);
  padding: 1px 5px;
  border-radius: var(--rad);
}
.prose ul { margin: 0 0 1.2em; padding-left: 1.5em; }
.prose ul.hollow { list-style: none; padding-left: 0; }
.prose ul.hollow li {
  padding-left: 14px;
  border-left: 2px solid var(--line);
  margin-bottom: 6px;
  color: var(--muted);
  font-style: italic;
}
.prose table {
  border-collapse: collapse;
  font-size: 13px;
  margin: 1em 0;
  width: 100%;
}
.prose table th, .prose table td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}
.prose table th {
  background: var(--line-2);
  font-weight: 700;
}

/* ============================================================
   Footer
   ============================================================ */
footer.site {
  margin-top: 60px;
  border-top: 1px solid var(--line);
  padding: 24px 0 40px;
  color: var(--hush);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.02em;
  background: var(--canvas);
}
footer.site a { color: var(--muted); }
footer.site a:hover { color: var(--ink); }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 820px) {
  .wrap { padding: 0 18px; }
  .browse-layout { grid-template-columns: 1fr; gap: 24px; }
  .browse-layout .sidebar {
    position: static;
    max-height: 380px;
  }
  #view-browse:not(.selection-open):not(.reader-open) .browse-layout {
    display: block;
  }
  #view-browse:not(.selection-open):not(.reader-open) .main-pane {
    display: none;
  }
  #view-browse:not(.selection-open):not(.reader-open) .browse-layout .sidebar {
    max-height: none;
  }
  #view-browse:not(.selection-open):not(.reader-open) .sidebar .tabs {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--line-2);
  }
  #view-browse:not(.selection-open):not(.reader-open) .filter-row {
    position: sticky;
    top: 52px;
    z-index: 9;
    background: var(--canvas);
  }
  #view-browse:not(.selection-open):not(.reader-open) .sidebar .list {
    overflow-y: visible;
    min-height: 0;
  }
  #view-browse:not(.selection-open):not(.reader-open) .year-jumper,
  #view-browse:not(.selection-open):not(.reader-open) .cat-pills {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #view-browse:not(.selection-open):not(.reader-open) .year-jumper::-webkit-scrollbar,
  #view-browse:not(.selection-open):not(.reader-open) .cat-pills::-webkit-scrollbar {
    display: none;
  }
  #view-browse:not(.selection-open):not(.reader-open) .year-jumper button {
    flex: 0 0 64px;
  }
  #view-browse:not(.selection-open):not(.reader-open) .sidebar .tabs button {
    min-height: 46px;
  }
  #view-browse:not(.selection-open):not(.reader-open) .cat-pills {
    flex-wrap: nowrap;
    gap: 6px;
    padding-bottom: 12px;
  }
  #view-browse:not(.selection-open):not(.reader-open) .cat-pills button {
    flex: 0 0 auto;
    white-space: nowrap;
  }
  #view-browse.selection-open:not(.reader-open) .browse-layout,
  #view-browse.reader-open .browse-layout {
    gap: 0;
  }
  #view-browse.selection-open:not(.reader-open) .browse-layout .sidebar,
  #view-browse.reader-open .browse-layout .sidebar {
    display: none;
  }
  #view-browse.selection-open:not(.reader-open) .main-pane,
  #view-browse.reader-open .main-pane {
    min-height: auto;
  }
  #view-browse.selection-open:not(.reader-open) .browse-back {
    display: inline-flex;
    align-items: center;
    position: sticky;
    top: 12px;
    z-index: 6;
    margin-bottom: 12px;
  }
  #view-browse.selection-open:not(.reader-open) .main-head {
    padding-bottom: 10px;
    margin-bottom: 14px;
  }
  #view-browse.selection-open:not(.reader-open) .main-head h2 {
    font-size: 20px;
  }
  #view-browse.selection-open:not(.reader-open) .doc-row {
    padding: 13px 0;
  }
  #view-browse.selection-open:not(.reader-open) .doc-row .meta {
    margin-bottom: 6px;
  }
  .home-intro { grid-template-columns: 1fr; gap: 24px; }
  .reader { padding: 24px 18px 32px; }
  .reader h2.doc-title { font-size: 22px; }
  .markdown { font-size: 15px; line-height: 1.8; }
  header.site { padding: 18px 0 0; }
  header.site .brand { gap: 10px; }
  header.site .tag { margin-top: 4px; font-size: 12px; line-height: 1.5; }
  header.site .stats { margin-top: 8px; font-size: 10px; letter-spacing: 0.01em; }
  header.site nav.top {
    margin-top: 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  header.site nav.top::-webkit-scrollbar { display: none; }
  header.site nav.top a { margin-right: 18px; padding: 12px 0; white-space: nowrap; }
  header.site nav.top a.ext { margin-left: 0; }

  /* iOS HIG: 44px minimum touch target */
  .sidebar .list .item { padding: 13px 14px; min-height: 48px; }
  .sidebar .tabs button { padding: 15px 0; min-height: 48px; }
  .sidebar .filter { padding: 14px; font-size: 14px; }
  .filter-row .filter-clear { min-width: 42px; }
  .year-jumper button { padding: 12px 0; min-height: 44px; }
  .cat-pills button { padding: 7px 12px; min-height: 34px; }
  .doc-row { padding: 16px 0; }
  .doc-row .title { padding: 0 14px; font-size: 15px; }
  .doc-row .meta { padding: 0 14px; }
  .recent-list .row-rich { padding: 18px 18px; }
  .spotlight .card { padding: 22px 20px; }
  .reader-nav button { padding: 14px 16px; }
  .reader-actions .reader-btn { padding: 8px 14px; }
  .reader-head { gap: 10px; }
  .inst-tree .cat-head { padding: 16px 18px; }
  .inst-tree .cat-items { padding: 0 18px 16px 28px; }
  .inst-tree .cat-items .inst-row { padding: 8px 0; min-height: 36px; }

  /* keyboard hint overlay full-width on small screens */
  .kbd-hint .panel { padding: 24px 22px; }
}

@media (max-width: 480px) {
  header.site { padding: 16px 0 0; }
  header.site h1 { font-size: 18px; }
  header.site .version { font-size: 10px; }
  header.site .tag { font-size: 11.5px; }
  header.site .stats { font-size: 9.5px; }
  .reader { padding: 20px 14px 28px; }
  .reader h2.doc-title { font-size: 19px; }
  .spotlight { grid-template-columns: 1fr; }
  .markdown { font-size: 14.5px; }
  .markdown table { font-size: 12px; }
  .reader-nav { flex-direction: column; }
  .reader-nav button { text-align: left; }
  .reader-nav .nav-next { text-align: left; }
}

/* ============================================================
   Skip link
   ============================================================ */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 12px;
  z-index: 200;
}
.skip-link:focus {
  left: 16px;
  top: 16px;
  text-decoration: none;
}

/* ============================================================
   Focus rings — brutalist
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--civic);
  outline-offset: 2px;
  border-radius: var(--rad);
}
.sidebar .list .item:focus-visible,
.doc-row:focus-visible,
.recent-list .row-rich:focus-visible,
.spotlight .card:focus-visible {
  outline-offset: -2px;
}

/* ============================================================
   Document type badge
   ============================================================ */
.badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1px 6px;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: var(--rad);
  background: var(--canvas);
  line-height: 1.4;
  white-space: nowrap;
}
.badge.b-gosi    { color: var(--civic);   border-color: var(--civic); }
.badge.b-gonggo  { color: var(--archive); border-color: var(--archive); }
.badge.b-yego    { color: var(--source);  border-color: var(--source); }
.badge.b-law     { color: var(--seal);    border-color: var(--seal); }
.badge.b-rule    { color: var(--seal);    border-color: var(--seal); }
.badge.b-etc     { color: var(--hush);    border-color: var(--line); }
.doc-row .meta .badge { font-size: 9px; }

/* ============================================================
   Spotlight — editorial entry cards
   ============================================================ */
.spotlight {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  border: 1px solid var(--line);
  background: var(--canvas);
}
.spotlight .card {
  padding: 20px 22px;
  border-right: 1px solid var(--line-2);
  border-bottom: 1px solid var(--line-2);
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  background: var(--canvas);
  transition: background 0.1s;
  display: block;
}
.spotlight .card:last-child,
.spotlight .card:nth-child(5) { border-right: 0; }
.spotlight .card:hover {
  background: var(--line-2);
  text-decoration: none;
}
.spotlight .card .num {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--hush);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.spotlight .card .label {
  display: block;
  font-size: 15px;
  font-weight: 700;
  margin: 8px 0 4px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.spotlight .card .hint {
  display: block;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
}

/* ============================================================
   Recent rich — date + sample titles
   ============================================================ */
.recent-list .row-rich {
  display: block;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-2);
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  background: var(--canvas);
}
.recent-list .row-rich:last-child { border-bottom: 0; }
.recent-list .row-rich:hover {
  background: var(--line-2);
  text-decoration: none;
}
.recent-list .row-rich .head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.recent-list .row-rich .head .date {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
}
.recent-list .row-rich .head .count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--hush);
}
.recent-list .row-rich .samples {
  margin: 0;
  padding: 0;
  list-style: none;
}
.recent-list .row-rich .samples li {
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
  padding: 2px 0 2px 14px;
  position: relative;
}
.recent-list .row-rich .samples li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: var(--line);
  font-family: var(--mono);
  font-size: 10px;
}
.recent-list .row-rich .samples .inst {
  color: var(--civic);
  font-weight: 600;
  margin-right: 8px;
}

/* ============================================================
   Heatmap density
   ============================================================ */
.heatmap .hm-bar {
  background: var(--ink);
  opacity: var(--density, 0.2);
  transition: opacity 0.15s, background 0.15s;
}
.heatmap .hm-bar:hover {
  opacity: 1;
  background: var(--civic);
}

/* ============================================================
   Year jumper
   ============================================================ */
.year-jumper[hidden],
.cat-pills[hidden] {
  display: none !important;
}
.year-jumper {
  display: flex;
  gap: 6px;
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--line-2);
  scroll-snap-type: x proximity;
}
.year-jumper button {
  flex: 1;
  border: 1px solid var(--line);
  background: var(--canvas);
  padding: 9px 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  cursor: pointer;
  border-radius: 999px;
  scroll-snap-align: start;
}
.year-jumper button:last-child { border-right: 1px solid var(--line); }
.year-jumper button:hover {
  color: var(--ink);
  background: var(--canvas);
}
.year-jumper button.active {
  color: var(--canvas);
  background: var(--ink);
  border-color: var(--ink);
}

/* ============================================================
   Category pills (institutions tab)
   ============================================================ */
.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--canvas);
  scroll-snap-type: x proximity;
}
.cat-pills button {
  border: 1px solid var(--line);
  background: var(--canvas);
  padding: 4px 10px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-radius: 999px;
  cursor: pointer;
  scroll-snap-align: start;
}
.cat-pills button:hover {
  color: var(--ink);
  border-color: var(--ink);
}
.cat-pills button.active {
  color: var(--canvas);
  background: var(--ink);
  border-color: var(--ink);
}

/* ============================================================
   Reader actions, permalink, prev/next
   ============================================================ */
.reader-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.reader-btn {
  background: var(--canvas);
  border: 1px solid var(--line);
  padding: 5px 11px;
  font: inherit;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  border-radius: var(--rad);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.reader-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
  text-decoration: none;
}
.reader-btn.primary {
  color: var(--source);
  border-color: var(--source);
}
.reader-btn.primary:hover {
  background: var(--source);
  color: var(--canvas);
}

.reader-nav {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 10px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.reader-nav button {
  background: var(--canvas);
  border: 1px solid var(--line);
  padding: 12px 16px;
  font: inherit;
  color: var(--muted);
  border-radius: var(--rad);
  cursor: pointer;
  line-height: 1.45;
  flex: 1 1 0;
  min-width: 0;
  text-align: left;
  font-family: var(--sans);
}
.reader-nav button:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.reader-nav button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.reader-nav .nav-label {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--hush);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.reader-nav .nav-text {
  display: block;
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.reader-nav .nav-next { text-align: right; }

/* ============================================================
   Reader TOC
   ============================================================ */
#reader-toc:empty { display: none; }
.toc-box {
  border-left: 2px solid var(--line);
  padding: 8px 0 8px 18px;
  margin: 8px 0 32px;
  background: transparent;
}
.toc-box .toc-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hush);
  margin-bottom: 10px;
}
.toc-box ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.toc-box li {
  margin: 5px 0;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
}
.toc-box a {
  color: var(--muted);
  border-bottom: 1px solid transparent;
}
.toc-box a:hover {
  color: var(--civic);
  border-bottom-color: var(--civic);
  text-decoration: none;
}
.toc-box .lvl-2 { padding-left: 0; }
.toc-box .lvl-3 { padding-left: 18px; font-size: 12px; }
.toc-box .lvl-4 { padding-left: 36px; font-size: 12px; color: var(--hush); }
.toc-box .lvl-5 { padding-left: 54px; font-size: 11px; color: var(--hush); }

/* ============================================================
   Size warning
   ============================================================ */
.size-warning {
  background: #fdf4e3;
  border: 1px solid var(--source);
  color: #4a3208;
  padding: 14px 18px;
  border-radius: var(--rad);
  font-size: 13px;
  margin: 0 0 24px;
  line-height: 1.55;
  font-family: var(--sans);
}
.size-warning strong { font-weight: 700; }
.size-warning a {
  color: var(--source);
  font-weight: 600;
  text-decoration: underline;
}
.size-warning .actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}
.size-warning button {
  background: var(--canvas);
  border: 1px solid var(--source);
  color: var(--source);
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--rad);
}
.size-warning button:hover {
  background: var(--source);
  color: var(--canvas);
}
@media (prefers-color-scheme: dark) {
  .size-warning {
    background: #2a1f0e;
    color: #e8d5a8;
    border-color: var(--source);
  }
}

/* ============================================================
   Spinner + loading hint
   ============================================================ */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -1px;
  margin-right: 8px;
}
.sub .spinner,
.docs-list .hint .spinner,
.search-hint .spinner {
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Keyboard shortcut overlay
   ============================================================ */
.kbd-hint {
  position: fixed;
  inset: 0;
  background: rgba(17, 19, 24, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.kbd-hint.open {
  display: flex;
  animation: fade 0.15s ease-out;
}
@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.kbd-hint .panel {
  background: var(--canvas);
  border: 1px solid var(--ink);
  padding: 32px 36px;
  max-width: 480px;
  width: calc(100% - 40px);
  box-shadow: 8px 8px 0 rgba(17, 19, 24, 0.85);
}
.kbd-hint h3 {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--hush);
  margin: 0 0 20px;
}
.kbd-hint table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.kbd-hint td {
  padding: 7px 0;
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
.kbd-hint td:first-child {
  width: 130px;
  white-space: nowrap;
}
.kbd-hint kbd {
  font-family: var(--mono);
  font-size: 11px;
  background: var(--line-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: var(--rad);
  padding: 1px 6px;
  color: var(--ink);
  display: inline-block;
  margin-right: 4px;
}
.kbd-hint .close-hint {
  margin-top: 18px;
  color: var(--hush);
  font-family: var(--mono);
  font-size: 10px;
  text-align: right;
  letter-spacing: 0.04em;
}

/* ============================================================
   Reader quick nav (top prev/next icon buttons)
   ============================================================ */
.reader-quick-nav {
  display: inline-flex;
  gap: 4px;
  margin-left: 4px;
}
.quick-nav-btn {
  background: var(--canvas);
  border: 1px solid var(--line);
  color: var(--muted);
  width: 32px;
  height: 32px;
  font-size: 18px;
  line-height: 1;
  border-radius: var(--rad);
  cursor: pointer;
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.quick-nav-btn:hover:not(:disabled) {
  border-color: var(--ink);
  color: var(--ink);
}
.quick-nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ============================================================
   Filter row (input + match count)
   ============================================================ */
.filter-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  background: var(--canvas);
}
.filter-row .filter {
  flex: 1;
  border: 0;
  padding: 11px 14px;
  font: inherit;
  font-size: 13px;
  background: var(--canvas);
  color: var(--ink);
  outline: 0;
  min-width: 0;
}
.filter-row .filter:focus {
  background: var(--civic-bg);
}
.filter-row .filter-clear {
  border: 0;
  background: var(--canvas);
  color: var(--hush);
  padding: 0 10px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.filter-row .filter-clear:hover {
  color: var(--ink);
}
.filter-row .filter-clear:focus-visible {
  outline: 2px solid var(--civic);
  outline-offset: -2px;
}
.filter-row .filter-clear[hidden] {
  display: none !important;
}
.filter-row .filter-count {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--hush);
  letter-spacing: 0.04em;
  background: var(--canvas);
  white-space: nowrap;
}
.filter-row .filter-count:empty {
  display: none;
}

/* ============================================================
   Floating "back to top"
   ============================================================ */
.scroll-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 44px;
  height: 44px;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: var(--rad);
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  z-index: 80;
  box-shadow: 4px 4px 0 rgba(17, 19, 24, 0.18);
  transition: transform 0.15s, opacity 0.15s;
  opacity: 0.85;
}
.scroll-top:hover {
  opacity: 1;
  transform: translateY(-2px);
}
.scroll-top[hidden] {
  display: none;
}
@media (prefers-color-scheme: dark) {
  .scroll-top {
    background: var(--paper);
    color: var(--ink);
    border-color: var(--paper);
  }
}

/* ============================================================
   Doc list loading skeleton
   ============================================================ */
.skeleton-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.skeleton-row .skel-line {
  background: linear-gradient(
    90deg,
    var(--line-2) 0%,
    var(--line) 50%,
    var(--line-2) 100%
  );
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  height: 11px;
  border-radius: 2px;
  margin: 0 14px;
}
.skeleton-row .skel-line.short { width: 35%; height: 9px; margin-bottom: 8px; }
.skeleton-row .skel-line.long  { width: 80%; }
@keyframes skel {
  0%   { background-position: 100% 50%; }
  100% { background-position: -100% 50%; }
}

/* ============================================================
   TOC collapse toggle
   ============================================================ */
.toc-box .toc-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  margin-bottom: 10px;
}
.toc-box .toc-head .toc-title {
  margin: 0;
  flex: 1;
}
.toc-box .toc-head .toc-toggle {
  border: 1px solid var(--line);
  background: var(--canvas);
  font-family: var(--mono);
  font-size: 9px;
  color: var(--hush);
  padding: 2px 7px;
  border-radius: var(--rad);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.toc-box .toc-head .toc-toggle:hover {
  color: var(--ink);
  border-color: var(--ink);
}
.toc-box.collapsed ul { display: none; }
.toc-box.collapsed { padding-bottom: 4px; margin-bottom: 16px; }

/* ============================================================
   Toast
   ============================================================ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink);
  color: var(--paper);
  padding: 11px 20px;
  border-radius: var(--rad);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0;
  transition: all 0.2s;
  pointer-events: none;
  z-index: 90;
  box-shadow: 4px 4px 0 rgba(17, 19, 24, 0.2);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Print — reader only
   ============================================================ */
@media print {
  :root { --paper: #fff; --canvas: #fff; }
  header.site, footer.site, .home-intro, .heatmap, .inst-tree,
  .recent-list, .spotlight, .browse-layout .sidebar, .main-head,
  .reader-head, .reader-nav, .reader-actions, .skip-link,
  .kbd-hint, .toast, nav.top, section.block > h2, section.block > .sub,
  .view:not(.active), .year-jumper, .cat-pills {
    display: none !important;
  }
  .reader {
    border: 0;
    padding: 0;
  }
  .markdown {
    font-size: 12pt;
    line-height: 1.7;
    max-width: none;
  }
  .markdown table { font-size: 10pt; }
  body { background: #fff; color: #000; }
  a { color: #000; text-decoration: none; }
  .toc-box { page-break-after: avoid; }
}
