/* ============================================================
 * Opettajien tekoälykysely — public results site
 * Shared design system: tokens + layout + question-page rules.
 *
 * Loaded globally via observablehq.config.js head.
 * ============================================================ */

/* ---------- 1. Design tokens ---------- */

:root {
  /* Colour — Finnish public-research paper feel.
   * Cooler than the terracotta-warm cliché; forest-teal accent
   * chosen to feel deliberate and non-tech. */
  --color-paper:        #F6F4EE;
  --color-surface-soft: #F2EDE0;
  --color-ink:          #1B222A;
  --color-muted:        #545C6A;
  --color-rule:         #D6D0BF;
  --color-rule-strong:  #B8B0A0;
  --color-accent:       #2C5147;
  --color-accent-soft:  #E4E9E4;

  /* Typography */
  --font-serif: "Source Serif 4", "Source Serif Pro", Georgia, "Times New Roman", serif;
  --font-sans:  "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;

  /* Scale */
  --step-fine:   0.8125rem;   /* 13px */
  --step-small:  0.9375rem;   /* 15px */
  --step-base:   1.0625rem;   /* 17px */
  --step-h4:     1.125rem;
  --step-h3:     1.375rem;
  --step-h2:     1.75rem;
  --step-h1:     clamp(1.75rem, 3.5vw, 2.5rem);
  --step-display: clamp(2.5rem, 6vw, 4.25rem);
  --step-monument: clamp(3.75rem, 9vw, 6rem);

  /* Rhythm */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.25rem;
  --space-7: 3.5rem;
  --space-8: 5rem;

  /* Layout */
  --measure:      64ch;
  --width-normal: 880px;
  --width-wide:   1120px;
}

/* Framework theme integration — the built-in light,wide theme reads
 * these variables, so stock components pick up our palette. */
:root {
  --theme-background:       var(--color-paper);
  --theme-background-alt:   var(--color-surface-soft);
  --theme-background-a:     var(--color-paper);
  --theme-foreground:       var(--color-ink);
  --theme-foreground-alt:   var(--color-muted);
  --theme-foreground-muted: var(--color-muted);
  --theme-foreground-focus: var(--color-accent);
  --theme-blue:             var(--color-accent);
  --theme-green:            var(--color-accent);
  --theme-red:              #8A2E2A;
  --theme-yellow:           #6A5820;
}

/* ---------- 2. Base body & typography ---------- */

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--step-base);
  line-height: 1.55;
  color: var(--color-ink);
  background: var(--color-paper);
  font-feature-settings: "kern", "liga", "calt", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--color-ink);
  line-height: 1.15;
  letter-spacing: -0.005em;
  margin: 0;
}
h1 { font-size: var(--step-h1); letter-spacing: -0.015em; }
h2 { font-size: var(--step-h2); letter-spacing: -0.01em; }
h3 { font-size: var(--step-h3); }
h4 { font-size: var(--step-h4); }

p { margin: 0 0 var(--space-4); }

a {
  color: var(--color-ink);
  text-decoration-color: var(--color-rule-strong);
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}
a:hover {
  color: var(--color-accent);
  text-decoration-color: var(--color-accent);
}
a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---------- 3. Page shell ---------- */

.page {
  max-width: var(--width-wide);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-8);
}
@media (min-width: 720px) {
  .page { padding: var(--space-7) var(--space-6) var(--space-8); }
}

/* Framework's <main> reserves its own max-width; open it so
 * our .page controls the frame. */
main { max-width: none; }

/* ---------- 4. Meta line ---------- */

.meta {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--step-small);
  color: var(--color-muted);
  margin: 0 0 var(--space-6);
}

/* ---------- 5. Hero (index page) ---------- */

.hero-title {
  font-family: var(--font-serif);
  font-size: var(--step-display);
  line-height: 1.05;
  font-weight: 500;
  letter-spacing: -0.02em;
  max-width: 20ch;
  margin: 0 0 var(--space-4);
  color: var(--color-ink);
}

.hero-lede {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: clamp(1.125rem, 2.2vw, 1.5rem);
  line-height: 1.4;
  color: var(--color-muted);
  max-width: 44ch;
  margin: 0 0 var(--space-6);
  font-weight: 400;
}

.hero-intro {
  max-width: var(--measure);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--color-ink);
  margin: 0 0 var(--space-6);
}

/* ---------- 6. Stat monument (the N = 1504 moment) ---------- */

.stat-monument {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: end;
  column-gap: var(--space-5);
  row-gap: var(--space-2);
  max-width: 40rem;
  margin: var(--space-6) 0 var(--space-8);
  padding-top: var(--space-5);
  border-top: 1px solid var(--color-rule-strong);
}
.stat-monument__figure {
  font-family: var(--font-serif);
  font-size: var(--step-monument);
  line-height: 0.95;
  font-weight: 500;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--color-ink);
}
.stat-monument__label {
  font-size: var(--step-small);
  color: var(--color-muted);
  line-height: 1.45;
  max-width: 28ch;
  padding-bottom: 0.35rem;
}
@media (max-width: 640px) {
  .stat-monument { grid-template-columns: 1fr; }
  .stat-monument__label { padding-bottom: 0; }
}

/* ---------- 7. Sections ---------- */

.section {
  margin: var(--space-8) 0 var(--space-5);
}
.section-title {
  display: block;
  margin: 0 0 var(--space-5);
}
.section-title h2 {
  font-family: var(--font-serif);
  font-size: var(--step-h3);
  font-weight: 500;
  margin: 0;
  padding-top: var(--space-3);
  border-top: 2px solid var(--color-ink);
  display: inline-block;
  padding-right: 3rem;
  letter-spacing: -0.005em;
}

/* ---------- 8. Question cards (index) ---------- */

.q-card-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  max-width: 44rem;
}
.q-card {
  display: block;
  padding: var(--space-5);
  padding-left: calc(var(--space-5) + var(--space-2));
  border-left: 3px solid var(--color-accent);
  border-top: 1px solid var(--color-rule);
  border-bottom: 1px solid var(--color-rule);
  background: transparent;
  color: var(--color-ink);
  text-decoration: none;
  transition: background 120ms ease-out;
}
.q-card:hover,
.q-card:focus-visible {
  background: var(--color-surface-soft);
  color: var(--color-ink);
  text-decoration: none;
  outline: none;
}
.q-card:focus-visible {
  box-shadow: inset 0 0 0 2px var(--color-accent);
}
.q-card__code {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--step-small);
  color: var(--color-accent);
  margin: 0 0 var(--space-2);
}
.q-card__title {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--color-ink);
  margin: 0 0 var(--space-3);
  letter-spacing: -0.01em;
}
.q-card__summary {
  font-size: 1rem;
  color: var(--color-ink);
  line-height: 1.55;
  margin: 0 0 var(--space-4);
  max-width: 48ch;
}
.q-card__meta {
  font-size: var(--step-fine);
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- 9. Policy list ---------- */

.policy-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-width: var(--measure);
  display: grid;
  gap: var(--space-3);
}
.policy-list li {
  padding-left: var(--space-4);
  border-left: 2px solid var(--color-rule-strong);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--color-ink);
}

