:root {
  --ink: #1a1410;
  --ink-soft: #2a211c;
  --umber: #3d2f28;
  --paper: #f3e6d4;
  --paper-dim: #e8d5bb;
  --rule: rgba(243, 230, 212, 0.12);
  --rule-strong: rgba(243, 230, 212, 0.28);
  --vermillion: #e23d28;
  --vermillion-soft: #ff6b4a;
  --mute: #a8947f;
  --ok: #7cb87a;
  --font-display: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Source Serif 4', Georgia, serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --rail: 15.5rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html,
body,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--paper);
  background: var(--ink);
  font-family: var(--font-body);
  font-optical-sizing: auto;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(226, 61, 40, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(243, 230, 212, 0.06), transparent 50%),
    linear-gradient(180deg, var(--ink) 0%, #120e0c 100%);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 30%, black, transparent);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.75rem 1.25rem 1.5rem;
  border-right: 1px solid var(--rule-strong);
  background: linear-gradient(180deg, rgba(26, 20, 16, 0.96), rgba(18, 14, 12, 0.92));
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  overflow: auto;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.brand-mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

.brand-mark span {
  color: var(--vermillion);
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mute);
}

.nav-block h2 {
  margin: 0 0 0.65rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mute);
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-list a,
.nav-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.45rem 0.55rem;
  border-radius: 2px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  color: var(--paper-dim);
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
  text-align: left;
}

.nav-list a:hover,
.nav-list button:hover {
  background: rgba(243, 230, 212, 0.06);
  color: var(--paper);
}

.nav-list a.active,
.nav-list button.active {
  background: rgba(226, 61, 40, 0.14);
  color: var(--paper);
  box-shadow: inset 2px 0 0 var(--vermillion);
}

.nav-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--mute);
}

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag-chip {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.22rem 0.45rem;
  border: 1px solid var(--rule-strong);
  color: var(--mute);
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.tag-chip:hover,
.tag-chip.active {
  border-color: var(--vermillion);
  color: var(--paper);
  background: rgba(226, 61, 40, 0.12);
}

.rail-foot {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--mute);
  line-height: 1.4;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.1rem 2rem;
  border-bottom: 1px solid var(--rule-strong);
  background: rgba(26, 20, 16, 0.82);
  backdrop-filter: blur(10px);
}

.search {
  flex: 1;
  position: relative;
  max-width: 32rem;
}

.search input {
  width: 100%;
  padding: 0.7rem 0.9rem 0.7rem 2.4rem;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.25);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search input::placeholder {
  color: var(--mute);
}

.search input:focus {
  border-color: var(--vermillion-soft);
  box-shadow: 0 0 0 3px rgba(226, 61, 40, 0.15);
}

.search-glyph {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--mute);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  pointer-events: none;
}

.top-meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mute);
  white-space: nowrap;
}

.content {
  padding: 2rem 2.25rem 3.5rem;
}

.hero {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 2rem;
  align-items: end;
  margin-bottom: 2.25rem;
  padding-bottom: 1.75rem;
  border-bottom: 1px solid var(--rule-strong);
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.4rem, 5vw, 3.8rem);
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.hero h1 em {
  font-style: normal;
  color: var(--vermillion);
}

.hero p {
  margin: 0.85rem 0 0;
  max-width: 34rem;
  color: var(--paper-dim);
  font-size: 1.05rem;
}

.hero-aside {
  justify-self: end;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--mute);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.hero-aside strong {
  display: block;
  margin-top: 0.35rem;
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--paper);
  text-transform: none;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17.5rem, 1fr));
  gap: 0.85rem;
}

.doc-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-height: 10.5rem;
  padding: 1.15rem 1.15rem 1rem;
  border: 1px solid var(--rule-strong);
  background:
    linear-gradient(145deg, rgba(243, 230, 212, 0.04), transparent 55%),
    rgba(0, 0, 0, 0.18);
  transition: transform 0.25s var(--ease), border-color 0.25s, background 0.25s;
  overflow: hidden;
}

.doc-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: var(--vermillion);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s var(--ease);
}

.doc-card:hover {
  transform: translateY(-3px);
  border-color: rgba(226, 61, 40, 0.45);
  background:
    linear-gradient(145deg, rgba(226, 61, 40, 0.08), transparent 55%),
    rgba(0, 0, 0, 0.28);
}

.doc-card:hover::before {
  transform: scaleX(1);
}

.doc-card-type {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--vermillion-soft);
}

.doc-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.doc-card p {
  margin: 0;
  flex: 1;
  color: var(--mute);
  font-size: 0.95rem;
}

.doc-card-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: auto;
}

.empty {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--mute);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.doc-view {
  max-width: 48rem;
}

.doc-view-header {
  margin-bottom: 1.75rem;
}

.doc-view-header .crumb {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mute);
  margin-bottom: 0.75rem;
}

.doc-view-header .crumb a:hover {
  color: var(--vermillion-soft);
}

.doc-view-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 4vw, 2.9rem);
  letter-spacing: -0.035em;
  line-height: 1.05;
}

.doc-view-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--mute);
}

.prose {
  padding: 1.75rem 1.85rem 2rem;
  background: var(--paper);
  color: var(--ink);
  border-radius: 2px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08) inset,
    0 24px 48px rgba(0, 0, 0, 0.35);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 28%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 27px,
      rgba(26, 20, 16, 0.04) 28px
    );
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h1,
.prose h2,
.prose h3 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink);
}

.prose h1 {
  font-size: 1.7rem;
}

.prose h2 {
  margin-top: 1.75rem;
  font-size: 1.3rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(26, 20, 16, 0.12);
}

.prose h3 {
  font-size: 1.1rem;
}

.prose p,
.prose li {
  font-size: 1.02rem;
}

.prose a {
  color: var(--vermillion);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(26, 20, 16, 0.07);
  padding: 0.1em 0.35em;
  border-radius: 2px;
}

.prose pre {
  margin: 1.25rem 0;
  padding: 1rem 1.1rem;
  overflow: auto;
  background: var(--ink);
  color: var(--paper);
  border-radius: 2px;
  border-left: 3px solid var(--vermillion);
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: 0.84rem;
  line-height: 1.55;
  color: inherit;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  font-size: 0.95rem;
}

.prose th,
.prose td {
  border: 1px solid rgba(26, 20, 16, 0.15);
  padding: 0.5rem 0.65rem;
  text-align: left;
}

.prose th {
  background: rgba(26, 20, 16, 0.06);
  font-family: var(--font-display);
}

.prose blockquote {
  margin: 1.25rem 0;
  padding: 0.25rem 0 0.25rem 1rem;
  border-left: 3px solid var(--vermillion);
  color: var(--umber);
}

.status-banner {
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  border: 1px solid rgba(226, 61, 40, 0.4);
  background: rgba(226, 61, 40, 0.12);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--paper-dim);
}

.reveal {
  opacity: 0;
}

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

  .rail {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--rule-strong);
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .hero-aside {
    justify-self: start;
    text-align: left;
  }

  .topbar,
  .content {
    padding-left: 1.15rem;
    padding-right: 1.15rem;
  }

  .top-meta {
    display: none;
  }
}
