:root {
  --paper: #faf6ef;
  --paper-deep: #f2ebe0;
  --card: #fffdfa;
  --ink: #1c1815;
  --ink-soft: #4a423a;
  --muted: #857a6d;
  --rule: #ded3c2;
  --rule-strong: #c4b6a0;
  --oxblood: #8c2f26;
  --oxblood-deep: #6d231c;
  --forest: #2c5442;
  --brass: #a8813a;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }

/* Class-level display rules would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  position: relative;
}

/* Paper tooth. Very low opacity so it reads as texture, not noise. */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 28px;
  position: relative;
  z-index: 1;
}

main.wrap { padding-bottom: 90px; }

/* ------------------------------------------------------------ masthead */

.masthead { padding: 54px 0 0; }

.rule-double {
  border-top: 2.5px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  height: 5px;
}

.masthead h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.9rem, 7vw, 4.6rem);
  letter-spacing: -0.022em;
  line-height: 1;
  margin: 26px 0 16px;
  text-align: center;
}

.standfirst {
  font-family: var(--serif);
  font-size: clamp(1rem, 1.6vw, 1.16rem);
  color: var(--ink-soft);
  max-width: 60ch;
  margin: 0 auto 26px;
  text-align: center;
  text-wrap: balance;
}

/* ------------------------------------------------------------ search */

.search-block { padding: 52px 0 8px; }

.field {
  display: flex;
  gap: 0;
  border: 1.5px solid var(--ink);
  background: var(--card);
  box-shadow: 5px 5px 0 var(--paper-deep);
  transition: box-shadow .18s ease, transform .18s ease;
}

.field:focus-within {
  box-shadow: 5px 5px 0 var(--rule-strong);
  transform: translate(-1px, -1px);
}

.field input {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 20px 22px;
  font-family: var(--mono);
  font-size: 1.22rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  min-width: 0;
}

.field input:focus { outline: none; }
.field input::placeholder { color: #b4a897; }

.field button {
  border: 0;
  border-left: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  padding: 0 30px;
  cursor: pointer;
  transition: background .18s ease;
}

.field button:hover { background: var(--oxblood); }
.field button:disabled { background: var(--muted); cursor: default; }

.hint {
  font-size: .9rem;
  color: var(--muted);
  margin: 14px 2px 0;
  min-height: 1.3em;
}

.hint.error { color: var(--oxblood); }

/* ------------------------------------------------------------ shared */

.section-label {
  font-family: var(--sans);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 16px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--rule);
}

.alert {
  background: #fdf0ee;
  border-top: 1px solid var(--oxblood);
  border-bottom: 1px solid var(--oxblood);
  color: var(--oxblood-deep);
  padding: 13px 28px;
  font-size: .92rem;
  position: relative;
  z-index: 1;
}

/* ------------------------------------------------------------ candidates */

.candidates { padding-top: 46px; }

.candidate-list { display: grid; gap: 12px; }

.candidate {
  display: flex;
  align-items: baseline;
  gap: 18px;
  flex-wrap: wrap;
  text-align: left;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--brass);
  padding: 17px 20px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-left-color .16s ease, transform .16s ease;
}

.candidate:hover {
  border-left-color: var(--oxblood);
  transform: translateX(3px);
}

.candidate .num {
  font-family: var(--mono);
  font-size: 1.02rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.candidate .why {
  font-size: .74rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.candidate .ttl {
  flex-basis: 100%;
  font-family: var(--serif);
  color: var(--ink-soft);
}

/* ------------------------------------------------------------ progress */

.progress {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 44px 0 0;
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 1.06rem;
}

.spinner {
  width: 17px;
  height: 17px;
  border: 2px solid var(--rule-strong);
  border-top-color: var(--oxblood);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex: none;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ family */

.family { padding-top: 46px; animation: rise .5s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: none; }
}

.family-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 22px;
  border-bottom: 2.5px solid var(--ink);
  padding-bottom: 18px;
  margin-bottom: 30px;
}

.family-head h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.5rem, 3.2vw, 2.05rem);
  line-height: 1.15;
  margin: 0 0 7px;
  text-wrap: balance;
}

.family-meta {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.ghost {
  flex: none;
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: .74rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  padding: 9px 15px;
  cursor: pointer;
  transition: border-color .16s ease, color .16s ease;
}

.ghost:hover { border-color: var(--ink); color: var(--ink); }

/* ------------------------------------------------------------ anomalies */

.anomalies { margin-bottom: 38px; }

.anomaly-list { list-style: none; margin: 0; padding: 0; }

.anomaly {
  border: 1px solid var(--rule);
  border-left: 3px solid var(--brass);
  background: var(--card);
  padding: 15px 18px;
  margin-bottom: 10px;
}

.anomaly.defect { border-left-color: var(--oxblood); }

.anomaly-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.anomaly-tag {
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .13em;
  text-transform: uppercase;
  padding: 3px 7px;
  border: 1px solid currentColor;
  color: var(--brass);
  flex: none;
}

.anomaly.defect .anomaly-tag { color: var(--oxblood); }

.anomaly-msg {
  font-family: var(--serif);
  font-size: 1.02rem;
  color: var(--ink);
  margin: 0;
}

.anomaly-evidence {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--muted);
  margin: 8px 0 0;
  overflow-x: auto;
  white-space: pre-wrap;
}

