:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #0f172a;
  --surface: #111827;
  --text: #e5e7eb;
  --muted: #a0aec0;
  --accent: #93c5fd;
  --border: rgba(255, 255, 255, 0.1);
  --shadow: rgba(0, 0, 0, 0.18);
  --accent-contrast: #0f172a;
  --input: #1e293b;
  --svgbob-stroke: var(--text);
  --svgbob-fill: var(--text);
  --svgbob-background: transparent;
}

:root[data-theme='light'] {
  color-scheme: light;
  /* --bg: #f7f7f9; */
  --bg: #ffffff;
  --panel: #ffffff;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #4b5563;
  --accent: #2563eb;
  --border: rgba(0, 0, 0, 0.08);
  --shadow: rgba(15, 23, 42, 0.06);
  --accent-contrast: #ffffff;
  --input: #f3f4f6;
  --input-focus: #fffff3;
}

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

body {
  margin: 0;
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(1080px, 92vw);
  margin: 0 auto;
  padding: 1.5rem 1rem;
  background: var(--panel);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 0.65rem;
  padding-bottom: 0.65rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.25rem 0;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-block;
  width: 28px;
  height: 28px;
  background: var(--surface);
  padding: 4px;
}

.brand-name {
  font-size: 1.05rem;
}

.tagline {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.3;
  padding-left: 1rem;
  border-left: 1px solid var(--border);
}

main {
  flex: 1;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  margin-top: 3rem;
}

.site-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.35rem 1.5rem;
  padding-top: 1.1rem;
  padding-bottom: 1.1rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer a {
  color: var(--text);
  font-weight: 600;
}

.site-footer .footer-label {
  color: rgba(160, 174, 192, 0.7);
}

:root[data-theme='light'] .site-footer .footer-label {
  color: rgba(75, 85, 99, 0.55);
}

.hero {
  margin: 3rem 0 2rem;
  /* padding: 1.5rem; */
  background: var(--panel);
  /* border: 1px solid var(--border); */
  /* border-radius: 14px; */
  /* box-shadow: 0 10px 24px var(--shadow); */
}

.hero h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.6rem, 2vw, 2.2rem);
}

.hero p {
  margin: 0;
  color: var(--muted);
}

.search-bar {
  margin-top: 1rem;
}

.search-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--input);
  border: 2px solid var(--input);
  border-radius: 12px;
  padding: 0.5rem 0.75rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);
}

.search-input:focus-within {
  border-color: var(--accent);
  background-color: var(--input-focus);
}

.search-input input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1rem;
  padding: 0.35rem 0.25rem;
}

.search-input input:focus {
  outline: none;
}

.search-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  padding: 0.15rem 0.35rem;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
}

.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;
}

.spec-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 3rem;
  display: grid;
  gap: 0.75rem;
}

.spec-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.spec-card:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 16px var(--shadow);
  text-decoration: none;
}

