:root,
[data-theme="obsidian"] {
  --bg: #0a0b0d;
  --bg-alt: #101216;
  --surface: #14171d;
  --border: rgba(236, 235, 230, 0.1);
  --border-strong: rgba(200, 169, 126, 0.4);
  --text: #ecebe6;
  --muted: #9499a3;
  --accent: #c8a97e;
  --accent-soft: rgba(200, 169, 126, 0.14);
  --danger: #e07a5f;
  --ok: #81b29a;
}

[data-theme="paper"] {
  --bg: #f6f3ec;
  --bg-alt: #ede8dd;
  --surface: #fbf9f4;
  --border: rgba(24, 24, 26, 0.12);
  --border-strong: rgba(120, 85, 39, 0.45);
  --text: #17181a;
  --muted: #575a61;
  --accent: #785527;
  --accent-soft: rgba(120, 85, 39, 0.12);
  --danger: #b5442b;
  --ok: #2d6a4f;
}

/* Metric-matched fallback font descriptors to guarantee CLS = 0.00 */
@font-face {
  font-family: "Fallback Serif";
  src: local("Georgia"), local("Times New Roman");
  ascent-override: 95%;
  descent-override: 25%;
  line-gap-override: 0%;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  transition: background-color 0.25s ease, color 0.25s ease;
  -webkit-font-smoothing: antialiased;
}

/* SKIP LINK FOR ACCESSIBILITY (WCAG AAA) */
.skip-link {
  position: absolute;
  top: -999px;
  left: 1rem;
  z-index: 1000;
  background: var(--surface);
  color: var(--accent);
  padding: 0.5rem 1rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82rem;
  text-decoration: none;
  font-weight: 500;
}

.skip-link:focus {
  top: 1rem;
}

.container {
  width: min(1040px, 92vw);
  margin: 0 auto;
}

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

/* TOPBAR */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
  gap: 0.8rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

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

.nav-links {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.88rem;
}

.nav-links a {
  color: var(--muted);
  transition: color 0.15s ease;
}

.nav-links a:hover {
  color: var(--text);
}

.ghost-pill {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.76rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.ghost-pill:hover {
  border-color: var(--border-strong);
}

kbd {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  opacity: 0.75;
}

/* HERO */
.hero {
  position: relative;
  overflow: hidden;
  padding: 5.5rem 0 4.5rem;
  border-bottom: 1px solid var(--border);
}

#harmony-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.75;
}

.hero-content {
  position: relative;
  z-index: 2;
}

.epigraph {
  font-family: "Instrument Serif", "Fallback Serif", Georgia, serif;
  font-style: italic;
  font-size: clamp(1.3rem, 2.4vw, 1.65rem);
  color: var(--accent);
  margin: 0 0 1.25rem;
}

.epigraph-author {
  font-style: normal;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
  margin-left: 0.4rem;
}

.hero h1 {
  font-family: "Instrument Serif", "Fallback Serif", Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.2rem, 4.7vw, 3.55rem);
  line-height: 1.12;
  letter-spacing: -0.01em;
  max-width: 19ch;
  margin: 0 0 1.35rem;
}

.lead {
  max-width: 66ch;
  color: var(--muted);
  font-size: 1.04rem;
  margin: 0 0 2rem;
}

.lead strong {
  color: var(--text);
  font-weight: 500;
}

.credential-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.8rem;
}

.cred-chip {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  transition: border-color 0.2s ease;
}

a.cred-chip:hover {
  border-color: var(--border-strong);
}

.cred-kicker,
.mono-label,
.kicker {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.cred-chip strong {
  font-size: 0.88rem;
  font-weight: 500;
}

.canvas-control-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px dashed var(--border);
}

.canvas-control-bar input[type="range"] {
  accent-color: var(--accent);
  width: 160px;
  cursor: pointer;
}

.canvas-hint {
  font-size: 0.82rem;
  color: var(--muted);
}

/* SECTIONS */
.section {
  padding: 4.5rem 0;
  border-bottom: 1px solid var(--border);
}

.section-alt {
  background: var(--bg-alt);
}

