:root {
  /* ACCA-like calm field, shifted toward dusty aqua / periwinkle */
  --field: #8eb8c4;
  --field-deep: #7aa8b6;
  --ink: #1a2a2e;
  --ink-soft: #2f454a;
  --muted: #3d5a61;
  --washed: rgba(26, 42, 46, 0.55);
  --panel: rgba(255, 255, 255, 0.22);
  --panel-strong: rgba(255, 255, 255, 0.45);
  --line: rgba(26, 42, 46, 0.18);
  --accent: #e85d4c;
  --white: #ffffff;
  --sans: "Schibsted Grotesk", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --sidebar: 15.5rem;
  --gutter: clamp(1.25rem, 3vw, 2.75rem);
  --measure: 48rem;
  --radius: 1.1rem;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.02rem;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: -0.01em;
  background: var(--field);
}

[hidden] {
  display: none !important;
}

/* Shared sidebar */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar);
  padding: 1.75rem 1.35rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  z-index: 20;
  background: transparent;
  overflow: hidden;
}

.sidebar__brand {
  flex-shrink: 0;
  display: grid;
  gap: 0.85rem;
}

.brand-logo {
  display: block;
  width: 3.25rem;
  height: auto;
}

.brand-title {
  margin: 0;
  max-width: 11rem;
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.sidebar__nav {
  display: grid;
  gap: 0.35rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
}

.sidebar__nav p {
  margin: 0;
}

.sidebar__toc {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 0.25rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(26, 42, 46, 0.25) transparent;
}

.toc__heading {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--washed);
}

.sidebar__toc nav {
  display: grid;
  gap: 1.35rem;
}

.toc-group {
  display: grid;
  gap: 0.28rem;
}

.sidebar__toc a {
  display: block;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.015em;
  transition: opacity 0.15s ease;
}

.sidebar__toc a:hover,
.sidebar__toc a.is-active {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sidebar__toc a.depth-3 {
  font-size: 0.84rem;
  font-weight: 400;
  color: var(--muted);
  padding-left: 0.15rem;
}

.sidebar__foot {
  margin-top: auto;
  display: grid;
  gap: 0.65rem;
  flex-shrink: 0;
}

.sidebar__action {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.sidebar__action:hover {
  color: var(--accent);
}

.sidebar__meta {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.3;
}

/* Gate */

.gate {
  min-height: 100vh;
  display: block;
}

.gate__main {
  margin-left: var(--sidebar);
  min-height: 100vh;
  padding: clamp(2rem, 6vw, 4.5rem) var(--gutter);
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: calc(var(--sidebar) + 40rem);
  animation: rise 0.65s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.section-label {
  margin: 0 0 1.25rem;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  color: var(--ink);
}

.gate__title {
  margin: 0;
  font-size: clamp(1.35rem, 2.5vw, 1.7rem);
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.gate__lede {
  margin: 0.85rem 0 1.75rem;
  max-width: 28rem;
  color: var(--ink-soft);
  font-size: 1.05rem;
}

.gate__form {
  display: grid;
  gap: 0.5rem;
  max-width: 20rem;
}

.gate__label {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--muted);
}

.gate__input {
  width: 100%;
  padding: 0.8rem 0.95rem;
  border: 0;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
}

.gate__input:focus {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.gate__error {
  margin: 0;
  color: #8b2e22;
  font-size: 0.9rem;
  font-weight: 600;
}

.gate__button {
  margin-top: 0.55rem;
  justify-self: start;
  padding: 0.7rem 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--field);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.gate__button:hover {
  background: var(--accent);
  color: var(--white);
  transform: translateY(-1px);
}

/* App */

.app {
  min-height: 100vh;
  animation: fade 0.4s ease both;
}

.menu-toggle {
  display: none;
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 30;
  padding: 0.55rem 0.9rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--field);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.main {
  margin-left: var(--sidebar);
  min-height: 100vh;
  padding: clamp(1.75rem, 4vw, 3rem) var(--gutter) 4.5rem;
}

.prose {
  width: min(100%, var(--measure));
  animation: rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) 0.05s both;
}

.loading {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}

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

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--ink);
  scroll-margin-top: 1.5rem;
}

.prose h1 {
  margin: 0 0 1.25rem;
  font-size: clamp(2rem, 4.5vw, 2.85rem);
  max-width: 18ch;
}

.prose h2 {
  margin: 2.75rem 0 0.9rem;
  font-size: clamp(1.35rem, 2.4vw, 1.7rem);
}

.prose h3 {
  margin: 1.75rem 0 0.55rem;
  font-size: 1.08rem;
  font-weight: 600;
}

.prose p {
  margin: 0 0 1rem;
  color: var(--ink-soft);
}

.prose h1 + p,
.prose > p:first-of-type {
  color: var(--ink);
}

.prose a {
  color: var(--ink);
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.prose a:hover {
  color: var(--accent);
}

.prose strong {
  font-weight: 650;
  color: var(--ink);
}

.prose ul,
.prose ol {
  margin: 0 0 1.1rem;
  padding-left: 1.2rem;
  color: var(--ink-soft);
}

.prose li {
  margin-bottom: 0.35rem;
}

.prose hr {
  border: 0;
  height: 1px;
  background: var(--line);
  margin: 2.25rem 0;
}

.prose blockquote {
  margin: 1.35rem 0;
  padding: 1rem 1.15rem;
  border: 0;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink-soft);
}

.prose table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.15rem 0 1.65rem;
  font-size: 0.9rem;
  display: block;
  overflow-x: auto;
  background: var(--panel-strong);
  border-radius: var(--radius);
}

