:root {
  --ink: #171410;
  --muted: #6d675f;
  --faint: #918a81;
  --paper: #f7f3eb;
  --panel: #fffaf0;
  --line: #ded4c6;
  --line-strong: #c9bca9;
  --accent: #1f6f5b;
  --accent-dark: #164f41;
  --accent-soft: #dcefe6;
  --gold: #b6792e;
  --rose: #9f4d4d;
  --code: #26211a;
  --shadow: 0 18px 48px rgba(55, 42, 25, 0.11);
  --sans: "Instrument Sans", ui-sans-serif, system-ui, sans-serif;
  --serif: "Newsreader", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html {
  color: var(--ink);
  background:
    linear-gradient(rgba(23, 20, 16, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 20, 16, 0.03) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family: var(--sans);
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main.site-shell {
  flex: 1 0 auto;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

a {
  color: inherit;
  text-decoration-color: rgba(31, 111, 91, 0.35);
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--accent-dark);
  text-decoration-color: currentColor;
}

button,
input {
  font: inherit;
}

.site-shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 24px;
  padding: 18px 0 14px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-mark::before {
  content: "W";
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--panel);
  font-family: var(--serif);
  font-size: 1rem;
  letter-spacing: 0;
}

.hero {
  padding: 32px 0 20px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1;
}

h1 {
  max-width: 720px;
  font-family: var(--serif);
  font-size: clamp(2.6rem, 6vw, 5rem);
  font-weight: 650;
}

.hero-copy {
  max-width: 620px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(1.05rem, 2vw, 1.25rem);
  line-height: 1.55;
}

.library-panel {
  margin: 16px 0 80px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  overflow: clip;
  background: rgba(255, 250, 240, 0.82);
  box-shadow: var(--shadow);
}

.library-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 243, 235, 0.9);
}

.search-wrap {
  position: relative;
}

.search-wrap input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 14px 0 40px;
  outline: none;
}

.search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 91, 0.12);
}

.search-wrap::before {
  content: "";
  position: absolute;
  left: 15px;
  top: 50%;
  width: 13px;
  height: 13px;
  border: 2px solid var(--faint);
  border-radius: 50%;
  transform: translateY(-55%);
}

.search-wrap::after {
  content: "";
  position: absolute;
  left: 27px;
  top: 28px;
  width: 7px;
  height: 2px;
  border-radius: 2px;
  background: var(--faint);
  transform: rotate(45deg);
}

.tabs,
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab-button,
.filter-button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 13px;
  cursor: pointer;
}

.tab-button[aria-selected="true"],
.filter-button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--panel);
}

.table-head {
  display: block;
}

.entry-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
}

.table-head {
  padding: 11px 18px;
  color: var(--faint);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}

.entry-row {
  position: relative;
  align-items: center;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  animation: entry-rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
  animation-delay: calc(40ms * min(var(--i, 0), 12));
}

.entry-main {
  min-width: 0;
}

.entry-row:last-child {
  border-bottom: 0;
}

.entry-row:hover {
  background: rgba(220, 239, 230, 0.34);
}

.entry-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
  font-weight: 800;
}

.entry-title a {
  text-decoration: none;
}

.entry-summary {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.kind {
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--accent-dark);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 4px 7px;
  text-transform: uppercase;
}

.tag,
.requirement-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 27px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 0.78rem;
  text-decoration: none;
  white-space: nowrap;
}

.prompt-actions,
.entry-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.copy-count {
  min-width: 76px;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: right;
}

.copy-button,
.grab-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--panel);
  padding: 0 14px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.copy-button:hover,
.grab-button:hover,
.back-link:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: var(--panel);
}

.grab-button .icon {
  flex: 0 0 auto;
}

.text-link {
  display: inline-flex;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
}

.text-link::before {
  content: "<";
  margin-right: 8px;
}