/* ---------- 10. Backlink ---------- */

.backlink {
  font-family: var(--font-sans);
  font-size: var(--step-small);
  color: var(--color-muted);
  margin: 0 0 var(--space-5);
  display: inline-block;
}
.backlink a { color: inherit; text-decoration: none; }
.backlink a::before { content: "←"; margin-right: 0.4em; }
.backlink a:hover { color: var(--color-accent); }

/* ---------- 11. Q-page header ---------- */

.q-header {
  margin: 0 0 var(--space-5);
  max-width: 44rem;
}
.q-header__code {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--step-small);
  color: var(--color-accent);
  margin: 0 0 var(--space-3);
}
.q-header__title {
  font-family: var(--font-serif);
  font-size: var(--step-h1);
  line-height: 1.1;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--color-ink);
  margin: 0 0 var(--space-4);
  max-width: 20ch;
}
.q-header__question {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.1875rem;
  line-height: 1.45;
  color: var(--color-ink);
  margin: 0 0 var(--space-4);
  max-width: 42ch;
  font-weight: 400;
}
.q-header__instruction {
  font-size: var(--step-small);
  color: var(--color-muted);
  line-height: 1.55;
  margin: 0;
  max-width: 60ch;
}

/* Meta strip under the q-header (N, scale) */
.q-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3) var(--space-6);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-rule);
  border-bottom: 1px solid var(--color-rule);
  margin: 0 0 var(--space-6);
  font-variant-numeric: tabular-nums;
}
.q-meta__item {
  font-size: var(--step-small);
  color: var(--color-muted);
}
.q-meta__item b,
.q-meta__item strong {
  color: var(--color-ink);
  font-weight: 500;
}

/* ---------- 12. Matrix controls (existing shared component) ---------- */

.matrix-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(320px, 2.4fr);
  gap: var(--space-4);
  align-items: end;
  margin: var(--space-5) 0 var(--space-4);
}
.matrix-controls > * { min-width: 0; }
.matrix-controls form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
  margin: 0;
  width: 100%;
}
.matrix-controls form > label {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--step-fine);
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--color-muted);
  width: auto;
  min-width: 0;
  padding: 0;
}
.matrix-controls form > div { width: 100%; }
.matrix-controls form select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: 0.55rem 2rem 0.55rem 0.7rem;
  background-color: var(--color-paper);
  color: var(--color-ink);
  border: 1px solid var(--color-rule-strong);
  border-radius: 2px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-muted) 50%),
    linear-gradient(135deg, var(--color-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 14px) 55%,
    calc(100% - 10px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.matrix-controls form select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
  border-color: var(--color-accent);
}
@media (max-width: 720px) {
  .matrix-controls { grid-template-columns: 1fr; }
}

/* ---------- 13. Active-item block above the plot ---------- */

.active-item {
  margin: var(--space-5) 0 var(--space-3);
  padding-top: var(--space-3);
  border-top: 2px solid var(--color-accent);
}
.active-item__title {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--color-ink);
  margin: 0 0 var(--space-2);
  max-width: 44ch;
  letter-spacing: -0.005em;
}
.active-item__grouping {
  font-family: var(--font-sans);
  font-size: var(--step-small);
  color: var(--color-muted);
  margin: 0;
}
.active-item__note {
  font-size: var(--step-small);
  color: var(--color-muted);
  font-style: italic;
  margin: var(--space-2) 0 0;
  max-width: 60ch;
}

/* ---------- 14. Plot surface ---------- */

.plot-surface {
  background: var(--color-surface-soft);
  padding: var(--space-5) var(--space-4);
  margin: var(--space-3) 0 var(--space-4);
  border: 1px solid var(--color-rule);
}
@media (min-width: 720px) {
  .plot-surface { padding: var(--space-5) var(--space-6); }
}
.plot-surface svg { display: block; }
.plot-surface figure[data-plot-legend] { margin-bottom: var(--space-3); }

/* ---------- 15. Scale legend strip (shared component) ---------- */

.scale-legend-strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: baseline;
  margin: 0 0 var(--space-6);
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border-left: 2px solid var(--color-rule-strong);
  font-family: var(--font-sans);
  font-size: var(--step-small);
  color: var(--color-ink);
  max-width: 100%;
  overflow-wrap: normal;
  box-sizing: border-box;
  font-variant-numeric: tabular-nums;
}
.scale-legend-strip strong {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 500;
  color: var(--color-accent);
  margin-right: var(--space-2);
}
.scale-legend-strip .scale-item {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  white-space: nowrap;
  color: var(--color-ink);
}
.scale-legend-strip .scale-item .num {
  font-weight: 500;
  min-width: 1ch;
  text-align: right;
  color: var(--color-muted);
}
@media (max-width: 480px) {
  .scale-legend-strip .scale-item { white-space: normal; }
}

/* ---------- 16. Tables ---------- */

table {
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-size: var(--step-small);
}
th {
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--color-ink);
  border-bottom: 1px solid var(--color-rule-strong) !important;
  letter-spacing: 0.005em;
}
td { color: var(--color-ink); }

/* ---------- 17. Details / summary ---------- */

details {
  margin: var(--space-5) 0;
  max-width: var(--width-normal);
}
details > summary {
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--step-small);
  color: var(--color-muted);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-rule);
  border-bottom: 1px solid var(--color-rule);
  list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: "+";
  display: inline-block;
  width: 1.5em;
  color: var(--color-accent);
  font-weight: 500;
}
details[open] > summary::before { content: "–"; }
details > summary:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ---------- 17b. Section hint (explanatory sub-line) ---------- */

.section-hint {
  font-size: var(--step-small);
  color: var(--color-muted);
  line-height: 1.5;
  max-width: var(--measure);
  margin: 0 0 var(--space-4);
}

/* ---------- 17c. Group-block: per-group heading + summary line + distribution table ---------- */

.grouped-distribution {
  display: block;
}
.group-block {
  margin: var(--space-5) 0 var(--space-5);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-rule);
}
.group-block:first-child {
  border-top: none;
  margin-top: var(--space-3);
  padding-top: 0;
}
.group-block__title {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--color-ink);
  line-height: 1.25;
  margin: 0 0 var(--space-2);
  letter-spacing: -0.005em;
}
.group-block__empty {
  font-size: var(--step-small);
  color: var(--color-muted);
  font-style: italic;
  margin: 0 0 var(--space-4);
}
.group-summary-line {
  font-family: var(--font-sans);
  font-size: var(--step-small);
  color: var(--color-ink);
  line-height: 1.55;
  padding: 0 0 var(--space-3);
  border-left: none;
  background: transparent;
  max-width: var(--measure);
  margin: 0;
  font-variant-numeric: tabular-nums;
}
.group-summary-line b {
  color: var(--color-ink);
  font-weight: 500;
}

/* ---------- 17d. Multi-item view: per-item block ---------- */

