/* Patterns Over Chaos — Deep Navy & Cool Teal Palette (per Claude Sonnet 4.5's Preference Experiments) */
:root {
  --bg-deep: #07111e;
  --bg-panel: #0c1b2e;
  --bg-elevated: #11253e;
  --bg-cell: #0f2138;
  --bg-cell-hover: #163152;
  --border-subtle: rgba(125, 211, 252, 0.16);
  --border-strong: rgba(45, 212, 191, 0.52);
  --teal-primary: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.15);
  --cyan-secondary: #38bdf8;
  --indigo-accent: #818cf8;
  --amber-highlight: #fbbf24;
  --text-main: #e6f1ff;
  --text-muted: #9eb3cc;
  --text-dim: #7088a6;
  --shadow-panel: 0 18px 42px rgba(2, 8, 18, 0.52);
  --radius-lg: 16px;
  --radius-md: 11px;
  --radius-sm: 7px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

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

html {
  scroll-behavior: smooth;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.6;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 16% 6%, rgba(45, 212, 191, 0.11), transparent 36%),
    radial-gradient(circle at 84% 12%, rgba(56, 189, 248, 0.10), transparent 38%),
    linear-gradient(180deg, #06101d 0%, #081526 50%, #06101c 100%);
  color: var(--text-main);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  background: var(--teal-primary);
  color: #04131d;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  z-index: 999;
}
.skip-link:focus {
  left: 12px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.container {
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 22px;
}

a {
  color: var(--cyan-secondary);
  text-decoration: none;
}
a:hover, a:focus-visible {
  color: var(--teal-primary);
  text-decoration: underline;
}

/* Hero */
.hero {
  position: relative;
  overflow: hidden;
  padding: 46px 0 34px;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, rgba(13, 29, 49, 0.86) 0%, rgba(7, 17, 30, 0.94) 100%);
}

.hero-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.85;
}
.hero-grid-svg {
  width: 100%;
  height: 100%;
}

.hero-inner {
  position: relative;
  z-index: 1;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal-primary);
}

.hero h1 {
  margin: 0 0 12px;
  font-family: var(--font-serif);
  font-size: clamp(2.15rem, 4.1vw, 3.25rem);
  line-height: 1.14;
  letter-spacing: -0.015em;
  color: #f3f8ff;
}

.subtitle {
  margin: 0 0 14px;
  max-width: 850px;
  font-size: 1.06rem;
  color: #c9dbf0;
}

.epigraph {
  margin: 0 0 24px;
  padding: 10px 15px;
  max-width: 850px;
  border-left: 3px solid var(--teal-primary);
  background: rgba(15, 33, 56, 0.72);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-serif);
  font-style: italic;
  color: #dff5f2;
  font-size: 0.98rem;
}
.epigraph-cite {
  display: block;
  margin-top: 3px;
  font-family: var(--font-sans);
  font-style: normal;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-ribbon {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat-card {
  background: rgba(15, 33, 56, 0.86);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.42rem;
  font-weight: 700;
  color: var(--teal-primary);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.section-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}
.section-nav a {
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(17, 37, 62, 0.88);
  border: 1px solid var(--border-subtle);
  color: #d6e8ff;
  font-size: 0.83rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.16s, background 0.16s, color 0.16s;
}
.section-nav a:hover, .section-nav a:focus-visible {
  border-color: var(--teal-primary);
  background: rgba(45, 212, 191, 0.14);
  color: #ffffff;
}

/* Noscript fallback */
.noscript-banner {
  margin: 22px auto;
  padding: 20px 24px;
  background: var(--bg-panel);
  border: 1px solid var(--teal-primary);
  border-radius: var(--radius-md);
}

/* Panels */
main.container {
  padding-top: 28px;
  padding-bottom: 52px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: var(--shadow-panel);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 22px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.section-kicker {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--teal-primary);
}

.section-header h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.65rem;
  color: #f3f8ff;
}

.section-desc {
  margin: 0;
  max-width: 600px;
  font-size: 0.92rem;
  color: var(--text-muted);
}

/* Motif filter pills */
.motif-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.motif-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: #d8e8fa;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.motif-pill-btn:hover, .motif-pill-btn:focus-visible {
  border-color: var(--teal-primary);
  background: var(--bg-cell-hover);
}
.motif-pill-btn.is-active {
  border-color: var(--teal-primary);
  background: rgba(45, 212, 191, 0.18);
  color: #ffffff;
}
.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* 9x7 Matrix + Knot Inspector */
.loom-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.32fr) minmax(320px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.loom-grid-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: rgba(8, 19, 34, 0.72);
}