.empty-state {
  display: none;
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state.is-visible {
  display: block;
}

.detail-shell {
  display: grid;
  grid-template-columns: minmax(0, 720px) minmax(190px, 250px);
  gap: clamp(28px, 5vw, 72px);
  align-items: start;
  padding: 28px 0 90px;
}

.detail-header {
  padding: 26px 0 24px;
  border-bottom: 1px solid var(--line);
}

.detail-title {
  max-width: 760px;
  font-family: var(--serif);
  font-size: clamp(2.4rem, 5.4vw, 4.6rem);
  font-weight: 650;
}

.detail-summary {
  max-width: 660px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.48;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}

.content {
  min-width: 0;
  font-size: 1rem;
  line-height: 1.62;
}

.content h2 {
  margin: 30px 0 10px;
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 650;
}

.content h2:first-child {
  margin-top: 0;
}

.content h3 {
  margin: 28px 0 8px;
  font-size: 1.1rem;
}

.content p,
.content ul,
.content ol {
  color: var(--muted);
}

.content li + li {
  margin-top: 6px;
}

.content pre {
  overflow-x: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--code);
  color: var(--panel);
  padding: 18px;
  line-height: 1.55;
}

.prompt-block {
  white-space: pre-wrap;
}

.content code {
  font-size: 0.92em;
}

.toc {
  position: sticky;
  top: 18px;
  border-left: 1px solid var(--line-strong);
  padding-left: 18px;
  color: var(--muted);
}

.toc strong {
  display: block;
  margin-bottom: 12px;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toc a {
  display: block;
  margin: 9px 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}

.rail-section {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.requirement-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

@media (max-width: 840px) {
  .detail-shell {
    grid-template-columns: 1fr;
  }

  .library-controls {
    grid-template-columns: 1fr;
  }

  .table-head {
    display: none;
  }

  .entry-row {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .prompt-actions,
  .entry-actions {
    justify-content: flex-start;
  }

  .toc {
    position: static;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 18px 0 0;
  }
}

@media (max-width: 560px) {
  .site-shell {
    width: min(100% - 22px, 1160px);
  }

  .hero {
    padding-top: 26px;
  }

  .newsletter {
    flex-direction: column;
    align-items: flex-start;
  }

  .newsletter-form input {
    min-width: 0;
    flex: 1 1 auto;
  }
}

/* Environment chip — the primary "can I use this?" gate.
   Local-agent reads in warm gold (needs setup); any-chat stays calm neutral,
   so the forest-green accent is reserved for the grab action alone. */
.env-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 4px 10px 4px 9px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.env-chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
}

.env-chip[data-env="local-agent"] {
  color: var(--gold);
  border-color: color-mix(in srgb, var(--gold) 42%, var(--line-strong));
  background: color-mix(in srgb, var(--gold) 9%, transparent);
}

.env-chip[data-env="local-agent"]::before {
  background: var(--gold);
}

.grab-count {
  color: var(--faint);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.grab-count[hidden] {
  display: none;
}

.grab-label {
  white-space: nowrap;
}

.rail-section--first {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.rail-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.see-also {
  margin-top: 44px;
}

.see-also h2 {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 650;
}

.see-also-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.see-also-card {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.see-also-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
}

.see-also-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.see-also-kind {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.see-also-card strong {
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 650;
  line-height: 1.2;
}

.see-also-summary {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.site-footer {
  border-top: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.62);
}

.footer-inner {
  padding: 38px 0 46px;
}

.newsletter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.newsletter-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.newsletter-copy strong {
  font-family: var(--serif);
  font-size: 1.32rem;
  font-weight: 650;
}

.newsletter-copy span {
  color: var(--muted);
  font-size: 0.95rem;
}

.newsletter-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.newsletter-form input {
  height: 44px;
  min-width: 220px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  padding: 0 14px;
  outline: none;
}

.newsletter-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 91, 0.12);
}

.newsletter-form button {
  height: 44px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--ink);
  color: var(--panel);
  padding: 0 20px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.newsletter-form button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.newsletter-note {
  flex-basis: 100%;
  color: var(--accent-dark);
  font-size: 0.9rem;
}

.newsletter-note[data-state="error"] {
  color: var(--rose);
}

.newsletter-note:empty {
  display: none;
}

.colophon {
  margin: 22px 0 0;
  color: var(--faint);
  font-size: 0.85rem;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@keyframes entry-rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .entry-row {
    animation: none;
  }
}