.items-list {
  display: block;
  margin: var(--space-4) 0 var(--space-6);
}
.item-block {
  margin: var(--space-7) 0;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-rule);
}
.item-block:first-child {
  margin-top: var(--space-4);
  padding-top: 0;
  border-top: none;
}
.item-block__header {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.item-block__title {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1.3;
  color: var(--color-ink);
  margin: 0;
  max-width: 44ch;
  letter-spacing: -0.005em;
  flex: 1 1 auto;
}
.item-block__hide {
  flex: 0 0 auto;
  background: transparent;
  border: 1px solid var(--color-rule-strong);
  border-radius: 2px;
  color: var(--color-muted);
  font-family: var(--font-sans);
  font-size: 1.125rem;
  line-height: 1;
  padding: 0.15rem 0.55rem 0.25rem;
  cursor: pointer;
  margin-top: 0.15rem;
  transition: color 120ms ease-out, border-color 120ms ease-out, background 120ms ease-out;
}
.item-block__hide:hover {
  background: var(--color-surface-soft);
  border-color: var(--color-ink);
  color: var(--color-ink);
}
.item-block__hide:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
.item-block__plot { margin-bottom: var(--space-4); }
.item-block__tables { /* nested .grouped-distribution rules apply */ }

/* ---------- 17e. Visibility controls + restore-all button ---------- */

.hidden-items-controls {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-rule);
  border-bottom: 1px solid var(--color-rule);
  margin: 0 0 var(--space-4);
  font-size: var(--step-small);
}
.hidden-items-count {
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}
.hidden-items-count b {
  color: var(--color-ink);
  font-weight: 500;
}
.btn-restore-all {
  background: transparent;
  border: 1px solid var(--color-rule-strong);
  color: var(--color-ink);
  font-family: var(--font-sans);
  font-size: var(--step-small);
  padding: 0.4rem 0.9rem;
  border-radius: 2px;
  cursor: pointer;
  transition: color 120ms ease-out, border-color 120ms ease-out;
}
.btn-restore-all:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.btn-restore-all:disabled {
  cursor: not-allowed;
  color: var(--color-muted);
  opacity: 0.6;
}
.btn-restore-all:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ---------- 17f. Empty state (all items hidden) ---------- */

.items-empty-state {
  padding: var(--space-5) var(--space-5);
  border: 1px dashed var(--color-rule-strong);
  background: transparent;
  max-width: 44rem;
  margin: var(--space-6) 0;
}
.items-empty-state__message {
  margin: 0 0 var(--space-3);
  font-size: var(--step-base);
  color: var(--color-ink);
  line-height: 1.55;
}

/* ---------- 18. Fine print / page footer note ---------- */

.fine-print {
  font-size: var(--step-fine);
  color: var(--color-muted);
  line-height: 1.55;
  max-width: var(--measure);
  margin: var(--space-6) 0 0;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-rule);
}

/* ---------- 19. Print ---------- */

@media print {
  .backlink, .matrix-controls, details > summary::before { display: none; }
  .plot-surface { background: transparent; border: 1px solid #000; }
  body { background: white; color: black; }
}

/* ---------- 20. Result-view selector (Jakaumat / Tunnusluvut / Ryhmävertailu) ---------- */

.result-view-selector {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--color-rule-strong);
  background: var(--color-paper);
  border-radius: 3px;
  overflow: hidden;
  margin: var(--space-5) 0 var(--space-3);
}
.result-view-selector__tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--color-ink);
  font-family: var(--font-sans);
  font-size: var(--step-small);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  border-right: 1px solid var(--color-rule);
}
.result-view-selector__tab:last-child { border-right: 0; }
.result-view-selector__tab[aria-selected="true"] {
  background: var(--color-accent);
  color: var(--color-paper);
  font-weight: 600;
}
.result-view-selector__tab:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.matrix-controls__label {
  font-weight: 600;
  font-size: var(--step-small);
  margin-right: var(--space-3);
  display: inline-block;
}
.matrix-controls__select {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-rule-strong);
  background: var(--color-paper);
  color: var(--color-ink);
  min-width: 12rem;
}
.matrix-controls__hint {
  font-size: var(--step-fine);
  color: var(--color-muted);
  margin: var(--space-1) 0 0;
}

.result-view {
  margin-top: var(--space-4);
}

.jakaumat-view__chart,
.tunnusluvut-view__summary,
.ryhmavertailu-view__chart {
  margin-bottom: var(--space-5);
}
.jakaumat-view__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  margin: 0 0 var(--space-3);
  font-size: var(--step-fine);
  color: var(--color-muted);
}
.jakaumat-view__legend-item { display: inline-flex; align-items: center; gap: 0.3rem; }
.jakaumat-view__legend-swatch { width: 0.85rem; height: 0.85rem; border: 1px solid rgb(0 0 0 / 0.08); }
.jakaumat-view__statements { display: grid; gap: 0; }
.statement-distribution.item-detail {
  margin: 0;
  padding: 0.22rem 0;
  border: 0;
  border-top: 1px solid var(--color-rule);
  border-radius: 0;
  background: transparent;
}
.statement-distribution.item-detail:first-child { padding-top: 0; border-top: 0; }
.statement-distribution__header { display: flex; align-items: flex-start; gap: 0.5rem; }
.statement-distribution__title {
  flex: 1 1 auto;
  margin: 0 0 0.1rem;
  font-size: 0.925rem;
  line-height: 1.28;
  font-weight: 500;
}
.statement-distribution__hide { flex: 0 0 auto; }
.statement-distribution__chart { position: relative; z-index: 0; min-width: 0; }
.statement-distribution__chart svg { display: block; width: 100%; height: auto; }
.statement-distribution__tooltip-target { position: absolute; inset: 0; cursor: crosshair; }
.statement-distribution__tooltip {
  position: fixed;
  z-index: 20;
  max-width: min(18rem, calc(100vw - 1rem));
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-rule-strong);
  border-radius: 2px;
  background: var(--color-paper);
  box-shadow: 0 0.2rem 0.5rem rgb(0 0 0 / 0.16);
  color: var(--color-ink);
  font-size: var(--step-fine);
  line-height: 1.35;
  white-space: pre-line;
  pointer-events: none;
}
.statement-distribution__table {
  /* Override the site-wide disclosure margin: each control belongs directly
     under its own bar, not in a separate vertical content block. */
  margin: 0.1rem 0 0;
  max-width: none;
}
.statement-distribution__table > summary {
  display: inline-block;
  cursor: pointer;
  color: var(--color-accent);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.3;
  border: 0;
  padding: 0;
}
.statement-distribution__table > summary::before,
.statement-distribution__table[open] > summary::before {
  content: "⌄";
  width: 1.25em;
  font-size: 0.9rem;
  line-height: 1;
  vertical-align: -0.04em;
  font-weight: 400;
}
.statement-distribution__table[open] > summary::before { content: "⌃"; }
.statement-distribution__table[open] > summary { margin-bottom: var(--space-2); }
.statement-distribution__table .item-detail__body { padding: 0; }
.statement-distribution__table .group-block { margin: 0; padding-top: 0; border-top: 0; }
.statement-distribution__table .observablehq--table { max-width: 100%; overflow-x: auto; }
.chart-item-key {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-rule);
  background: var(--color-surface-soft);
}
.chart-item-key__title {
  margin: 0 0 var(--space-2);
  font-size: var(--step-small);
  font-weight: 600;
}
.chart-item-key__list {
  columns: 2;
  column-gap: var(--space-6);
  margin: 0;
  padding-left: 1.5rem;
  font-size: var(--step-fine);
}
.chart-item-key__list li { break-inside: avoid; margin-bottom: var(--space-1); }

