/* ===================================================
   Distant Reading Visualization
   =================================================== */

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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252833;
  --text: #e0e0e0;
  --muted: #8b8fa3;
  --accent: #81b29a;
  --border: #2e3245;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}

a { color: var(--accent); }

/* ── Header ───────────────────────────────────────────────────────────────── */
header {
  text-align: center;
  padding: 3.5rem 1.5rem 2.5rem;
  border-bottom: 1px solid var(--border);
}
header h1 {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.4rem;
}
.subtitle {
  color: var(--muted);
  max-width: 640px;
  margin: 0 auto;
  font-size: 1rem;
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

section {
  padding: 2.5rem 0;
  border-bottom: 1px solid var(--border);
}
section:last-child { border-bottom: none; }

h2 {
  font-size: 1.5rem;
  margin-bottom: 0.6rem;
  color: #fff;
}

.section-desc {
  color: var(--muted);
  margin-bottom: 1.2rem;
  font-size: 0.92rem;
}

h3 { font-size: 1rem; margin-bottom: 0.5rem; }

.color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* ── Controls ─────────────────────────────────────────────────────────────── */
.controls {
  margin-bottom: 1.2rem;
}
.controls label {
  font-size: 0.88rem;
  color: var(--muted);
}
.controls select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  font-size: 0.88rem;
  margin-left: 0.3rem;
}

/* ── Corpus cards ─────────────────────────────────────────────────────────── */
.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.corpus-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: 6px;
  padding: 1.2rem 1.3rem;
}
.corpus-card h3 {
  font-size: 0.95rem;
  color: #fff;
  margin-bottom: 0.25rem;
}
.corpus-card .author {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}
.corpus-card .stats {
  display: flex;
  gap: 1.2rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.corpus-card .stats strong {
  color: var(--text);
}

/* ── Frequency charts ─────────────────────────────────────────────────────── */
#freq-charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 2rem;
}
.freq-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2rem;
}
.freq-block h3 {
  margin-bottom: 0.8rem;
  font-size: 0.9rem;
}
.bar-row {
  display: flex;
  align-items: center;
  margin-bottom: 2px;
  height: 18px;
}
.bar-label {
  width: 75px;
  text-align: right;
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--muted);
  padding-right: 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-track {
  flex: 1;
  height: 14px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}
.bar-val {
  width: 42px;
  text-align: right;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--muted);
  padding-left: 0.4rem;
}

/* ── Comparison chart ─────────────────────────────────────────────────────── */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.legend-item {
  display: flex;
  align-items: center;
}
.comp-row {
  display: flex;
  align-items: center;
  margin-bottom: 3px;
  padding: 2px 0;
  border-radius: 3px;
  transition: background 0.15s;
}
.comp-row:hover {
  background: var(--surface);
}
.comp-label {
  width: 90px;
  text-align: right;
  font-size: 0.82rem;
  font-family: var(--mono);
  padding-right: 0.7rem;
  color: var(--accent);
  font-weight: 600;
}
.comp-track {
  flex: 1;
  display: flex;
  height: 20px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.comp-seg {
  height: 100%;
  transition: width 0.3s;
  opacity: 0.85;
}
.comp-seg:hover { opacity: 1; }
.comp-total {
  width: 50px;
  text-align: right;
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--muted);
  padding-left: 0.5rem;
}

/* ── Concordance (KWIC) ──────────────────────────────────────────────────── */
.kwic-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.2rem;
  margin-bottom: 1rem;
}
.kwic-block h3 {
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}
.kwic-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.7;
}
.kwic-table td {
  padding: 0.15rem 0.3rem;
  vertical-align: top;
}
.kwic-left {
  text-align: right;
  color: var(--muted);
  width: 40%;
}
.kwic-kw {
  text-align: center;
  color: #fff;
  font-weight: 700;
  background: rgba(129, 178, 154, 0.2);
  border-radius: 2px;
  white-space: nowrap;
  width: 1%;
}
.kwic-right {
  color: var(--muted);
  width: 40%;
}
.empty {
  color: var(--muted);
  font-style: italic;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  header h1 { font-size: 1.5rem; }
  #freq-charts { grid-template-columns: 1fr; }
  .card-row { grid-template-columns: 1fr; }
  .bar-label { width: 60px; font-size: 0.65rem; }
  .comp-label { width: 70px; font-size: 0.75rem; }
  .kwic-table { font-size: 0.7rem; }
}
