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

html {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input { font: inherit; color: inherit; }
::selection { background: color-mix(in srgb, var(--lime) 45%, transparent); }
[hidden] { display: none !important; }

.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }

.shell { display: flex; min-height: 100vh; }

.side {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 12px;
  color: inherit;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--lime);
  color: #1c1917;
  font-weight: 700;
}
.brand-copy { min-width: 0; }
.brand-name { display: block; font-weight: 700; letter-spacing: -0.02em; }
.brand-sub { display: block; font-size: 12px; color: var(--muted); }

.side-search { padding: 0 12px 8px; }
.book-open { display: flex; gap: 8px; align-items: center; }
.book-open a {
  flex: 1;
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}
.book-open a:hover, .book-open a.on { background: var(--accent); text-decoration: none; }
.related-card h3 a { color: inherit; text-decoration: none; }
.related-card h3 a:hover { text-decoration: underline; }
.score-id a, .rule-h a { color: inherit; }
.score h3 .textbtn, .title-row .textbtn { margin-left: 8px; vertical-align: middle; }
input[type="search"] {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  outline: none;
}
input[type="search"]:focus { border-color: #a8a29e; }

.nav { flex: 1; overflow: auto; padding: 0 10px 16px; }
.nav-label {
  padding: 14px 8px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--muted) 80%, transparent);
}
.nav a {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--foreground);
  text-decoration: none;
}
.nav a:hover { background: var(--accent); text-decoration: none; }
.nav a.on { background: var(--accent); font-weight: 600; }
.nav a.on::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 99px;
  background: var(--lime);
}
.nav-all { font-weight: 500; }
.nav-copy { flex: 1; min-width: 0; }
.nav-text {
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}
.verify { display: block; margin-top: 2px; font-size: 11px; font-weight: 600; color: #b45309; }
.verify.done { color: #166534; }
.pct {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.pct.big { font-size: 16px; font-weight: 600; color: var(--foreground); }

.main { flex: 1; min-width: 0; }
.page {
  max-width: 980px;
  padding: 28px 32px 72px;
  display: grid;
  gap: 18px;
  align-content: start;
}

.page-head h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  letter-spacing: -0.03em;
}
.page-head p { margin: 8px 0 0; color: var(--muted); max-width: 62ch; }
.page-head p.url { max-width: none; overflow-wrap: anywhere; word-break: break-word; }
.record { font-size: 20px !important; word-break: break-all; }
.url { word-break: break-all; }
.crumb { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.crumb a { color: var(--muted); }
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.index-pill {
  flex-shrink: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: #1c1917;
  color: #fafaf9;
  font-family: var(--font-mono);
  font-weight: 600;
}

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 8%, transparent);
  padding: 14px 14px 12px;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { margin-top: 6px; font-family: var(--font-mono); font-size: 26px; font-weight: 600; letter-spacing: -0.03em; }
.stat .hint { margin-top: 4px; font-size: 12px; color: var(--muted); }

.block h2 { margin: 8px 0; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card {
  display: block;
  background: var(--card);
  color: inherit;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 8%, transparent);
  padding: 14px;
}
a.card:hover {
  text-decoration: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 18%, transparent);
}
.card h3 { margin: 8px 0 2px; font-size: 15px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.35; }
.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.id { font-size: 11px; color: var(--muted); }
.meta { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.meter { height: 4px; margin-top: 12px; border-radius: 99px; background: #eceae6; overflow: hidden; }
.meter.lg { margin-top: 14px; height: 6px; }
.meter span { display: block; height: 100%; background: var(--lime); border-radius: inherit; }

.toolbar input { max-width: 420px; }

.dim { display: grid; gap: 10px; }
.dim-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.dim-h h2 { margin: 0; font-size: 18px; letter-spacing: -0.02em; text-transform: none; color: var(--foreground); }

.score, .related-card { display: grid; gap: 8px; }
.score {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 8%, transparent);
  padding: 14px 16px 12px;
}
.score-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.score-side { display: flex; align-items: center; gap: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.check input { width: 16px; height: 16px; }
.score:has(.check input:checked) { box-shadow: 0 0 0 1px #86efac; }
.check-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.score-id { font-size: 12px; color: var(--muted); }
.score h3, .related-card h3 { margin: 0; font-size: 16px; letter-spacing: -0.02em; }
.anchor { margin: 0; color: var(--muted); }
.anchor span {
  display: inline-block;
  margin-right: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.rationale, .related-card p { margin: 0; }
.excerpt {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fafaf9;
  color: #44403c;
  font-size: 13px;
}
.excerpt span {
  display: block;
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.obs, .proof { display: grid; gap: 8px; margin-top: 12px; }
.obs h4, .proof h4 {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.obs p { margin: 0; }
.obs .note { color: var(--muted); }
.obs .gap { padding: 8px 10px; border-radius: 8px; background: #fff7ed; }
.obs .k { font-weight: 700; }
.live { margin: 4px 0 0; }
.samples { margin: 4px 0 0; padding-left: 1.2rem; }
.samples li { margin: 2px 0; }
.live a::after { content: " ↗"; }
.proof { display: grid; gap: 10px; }
.proof-note { margin: 0; color: var(--muted); font-size: 13px; }
.proof-warn { margin: 0; color: var(--warn-fg); font-size: 13px; }
.proof-file { display: grid; gap: 8px; }
.chip.lit { background: #fef9c3; color: #854d0e; }
.related-card.on, .score.on { box-shadow: 0 0 0 2px var(--lime); }

.badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  flex-shrink: 0;
}
.s0 { background: var(--s0); color: var(--s0-fg); }
.s1 { background: var(--s1); color: var(--s1-fg); }
.s2 { background: var(--s2); color: var(--s2-fg); }
.s3 { background: var(--s3); color: var(--s3-fg); }
.s4 { background: var(--s4); color: var(--s4-fg); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #44403c;
  font-size: 12px;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.chip:hover { text-decoration: none; background: #e7e5e4; }
.chip.ok { background: var(--ok-bg); color: var(--ok-fg); }
.chip.bad { background: var(--bad-bg); color: var(--bad-fg); }
.chip.warn { background: var(--warn-bg); color: var(--warn-fg); }

.related { display: grid; gap: 10px; }
.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.files li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 8%, transparent);
}
.files a { font-family: var(--font-mono); font-size: 13px; }

pre {
  margin: 0;
  max-height: 28rem;
  overflow: auto;
  padding: 14px;
  border-radius: 12px;
  background: #1c1917;
  color: #f5f5f4;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
pre.note {
  max-height: 16rem;
  background: #fafaf9;
  color: #1c1917;
  border: 1px solid var(--border);
}
pre mark {
  background: #fde047;
  color: #1c1917;
  border-radius: 2px;
  padding: 0 2px;
}

.textbtn {
  font: inherit;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--foreground);
  padding: 4px 10px;
  cursor: pointer;
}
.textbtn:hover { background: #e7e5e4; }

.rule-group { display: grid; gap: 10px; }
.rule-group h2 { margin: 8px 0 0; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.rule {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 8%, transparent);
  padding: 14px 16px;
}
.rule-h { display: flex; align-items: baseline; gap: 10px; }
.rule-h h3, .rule h3 { margin: 0; font-size: 16px; }
.fields { width: 100%; border-collapse: collapse; margin: 8px 0 0; font-size: 0.92rem; }
.fields th, .fields td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.fields th { color: var(--muted); font-weight: 600; }
.scale { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.scale li { display: flex; gap: 8px; align-items: flex-start; }
.scale .badge { width: 28px; height: 28px; flex-shrink: 0; }

.rail {
  width: 248px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--border);
  background: var(--sidebar);
  padding: 20px 12px 28px;
}
.rail-label { margin: 0 8px 12px; font-weight: 700; letter-spacing: -0.02em; }
.crit { display: grid; gap: 6px; }
.crit-dim {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
}
.crit-dim:hover { text-decoration: none; background: var(--accent); }
.crit-dim.on { background: var(--accent); box-shadow: inset 3px 0 0 var(--lime); font-weight: 600; }
.crit-dim .mono { width: 1.2rem; font-weight: 700; }
.crit-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.crit-group > span {
  width: 100%;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.crit-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 8px;
  border-radius: 999px;
  background: #fff;
  color: inherit;
  text-decoration: none;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 10%, transparent);
}
.crit-link:hover { text-decoration: none; background: var(--accent); }
.crit-link.on { box-shadow: 0 0 0 2px var(--lime); }
.crit-link .badge { width: 22px; height: 22px; border-radius: 999px; font-size: 12px; }

.page-frame {
  width: 100%;
  height: 520px;
  border: 0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--foreground) 10%, transparent);
}

dialog.book {
  width: min(760px, calc(100vw - 32px));
  max-height: min(82vh, 860px);
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--background);
  color: var(--foreground);
  box-shadow: 0 24px 80px rgb(28 25 23 / 28%);
}
dialog.book::backdrop { background: rgb(28 25 23 / 45%); }
.book-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.book-bar input { flex: 1; }
.book-body { padding: 8px 16px 20px; overflow: auto; max-height: calc(82vh - 64px); }

@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: relative; order: 1; border-right: 0; border-bottom: 1px solid var(--border); }
  .rail { width: auto; height: auto; position: relative; order: 2; max-height: 280px; border-left: 0; border-bottom: 1px solid var(--border); }
  .main { order: 3; }
  .nav { max-height: 220px; }
  .page { padding: 20px 16px 48px; }
  .title-row { flex-direction: column; }
}