.prose thead {
  background: rgba(26, 42, 46, 0.08);
}

.prose th,
.prose td {
  border-bottom: 1px solid var(--line);
  padding: 0.7rem 0.85rem;
  text-align: left;
  vertical-align: top;
  min-width: 5rem;
  color: var(--ink);
}

.prose tr:last-child td {
  border-bottom: 0;
}

.prose th {
  font-weight: 650;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.prose th:first-child,
.prose td:first-child {
  white-space: nowrap;
}

.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: rgba(255, 255, 255, 0.45);
  padding: 0.1em 0.35em;
  border-radius: 0.35rem;
}

.prose pre {
  margin: 1.25rem 0;
  padding: 1.1rem 1.2rem;
  overflow: auto;
  background: rgba(26, 42, 46, 0.9);
  color: #eef6f7;
  border-radius: var(--radius);
  font-size: 0.86rem;
}

.prose pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.prose .mermaid {
  margin: 1.5rem 0;
  padding: 1.15rem;
  background: var(--panel-strong);
  border-radius: var(--radius);
  overflow-x: auto;
}

.priority-must {
  color: #b23a2c;
  font-weight: 700;
}

.priority-should {
  color: #1f5f56;
  font-weight: 700;
}

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

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 900px) {
  .sidebar {
    width: min(80vw, 18rem);
    background: var(--field-deep);
    box-shadow: 16px 0 40px rgba(26, 42, 46, 0.18);
    transform: translateX(-105%);
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .menu-toggle {
    display: inline-flex;
  }

  .main,
  .gate__main {
    margin-left: 0;
  }

  .gate-sidebar {
    display: none;
  }
}

@media (max-width: 640px) {
  .prose h1 {
    max-width: none;
  }
}

/* Document chat */

.chat {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
}

.chat__toggle {
  width: 3.5rem;
  height: 3.5rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--field);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(26, 42, 46, 0.28);
  transition: transform 0.2s ease, background 0.2s ease;
}

.chat__toggle:hover {
  background: var(--accent);
  color: var(--white);
  transform: translateY(-2px);
}

.chat.is-open .chat__toggle {
  background: var(--accent);
  color: var(--white);
}

.chat__panel {
  width: min(calc(100vw - 2rem), 22.5rem);
  height: min(70vh, 32rem);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.82);
  border-radius: 1.35rem;
  box-shadow: 0 18px 50px rgba(26, 42, 46, 0.22);
  backdrop-filter: blur(10px);
  overflow: hidden;
  animation: rise 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--line);
}

.chat__eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.chat__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.chat__close {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.1rem 0.35rem;
}

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

.chat__log {
  flex: 1;
  overflow: auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.chat__bubble {
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.92rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.chat__bubble--assistant {
  align-self: flex-start;
  background: rgba(26, 42, 46, 0.08);
  color: var(--ink);
}

.chat__link {
  color: inherit;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--accent);
}

.chat__bubble--assistant .chat__link:hover {
  color: var(--accent);
}

.chat__bubble--user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--field);
}

.chat__bubble.is-pending {
  opacity: 0.7;
  font-style: italic;
}

.chat__bubble.is-error {
  background: rgba(232, 93, 76, 0.15);
  color: #8b2e22;
}

.chat__status {
  margin: 0;
  padding: 0 1rem;
  font-size: 0.78rem;
  color: #8b2e22;
}

.chat__form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--line);
}

.chat__input {
  width: 100%;
  resize: none;
  border: 0;
  border-radius: 0.9rem;
  padding: 0.7rem 0.85rem;
  background: rgba(26, 42, 46, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
}

.chat__input:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

.chat__send {
  align-self: end;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  background: var(--ink);
  color: var(--field);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.chat__send:hover:not(:disabled) {
  background: var(--accent);
  color: var(--white);
}

.chat__send:disabled {
  opacity: 0.55;
  cursor: wait;
}