.spec-card-main {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.spec-card-title-row {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.spec-card-title-row .spec-id {
  font-size: 0.82rem;
}

.spec-card > .tag {
  flex-shrink: 0;
  margin-top: 0.2rem;
}

.spec-card-byline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.6rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.byline-item + .byline-item::before {
  content: '·';
  margin-right: 0.6rem;
  opacity: 0.6;
}

.byline-authors {
  color: var(--text);
  font-weight: 500;
}

.spec-id {
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(147, 197, 253, 0.14);
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.2px;
}

:root[data-theme='light'] .spec-id {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

.spec-dir {
  opacity: 0.8;
}

.spec-title {
  font-size: 1.1rem;
  font-weight: 650;
  color: var(--text);
}

.spec-authors {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.35rem 0 0.25rem;
  color: var(--muted);
}

.spec-author-list {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.meta-label {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 0.8rem;
  display: inline-block;
  width: 5rem;
  align-self: flex-end;
}

.meta-value {
  flex: 1;
  min-width: 0;
}

.meta-value--markdown {
  line-height: 1.5;
}

.meta-value--markdown p {
  margin: 0.15rem 0;
}

.meta-value--markdown p:first-child {
  margin-top: 0;
}

.meta-value--markdown p:last-child {
  margin-bottom: 0;
}

.meta-divider {
  color: var(--muted);
  margin: 0 0.4rem;
}

.spec-author-link,
.spec-metadata-link {
  font-weight: 600;
  color: var(--text);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.spec-author-link:hover,
.spec-metadata-link:hover {
  color: var(--accent);
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  background: rgba(100, 116, 139, 0.12);
  color: #475569;
}

:root[data-theme='dark'] .tag {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.tag::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}

a.tag {
  text-decoration: none;
}

a.tag:hover {
  text-decoration: none;
  filter: brightness(0.97);
}

a.tag:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tag.discussion,
.tag.progress,
.tag.review {
  background: rgba(59, 130, 246, 0.1);
  color: #1d4ed8;
}

:root[data-theme='dark'] .tag.discussion,
:root[data-theme='dark'] .tag.progress,
:root[data-theme='dark'] .tag.review {
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
}

.tag.draft {
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
}

:root[data-theme='dark'] .tag.draft {
  background: rgba(251, 191, 36, 0.14);
  color: #fbbf24;
}

.tag.implemented,
.tag.completed,
.tag.done {
  background: rgba(16, 185, 129, 0.1);
  color: #047857;
}

:root[data-theme='dark'] .tag.implemented,
:root[data-theme='dark'] .tag.completed,
:root[data-theme='dark'] .tag.done {
  background: rgba(52, 211, 153, 0.14);
  color: #6ee7b7;
}

.tag.published {
  background: rgba(139, 92, 246, 0.1);
  color: #6d28d9;
}

:root[data-theme='dark'] .tag.published {
  background: rgba(167, 139, 250, 0.15);
  color: #c4b5fd;
}

.tag.abandoned {
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
}

:root[data-theme='dark'] .tag.abandoned {
  background: rgba(248, 113, 113, 0.14);
  color: #fca5a5;
}

.back-link {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  color: var(--muted);
  margin-top: 1rem;
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.spec-header {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;

  margin-bottom: 1rem;
  margin-top: 1rem;
}

.spec-header h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2.2vw, 2rem);
}

.spec-id-block {
  width: 5rem;
  display: inline-block;
  align-self: flex-end;
  margin-bottom: 0.3em;
}

.spec-title-block {
  /* display: flex; */
  /* flex-direction: column; */
  /* gap: 0.35rem; */
}

.spec-dates {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.25rem 0 1rem;
}

.spec-date {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.doc-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  grid-template-areas: "content toc";
  gap: 2.25rem;
  align-items: start;
  margin-top: 2.25rem;
}

.doc-layout.doc-layout--single {
  grid-template-columns: 1fr;
  grid-template-areas: "content";
}

.doc-content {
  grid-area: content;
  /* background: var(--panel); */
  /* border: 1px solid var(--border); */
  /* border-radius: 14px; */
  /* box-shadow: 0 18px 48px var(--shadow); */
  line-height: 1.65;
  color: var(--text);
  padding: 0 0 0 6rem;
}

.doc-content h1,
.doc-content h2,
.doc-content h3,
.doc-content h4 {
  color: var(--text);
  margin-top: 1.4em;
  margin-bottom: 0.35em;
}

.doc-content a {
  color: var(--accent);
}

.doc-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.25rem auto;
  border-radius: 10px;
  box-shadow: 0 12px 28px var(--shadow);
}

.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}

.doc-content th,
.doc-content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
}

.doc-content :not(pre) > code {
  background: rgba(255, 255, 255, 0.04);
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
}

:root[data-theme='light'] .doc-content :not(pre) > code {
  background: rgba(15, 23, 42, 0.05);
}

.doc-content pre {
  background: #0b1220;
  border-radius: 10px;
  padding: 1rem;
  overflow-x: auto;
  border: 1px solid var(--border);
}

.doc-content pre code {
  background: inherit;
  padding: 0;
  border-radius: 0;
  display: block;
}

:root[data-theme='light'] .doc-content pre {
  background: #f7f9fb;
  border-color: rgba(0, 0, 0, 0.08);
}

.doc-content pre.mermaid[data-processed] {
  background: transparent;
  border: none;
  padding: 0.35rem 0;
  overflow: visible;
}

.doc-content pre.mermaid[data-processed] svg {
  max-width: 100%;
  height: auto;
}

.doc-content .svgbob svg {
  max-width: 100%;
  height: auto;
  display: block;
}

.doc-content ul,
.doc-content ol {
  padding-left: 1.2rem;
}

.mini-toc {
  grid-area: toc;
  position: sticky;
  top: 6.5rem;
  background: var(--surface);
  padding: 1rem;
  max-height: calc(100vh - 7rem);
  overflow: auto;
  font-size: 0.8rem;
}

.mini-toc__title {
  margin: 0;
  /* font-size: 0.95rem; */
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}

.mini-toc__list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0;
  display: flex;
  flex-direction: column;
}