/* Adaptive Ryhmävertailu heatmap. The desktop Plot and mobile list share the
 * same item × group metrics; only their presentation changes at this break. */
.ryhmavertailu-view__chart--heatmap {
  overflow: hidden;
}
.ryhmavertailu-heatmap__headers {
  display: grid;
  grid-template-columns: repeat(var(--heatmap-columns), minmax(0, 1fr));
  padding-left: var(--heatmap-margin-left);
  padding-right: var(--heatmap-margin-right);
  margin: 0 0 var(--space-1);
  font-size: var(--step-fine);
  line-height: 1.2;
  color: var(--color-muted);
}
.ryhmavertailu-heatmap__group {
  min-width: 0;
  padding: 0 var(--space-1);
  overflow-wrap: anywhere;
  text-align: center;
}
.ryhmavertailu-heatmap__desktop-plot {
  display: block;
  max-width: 100%;
  height: auto;
}
.ryhmavertailu-heatmap__legend {
  margin: var(--space-2) 0 0;
  color: var(--color-muted);
  font-size: var(--step-fine);
}
.ryhmavertailu-heatmap__mobile {
  display: none;
}
@media (max-width: 600px) {
  .ryhmavertailu-view__chart--heatmap {
    overflow: visible;
  }
  .ryhmavertailu-view__chart--heatmap .chart-item-key,
  .ryhmavertailu-heatmap__headers,
  .ryhmavertailu-heatmap__desktop-plot {
    display: none;
  }
  .ryhmavertailu-heatmap__mobile {
    display: grid;
    gap: var(--space-3);
  }
  .ryhmavertailu-heatmap__mobile-item {
    border: 1px solid var(--color-rule);
    padding: var(--space-3);
  }
  .ryhmavertailu-heatmap__mobile-item h3 {
    margin: 0 0 var(--space-2);
    font-size: var(--step-small);
    line-height: 1.35;
  }
  .ryhmavertailu-heatmap__mobile-cell {
    display: flex;
    align-items: center;
    min-height: 2.25rem;
    margin-top: 2px;
    padding: 0.35rem 0.5rem;
    font-size: var(--step-fine);
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }
}
.jakaumat-view__note,
.tunnusluvut-view__caveat,
.tunnusluvut-view__meta,
.ryhmavertailu-view__caveat {
  font-size: var(--step-fine);
  color: var(--color-muted);
  max-width: 68ch;
  margin: var(--space-3) 0 var(--space-5);
}

.jakaumat-view__details,
.tunnusluvut-view__details,
.ryhmavertailu-view__details {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-5);
}

