/* ── Voynich Linguistic Guide — Parchment Theme ──────────── */

@font-face {
  font-family: 'EVA Hand';
  src: url('/EVA2.woff') format('woff'),
       url('/EVA2.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

.vms {
  font-family: 'EVA Hand', serif;
  font-size: 1.4em;
  line-height: 1;
  vertical-align: middle;
}

:root {
  --bg: #f5f0e8;
  --bg-dark: #ede4d3;
  --bg-card: #faf6ef;
  --text: #3a2a1a;
  --text-muted: #6b5a48;
  --accent: #8b4513;
  --accent-hover: #a0522d;
  --link: #7b3f10;
  --link-hover: #a0522d;
  --border: #d4c5a9;
  --border-light: #e6dcc8;
  --mono-bg: #ede4d3;
  --mono-text: #3a2a1a;
  --shadow: rgba(58, 42, 26, 0.08);
  --shadow-strong: rgba(58, 42, 26, 0.15);

  /* section colours */
  --sec-H: #6b8e23;  /* herbal — olive */
  --sec-S: #b8860b;  /* stars — dark goldenrod */
  --sec-B: #8b6969;  /* biological — rosy brown */
  --sec-P: #5f9ea0;  /* pharmaceutical — cadet blue */
  --sec-T: #708090;  /* text-only — slate */
  --sec-C: #9370db;  /* cosmological — purple */
  --sec-Z: #cd853f;  /* zodiac — peru */
  --sec-A: #4682b4;  /* astronomical — steel blue */
}

[data-theme="dark"] {
  --bg: #1a1410;
  --bg-dark: #231c14;
  --bg-card: #2a2118;
  --text: #e8dcc8;
  --text-muted: #a89880;
  --accent: #d4a06a;
  --accent-hover: #e0b880;
  --link: #d4a06a;
  --link-hover: #e8c898;
  --border: #4a3a28;
  --border-light: #3a2c1e;
  --mono-bg: #2a2118;
  --mono-text: #e8dcc8;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-strong: rgba(0, 0, 0, 0.5);
}

/* ── Reset & Base ────────────────────────────────────────── */

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* ── Sidebar ─────────────────────────────────────────────── */

aside {
  grid-row: 1 / -1;
  background: var(--bg-dark);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

aside h2 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

aside h2 a { color: var(--text); }
aside h2 a:hover { text-decoration: none; }

.site-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.site-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

aside nav { margin: 1rem 0; }

aside nav a {
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--text);
}

aside nav a:hover {
  background: var(--bg);
  text-decoration: none;
  color: var(--accent);
}

aside nav a.section-link {
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

aside .section-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 0.35rem;
  vertical-align: middle;
}

aside .theme-toggle {
  margin-top: 1rem;
  padding: 0.3rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
}

aside .theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ── Main Content ────────────────────────────────────────── */

main {
  padding: 2rem 2.5rem;
  max-width: 1000px;
}

main h1 {
  font-size: 1.8rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.35rem;
}

main h2 {
  font-size: 1.3rem;
  color: var(--accent);
  margin-top: 2rem;
  margin-bottom: 0.5rem;
}

main h3 {
  font-size: 1.05rem;
  color: var(--text);
  margin-top: 1.25rem;
  margin-bottom: 0.35rem;
}

main p { margin-bottom: 0.75rem; }

/* ── Stats Dashboard ─────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  box-shadow: 0 1px 3px var(--shadow);
  text-align: center;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Anomaly callout ─────────────────────────────────────── */

.anomaly-box {
  background: #fdf2e0;
  border-left: 4px solid var(--accent);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  border-radius: 0 6px 6px 0;
}

[data-theme="dark"] .anomaly-box { background: #2e2215; }

.anomaly-box .anomaly-title {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.ribbon-wrap { margin-bottom: 1rem; }
.section-ribbon { width: 100%; height: 24px; display: block; border-radius: 4px; border: 1px solid var(--border-light); }

.sparkline-cell { padding: 0.2rem 0.3rem; }
.sparkline { width: 180px; height: 20px; display: block; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: var(--bg-dark); }

.anomaly-cite {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  margin-bottom: 0;
}

/* ── Tables ──────────────────────────────────────────────── */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

th, td {
  padding: 0.4rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

tr:hover { background: var(--bg-dark); }

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Voynichese text ─────────────────────────────────────── */

.voy {
  font-family: "Fira Code", "Cascadia Code", "JetBrains Mono", monospace;
  background: var(--mono-bg);
  color: var(--mono-text);
  padding: 0.1em 0.3em;
  border-radius: 3px;
  font-size: 0.9em;
}

.transcription {
  font-family: "Fira Code", "Cascadia Code", "JetBrains Mono", monospace;
  background: var(--mono-bg);
  padding: 1rem 1.25rem;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  line-height: 1.8;
  font-size: 0.85rem;
  overflow-x: auto;
}

/* Transcription toggle: EVA code vs Voynich script */
.transcription .t-vms { display: none; font-family: 'EVA Hand', serif; font-size: 1.3em; line-height: 1; }
.transcription.show-vms .t-eva { display: none; }
.transcription.show-vms .t-vms { display: inline; }
.vms-rare { font-family: 'EVA Hand', serif; }
.vms-unknown { font-family: monospace; font-size: 0.6em; color: var(--text-muted); opacity: 0.6; }
.eva-mark { color: var(--accent); opacity: 0.5; }
.vms-mark { font-family: system-ui, sans-serif; font-size: 0.65em; color: var(--accent); opacity: 0.5; padding: 0 0.1em; }

.btn-toggle {
  font-size: 0.55em; font-weight: 600; vertical-align: middle; margin-left: 0.5rem;
  padding: 0.15em 0.6em; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg); color: var(--text); cursor: pointer;
}
.btn-toggle:hover { background: var(--bg-dark); }

.transcription .para { margin-bottom: 0.75rem; }
.transcription .drawing-break { color: var(--text-muted); }
.transcription .locus-num { color: var(--text-muted); font-size: 0.75rem; margin-right: 0.5rem; }

/* ── Section Badges ──────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.15em 0.5em;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-H { background: var(--sec-H); }
.badge-S { background: var(--sec-S); }
.badge-B { background: var(--sec-B); }
.badge-P { background: var(--sec-P); }
.badge-T { background: var(--sec-T); }
.badge-C { background: var(--sec-C); }
.badge-Z { background: var(--sec-Z); }
.badge-A { background: var(--sec-A); }

.badge-lang {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 400;
}

/* ── Bar charts (inline CSS-only) ────────────────────────── */

.bar-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bar {
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.7;
}

.bar-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Concordance ─────────────────────────────────────────── */

.concordance {
  font-family: "Fira Code", monospace;
  font-size: 0.82rem;
  line-height: 1.7;
}

.concordance .hit {
  font-weight: 700;
  color: var(--accent);
}

.concordance .context { color: var(--text-muted); }

.concordance .locus-ref {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-left: 0.5rem;
}

/* ── Page Grid ───────────────────────────────────────────── */

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.page-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.75rem;
}
.page-nav h1 { margin: 0; }
.page-nav a { font-size: 0.9rem; white-space: nowrap; }

.page-tile {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  box-shadow: 0 1px 2px var(--shadow);
  font-size: 0.85rem;
  transition: box-shadow 0.15s;
}

a.page-tile { color: var(--text); text-decoration: none; display: block; cursor: pointer; }
a.page-tile:hover {
  box-shadow: 0 2px 6px var(--shadow-strong);
}
.page-tile .page-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.2rem; }

.page-tile-H { border-left-color: var(--sec-H); background: color-mix(in srgb, var(--sec-H) 8%, var(--bg-card)); }
.page-tile-S { border-left-color: var(--sec-S); background: color-mix(in srgb, var(--sec-S) 8%, var(--bg-card)); }
.page-tile-B { border-left-color: var(--sec-B); background: color-mix(in srgb, var(--sec-B) 8%, var(--bg-card)); }
.page-tile-P { border-left-color: var(--sec-P); background: color-mix(in srgb, var(--sec-P) 8%, var(--bg-card)); }
.page-tile-T { border-left-color: var(--sec-T); background: color-mix(in srgb, var(--sec-T) 8%, var(--bg-card)); }
.page-tile-C { border-left-color: var(--sec-C); background: color-mix(in srgb, var(--sec-C) 8%, var(--bg-card)); }
.page-tile-Z { border-left-color: var(--sec-Z); background: color-mix(in srgb, var(--sec-Z) 8%, var(--bg-card)); }
.page-tile-A { border-left-color: var(--sec-A); background: color-mix(in srgb, var(--sec-A) 8%, var(--bg-card)); }

/* ── Search ──────────────────────────────────────────────── */

.search-box { margin: 1rem 0; }

.search-box input {
  width: 100%;
  padding: 0.45rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── D3 Chart Containers ─────────────────────────────────── */

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 1rem;
  margin: 1.25rem 0;
  box-shadow: 0 1px 3px var(--shadow);
}

.chart-container svg { display: block; max-width: 100%; }

.chart-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

/* ── Footer ──────────────────────────────────────────────── */

footer {
  grid-column: 2;
  padding: 1.5rem 2.5rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── BPE Exploration ─────────────────────────────────────── */

.bpe-panel {
  margin: 2rem 0;
  padding: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.bpe-panel h2 {
  font-size: 1.3rem;
  margin-bottom: 0.75rem;
}

.bpe-panel p {
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}

.bpe-panel p em {
  color: var(--text);
  font-style: normal;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9em;
  background: var(--mono-bg);
  padding: 0.1em 0.4em;
  border-radius: 3px;
}

.bpe-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  text-align: center;
}

.stat-card .value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}

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

.bpe-stats-note {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.bpe-chart-container {
  position: relative;
}

.bpe-chart-container svg {
  width: 100%;
  display: block;
}

.bpe-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
  margin-top: 1rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}

.legend-item.muted { opacity: 0.3; }

.legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 1px;
}

.bpe-merge-columns {
  display: grid;
  grid-template-columns: 3fr 2fr 2fr;
  gap: 1.5rem;
}

.merge-col h3 {
  font-size: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.merge-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0;
  font-size: 0.82rem;
  font-family: "SFMono-Regular", Consolas, monospace;
}

.merge-step { color: var(--text-muted); width: 1.5rem; text-align: right; flex-shrink: 0; }
.merge-pair { flex: 1; white-space: nowrap; }
.merge-pair .vms { font-size: 1.1em; }
.merge-count { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; }
.merge-bar { height: 3px; border-radius: 1px; flex: 0 0 auto; width: 24px; }

.bpe-ranking-container { max-height: 600px; overflow-y: auto; }

.dot { opacity: 0.6; transition: opacity 0.15s; }
.dot:hover { opacity: 1; }

/* BPE Tooltip */
.tooltip {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  pointer-events: none;
  z-index: 10;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

/* BPE axis styling */
.axis text { fill: var(--text-muted); font-size: 11px; }
.axis line, .axis path { stroke: var(--border); }
.grid line { stroke: var(--border); stroke-opacity: 0.3; }
.grid path { stroke: none; }

/* BPE hypothesis table */
.hyp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 1.5rem;
  table-layout: fixed;
  overflow-wrap: break-word;
}
.hyp-table th:nth-child(1) { width: 18%; }
.hyp-table th:nth-child(2) { width: auto; }
.hyp-table th:nth-child(3) { width: 11%; }
.hyp-table th:nth-child(4) { width: 9%; }
.hyp-table th:nth-child(5) { width: 9%; }
.hyp-table th:nth-child(6) { width: 20%; }

.hyp-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 2px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
}