.excluded-note {
  border-top: 1px solid var(--rule);
  margin-top: 16px;
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
}

.excluded-note p {
  margin: 0;
  font-family: var(--serif);
  font-size: .96rem;
  color: var(--ink-soft);
  flex: 1 1 320px;
}

.app-row.is-excluded { opacity: .62; }
.app-row.is-excluded .app-num { text-decoration: line-through; text-decoration-color: var(--oxblood); }

.plate { margin: 0 0 42px; }

.plate-inner {
  border: 1px solid var(--rule-strong);
  background: var(--card);
  padding: 22px;
  overflow-x: auto;
}

.plate img { display: block; max-width: 100%; height: auto; margin: 0 auto; }

.plate figcaption {
  font-family: var(--serif);
  font-style: italic;
  font-size: .89rem;
  color: var(--muted);
  margin-top: 10px;
}

/* ------------------------------------------------------------ app list */

.app-list { display: grid; gap: 0; }

.app-row {
  border-bottom: 1px solid var(--rule);
  padding: 22px 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px 26px;
  align-items: start;
}

.app-row:first-child { border-top: 1px solid var(--rule); }

.app-row.is-seed { background: linear-gradient(90deg, #fdf6e8 0%, transparent 62%); }

.app-num {
  font-family: var(--mono);
  font-size: 1.06rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tag {
  font-family: var(--sans);
  font-size: .62rem;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 3px 7px;
  border: 1px solid currentColor;
  color: var(--muted);
}

.tag.seed { color: var(--brass); }
.tag.granted { color: var(--forest); }
.tag.pct { color: #2b6a8f; }
.tag.warn { color: var(--oxblood); }

.app-title {
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--ink-soft);
  margin: 5px 0 3px;
}

.app-detail {
  font-size: .86rem;
  color: var(--muted);
}

.app-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  min-width: 190px;
}

.action {
  background: var(--card);
  border: 1px solid var(--ink);
  color: var(--ink);
  font-family: var(--sans);
  font-size: .76rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 10px 14px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: block;
  transition: background .16s ease, color .16s ease;
}

.action:hover { background: var(--ink); color: var(--paper); }

/* Solid is reserved for the finished download. Starting a build is the expensive,
   several-minute action, so it stays quiet until there is something to collect. */
.action.primary { background: var(--oxblood); border-color: var(--oxblood); color: #fff; }
.action.primary:hover { background: var(--oxblood-deep); border-color: var(--oxblood-deep); }

.action.quiet { border-color: var(--rule-strong); color: var(--muted); background: transparent; }
.action.quiet:hover { border-color: var(--ink); color: var(--ink); background: transparent; }

.action.cancel { border-color: var(--rule-strong); color: var(--oxblood); background: transparent; }
.action.cancel:hover { border-color: var(--oxblood); color: var(--oxblood); background: transparent; }
.action.cancel:disabled { border-color: var(--rule); color: var(--muted); }

.action:disabled { border-color: var(--rule-strong); color: var(--muted); background: transparent; cursor: default; }
.action:disabled:hover { background: transparent; color: var(--muted); }

.action-note {
  font-size: .74rem;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------ external */

.external { margin-top: 38px; }
.external ul { margin: 0; padding-left: 18px; color: var(--ink-soft); }
.external li { font-family: var(--mono); font-size: .9rem; margin: 5px 0; }

/* ------------------------------------------------------------ recent */

.recent { padding-top: 62px; }

.recent-list { list-style: none; margin: 0; padding: 0; }

.recent-item {
  border-bottom: 1px solid var(--rule);
}

.recent-item button {
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 17px 4px;
  display: grid;
  grid-template-columns: 128px 1fr auto;
  gap: 20px;
  align-items: baseline;
  transition: padding-left .16s ease, color .16s ease;
}

.recent-item button:hover { padding-left: 12px; color: var(--oxblood); }

.recent-num {
  font-family: var(--mono);
  font-size: .96rem;
  font-variant-numeric: tabular-nums;
}

.recent-title {
  font-family: var(--serif);
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-count {
  font-size: .78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ------------------------------------------------------------ colophon */

.colophon { padding: 0 0 64px; }
.rule-thin { border-top: 1px solid var(--rule); margin-bottom: 18px; }

.colophon p {
  font-family: var(--serif);
  font-size: .9rem;
  font-style: italic;
  color: var(--muted);
  max-width: 68ch;
  margin: 0;
}

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

@media (max-width: 720px) {
  .wrap { padding: 0 20px; }
  .field { flex-direction: column; }
  .field button { border-left: 0; border-top: 1.5px solid var(--ink); padding: 15px; }
  .app-row { grid-template-columns: 1fr; }
  .app-actions { min-width: 0; }
  .recent-item button { grid-template-columns: 1fr; gap: 4px; }
  .recent-title { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