.section-head {
  margin-bottom: 2.2rem;
}

.kicker {
  color: var(--accent);
  display: block;
  margin-bottom: 0.45rem;
}

.section-head h2 {
  font-family: "Instrument Serif", "Fallback Serif", Georgia, serif;
  font-weight: 400;
  font-size: clamp(1.9rem, 3.3vw, 2.55rem);
  margin: 0 0 0.5rem;
  line-height: 1.18;
}

.section-sub {
  color: var(--muted);
  max-width: 64ch;
  margin: 0;
}

/* ACCORDION NOTES */
.notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.note-card.is-open {
  border-color: var(--border-strong);
}

.note-trigger {
  width: 100%;
  background: none;
  border: 0;
  color: inherit;
  padding: 1.15rem 1.3rem;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  text-align: left;
  cursor: pointer;
  gap: 0.8rem;
}

.note-num {
  font-family: "Instrument Serif", "Fallback Serif", Georgia, serif;
  font-style: italic;
  font-size: 1.35rem;
  color: var(--accent);
}

.note-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.note-title-wrap strong {
  font-size: 1.03rem;
  font-weight: 500;
}

.note-meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  color: var(--muted);
}

.note-icon {
  font-family: "JetBrains Mono", monospace;
  font-size: 1.1rem;
  color: var(--accent);
}

.note-body {
  display: none;
  padding: 0 1.3rem 1.35rem 4.35rem;
  color: var(--muted);
}

.note-card.is-open .note-body {
  display: block;
}

.note-body p {
  margin: 0 0 0.85rem;
  max-width: 68ch;
}

.note-body p:last-child {
  margin-bottom: 0;
}

/* INTERACTIVE LAB */
.lab-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
}

/* MASTER LAB TABS */
.lab-main-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.2rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.tab-pill {
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-pill:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.tab-pill.active {
  border-color: var(--border-strong);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.lab-tab-panel[hidden] {
  display: none !important;
}

.lab-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem;
}

.seg-btn {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 999px;
  padding: 0.42rem 0.9rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.76rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

.lab-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.lab-actions select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.76rem;
  margin-left: 0.35rem;
}

.lab-slider-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.1rem;
}

.lab-slider-row label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lab-slider-row input[type="range"] {
  accent-color: var(--accent);
  width: 105px;
  cursor: pointer;
}

.lab-canvas-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

#leakage-canvas,
#smile-canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
}

.canvas-hover-readout {
  padding: 0.55rem 0.85rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  color: var(--muted);
  background: var(--bg);
  border-top: 1px solid var(--border);
  min-height: 28px;
  display: flex;
  align-items: center;
}

.lab-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  margin-top: 1rem;
}

.metric-item {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.metric-item strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.86rem;
  font-weight: 500;
}

.lab-note {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
  padding-top: 0.85rem;
  line-height: 1.6;
}

.lab-note strong {
  color: var(--text);
}

/* WORK GRID */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.filter-pill {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.38rem 0.85rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.76rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-pill.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.work-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 1.1rem;
}

.work-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.3rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color 0.2s ease;
}

.work-card:hover {
  border-color: var(--border-strong);
}

.work-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.work-idx {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.73rem;
  color: var(--accent);
}

.work-link {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.76rem;
  color: var(--muted);
}

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

.work-card h3 {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.35;
}

.work-card p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.work-card p strong {
  color: var(--text);
  font-weight: 500;
}

.work-card p a strong {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: 0.3rem;
}

.tag-row span {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  padding: 0.2rem 0.52rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.ci-toggle {
  align-self: flex-start;
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  cursor: pointer;
}

.ci-drawer {
  margin: 0;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--ok);
  overflow-x: auto;
  white-space: pre-wrap;
}

.ci-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.compact-links {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.87rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.compact-links a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.pattern-tag {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--ok);
  margin-top: 0.15rem;
}

/* NOW LEDGER */
.ledger {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.ledger-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 1rem;
  align-items: start;
}

.badge {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.71rem;
  text-transform: uppercase;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  text-align: center;
  border: 1px solid var(--border);
}