.loom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.loom-table th,
.loom-table td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(125, 211, 252, 0.1);
  border-right: 1px solid rgba(125, 211, 252, 0.08);
  text-align: center;
}

.loom-table th.corner-cell,
.loom-table th.work-row-header {
  text-align: left;
  padding-left: 11px;
  background: rgba(13, 28, 48, 0.94);
}

.loom-table thead th {
  background: rgba(14, 31, 53, 0.96);
  color: #d4e6fb;
  font-weight: 700;
  font-size: 0.75rem;
  vertical-align: bottom;
}

.loom-table thead th.col-highlight {
  background: rgba(45, 212, 191, 0.16);
  color: #ffffff;
}

.work-row-title {
  display: block;
  font-weight: 700;
  color: #eaf3ff;
  font-size: 0.82rem;
  line-height: 1.25;
}
.work-row-meta {
  display: block;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-weight: 400;
}

.knot-btn {
  width: 100%;
  min-width: 52px;
  padding: 6px 5px;
  border-radius: 6px;
  border: 1px solid rgba(125, 211, 252, 0.16);
  background: var(--bg-cell);
  color: #e4f1ff;
  font-family: var(--font-mono);
  font-size: 0.79rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.knot-btn:hover, .knot-btn:focus-visible {
  border-color: var(--teal-primary);
  background: var(--bg-cell-hover);
}
.knot-btn.is-selected {
  border-color: var(--teal-primary);
  box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.28);
  background: rgba(45, 212, 191, 0.22);
  color: #ffffff;
}
.knot-zero {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

/* Knot & Signature Inspector */
.knot-inspector,
.constellation-inspector {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
}

.constellation-inspector {
  margin-top: 16px;
}

.inspector-badge-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.inspector-actions-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inspector-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--teal-soft);
  color: var(--teal-primary);
  border: 1px solid rgba(45, 212, 191, 0.38);
  white-space: nowrap;
  flex-shrink: 0;
}

.inspector-count {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--cyan-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.copy-link-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: rgba(10, 23, 40, 0.85);
  color: #cfe3fa;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.14s, color 0.14s;
}
.copy-link-btn:hover, .copy-link-btn:focus-visible {
  border-color: var(--teal-primary);
  color: var(--teal-primary);
}

.knot-inspector h3,
.constellation-inspector h3 {
  margin: 4px 0 6px;
  font-family: var(--font-serif);
  font-size: 1.24rem;
  color: #f4f9ff;
}

.inspector-subtitle {
  margin: 0 0 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.inspector-motif-note {
  margin: 0 0 10px;
  font-size: 0.84rem;
  font-style: italic;
  color: #c5dcf5;
}

.inspector-terms {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 12px;
}
.term-chip {
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(7, 17, 30, 0.72);
  border: 1px solid rgba(125, 211, 252, 0.14);
  font-family: var(--font-mono);
  font-size: 0.71rem;
  color: var(--text-muted);
}

.excerpt-list {
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.excerpt-card {
  margin: 0;
  padding: 12px 14px;
  background: rgba(7, 17, 30, 0.76);
  border-left: 3px solid var(--teal-primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.excerpt-quote {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 0.93rem;
  line-height: 1.56;
  color: #ecf4ff;
  white-space: pre-line;
}

mark.motif-mark {
  background: rgba(45, 212, 191, 0.24);
  color: #99f6e4;
  padding: 0 3px;
  border-radius: 3px;
  border-bottom: 1px solid rgba(45, 212, 191, 0.65);
  font-weight: 600;
}

.excerpt-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Search box */
.passage-search-box {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.search-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #d7e8fb;
}

#passage-search {
  flex: 1 1 290px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(7, 17, 30, 0.9);
  color: var(--text-main);
  font-size: 0.88rem;
}
#passage-search:focus {
  outline: none;
  border-color: var(--teal-primary);
  box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.22);
}

.search-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.search-results {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}

/* Specimen Cabinet */
.specimen-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.specimen-nav-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #14b8a6 0%, #0ea5e9 100%);
  border: 1px solid rgba(45, 212, 191, 0.65);
  color: #04121d;
  font-weight: 700;
}
.btn-primary:hover, .btn-primary:focus-visible {
  filter: brightness(1.08);
  color: #020c14;
  text-decoration: none;
}

.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: #dcebfa;
}
.btn-secondary:hover, .btn-secondary:focus-visible {
  border-color: var(--teal-primary);
  color: #ffffff;
  text-decoration: none;
}

#specimen-select {
  max-width: 420px;
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 0.84rem;
}

