:root {
  --bg: #11130f;
  --bg-elev: #1a1e17;
  --bg-soft: #22281d;
  --line: #343c2e;
  --ink: #eef2e6;
  --muted: #8a937c;
  --accent: #c9a227;
  --accent-hot: #dfb83a;
  --leaf: #6f9b62;
  --warn: #c45c4a;
  --paper: #f4f0e4;
  --paper-ink: #1c2118;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font-ui: "Outfit", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(1000px 520px at 8% -8%, rgba(201, 162, 39, 0.14), transparent 55%),
    radial-gradient(800px 480px at 92% 8%, rgba(111, 155, 98, 0.1), transparent 50%),
    linear-gradient(180deg, #161910 0%, var(--bg) 42%, #0d0f0b 100%);
  min-height: 100%;
}

.noise {
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 0;
}

[hidden] { display: none !important; }

.gate, .app { position: relative; z-index: 2; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-panel {
  width: min(420px, 100%);
  padding: 32px 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  animation: rise 0.55s ease both;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 600;
}

.gate h1, .top h2 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: clamp(1.8rem, 3vw, 2.35rem);
}

.lede, .hint {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  color: var(--muted);
}

label em {
  font-style: normal;
  color: var(--accent-hot);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
  padding: 12px 14px;
  font: inherit;
}

input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-soft);
  color: var(--ink);
}

.btn.primary {
  background: linear-gradient(180deg, var(--accent-hot), var(--accent));
  color: #1a1608;
  border-color: transparent;
}

.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 0.82rem; }
.btn:hover { filter: brightness(1.06); }

.error {
  margin: 0;
  color: #ffb4a8;
  background: color-mix(in srgb, var(--warn) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
  border-radius: 8px;
  padding: 10px 12px;
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
}

.rail {
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.25rem;
}

.brand small {
  color: var(--muted);
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.doc-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.doc-btn {
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  padding: 12px;
  cursor: pointer;
  font: inherit;
}

.doc-btn:hover, .doc-btn.active {
  background: var(--bg-soft);
  border-color: var(--line);
}

.doc-btn strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.doc-btn span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.logout { margin-top: auto; }

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

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 22px 28px 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.reader {
  margin: 8px 22px 28px;
  padding: clamp(22px, 4vw, 42px);
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: auto;
  max-width: 920px;
  animation: rise 0.4s ease both;
}

.reader .hint { color: #6b725f; }

.reader :is(h1, h2, h3, h4) {
  font-family: var(--font-display);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.reader h1 { font-size: 2rem; margin-top: 0; }
.reader h2 { font-size: 1.45rem; margin-top: 1.6em; }
.reader h3 { font-size: 1.15rem; margin-top: 1.35em; }
.reader p, .reader li { line-height: 1.65; }
.reader a { color: #6a4e12; }
.reader code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: rgba(28, 33, 24, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.reader pre {
  overflow: auto;
  background: #1c2118;
  color: #eef2e6;
  padding: 14px;
  border-radius: 10px;
}
.reader pre code { background: transparent; padding: 0; color: inherit; }
.reader table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  margin: 1em 0;
}
.reader th, .reader td {
  border: 1px solid #d5ceb8;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.reader th { background: #ebe4d2; }
.reader blockquote {
  margin: 1em 0;
  padding: 0.2em 0 0.2em 1em;
  border-left: 3px solid #c9a227;
  color: #4a5240;
}
.reader hr {
  border: 0;
  border-top: 1px solid #d5ceb8;
  margin: 1.8em 0;
}

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

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .doc-list { max-height: 220px; }
  .top { padding: 16px 16px 8px; }
  .reader { margin: 8px 12px 18px; }
}