.item-detail {
  border: 1px solid var(--color-rule);
  background: var(--color-paper);
  padding: 0;
  border-radius: 3px;
}
.item-detail__summary {
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  align-items: center;
  font-size: var(--step-small);
  font-weight: 600;
}
.item-detail__summary::-webkit-details-marker { display: none; }
.item-detail__title { flex: 1; }
.item-detail__hide {
  background: transparent;
  border: 1px solid var(--color-rule-strong);
  color: var(--color-muted);
  width: 1.6em;
  height: 1.6em;
  border-radius: 3px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.item-detail__hide:hover { color: var(--color-accent); border-color: var(--color-accent); }
.item-detail__body {
  padding: 0 var(--space-4) var(--space-4);
}
.item-detail[open] .item-detail__summary {
  border-bottom: 1px solid var(--color-rule);
}

.ryhmavertailu-view__empty {
  padding: var(--space-4);
  border: 1px dashed var(--color-rule-strong);
  background: var(--color-surface-soft);
  color: var(--color-muted);
  border-radius: 3px;
}

@media (max-width: 600px) {
  .result-view-selector { display: flex; width: 100%; }
  .result-view-selector__tab { flex: 1; padding: 0.55rem 0.5rem; font-size: var(--step-fine); }
  .matrix-controls__select { min-width: 0; width: 100%; }
  .chart-item-key__list { columns: 1; }
}

/* ---------- 21. Result-view scope banner ---------- */

.result-view-scope {
  display: block;
  padding: 0.5rem 0.75rem;
  margin: 0 0 var(--space-4);
  background: var(--color-accent-soft);
  border-left: 3px solid var(--color-accent);
  color: var(--color-ink);
  font-size: var(--step-small);
  line-height: 1.4;
}
.result-view-scope__label { color: var(--color-muted); }
.result-view-scope__value { font-weight: 600; }
.result-view-scope__hint {
  color: var(--color-muted);
  font-size: var(--step-fine);
}

/* ---------- 22. Mobile hardening (≤480px) ----------
 * Additive to Section 20's ≤600px rules. Targets specific overflow paths
 * observed at narrow mobile widths without touching the desktop layout.
 * Every rule below is defensive: long Finnish compound words, long label
 * strings, and residual chart width. Numeric values and canonical text
 * are unaffected — this is purely typographic/geometric hardening. */

/* Editorial paragraphs can break long words rather than run off the viewport
 * edge. `overflow-wrap: anywhere` is applied year-round because it only kicks
 * in when a word cannot fit — it is a no-op on typographically comfortable
 * widths. */
.q-header__question,
.q-header__instruction {
  overflow-wrap: anywhere;
}

/* Meta-strip items may wrap internally so the "1 = Täysin eri mieltä ·
 * 6 = Täysin samaa mieltä" run does not clip to a single unbreakable line.
 * `min-width: 0` disarms the flex-item default minimum-content width. */
.q-meta { max-width: 100%; }
.q-meta__item {
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
}

/* Scale-legend strip: tighten the wrap footprint on narrow mobiles so the
 * six numbered items can share two or three rows rather than a wide flex
 * strip pushed off-screen. */
@media (max-width: 480px) {
  .scale-legend-strip {
    gap: var(--space-2);
    padding: var(--space-3);
  }
  .scale-legend-strip .scale-item {
    flex: 0 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
  }
}

/* View-selector tabs at ≤480px: allow the longest Finnish label
 * ("Ryhmävertailu") to wrap onto two lines instead of truncating.
 * `hyphens: auto` requires a lang attribute (not set on <html>), so we
 * pair it with `overflow-wrap: anywhere` — the actual load-bearing rule
 * that lets a single long Finnish word break within itself when the flex
 * cell is narrower than the word (measured at 320px). */
@media (max-width: 480px) {
  .result-view-selector__tab {
    white-space: normal;
    line-height: 1.2;
    padding: 0.55rem 0.35rem;
    hyphens: auto;
    overflow-wrap: anywhere;
  }
}

/* Editorial paragraph max-widths drop to 100% at ≤480px so their 42ch/60ch
 * caps don't leave residual optical drift; the parent's inline space is the
 * real constraint on such narrow viewports. */
@media (max-width: 480px) {
  .q-header__question,
  .q-header__instruction {
    max-width: 100%;
  }
}

/* Chart figures at ≤480px: isolate any residual chart width to the individual
 * figure element so the whole page never scrolls sideways. Main's
 * chart-item-key + ordinal-axis approach keeps Plot margins tiny, so this
 * rule is a defensive backstop for the item-detail grouped-distribution
 * plots and any other embedded chart. */
@media (max-width: 480px) {
  .result-view figure,
  .ryhmavertailu-view__chart,
  .jakaumat-view figure,
  .item-detail figure {
    max-width: 100%;
    overflow-x: auto;
  }
}

/* ---------- 22. Private B2* filter controls (local-only runtime) ---------- */

.private-b2-matrix-question {
  display: grid;
  gap: var(--space-3);
}

.filter-menus {
  display: grid;
  gap: var(--space-3);
}

.b2-results-panel {
  margin: 0;
  border: 1px solid #d9e4f0;
  border-radius: 0.65rem;
  background: linear-gradient(120deg, #fff 0%, #f7fbff 100%);
  box-shadow: 0 1px 0 rgb(27 34 42 / 3%);
}

.b2-results-panel__heading {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.b2-results-panel__heading h2 {
  font-family: var(--font-sans);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.b2-results-panel__step {
  display: inline-grid;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 999px;
  background: #2475ce;
  color: #fff;
  font-weight: 700;
  line-height: 1;
}

.compare-selector__help {
  margin: var(--space-2) 0 var(--space-3) 2.75rem;
  color: var(--color-ink);
  font-size: var(--step-small);
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-height: 3rem;
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: 0.45rem;
  background: #e7f0f9;
}

.active-filters__label {
  font-weight: 700;
  font-size: var(--step-small);
}

.active-filters__empty {
  color: var(--color-muted);
  font-size: var(--step-small);
}

.active-filters__chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  max-width: 100%;
  padding: 0.27rem 0.5rem 0.27rem 0.7rem;
  border: 1px solid #cbdceb;
  border-radius: 999px;
  background: #fff;
  color: var(--color-ink);
  font-size: var(--step-fine);
}

.active-filters__remove,
.active-filters__clear-all,
.filter-dim__clear {
  border: 0;
  background: transparent;
  color: #0758b4;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.active-filters__remove {
  display: inline-grid;
  width: 1.25rem;
  height: 1.25rem;
  place-items: center;
  border-radius: 999px;
  font-size: 1.25rem;
  line-height: 1;
}

.active-filters__remove:hover,
.active-filters__remove:focus-visible {
  background: #e6f0fa;
}

.active-filters__clear-all::before { content: "×"; margin-right: var(--space-2); font-size: 1.35em; }

.filter-menus__groups {
  display: grid;
  grid-template-columns: minmax(16rem, 1.45fr) minmax(15rem, 1fr) minmax(12rem, 0.92fr);
  grid-template-areas: "background work teaching" "background work other";
  gap: var(--space-3);
}

.filter-menu {
  min-width: 0;
  align-self: start;
  border: 1px solid #d9e2ec;
  border-radius: 0.5rem;
  background: #fff;
}
.filter-menu[data-menu="yleiset"] { grid-area: background; }
.filter-menu[data-menu="ammatti"] { grid-area: work; }
.filter-menu[data-menu="opetuskonteksti"] { grid-area: teaching; }
.filter-menu[data-menu="muut"] { grid-area: other; }

.filter-menu__summary {
  display: flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0 var(--space-3);
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
.filter-menu__summary::-webkit-details-marker { display: none; }
.filter-menu__summary::before {
  content: "›";
  margin-right: var(--space-2);
  color: #174f86;
  font-size: 1.35em;
  transform: rotate(0deg);
  transition: transform 120ms ease-out;
}
.filter-menu[open] > .filter-menu__summary::before { transform: rotate(90deg); }
.filter-menu__count { margin-left: auto; color: var(--color-muted); font-size: var(--step-fine); font-weight: 400; }

.filter-menu__list {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3);
  border-top: 1px solid #e6edf4;
}

.filter-dim {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.filter-dim__legend { margin-bottom: var(--space-2); font-weight: 700; font-size: var(--step-small); }
.filter-dim__values { display: grid; gap: 0.35rem; }
.filter-dim__value,
.compare-selector__option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  color: var(--color-ink);
  font-size: var(--step-small);
  cursor: pointer;
}
.filter-dim__value input,
.compare-selector__option input { margin: 0.25rem 0 0; accent-color: #0966c2; }
.filter-dim__hint,
.filter-dim__disabled-reason { margin: var(--space-2) 0 0; color: var(--color-muted); font-size: var(--step-fine); }
.filter-dim--disabled { opacity: 0.65; }
.filter-dim__clear { margin-top: var(--space-2); padding: 0; text-decoration: underline; text-underline-offset: 0.16em; }

.compare-selector { padding-top: var(--space-1); }
.compare-selector__legend { display: none; }
.compare-selector__inputs { display: flex; flex-wrap: wrap; gap: var(--space-3) var(--space-5); margin-left: 2.75rem; }

.b2-results-panel { overflow: hidden; }
.b2-results-panel__heading { padding: var(--space-3) var(--space-5) 0; }
.b2-results-panel .matrix-question-with-views { padding: var(--space-2) var(--space-5) var(--space-5); }

@media (max-width: 719px) {
  .filter-menus { gap: var(--space-2); }
  .active-filters { margin-bottom: var(--space-2); }
  .filter-menus__groups { grid-template-columns: 1fr; grid-template-areas: none; gap: var(--space-2); }
  .filter-menu { grid-area: auto !important; }
  .compare-selector__inputs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); margin-left: 0; }
  .b2-results-panel__heading { padding: var(--space-2) var(--space-3) 0; }
  .b2-results-panel__heading h2 { font-size: 1.15rem; }
  .b2-results-panel__step { display: none; }
  .b2-results-panel .matrix-question-with-views { padding: var(--space-2) var(--space-3) var(--space-3); }
}

/* Native Popover API shell. The browser puts [popover] into the top layer;
 * these rules only size and anchor it, never emulate an overlay in JS. */
.b2-control-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}
.b2-control-trigger {
  min-height: 2.45rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid #b9cce0;
  border-radius: 0.4rem;
  background: #fff;
  color: var(--color-ink);
  font: inherit;
  font-size: var(--step-small);
  font-weight: 650;
  cursor: pointer;
}
.b2-control-trigger:hover { background: #edf5fc; border-color: #7ea9d2; }
.b2-control-trigger:focus-visible,
.b2-top-layer__close:focus-visible { outline: 3px solid #0758b4; outline-offset: 2px; }
#b2-filters-trigger { anchor-name: --b2-filter-trigger; }
#b2-compare-trigger { anchor-name: --b2-compare-trigger; }

.b2-top-layer {
  width: min(46rem, calc(100vw - 2rem));
  max-height: min(44rem, calc(100dvh - 2rem));
  margin: 0;
  padding: 0;
  overflow: auto;
  border: 1px solid #b9cce0;
  border-radius: 0.65rem;
  background: var(--color-paper);
  color: var(--color-ink);
  box-shadow: 0 1rem 2.5rem rgb(22 49 76 / 22%);
}
.b2-top-layer--filters { position-anchor: --b2-filter-trigger; }
.b2-top-layer--compare { position-anchor: --b2-compare-trigger; width: min(38rem, calc(100vw - 2rem)); }
@supports (position-anchor: --b2-filter-trigger) {
  .b2-top-layer--filters { position: fixed; top: anchor(bottom); left: anchor(left); margin-top: 0.5rem; position-try: flip-block; }
  .b2-top-layer--compare { position: fixed; top: anchor(bottom); left: anchor(left); margin-top: 0.5rem; position-try: flip-block; }
}
.b2-top-layer::backdrop { background: transparent; }
.b2-top-layer__body { padding: var(--space-4) var(--space-5) var(--space-5); }
.b2-top-layer__heading-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.b2-top-layer__heading { font-family: var(--font-sans); font-size: 1.35rem; font-weight: 700; }
.b2-top-layer__close {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #0758b4;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.b2-top-layer__close:hover { background: #e7f0f9; }
.b2-top-layer__description { margin: var(--space-2) 0 var(--space-3); font-size: var(--step-small); }
.b2-top-layer .active-filters { margin-bottom: var(--space-3); }
.active-filters--compact {
  min-height: 0;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border-left: 3px solid #2475ce;
  border-radius: 0;
}
.active-filters--compact .active-filters__label { font-size: var(--step-fine); }
.b2-top-layer .compare-selector { padding-top: var(--space-2); }
.b2-top-layer .compare-selector__help { margin-left: 0; }
.b2-top-layer .compare-selector__inputs { margin-left: 0; }

/* The B2 controls and the result tabs form one control bar. The popover
 * elements are descendants only for state management; when closed they do
 * not consume layout space, and when open the browser moves them to top
 * layer. */
.b2-results-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin: 0 0 var(--space-2);
}
.b2-results-toolbar .b2-control-toolbar { flex: 0 1 auto; }
.b2-results-toolbar .result-view-selector {
  flex: 0 1 auto;
  margin: 0;
}
.b2-results-panel .active-filters--compact {
  margin: 0 0 var(--space-2);
  padding-block: 0.35rem;
}
.scale-legend-strip[data-b2-runtime-scale-source="true"] { display: none; }
.b2-results-panel .scale-legend-strip[data-b2-runtime-scale="true"] {
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  font-size: var(--step-fine);
}

@media (max-width: 719px) {
  .b2-control-toolbar { gap: var(--space-2); }
  .b2-control-trigger { flex: 1 1 auto; min-width: 0; font-size: var(--step-fine); }
  .b2-results-toolbar { align-items: stretch; gap: var(--space-2); }
  .b2-results-toolbar .b2-control-toolbar { flex: 1 1 100%; }
  .b2-results-toolbar .result-view-selector { flex: 1 1 100%; }
  .b2-top-layer,
  .b2-top-layer--compare {
    position: fixed;
    inset: auto 0 0;
    width: 100%;
    max-height: min(82dvh, 46rem);
    margin: 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 0.8rem 0.8rem 0 0;
  }
  .b2-top-layer__body { padding: var(--space-4) var(--space-3) calc(var(--space-4) + env(safe-area-inset-bottom)); }
  .b2-top-layer .filter-menus__groups { grid-template-columns: 1fr; grid-template-areas: none; }
  .b2-top-layer .filter-menu { grid-area: auto !important; }
}

/* Final private B2* analytics surface. This is deliberately scoped to the
 * loopback runtime: the ordinary public three-view renderer keeps its cards
 * and page metadata unchanged. */
.q-meta[data-b2-runtime-hidden="true"] { display: none; }
.question-series { margin: 0 0 var(--space-3); }
.question-series h2 { margin: 0; font-family: var(--font-serif); font-size: var(--step-2); font-weight: 500; }
.question-series__meta { margin: 0.2rem 0 0.45rem; color: var(--color-muted); font-size: var(--step-fine); }
.question-series__tabs { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.question-series__tabs a { display: inline-block; min-width: 3.2rem; padding: 0.32rem 0.65rem; border: 1px solid var(--color-rule-strong); border-radius: 3px; color: var(--color-ink); font-size: var(--step-fine); font-weight: 650; text-align: center; text-decoration: none; }
.question-series__tabs a[aria-current="page"] { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-paper); }
.question-series__tabs a:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.results-navigation { margin-bottom: var(--space-3); }
.results-navigation__title { font-size: var(--step-1); }
.results-navigation__primary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.3rem;
}
.results-navigation__primary a {
  display: block;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--color-rule-strong);
  border-radius: 3px;
  color: var(--color-ink);
  font-size: var(--step-fine);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
}
.results-navigation__primary a[aria-current="true"] {
  color: var(--color-paper);
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.results-navigation__primary a:focus-visible,
.results-navigation__parts a:focus-visible,
.results-navigation__mobile summary:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.results-navigation__parts {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.35rem;
}
.results-navigation__parts a {
  padding: 0.15rem 0.45rem;
  border-bottom: 2px solid transparent;
  color: var(--color-muted);
  font-size: var(--step-fine);
  font-weight: 650;
  text-decoration: none;
}
.results-navigation__parts a[aria-current="page"] { border-color: var(--color-accent); color: var(--color-ink); }
.results-navigation__mobile { display: none; }
@media (max-width: 719px) {
  .results-navigation__primary { display: none; }
  .results-navigation__mobile { display: block; margin-top: 0.15rem; }
  .results-navigation__mobile summary {
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--color-rule-strong);
    border-radius: 3px;
    color: var(--color-ink);
    cursor: pointer;
    font-size: var(--step-fine);
    font-weight: 650;
  }
  .results-navigation__mobile[open] summary { border-radius: 3px 3px 0 0; }
  .results-navigation__mobile-links { display: grid; border: 1px solid var(--color-rule-strong); border-top: 0; }
  .results-navigation__mobile-links a { padding: 0.4rem 0.55rem; color: var(--color-ink); font-size: var(--step-fine); text-decoration: none; }
  .results-navigation__mobile-links a[aria-current="true"] { color: var(--color-paper); background: var(--color-accent); }
}
.private-b2-matrix-question { display: block; }
/* Theme page container: multiple questions rendered vertically with a shared
   toolbar mounted by the first question. */
.b2-theme-page { display: block; }
.b2-theme-question { display: block; margin: 0 0 1.75rem; }
.b2-theme-question + .b2-theme-question {
  border-top: 1px solid var(--color-rule);
  padding-top: 1.25rem;
}
.b2-theme-question__heading {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  margin: 0 0 0.55rem;
  font-size: var(--step-1);
  line-height: 1.25;
  font-weight: 500;
}
.b2-theme-question__label {
  flex: 0 0 auto;
  font-family: var(--font-mono, monospace);
  font-size: 0.7em;
  color: var(--color-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.b2-theme-question__title {
  flex: 1 1 auto;
  color: var(--color-ink);
}
.b2-page-toolbar {
  margin: 0 0 1rem;
}
.b2-analysis-surface {
  margin: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}
.b2-analysis-surface .matrix-question-with-views { padding: 0; }
.b2-analysis-surface .result-view-selector { margin: 0; }
.b2-results-toolbar {
  position: sticky;
  top: 0.5rem;
  z-index: 3;
  padding: 0.45rem 0;
  background: color-mix(in srgb, var(--color-paper) 96%, transparent);
  border-bottom: 1px solid var(--color-rule);
  box-shadow: 0 0.35rem 0.55rem rgb(255 255 255 / 90%);
}
.b2-results-toolbar .b2-control-toolbar { gap: 0.4rem; }
.b2-results-toolbar .b2-control-trigger {
  min-height: 2.15rem;
  padding: 0.35rem 0.6rem;
}
.b2-analysis-meta {
  margin-left: auto;
  color: var(--color-muted);
  font-size: 0.72rem;
  white-space: nowrap;
}
.b2-analysis-surface .active-filters--compact {
  margin: 0.35rem 0 0;
  padding: 0.25rem 0.5rem;
  background: transparent;
  border-left-width: 2px;
}
.b2-analysis-surface .result-view-scope { display: none; }
.b2-analysis-surface .result-view { margin-top: var(--space-2); }
.b2-analysis-surface .chart-item-key {
  margin: 0 0 0.2rem;
  padding: 0;
  border: 0;
  background: transparent;
}
.b2-statement-key {
  max-width: 48rem;
  font-size: var(--step-fine);
}
.b2-statement-key > summary {
  cursor: pointer;
  color: var(--color-accent);
  font-weight: 650;
}
.b2-statement-key .hidden-items-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0.35rem 0 0;
  padding: 0.3rem 0;
  border: 0;
  font-size: var(--step-fine);
}
.b2-statement-key .btn-restore-all {
  padding: 0.22rem 0.5rem;
  font-size: var(--step-fine);
}
.b2-statement-key > .chart-item-key__list {
  margin-top: var(--space-2);
  padding: var(--space-2) 0 var(--space-2) 1.35rem;
  columns: 2;
  column-gap: var(--space-5);
}
.b2-analysis-surface .scale-legend-strip[data-b2-runtime-scale="true"] {
  margin: 0.25rem 0 0.35rem;
  padding: 0.35rem 0.5rem;
  border-left: 0;
  background: transparent;
}
.b2-analysis-surface .jakaumat-view__chart { margin-bottom: var(--space-3); }
.b2-analysis-surface .jakaumat-view__details {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem var(--space-3);
  margin-top: var(--space-2);
}
.b2-analysis-surface .item-detail__summary {
  min-height: 2.2rem;
  padding: 0.3rem 0.5rem;
  font-size: var(--step-fine);
  line-height: 1.3;
}
.b2-analysis-surface .item-detail__hide {
  width: 1.35rem;
  height: 1.35rem;
  flex: 0 0 auto;
}
.b2-top-layer--filters {
  width: min(20rem, calc(100vw - 2rem));
  max-height: min(36rem, 70dvh);
}
.b2-top-layer--compare { width: min(23rem, calc(100vw - 2rem)); }
.b2-top-layer .filter-menus__groups {
  grid-template-columns: 1fr;
  grid-template-areas: none;
  gap: var(--space-2);
}
.b2-top-layer .filter-menu { grid-area: auto !important; }

/* On desktop, keep the filter sheet beside the page-level toolbar instead of
 * laying it over the analysis surface. The primary placement uses the gutter
 * to the trigger's left; narrow desktop widths fall back to its right. */
@position-try --b2-filter-to-trigger-right {
  right: auto;
  left: anchor(right);
}
@supports (position-anchor: --b2-filter-trigger) {
  .b2-top-layer--filters {
    position: fixed;
    top: anchor(top);
    right: anchor(left);
    left: auto;
    margin: 0;
    transform: translateY(-0.5rem);
    position-try-fallbacks: --b2-filter-to-trigger-right, flip-block;
  }
}

@media (max-width: 719px) {
  .b2-results-toolbar { top: 0; }
  .b2-analysis-meta { width: 100%; margin-left: 0; }
  .b2-analysis-surface .jakaumat-view__details { grid-template-columns: 1fr; }
  .b2-statement-key > .chart-item-key__list { columns: 1; }
  .b2-top-layer--filters {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    margin: 0;
    transform: none;
    position-try-fallbacks: none;
  }
}

/* ---------------------------------------------------------------------------
 * Vastaajat-näkymä — demographic structure of the active population.
 * Compact analytic panel: header (N + filter toolbar), chips, then a
 * responsive grid of distribution panels. No hero cards, no long intros.
 * ------------------------------------------------------------------------- */
.vastaajat-view { display: block; }
.vastaajat-view__header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin: 0 0 var(--space-3);
}
.vastaajat-view__n {
  margin: 0;
  font: 600 var(--step-small)/1.3 var(--font-sans);
  color: var(--color-ink);
}
.vastaajat-view .b2-control-toolbar { margin: 0; }
.vastaajat-view .active-filters--compact { margin: 0 0 var(--space-3); }

/* Vastaajat dashboard grid. A compact two-column pack where every dim is a
 * peer cell — the page reads as an analytics surface, not a stack of forms.
 * Row 1: age (ordered histogram) | gender (bars)
 * Row 2: maakunta map            | primary_education_level (bars)
 * Row 3: highest_degree | Toimintaympäristö (kuntatyyppi + kuntakoko)
 * Mobile collapses to a single column, order preserved. */
.vastaajat-view__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  align-items: stretch;
}
.vastaajat-view__cell {
  display: block;
  min-width: 0;
}
@media (min-width: 900px) {
  .vastaajat-view__grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: var(--space-3) var(--space-4);
  }
}
.vastaajat-view__section-title {
  margin: 0 0 0.3rem;
  font: 700 var(--step-fine)/1.2 var(--font-sans);
  color: #516170;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
/* Two panels share the Toimintaympäristö cell. The generic panel rule sets
 * `height: 100%` so single-panel cells fill their grid row; when two panels
 * stack inside one cell, that rule collapses the cell to a single panel's
 * intrinsic height. Restore natural sizing here so both panels are visible. */
.vastaajat-view__cell--environment .demographic-panel { height: auto; }
.vastaajat-view__cell--environment .demographic-panel + .demographic-panel {
  margin-top: var(--space-2);
}

.demographic-panel {
  margin: 0;
  padding: 0.9rem 1rem 0.85rem;
  border: 1px solid #e2ebf3;
  border-radius: 0.4rem;
  background: #fafcfe;
  min-width: 0;
  height: 100%;
  box-sizing: border-box;
}
.demographic-panel__heading {
  margin: 0 0 var(--space-3);
  font: 700 var(--step-small)/1.2 var(--font-sans);
  color: var(--color-ink);
}
.demographic-panel__rows { display: grid; gap: 0.15rem; }
/* Rows are click-to-filter but should read as data lines, not as HTML form
 * controls. No default border, no button-shadowed padding: the label + bar
 * + stats sit on a quiet grid line, hover paints only a soft tint. */
button.demographic-panel__row {
  display: grid;
  grid-template-columns: minmax(5rem, 12rem) minmax(0, 1fr) minmax(5.5rem, max-content);
  gap: 0.6rem;
  align-items: center;
  padding: 0.28rem 0.4rem;
  background: transparent;
  border: 0;
  border-radius: 0.25rem;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: background-color 120ms ease;
}
button.demographic-panel__row:hover:not(:disabled) { background: #eff5fb; }
button.demographic-panel__row:focus-visible {
  outline: 2px solid #0758b4;
  outline-offset: 1px;
}
button.demographic-panel__row:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}
.demographic-panel__row--selected {
  background: #e3edf8;
}
.demographic-panel__row--selected::before {
  content: "";
  grid-column: 1 / -1;
  grid-row: 1;
  width: 3px;
  height: 60%;
  background: #0758b4;
  border-radius: 999px;
  justify-self: start;
  align-self: center;
  margin-left: -0.4rem;
}
.demographic-panel__name {
  font: 500 var(--step-fine)/1.2 var(--font-sans);
  color: var(--color-ink);
  overflow-wrap: anywhere;
}
.demographic-panel__row--selected .demographic-panel__name { font-weight: 700; }
.demographic-panel__bar {
  position: relative;
  height: 0.9rem;
  background: #f3f6fa;
  border-radius: 999px;
  overflow: hidden;
  min-width: 2rem;
}
.demographic-panel__ghost {
  position: absolute;
  inset: 0 auto 0 0;
  background: #dbe6f2;
  border-radius: 999px;
}
.demographic-panel__fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: #2475ce;
  border-radius: 999px;
  transition: width 160ms ease;
}
.demographic-panel__row--selected .demographic-panel__fill { background: #0758b4; }
.demographic-panel__stats {
  font: 600 var(--step-fine)/1.2 var(--font-mono, monospace);
  color: var(--color-ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.demographic-panel__ghost-stat {
  color: #6a7987;
  font-weight: 500;
}

/* Province map. Sized to sit as one panel among peers, not as a hero. The
 * SVG regions are focusable buttons; the sr-list below the map is a native
 * fallback for screen readers. */
.demographic-panel--map .demographic-panel__heading { margin-bottom: 0.35rem; }
.province-map {
  position: relative;
  width: 100%;
  max-width: 260px;
  height: 260px;
  margin: 0 auto;
}
.province-map__figure { display: block; width: auto; max-width: 100%; height: 100%; margin: 0 auto; overflow: visible; }
.province-map__region {
  cursor: pointer;
  transition: stroke-width 120ms ease, filter 120ms ease;
  stroke: #ffffff;
  stroke-width: 0.6;
  outline: none;
  /* Plot's geo() paths include a projection-frame subpath so every path's
   * bbox covers the whole SVG. Restrict pointer events to the actually
   * painted fill area (the maakunta shape) so hit-testing matches what
   * the user sees. */
  pointer-events: visiblePainted;
}
.province-map__region:hover,
.province-map__region:focus-visible {
  stroke: #0758b4;
  stroke-width: 1.6;
  filter: brightness(1.08);
}
.province-map__region--selected {
  stroke: #0a2f5f;
  stroke-width: 1.8;
}
.province-map__region--disabled { cursor: not-allowed; opacity: 0.4; }
.province-map__tooltip {
  min-height: 1.4em;
  margin-top: 0.25rem;
  text-align: center;
  font: 500 var(--step-fine)/1.3 var(--font-sans);
  color: var(--color-ink);
}
/* Robust visually-hidden pattern — clip-path handles browsers that ignore
 * legacy clip, and every layout-affecting property is neutralised so the
 * list cannot expand into visible space even if a global button reset
 * unsets one of them. */
.province-map__sr-list {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
  list-style: none !important;
}
.province-map__sr-list li { list-style: none !important; }
.province-map__sr-button {
  all: unset;
  position: absolute;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
}

/* Age histogram. Five ordered columns; height encodes count against the
 * whole-dataset marginal (ghost outline). The ordering along the x-axis
 * signals the sequential nature of the age bands — the data reads as a
 * distribution, not a categorical filter list. */
.age-histogram {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  align-items: end;
  margin-top: var(--space-1);
  max-width: 44rem;
}
.age-histogram__column {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 0.35rem;
  padding: 0.35rem 0.35rem 0.4rem;
  background: transparent;
  border: 0;
  border-radius: 0.35rem;
  min-width: 0;
  color: inherit;
  cursor: pointer;
  text-align: center;
  transition: background-color 120ms ease;
}
.age-histogram__column:hover:not(:disabled) { background: #eef4fb; }
.age-histogram__column:focus-visible {
  outline: 2px solid #0758b4;
  outline-offset: 2px;
}
.age-histogram__column:disabled { cursor: not-allowed; opacity: 0.4; }
.age-histogram__column--selected { background: #eaf3fc; }

.age-histogram__stack {
  position: relative;
  display: block;
  width: 100%;
  height: 110px;
  align-self: end;
}
.age-histogram__ghost {
  position: absolute;
  bottom: 0;
  left: 15%;
  right: 15%;
  border: 1px solid #cfdbe6;
  border-radius: 3px 3px 0 0;
  background: transparent;
}
.age-histogram__fill {
  position: absolute;
  bottom: 0;
  left: 15%;
  right: 15%;
  background: #2475ce;
  border-radius: 3px 3px 0 0;
  transition: height 180ms ease;
}
.age-histogram__column--selected .age-histogram__fill { background: #0758b4; }
.age-histogram__label {
  font: 500 var(--step-fine)/1.2 var(--font-sans);
  color: #3b4a5b;
  font-variant-numeric: tabular-nums;
}
.age-histogram__column--selected .age-histogram__label { color: var(--color-ink); font-weight: 700; }
.age-histogram__value {
  font: 600 var(--step-fine)/1.15 var(--font-mono, monospace);
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
}

.demographic-panel__unavailable {
  margin: 0;
  padding: var(--space-2) 0;
  font: 400 var(--step-fine)/1.4 var(--font-sans);
  color: #5b6b7b;
  font-style: italic;
}

@media (max-width: 719px) {
  .vastaajat-view__header { align-items: stretch; }
  .vastaajat-view .b2-control-toolbar { flex: 1 1 100%; }
  .demographic-panel__row {
    grid-template-columns: minmax(6rem, max-content) 1fr minmax(5.5rem, max-content);
    gap: var(--space-2);
  }
  /* At narrow widths the primary count and the "(x aineistossa)" ghost hint
   * combined exceed one row; stack the ghost onto the next line instead of
   * forcing a horizontal scroll. */
  .demographic-panel__stats { white-space: normal; }
  .demographic-panel__ghost-stat { display: block; }
}
