/* The encyclopedia as a reference tool.
   Compartments, tables, live filtering. The book idiom (justified columns,
   mastheads, folios) stays in scripts/render.py for the printed and static
   editions; this file is the working surface. */

:root {
  --bg: #f1f2f4;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --ink: #12161d;
  --ink-2: #46505f;
  --ink-3: #7b8798;
  --line: #dfe3e9;
  --line-2: #eceff3;
  --blue: #1d4ed8;
  --blue-soft: #eaeffd;
  --red: #b3261e;
  --red-soft: #fceceb;
  --green: #0b7a53;
  --green-soft: #e6f4ee;
  --amber: #a35c00;
  --amber-soft: #fdf1de;
  --radius: 10px;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- header ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 56px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand .mark { font-size: 15px; }
.brand .sub {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tabs a {
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.on { background: var(--ink); color: #fff; }

.searchbox { margin-left: auto; position: relative; }
.searchbox input {
  width: 290px;
  max-width: 46vw;
  padding: 8px 30px 8px 32px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.searchbox input:focus {
  outline: none;
  border-color: var(--blue);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}
.searchbox .icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: 13px;
  pointer-events: none;
}
.searchbox kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  background: #fff;
}

/* ---------- page frame ---------- */

.wrap { max-width: 1320px; margin: 0 auto; padding: 20px; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--ink-3);
  margin-bottom: 12px;
}
.crumbs a { color: var(--ink-2); font-weight: 600; }

.pagehead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}
.pagehead h1 {
  margin: 0 0 4px;
  font-size: 25px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.pagehead .lede { margin: 0; color: var(--ink-2); font-size: 13.5px; max-width: 62ch; }

.folio {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
  padding-top: 6px;
}

/* ---------- layout ---------- */

.split { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 18px; align-items: start; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }

/* ---------- panels ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel > h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 11px 14px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-2);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.panel > h2 .count {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--ink-3);
}
.panel .body { padding: 14px; }
.panel .body.tight { padding: 0; overflow: auto; max-height: calc(100vh - 210px); }
.panel .body p { margin: 0 0 0.7em; }
.panel .body p:last-child { margin-bottom: 0; }

.stack { display: flex; flex-direction: column; gap: 16px; }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface-2);
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
thead th .arrow { opacity: 0.35; margin-left: 4px; font-size: 9px; }
thead th.sorted .arrow { opacity: 1; }

tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-2);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfe; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td:first-child { box-shadow: inset 3px 0 0 var(--blue); }

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }
td.name { font-weight: 650; }
td.name .kicker { display: block; font-size: 11.5px; font-weight: 500; color: var(--ink-3); }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge.blue { background: var(--blue-soft); color: var(--blue); border-color: #cfdaf9; }
.badge.red { background: var(--red-soft); color: var(--red); border-color: #f6d4d1; }
.badge.green { background: var(--green-soft); color: var(--green); border-color: #cbe7db; }
.badge.amber { background: var(--amber-soft); color: var(--amber); border-color: #f2ddba; }
.badge.grey { background: #f1f3f6; color: var(--ink-2); border-color: var(--line); }
.badge.outline { background: #fff; color: var(--ink-2); border-color: var(--line); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- grade meter ---------- */

.meter { display: inline-flex; height: 6px; width: 74px; border-radius: 3px; overflow: hidden; background: var(--line); vertical-align: middle; }
.meter i { display: block; height: 100%; }
.meter .a { background: var(--green); }
.meter .b { background: var(--blue); }
.meter .c { background: var(--amber); }
.meter .d { background: var(--red); }
.grades { font-family: var(--mono); font-size: 11px; color: var(--ink-3); margin-left: 6px; }

/* ---------- filter rail ---------- */

.rail { position: sticky; top: 76px; }
.rail .panel .body { padding: 12px; }
.rail h3 {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.rail h3 + h3 { margin-top: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  border-radius: 999px;
  padding: 3px 9px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.chip:hover { border-color: var(--ink-3); }
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .n { opacity: 0.6; margin-left: 4px; font-family: var(--mono); font-size: 10.5px; }

select {
  width: 100%;
  padding: 7px 9px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.railtools { margin-top: 14px; display: flex; gap: 8px; }
.btn {
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  padding: 6px 11px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-2);
  cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #000; color: #fff; }

/* ---------- article ---------- */

.art-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 18px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-top: 3px solid var(--blue);
  margin-bottom: 16px;
}
.art-head.bestiary { border-top-color: var(--red); }
.art-head h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -0.02em; line-height: 1.1; }
.art-head .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.art-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: flex-start; }

.facts { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.fact { background: var(--surface); padding: 12px 14px; }
.fact .k { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
.fact .v { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.fact .v small { display: block; font-size: 11.5px; font-weight: 500; color: var(--ink-3); margin-top: 2px; letter-spacing: 0; }

.prose { font-family: var(--serif); font-size: 16px; line-height: 1.62; }
.prose p { margin: 0 0 0.8em; }
.prose p:last-child { margin-bottom: 0; }

ol.steps, ul.plain { margin: 0; padding-left: 18px; }
ol.steps li, ul.plain li { margin-bottom: 7px; }
ol.steps li:last-child, ul.plain li:last-child { margin-bottom: 0; }
ol.steps li::marker { color: var(--ink-3); font-family: var(--mono); font-size: 11px; }

.tiles { display: flex; flex-wrap: wrap; gap: 6px; }
.tile { border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; font-size: 12.5px; background: var(--surface-2); }

.patho { border-left: 3px solid var(--red); padding: 2px 0 2px 11px; margin-bottom: 12px; }
.patho:last-child { margin-bottom: 0; }
.patho .n { font-weight: 700; font-size: 13px; }
.patho .d { color: var(--ink-2); font-size: 13px; }

.killer { display: flex; gap: 9px; padding: 6px 0; border-bottom: 1px dashed var(--line-2); }
.killer:last-child { border-bottom: 0; }
.killer .n { font-family: var(--mono); font-size: 11px; color: var(--ink-3); padding-top: 2px; }

/* ---------- tags for tabs ---------- */

.tabbar { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabbar button {
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-3);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 9px 12px;
  cursor: pointer;
}
.tabbar button:hover { color: var(--ink); }
.tabbar button.on { color: var(--ink); border-bottom-color: var(--ink); }
.tabpane[hidden] { display: none; }

/* ---------- matrix ---------- */

.matrix td.v { text-align: center; font-family: var(--mono); font-size: 11.5px; font-weight: 600; width: 34px; }
.matrix td.v-1 { background: var(--blue-soft); color: var(--blue); }
.matrix td.v-0 { color: var(--ink-3); }
.matrix td.v-2 { background: var(--amber-soft); color: var(--amber); }
.matrix th.rowh { text-align: left; font-size: 12.5px; font-weight: 650; letter-spacing: 0; text-transform: none; color: var(--ink); white-space: nowrap; }
.matrix td.hint { font-size: 12px; color: var(--ink-3); font-style: italic; }

/* ---------- snippets ---------- */

.snippet { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.snippet mark { background: #fff2b8; color: var(--ink); padding: 0 2px; border-radius: 2px; }

.empty { padding: 26px 14px; text-align: center; color: var(--ink-3); font-size: 13px; }

.foot { margin: 26px 0 8px; font-size: 11.5px; color: var(--ink-3); display: flex; gap: 16px; flex-wrap: wrap; }
.foot .mono { font-size: 11px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s, transform 0.16s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading { padding: 40px; text-align: center; color: var(--ink-3); font-size: 13px; }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .rail { position: static; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pagehead { flex-direction: column; gap: 6px; }

  /* the header wraps: brand, search, then the nav as its own scrollable row */
  .top { height: auto; flex-wrap: wrap; padding: 10px 12px 0; gap: 8px; row-gap: 6px; }
  .tabs { display: flex; order: 3; width: 100%; margin: 0 0 8px; overflow-x: auto; }
  .tabs a { white-space: nowrap; }
  .searchbox { order: 2; margin-left: auto; }
  .searchbox input { width: 46vw; }
  .searchbox kbd { display: none; }
  .wrap { padding: 14px 12px; }

  /* the species table drops its least-important columns instead of squeezing all nine */
  #speciesTable th:nth-child(2), #speciesTable td:nth-child(2),
  #speciesTable th:nth-child(3), #speciesTable td:nth-child(3),
  #speciesTable th:nth-child(8), #speciesTable td:nth-child(8),
  #speciesTable th:nth-child(9), #speciesTable td:nth-child(9) { display: none; }
  #speciesTable td, #speciesTable th { padding: 8px 9px; }
  td.name { font-size: 13px; }
}

/* very narrow: drop the year column too, and shrink the grade meter */
@media (max-width: 480px) {
  #speciesTable th:nth-child(7), #speciesTable td:nth-child(7) { display: none; }
  .meter { width: 46px; }
  .grades { display: inline; font-size: 10px; }
}