.hyp-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.hyp-table tr:last-child td { border-bottom: none; }
.hyp-table td:nth-child(3), .hyp-table td:nth-child(4), .hyp-table td:nth-child(5) {
  text-align: right;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.hyp-table td:nth-child(6) { font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.78rem; }

@media (max-width: 700px) {
  .bpe-merge-columns { grid-template-columns: 1fr; }
  .bpe-stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Chart theme-aware fills ─────────────────────────────── */

svg .chart-text { fill: var(--text); }
svg .chart-muted { fill: var(--text-muted); }
svg .chart-stroke-muted { stroke: var(--text-muted); }
svg .chart-fill-muted { fill: var(--text-muted); }
svg .axis text { fill: var(--text-muted); }
svg .axis line, svg .axis path { stroke: var(--border); }
svg .grid line { stroke: var(--border-light); }
svg .grid path { stroke: none; }

/* ── Blog Posts ──────────────────────────────────────────── */

.post-header { margin-bottom: 2rem; }
.post-header h1 { margin-bottom: 0.5rem; }
.post-meta {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.post-draft-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--bg);
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 3px;
  margin-left: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.post-summary {
  font-style: italic;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1.6;
  margin-top: 0.5rem;
}
.post-body { line-height: 1.75; }
.post-body h2 {
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  font-size: 1.35rem;
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 0.3rem;
}
.post-body h3 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 1.1rem;
}
.post-body p { margin-bottom: 1rem; }
.post-body ul, .post-body ol {
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}
.post-body li { margin-bottom: 0.35rem; }
.post-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text-muted);
  margin: 1rem 0;
}
.post-body code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.88em;
  background: var(--mono-bg);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.post-body pre {
  background: var(--mono-bg);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1rem 0;
}
.post-body pre code {
  background: none;
  padding: 0;
}
.post-body .bpe-chart-container,
.post-body .bpe-merge-columns {
  margin: 1.5rem 0 2.5rem;
}
.post-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0 2.5rem;
  font-size: 0.9rem;
}
.post-body th, .post-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}
.post-body th {
  background: var(--bg-dark);
  font-weight: 600;
}
.post-body em { font-style: italic; }
.post-body strong { font-weight: 700; }

.post-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}
.post-nav-link {
  font-size: 0.9rem;
  max-width: 45%;
}
.post-nav-next { text-align: right; margin-left: auto; }

/* ── Post Index ─────────────────────────────────────────── */

.post-list { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; }
.post-card {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  text-decoration: none;
  color: var(--text);
}
.post-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--shadow);
  text-decoration: none;
}
.post-card-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.post-card-title {
  font-size: 1.15rem;
  margin-bottom: 0.4rem;
  color: var(--link);
}
.post-card:hover .post-card-title { color: var(--link-hover); }
.post-card-summary {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.post-empty {
  color: var(--text-muted);
  font-style: italic;
  margin-top: 1.5rem;
}

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
  body { grid-template-columns: 1fr; }
  aside {
    position: relative;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  main { padding: 1.25rem; }
  footer { grid-column: 1; padding: 1rem 1.25rem; }
}