.badge-now {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--border-strong);
}

.badge-open {
  color: var(--ok);
  border-color: var(--ok);
}

.ledger-row strong {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
}

.ledger-row p {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

/* SHELF */
.shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
}

.shelf-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem;
}

.shelf-card h3 {
  font-size: 1rem;
  font-weight: 500;
  margin: 0.4rem 0 0.5rem;
}

.shelf-card h3 a:hover {
  color: var(--accent);
}

.shelf-card p {
  margin: 0;
  font-size: 0.89rem;
  color: var(--muted);
}

/* FOOTER */
.footer {
  padding: 3.5rem 0 2.5rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--border);
}

.footer-heading {
  font-family: "Instrument Serif", "Fallback Serif", Georgia, serif;
  font-size: 1.85rem;
  margin: 0 0 0.25rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.83rem;
}

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

.email-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}

.copy-tag {
  color: var(--accent);
  font-size: 0.72rem;
}

.colophon {
  padding-top: 1.2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  color: var(--muted);
}

/* COMMAND MODAL */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: start center;
  padding-top: 12vh;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-panel {
  width: min(520px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

#cmd-input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text);
  font-family: "Inter", sans-serif;
  font-size: 0.95rem;
  outline: none;
}

.cmd-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem;
  max-height: 310px;
  overflow-y: auto;
}

.cmd-list li {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--muted);
}

.cmd-list li:hover {
  background: var(--accent-soft);
  color: var(--text);
}

/* RESPONSIVE */
@media (max-width: 720px) {
  .mono-hide,
  .nav-links a {
    display: none;
  }
  .note-body {
    padding-left: 1.3rem;
  }
  .ledger-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  .badge {
    justify-self: start;
  }
  .lab-slider-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
}

/* PRINT BRIEF STYLESHEET (1-PAGE EXECUTIVE SUMMARY) */
@media print {
  @page {
    margin: 1.2cm;
    size: letter portrait;
  }

  body {
    background: #fff !important;
    color: #111 !important;
    font-size: 10.5pt;
    line-height: 1.45;
  }

  .skip-link,
  .topbar,
  #harmony-canvas,
  .canvas-control-bar,
  #lab,
  .filter-bar,
  .ci-toggle,
  .modal-backdrop,
  .ghost-pill,
  .print-btn,
  #cmd-btn,
  #theme-toggle {
    display: none !important;
  }

  .container {
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .hero {
    padding: 0.5rem 0 1.2rem !important;
    border-bottom: 2px solid #222 !important;
  }

  .hero h1 {
    font-size: 18pt !important;
    color: #000 !important;
    max-width: none !important;
    margin-bottom: 0.8rem !important;
  }

  .lead {
    font-size: 10pt !important;
    color: #333 !important;
    margin-bottom: 1rem !important;
  }

  .credential-strip {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.4rem !important;
  }

  .cred-chip {
    background: #fdfdfd !important;
    border: 1px solid #ccc !important;
    padding: 0.45rem !important;
  }

  .section {
    padding: 1.2rem 0 !important;
    border-bottom: 1px solid #ddd !important;
    page-break-inside: avoid;
  }

  .section-alt {
    background: transparent !important;
  }

  .section-head h2 {
    font-size: 13pt !important;
    color: #000 !important;
  }

  .note-card,
  .work-card,
  .ledger-row,
  .shelf-card {
    background: #fff !important;
    border: 1px solid #ddd !important;
    color: #111 !important;
    box-shadow: none !important;
    page-break-inside: avoid;
  }

  .note-body {
    display: block !important;
    padding-left: 1.2rem !important;
    color: #333 !important;
  }

  .note-icon {
    display: none !important;
  }

  .ci-drawer {
    display: block !important;
    color: #222 !important;
    border: 1px solid #ccc !important;
    background: #f9f9f9 !important;
  }

  .work-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.6rem !important;
  }

  .footer {
    padding: 1rem 0 !important;
    border-top: 1px solid #000 !important;
  }

  a {
    color: #000 !important;
    text-decoration: underline !important;
  }
}