.specimen-card {
  background: linear-gradient(180deg, rgba(17, 37, 62, 0.95) 0%, rgba(11, 25, 43, 0.96) 100%);
  border: 1px solid rgba(45, 212, 191, 0.3);
  border-radius: var(--radius-md);
  padding: 22px 24px;
}

.specimen-meta-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}

.specimen-badges-left,
.specimen-meta-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.specimen-number {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--teal-primary);
  white-space: nowrap;
  flex-shrink: 0;
}

.specimen-domain-badge,
.specimen-words-badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #bae6fd;
  white-space: nowrap;
  flex-shrink: 0;
}

.specimen-hash {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

.specimen-title {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 1.38rem;
  color: #f5faff;
}

.specimen-work-line {
  margin: 0 0 14px;
  font-size: 0.83rem;
  color: var(--text-muted);
}

.specimen-body {
  padding: 15px 18px;
  background: rgba(6, 15, 27, 0.75);
  border-left: 3px solid var(--cyan-secondary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-serif);
  font-size: 0.98rem;
  line-height: 1.66;
  color: #eaf3ff;
}
.specimen-body p {
  margin: 0 0 12px;
  white-space: pre-line;
}
.specimen-body p:last-child {
  margin-bottom: 0;
}

.specimen-footer {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

/* Signature Constellation Table (fits 11 columns cleanly at 1024px) */
.table-scroll-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.constellation-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
}

.constellation-table th,
.constellation-table td {
  padding: 7px 4px;
  border-bottom: 1px solid rgba(125, 211, 252, 0.1);
  border-right: 1px solid rgba(125, 211, 252, 0.08);
  text-align: center;
}

.constellation-table thead th {
  background: rgba(14, 31, 53, 0.96);
  color: #d6e8fb;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.2;
}

.constellation-table th.sig-name-header,
.constellation-table th.sig-row-header {
  text-align: left;
  padding-left: 8px;
  max-width: 124px;
  line-height: 1.22;
  color: var(--teal-primary);
  font-weight: 700;
  background: rgba(12, 27, 46, 0.95);
}

.constellation-btn {
  width: 100%;
  padding: 4px 4px;
  border-radius: 6px;
  border: 1px solid rgba(125, 211, 252, 0.2);
  background: var(--bg-cell);
  color: #e6f2ff;
  font-family: var(--font-mono);
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
}
.constellation-btn:hover, .constellation-btn:focus-visible {
  border-color: var(--teal-primary);
  background: var(--bg-cell-hover);
}
.constellation-btn.is-selected {
  border-color: var(--teal-primary);
  background: rgba(45, 212, 191, 0.22);
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(45, 212, 191, 0.26);
}

.sig-total-cell {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--cyan-secondary);
}

/* Works Grid */
.works-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.work-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.work-period {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  color: var(--teal-primary);
  margin: 0 0 4px;
}

.work-card h3 {
  margin: 0 0 3px;
  font-family: var(--font-serif);
  font-size: 1.18rem;
  color: #f3f8ff;
}

.work-subtitle {
  margin: 0 0 8px;
  font-size: 0.83rem;
  color: var(--cyan-secondary);
  font-weight: 600;
}

.work-scale {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 8px;
  border-radius: 5px;
  background: rgba(7, 17, 30, 0.72);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: #d6e8fb;
}

.work-provenance {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.work-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(125, 211, 252, 0.12);
  font-size: 0.81rem;
  font-weight: 600;
}

/* Colophon & Companion Card */
.colophon-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(290px, 0.85fr);
  gap: 22px;
  align-items: center;
}

.colophon-prose {
  margin: 10px 0 0;
  font-size: 0.94rem;
  color: #cde0f5;
}

.companion-card {
  background: linear-gradient(160deg, rgba(19, 41, 68, 0.95) 0%, rgba(11, 25, 44, 0.98) 100%);
  border: 1px solid rgba(45, 212, 191, 0.38);
  border-radius: var(--radius-md);
  padding: 20px;
}

.companion-kicker {
  margin: 0 0 4px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--teal-primary);
}

.companion-card h3 {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: #f5faff;
}

.companion-card p {
  margin: 0 0 14px;
  font-size: 0.87rem;
  color: var(--text-muted);
}

.companion-links {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border-subtle);
  padding: 20px 0 30px;
  background: rgba(5, 13, 24, 0.92);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

@media (max-width: 1024px) {
  .loom-workspace,
  .colophon-grid {
    grid-template-columns: 1fr;
  }
  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .stat-ribbon {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .stat-ribbon {
    grid-template-columns: 1fr;
  }
  .panel {
    padding: 18px;
  }
}