.mini-toc__item a {
  display: block;
  padding: 0.35rem 0.5rem 0.35rem 0.9rem;
  color: var(--text);
  text-decoration: none;
  border-left: 3px solid var(--border);
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.mini-toc__item.level-3 a {
  padding-left: 1.4rem;
  /* font-size: 0.95rem; */
}

.mini-toc__item.level-4 a {
  padding-left: 1.9rem;
  /* font-size: 0.92rem; */
}

.mini-toc__item a:hover {
  background: rgba(255, 255, 255, 0.04);
  border-left-color: rgba(255, 255, 255, 0.3);
  text-decoration: none;
}

:root[data-theme='light'] .mini-toc__item a:hover {
  background: rgba(37, 99, 235, 0.08);
  border-left-color: rgba(15, 23, 42, 0.15);
}

.mini-toc__item a.active {
  color: var(--accent);
  border-left-color: var(--accent);
}

:root[data-theme='light'] .mini-toc__item a.active {
  /* background: rgba(37, 99, 235, 0.12); */
}

.mini-toc[hidden] {
  display: none !important;
}

@media (max-width: 1100px) {
  .doc-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "content";
  }

  .mini-toc {
    display: none;
  }

  .doc-content {
    padding: clamp(1.25rem, 3vw, 2.25rem);
  }
}

@media (max-width: 720px) {
  .mini-toc {
    padding: 0.75rem;
  }

  .mini-toc__item a {
    padding: 0.3rem 0.4rem;
  }
}

.empty-state {
  margin-top: 2rem;
  color: var(--muted);
}

.theme-toggle {
  margin-left: auto;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
  border: 1px solid transparent;
  border-radius: 8px;
}

.theme-toggle:hover {
  background: var(--input);
  color: var(--text);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

:root[data-theme-mode='auto'] .theme-toggle {
  border: 1px dashed var(--border);
}

/* Hero header with create button */
.hero-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.create-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.create-btn:hover {
  background: var(--accent);
  color: var(--accent-contrast);
}

.create-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  width: min(480px, 90vw);
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  margin: 0 0 1rem;
  font-size: 1.25rem;
}

.modal-content label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.modal-content input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.modal-content input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.create-preview {
  margin: 0.75rem 0 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.create-preview code {
  padding: 0.2rem 0.4rem;
  background: var(--surface);
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.btn-primary,
.btn-secondary {
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: opacity 120ms ease;
}

.btn-primary {
  color: var(--accent-contrast);
  background: var(--accent);
}

.btn-secondary {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

.btn-primary:hover,
.btn-secondary:hover {
  opacity: 0.9;
}

.btn-primary:focus-visible,
.btn-secondary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
