:root {
  --bg: #fafaf7;
  --panel-bg: #ffffff;
  --fg: #1c1c1a;
  --muted: #6b6b66;
  --rule: #d8d6cf;
  --accent: #a9221e;
  --accent-hover: #871a17;
  --pos: #2f7d3b;
  --neg: #c14a3c;
  --neu: #b3a877;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --panel-bg: #1c1d22;
    --fg: #ececea;
    --muted: #9d9d97;
    --rule: #2c2d33;
    --accent: #d6605c;
    --accent-hover: #ec7a76;
    --pos: #6db377;
    --neg: #d97a6c;
    --neu: #8c815a;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

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

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--rule);
  gap: 1.5rem;
}
.brand { display: flex; align-items: baseline; gap: 0.6rem; }
.brand h1 {
  font-family: ui-serif, Georgia, "Iowan Old Style", serif;
  font-size: 1.6rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand .logo {
  width: 22px; height: 22px;
  background: var(--accent);
  display: inline-block;
  border-radius: 3px;
  position: relative;
}
.brand .logo::before, .brand .logo::after {
  content: "";
  position: absolute;
  background: white;
}
.brand .logo::before { left: 4px; right: 4px; top: 9px; height: 4px; }
.brand .logo::after  { top: 4px; bottom: 4px; left: 9px; width: 4px; }
.brand .tagline {
  font-style: italic;
  color: var(--muted);
  font-size: 0.95rem;
}

.controls { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
fieldset.seg {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.25rem 0.5rem 0.25rem 0.6rem;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--panel-bg);
}
.seg legend {
  padding: 0 0.3rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.seg label {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.9rem; cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  transition: background 80ms;
}
.seg label:hover { background: var(--rule); }
.seg input[type=radio] { accent-color: var(--accent); }

.ui-lang {
  display: flex;
  gap: 0.1rem;
  font-size: 0.78rem;
}
.ui-lang button {
  background: none;
  border: 1px solid var(--rule);
  color: var(--muted);
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.05em;
}
.ui-lang button:first-child { border-radius: 4px 0 0 4px; }
.ui-lang button:last-child  { border-radius: 0 4px 4px 0; }
.ui-lang button + button    { border-left: none; }
.ui-lang button.active { color: var(--fg); font-weight: 600; background: var(--rule); }
.ui-lang button:hover { color: var(--accent); }

/* MAIN GRID */
main {
  display: grid;
  grid-template-columns: minmax(420px, 1.4fr) minmax(360px, 1fr);
  gap: 1.25rem;
  padding: 1.5rem 2rem;
  max-width: 1400px;
  margin: 0 auto;
}
.timeline-row { grid-column: 1 / -1; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

/* SPEAKER CARD */
.speaker-card { display: flex; gap: 1.25rem; align-items: flex-start; }
.map-wrap { flex: 1 1 auto; min-width: 320px; }
#ch-map { width: 100%; height: auto; max-height: 380px; }
#ch-cantons path {
  fill: color-mix(in srgb, var(--rule) 60%, var(--bg));
  stroke: color-mix(in srgb, var(--muted) 50%, transparent);
  stroke-width: 0.6;
  stroke-linejoin: round;
  transition: fill 200ms ease;
}
#ch-cantons path.active {
  fill: var(--accent);
  stroke: var(--accent);
  stroke-width: 1.2;
}
#ch-country path {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.2;
  stroke-linejoin: round;
  pointer-events: none;
}
#speaker-label text {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 11px;
  font-weight: 600;
  text-anchor: middle;
  fill: var(--fg);
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.meta { flex: 0 0 200px; min-width: 0; }
.year-big {
  font-size: 3.2rem;
  line-height: 1;
  font-weight: 700;
  font-family: ui-serif, Georgia, serif;
  letter-spacing: -0.02em;
}
.speaker-name {
  font-size: 1.15rem;
  margin-top: 0.35rem;
  font-weight: 600;
}
.speaker-meta {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* RIGHT PANEL — TABS */
.right-panel { display: flex; flex-direction: column; min-height: 380px; }
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--rule);
  margin: -0.4rem -0.5rem 0.6rem;
}
.tab {
  background: none;
  border: none;
  font: inherit;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--fg); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.tab-body { flex: 1; min-height: 0; overflow-y: auto; }

/* keyword bars */
.kw-row {
  display: grid;
  grid-template-columns: minmax(110px, max-content) 1fr 50px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.18rem 0;
  font-size: 0.92rem;
}
.kw-row .lemma { font-weight: 500; }
.kw-row .bar-wrap {
  height: 10px;
  background: var(--rule);
  border-radius: 6px;
  overflow: hidden;
}
.kw-row .bar {
  height: 100%;
  background: var(--accent);
  border-radius: 6px;
  transition: width 250ms;
}
.kw-row .freq {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: right;
}
.kw-empty {
  padding: 1rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

/* themes view */
.theme-card {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  margin: 0.4rem 0;
}
.theme-card.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.theme-card h3 {
  margin: 0 0 0.3rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.theme-card .keywords { color: var(--muted); font-size: 0.88rem; }
.theme-card .meta-line {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

/* TIMELINE */
.timeline-row h2 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.sentiment-strip {
  position: relative;
  height: 60px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background:
    linear-gradient(to bottom,
      color-mix(in srgb, var(--pos) 10%, transparent) 0%,
      color-mix(in srgb, var(--pos) 0%, transparent) 50%,
      color-mix(in srgb, var(--neg) 10%, transparent) 100%);
}
.sentiment-strip svg { width: 100%; height: 100%; display: block; }
.sentiment-strip .axis-line {
  stroke: var(--rule);
  stroke-width: 0.5;
  stroke-dasharray: 2,3;
}
.sentiment-strip .point {
  fill: var(--accent);
  cursor: pointer;
}
.sentiment-strip .point.active {
  fill: var(--fg);
  stroke: var(--accent);
  stroke-width: 1.5;
  r: 3.5;
}
.sentiment-strip .line {
  fill: none;
  stroke: color-mix(in srgb, var(--accent) 60%, transparent);
  stroke-width: 1.2;
}

.slider-wrap {
  margin-top: 0.6rem;
  position: relative;
}
#year-slider {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
}
.year-marks {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}

/* footer */
.meta-footer {
  border-top: 1px solid var(--rule);
  padding: 1rem 2rem;
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}
.meta-footer a {
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
}
.meta-footer a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* mobile */
@media (max-width: 760px) {
  .topbar { padding: 0.8rem 1rem; }
  main { padding: 1rem; grid-template-columns: 1fr; }
  .speaker-card { flex-direction: column; }
  .map-wrap { max-width: 220px; margin: 0 auto; }
  .meta { text-align: center; }
}
