:root {
  --navy: #1B365D;
  --navy-ink: #10233F;
  --gold: #B8860B;
  --cream: #FFFBF3;
  --paper: #FFFFFF;
  --ink: #111111;
  --muted: #3A3A3A;
  --line: #1A1A1A;
  --chip: #EEF2F7;
  --verified-bg: #0B5C32;
  --verified-fg: #FFFFFF;
  --review-bg: #8A5300;
  --review-fg: #FFFFFF;
  --gap-bg: #8B1A1A;
  --gap-fg: #FFFFFF;
  --mark-bg: #FFE566;
  --mark-fg: #111111;
  --shadow: 0 2px 0 #111111;
  --radius: 14px;
  --touch: 52px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: var(--cream);
  --card: var(--paper);
  --header-bg: var(--navy);
  --header-fg: #FFFFFF;
  --link: #0B3A82;
  color-scheme: light;
}

body.theme-dark {
  --bg: #0B0D10;
  --card: #171B22;
  --ink: #F4F1EA;
  --muted: #C9C4B8;
  --line: #E8E2D4;
  --chip: #232A35;
  --cream: #0B0D10;
  --paper: #171B22;
  --shadow: 0 2px 0 #000000;
  --mark-bg: #C9A227;
  --mark-fg: #111111;
  --link: #8CB4FF;
  --header-bg: #10233F;
  --navy-ink: #071422;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--gold);
  color: #111;
  padding: 8px 16px;
  z-index: 20;
}
.skip-link:focus { left: 8px; top: 8px; }

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--header-bg);
  color: var(--header-fg);
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 3px solid #000;
}

.header-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--navy-ink);
  flex-shrink: 0;
}
.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-stamp {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: #F0E6C8;
  font-weight: 600;
}

.icon-btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0 14px;
  border: 2px solid #F0E6C8;
  background: transparent;
  color: #FFF;
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.icon-btn:active { background: rgba(255,255,255,0.15); }
.icon-btn[hidden] { display: none; }
#back-btn { flex-shrink: 0; font-size: 1rem; }

.search-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
#search-input {
  flex: 1;
  min-height: 56px;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 10px 16px;
  border: 3px solid #000;
  border-radius: 12px;
  background: #FFF;
  color: #111;
  outline: none;
}
#search-input:focus { box-shadow: 0 0 0 3px var(--gold); }
#search-input::placeholder { color: #555; font-weight: 500; }
.clear-btn {
  background: #FFF;
  color: #111;
  border-color: #000;
  min-width: 72px;
}

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 12px;
  padding-bottom: 4px;
}
.chip {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid #F0E6C8;
  background: transparent;
  color: #FFF;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.chip[aria-pressed="true"] {
  background: var(--gold);
  color: #111;
  border-color: var(--gold);
}
.chip:focus-visible { outline: 3px solid #FFF; outline-offset: 2px; }

.app-main {
  padding: 16px 16px 40px;
  max-width: 1100px;
  margin: 0 auto;
}
.app-main:focus { outline: none; }

.cite-banner {
  margin: 0 0 16px;
  padding: 10px 14px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.page-title {
  margin: 0 0 6px;
  font-size: 1.7rem;
  font-weight: 800;
}
.page-lead {
  margin: 0 0 18px;
  color: var(--muted);
  font-weight: 500;
}

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (min-width: 900px) {
  .tile-grid { grid-template-columns: 1fr 1fr 1fr 1fr; }
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-height: 140px;
  padding: 16px;
  text-align: left;
  background: var(--card);
  color: var(--ink);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.tile:active { transform: translateY(1px); box-shadow: none; }
.tile h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.25;
}
.tile .count {
  margin-top: auto;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--navy);
}
body.theme-dark .tile .count { color: var(--gold); }
.tile .count span { font-size: 0.9rem; font-weight: 600; color: var(--muted); }

.category-block { margin: 0 0 22px; }
.category-block h2 {
  margin: 0 0 10px;
  font-size: 1.15rem;
  font-weight: 800;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--line);
}

.item-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.item-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: var(--card);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 12px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
}
.item-card:active { background: var(--chip); }
.item-card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.item-card h3 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  flex: 1;
}
.item-meta {
  margin: 6px 0 0;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 600;
}
.item-snippet {
  margin: 8px 0 0;
  color: var(--ink);
}

.badge {
  display: inline-block;
  flex-shrink: 0;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.2;
  border: 2px solid transparent;
}
.badge-verified { background: var(--verified-bg); color: var(--verified-fg); }
.badge-review { background: var(--review-bg); color: var(--review-fg); }
.badge-gap { background: var(--gap-bg); color: var(--gap-fg); }

mark, .hl {
  background: var(--mark-bg);
  color: var(--mark-fg);
  padding: 0 2px;
  border-radius: 2px;
  font-weight: 800;
}

.detail {
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 24px;
  box-shadow: var(--shadow);
}
.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}
.detail h2 { margin: 0; font-size: 1.45rem; font-weight: 800; }
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 10px 0 16px;
  font-weight: 700;
  color: var(--muted);
}
.detail-meta span { display: inline-block; }
.req-label, .src-label {
  margin: 16px 0 6px;
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.requirement {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 500;
  white-space: pre-wrap;
}
.source-block {
  margin-top: 8px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.source-block p { margin: 0 0 6px; }
.source-block p:last-child { margin-bottom: 0; }
.ext-link {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--navy);
  color: #FFF;
  font-weight: 800;
  text-decoration: none;
  border-radius: 12px;
  border: 2px solid #000;
}
body.theme-dark .ext-link { background: var(--gold); color: #111; }
.ext-link[hidden], .video-link[hidden] { display: none; }
.path-note {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  word-break: break-all;
}

.empty {
  padding: 28px 16px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  font-weight: 700;
}

.app-footer {
  padding: 16px 16px max(20px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
.app-footer p { margin: 0 0 4px; }

.error {
  padding: 20px;
  border: 3px solid var(--gap-bg);
  border-radius: 12px;
  background: var(--card);
  font-weight: 700;
}
