/* Eurovision scrollytelling — pattern demo
   Visual language matched to the main project (Source Serif + Inter, #fafafa,
   #c0392b accent). Layout is overlay-style: a sticky full-width chart behind,
   cards floating over on the right (desktop) or stacking centred (mobile). */

:root {
  --bg:        #fafafa;
  --fg:        #1a1a1a;
  --muted:     #666;
  --rule:      #d8d4cc;
  --accent:    #c0392b;
  --highlight: #f1c40f;
  --card-bg-desktop: rgba(255, 255, 255, 0.92);
  --card-bg-mobile:  #ffffff;
  --card-shadow:     0 2px 16px rgba(0, 0, 0, 0.06);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: "Source Serif 4", Georgia, serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3 { font-family: "Source Serif 4", Georgia, serif; font-weight: 700; line-height: 1.2; }

/* ── Hero / intro ─────────────────────────────────────────── */
header.intro {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  background: #1a1a2e;
  color: #fff;
}
header.intro h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  max-width: 760px;
  margin-bottom: 0.6em;
  letter-spacing: -0.005em;
}
header.intro .dek {
  font-size: clamp(1rem, 1.4vw, 1.2rem);
  opacity: 0.85;
  max-width: 540px;
  font-style: italic;
}
header.intro .hint {
  margin-top: 3rem;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.5;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50%      { opacity: 0.95; }
}

/* ── Desktop-recommended ribbon (mobile-only) ─────────────── */
.desktop-hint {
  display: none;
}
@media (max-width: 720px) {
  .desktop-hint {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    background: #1a1a2e;
    color: #fff;
    font-family: "Inter", system-ui, sans-serif;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    padding: 0.55em 1em;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.12);
  }
  .desktop-hint-icon {
    font-size: 0.95em;
    line-height: 1;
  }
}

/* ── Primer between intro hero and the scrolly chart ──────── */
.primer {
  background: var(--bg);
  padding: 4rem 1.5rem 3rem;
  display: flex;
  justify-content: center;
}
.primer-inner {
  max-width: 640px;
  text-align: center;
}
.primer .kicker {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1.4em;
}
.primer p {
  font-size: clamp(1rem, 1.25vw, 1.1rem);
  line-height: 1.6;
  color: #2a2a2a;
  margin: 0 0 1em;
}
.primer .hint {
  margin-top: 2.2rem;
  font-family: "Inter", system-ui, sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  animation: pulse 2s ease-in-out infinite;
}

/* ── Scroll container (overlay style) ─────────────────────── */
.scrolly {
  position: relative;
}

/* The chart sits sticky in the background — full viewport width on every
   breakpoint. Cards float on top via z-index. */
.chart {
  position: sticky;
  top: 0;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 1;
  margin: 0;
  /* Tell the browser the chart's repaints don't escape this box and that
     transforms are coming, so it can promote it to its own paint layer. */
  contain: layout paint;
  will-change: transform;
}
#chart {
  position: relative;
  width: 100%;
  max-width: 900px;
  height: 80vh;
  /* Inner SVG container — same containment hint, narrower scope. */
  contain: layout paint;
}

/* Loading overlay — covers #chart from initial HTML paint until the chart
   has rendered its first frame, then fades out. */
.chart-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1em;
  background: var(--bg);
  z-index: 3;
  pointer-events: none;
  transition: opacity 380ms ease-out;
}
.chart-loading.is-hidden { opacity: 0; }
.chart-loading-spinner {
  width: 34px;
  height: 34px;
  border: 3px solid #e6e2d8;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chart-loading-spin 0.9s linear infinite;
}
.chart-loading-text {
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
@keyframes chart-loading-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .chart-loading-spinner { animation-duration: 1.8s; }
  .chart-loading { transition: none; }
}
.caption {
  margin-top: 0.6em;
  color: var(--muted);
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
  font-style: italic;
}

.steps {
  position: relative;
  z-index: 2;
  pointer-events: none;        /* let chart receive scroll/hover */
  padding: 0;
}

.step {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 1.44rem 1.08rem;     /* was 2rem 1.5rem — 28% trim */
  max-width: 21.6em;            /* was 30em — 28% narrower */
  margin-left: 5%;
  pointer-events: auto;        /* but the card itself is interactive */
}
/* Empty spacer step — no card, just lets the sticky chart breathe. */
.step.is-spacer {
  min-height: 90vh;
  background: transparent;
  pointer-events: none;
  padding: 0;
  margin: 0;
}
.step h2 {
  background: var(--card-bg-desktop);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: inline-block;
  padding: 0.45em 0.7em;
  border-radius: 6px 6px 0 0;
  font-size: clamp(1.0rem, 1.73vw, 1.22rem);   /* was 1.4-1.7rem · 28% smaller */
  margin: 0;
  letter-spacing: -0.005em;
}
.step .body {
  background: var(--card-bg-desktop);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 0.72rem 0.99rem 0.85rem;            /* was 1rem 1.4rem 1.2rem */
  border-radius: 0 8px 8px 8px;
  box-shadow: var(--card-shadow);
  font-size: 0.78rem;                           /* was 1rem · ~22% smaller; floor for legibility */
}
.step .body p { margin: 0 0 0.8em; color: #2c2c2c; }
.step .body p:last-child { margin-bottom: 0; }

/* ── Vocabulary section · centred, larger cards ───────────── */
/* Used by steps 15-20 (section intro + 5 word spotlights). The dot chart
   fades behind these cards so the words and their sparklines take the
   visual lead. */
.step.is-word {
  margin-left: auto;
  margin-right: auto;
  max-width: 25.9em;        /* was 36em · 28% narrower */
  text-align: left;
}
.step.is-word h2 {
  font-size: clamp(1.15rem, 2.16vw, 1.44rem);  /* was 1.6-2rem · 28% smaller */
  padding: 0.5em 0.85em;
}
.step.is-word .body {
  padding: 0.85em 1.17em 1.03em;                /* was 1.2em 1.6em 1.4em */
  font-size: 0.81rem;                            /* was 1.05rem · ~22% smaller */
}
.step.is-word .step-chart {
  margin-top: 0.9em;
  padding: 0.76em 0.9em 0.67em;
}
.step.is-word .step-chart svg {
  height: 108px;            /* was 140px */
}
/* The section's opening card — distinct from the spotlight cards that follow */
.step.section-intro h2 {
  font-size: clamp(1.22rem, 2.3vw, 1.58rem);   /* was 1.7-2.2rem · 28% smaller */
  background: #1a1a2e;
  color: #fff;
  border-radius: 6px;
}
.step.section-intro .body {
  background: var(--card-bg-desktop);
  font-size: 1.08rem;
  line-height: 1.7;
}
.step.section-intro .kicker {
  font-family: "Inter", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.6em;
  padding: 0.25em 0.7em;
  background: var(--card-bg-desktop);
  display: inline-block;
  border-radius: 4px;
  font-weight: 600;
}
@media (max-width: 720px) {
  .step.is-word { max-width: none; }
  .step.section-intro h2 { background: #1a1a2e; }
  /* Compact the theme legend so the closing card doesn't tower over the
     stacked bubbles. */
  .theme-key {
    grid-template-columns: 1fr 1fr;
    gap: 0.25em 0.7em;
    padding: 0.5em 0.7em;
    font-size: 0.72rem;
  }
  .theme-key .swatch { width: 9px; height: 9px; flex: 0 0 9px; }
}

/* ── Theme legend (step 2) ────────────────────────────────── */
.theme-key,
.lang-key {
  list-style: none;
  margin: 1em 0 0;
  padding: 0.7em 0.9em;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35em 1em;
  font-family: "Inter", sans-serif;
  font-size: 0.8rem;
}
.lang-key li {
  display: flex;
  align-items: center;
  gap: 0.55em;
  color: #333;
}
.lang-key .swatch {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block; flex: 0 0 11px;
}
.theme-key li {
  display: flex;
  align-items: center;
  gap: 0.55em;
  color: #333;
}
.theme-key .swatch {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 11px;
}

/* Mini swatch inside winner/cluster meta-pill "Theme" values. */
.meta-value .swatch {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 0.4em;
  vertical-align: 1px;
  flex: 0 0 9px;
}

/* ── Inline mini chart (steps 5/6/7) ──────────────────────── */
.step-chart {
  margin-top: 1em;
  padding: 0.8em 1em 0.7em;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
}
.step-chart svg { display: block; width: 100%; height: 110px; }
.step-chart .mini-title {
  font-family: "Inter", sans-serif;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5em;
}

/* ── Example songs (theme cards) ──────────────────────────── */
.examples {
  list-style: none;
  margin: 0.9em 0 0;
  padding: 0;
  font-family: "Inter", sans-serif;
  font-size: 0.82rem;
  border-top: 1px solid var(--rule);
  padding-top: 0.7em;
}
.examples li {
  padding: 0.25em 0;
  color: #2c2c2c;
  line-height: 1.4;
}
.examples em { font-style: italic; color: #1a1a1a; }
.examples .ex-win {
  display: inline-block;
  background: var(--highlight);
  color: #1a1a1a;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.1em 0.45em;
  border-radius: 3px;
  margin-right: 0.35em;
  vertical-align: 1px;
}
.examples .ex-place {
  color: var(--muted);
  font-size: 0.78rem;
}

/* ── Bridge (between scrolly and explore) ─────────────────── */
.bridge {
  position: relative;
  z-index: 3;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  padding: 5em 6vw 3em;
}
.bridge-inner {
  max-width: 720px;
  margin: 0 auto;
  text-align: center;
}
.bridge .kicker {
  font-family: "Inter", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 1em;
}
.bridge h2 {
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  margin-bottom: 0.6em;
}
.bridge .lede {
  font-size: 1.05rem;
  color: #2c2c2c;
  max-width: 640px;
  margin: 0 auto;
}

/* ── Explore (interactive widgets) ────────────────────────── */
.explore {
  position: relative;
  z-index: 3;
  background: var(--bg);
  padding: 2em 6vw 5em;
  max-width: 1100px;
  margin: 0 auto;
}

/* Wrap that sits the explore widget next to a sticky ad rail on desktop.
   Default: single column (matches the previous full-width layout). When
   .has-rail is added by PHP — i.e. ads are switched on — split into two. */
.explore-wrap {
  position: relative;
  z-index: 3;
}
.explore-wrap.has-rail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 2em;
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 6vw;
  align-items: start;
}
.explore-wrap.has-rail > .explore {
  padding-left: 0;
  padding-right: 0;
  margin: 0;
  max-width: none;
}
.explore-rail {
  position: sticky;
  top: 1.5em;
  align-self: start;
  padding-top: 2em;
}

/* Inline ad slot (between sections). Centred, with the same neutral framing
   as the rail so both ads read as "page chrome", not story content. */
.ad-inline {
  display: flex;
  justify-content: center;
  margin: 2em auto 1em;
  position: relative;
  z-index: 3;
}
.ad-card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.6em 0.7em 0.7em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  font-family: "Inter", sans-serif;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4em;
}
.ad-card .ad-tag {
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  align-self: stretch;
  text-align: left;
}

@media (max-width: 980px) {
  /* Below this width, drop the side rail beneath the explore section. */
  .explore-wrap.has-rail {
    grid-template-columns: 1fr;
    padding: 0;
  }
  .explore-wrap.has-rail > .explore { padding: 2em 6vw 1em; }
  .explore-rail {
    position: static;
    padding: 0 6vw 2em;
    display: flex;
    justify-content: center;
  }
}

/* Tab strip */
.tabs {
  display: flex;
  gap: 0.4em;
  border-bottom: 1px solid var(--rule);
  margin-bottom: -1px;            /* lap onto the panel border */
  flex-wrap: wrap;
}
.tab {
  font-family: "Inter", sans-serif;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  padding: 0.7em 1.1em;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  position: relative;
  top: 1px;                        /* sit on the rule */
}
.tab:hover { color: var(--fg); background: rgba(0, 0, 0, 0.025); }
.tab.is-active {
  color: var(--fg);
  background: #fff;
  border-color: var(--rule);
  border-bottom-color: #fff;       /* hide the rule under the active tab */
  font-weight: 600;
}
.tab .tab-badge {
  display: inline-block;
  background: var(--rule);
  color: #555;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.15em 0.45em;
  border-radius: 3px;
  margin-left: 0.4em;
  vertical-align: 1px;
}

/* Panels */
.tab-panel {
  border-radius: 0 10px 10px 10px;
}
.tab-panel[hidden] { display: none; }
.widget {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.6em 1.8em 1.4em;
  box-shadow: var(--card-shadow);
}
.widget-head h3 {
  font-size: 1.3rem;
  margin-bottom: 0.35em;
}
.widget-head p {
  font-family: "Inter", sans-serif;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 1.1em;
}
.widget-head .badge {
  display: inline-block;
  background: var(--rule);
  color: #555;
  font-family: "Inter", sans-serif;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.2em 0.55em;
  border-radius: 3px;
  margin-left: 0.4em;
  vertical-align: 4px;
}

.widget-controls {
  display: flex;
  gap: 0.6em;
  align-items: stretch;
  margin-bottom: 1em;
}
.search-wrap {
  position: relative;
  flex: 1;
}
#song-search,
#ngram-input {
  width: 100%;
  font-family: "Inter", sans-serif;
  font-size: 0.95rem;
  padding: 0.6em 0.9em;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fafafa;
  color: var(--fg);
}
#song-search:focus,
#ngram-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  list-style: none;
  margin: 0;
  padding: 0.3em 0;
  max-height: 280px;
  overflow-y: auto;
  z-index: 10;
  font-family: "Inter", sans-serif;
  font-size: 0.88rem;
}
.suggestions li {
  padding: 0.45em 0.9em;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 1em;
}
.suggestions li:hover,
.suggestions li.active {
  background: #f4efe6;
}
.suggestions .s-meta {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.btn-ghost {
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
  padding: 0 1em;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
}
.btn-ghost:hover { background: #f4efe6; color: var(--fg); }

/* Theme toggles */
.theme-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45em 0.6em;
  align-items: center;
  margin: 0 0 1em;
  font-family: "Inter", sans-serif;
}
.theme-toggles .toggles-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 0.3em;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.28em 0.7em 0.28em 0.4em;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 150ms, color 150ms, border-color 150ms;
}
.theme-toggle .swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: transparent;
  flex: 0 0 12px;
  transition: background 150ms;
}
.theme-toggle.is-on {
  color: var(--fg);
  border-color: currentColor;
  background: #fafafa;
  font-weight: 600;
}
.theme-toggle.is-on .swatch { background: currentColor; }

/* Card meta-pills — small chips at the top of a step card showing the
   theme / language of the song being spotlighted. Used in the winner
   spotlight cards so every card has a consistent label-strip. */
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  margin: 0 0 0.9em;
  padding: 0;
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
}
.meta-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45em;
  padding: 0.22em 0.7em;
  border-radius: 999px;
  background: #fffaf0;
  border: 1px solid var(--rule);
  color: #2c2c2c;
  line-height: 1.4;
}
.meta-pill .meta-label {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.66rem;
  color: var(--muted);
}
.meta-pill .meta-value {
  font-weight: 500;
}
/* Composite swatches keep their inline gradient (inline beats currentColor). */
.theme-toggle .swatch.swatch-twotone,
.theme-toggle .swatch.swatch-rainbow { border-width: 1px; }
.theme-toggle:hover { color: var(--fg); }
.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.widget-chart {
  position: relative;
}
#explore-chart {
  width: 100%;
  height: 460px;
}
.tooltip {
  position: absolute;
  pointer-events: none;
  background: #1a1a1a;
  color: #fff;
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 0.5em 0.7em;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  max-width: 240px;
  z-index: 5;
}
.tooltip strong { color: #f1c40f; font-weight: 600; }
.tooltip .t-meta { color: #bbb; font-size: 0.72rem; margin-top: 2px; }

.widget-foot {
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.6em;
}

/* ── Language picker (3rd tab) ────────────────────────────── */
.lang-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  font-family: "Inter", sans-serif;
  font-size: 0.84rem;
  color: var(--muted);
}
.lang-picker select {
  font-family: "Inter", sans-serif;
  font-size: 0.9rem;
  padding: 0.4em 0.7em;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fafafa;
  color: var(--fg);
  cursor: pointer;
}
.lang-picker select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}
#language-chart { width: 100%; height: 460px; }
.lang-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em 0.9em;
  font-family: "Inter", sans-serif;
  font-size: 0.8rem;
  margin-top: 0.6em;
}
.lang-legend .lg-item {
  display: inline-flex; align-items: center; gap: 0.35em;
}
.lang-legend .lg-swatch {
  width: 11px; height: 11px; border-radius: 50%;
  display: inline-block; flex: 0 0 11px;
}
@media (max-width: 720px) {
  #language-chart { height: 360px; }
}

/* ── n-gram widget ────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { background: #a23120; color: #fff; }

.ngram-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em 0.7em;
  align-items: center;
  margin-bottom: 0.7em;
  font-family: "Inter", sans-serif;
  font-size: 0.82rem;
}
.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.25em 0.7em;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: #fafafa;
  cursor: pointer;
  user-select: none;
}
.toggle-pill input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}
.toggle-pill:has(input:checked) {
  background: #fff;
  border-color: var(--accent);
  color: var(--fg);
  font-weight: 600;
}
.toggle-hint {
  color: var(--muted);
  font-size: 0.76rem;
  margin-left: 0.3em;
}

/* Sliding switch — standard <input type="checkbox"> styled as an iOS-style toggle. */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-family: "Inter", sans-serif;
  font-size: 0.82rem;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
}
.switch input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #d6d2c4;
  border: 1px solid var(--rule);
  cursor: pointer;
  transition: background 150ms, border-color 150ms;
  flex: 0 0 36px;
  margin: 0;
}
.switch input::before {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 150ms;
}
.switch input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked::before {
  transform: translateX(16px);
}
.switch input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ngram-presets {
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 1em;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  align-items: center;
}
.ngram-presets .preset {
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
  background: #fafafa;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.2em 0.7em;
  color: var(--muted);
  cursor: pointer;
}
.ngram-presets .preset:hover { color: var(--fg); border-color: var(--fg); }

#ngram-chart { width: 100%; height: 320px; }

.ngram-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8em;
  font-family: "Inter", sans-serif;
  font-size: 0.82rem;
  margin: 0.4em 0 0.2em;
}
.ngram-legend .lg-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
}
.ngram-legend .lg-swatch {
  width: 14px; height: 3px; border-radius: 2px; display: inline-block;
}

.ngram-detail h4 {
  font-size: 0.85rem;
  font-family: "Inter", sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.4em 0 0.6em;
}
.ngram-examples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1em 1.4em;
  font-family: "Inter", sans-serif;
  font-size: 0.86rem;
}
.ngram-examples .ex-group { }
.ngram-examples .ex-token {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 0.4em;
  display: flex;
  align-items: center;
  gap: 0.5em;
}
.ngram-examples .ex-token .ex-swatch {
  width: 14px; height: 3px; border-radius: 2px; display: inline-block;
}
.ngram-examples ul { list-style: none; padding: 0; margin: 0; }
.ngram-examples li {
  padding: 0.2em 0;
  line-height: 1.4;
  border-left: 2px solid var(--rule);
  padding-left: 0.7em;
  margin-bottom: 0.45em;
}
.ngram-examples em { font-style: italic; color: #1a1a1a; }
.ngram-examples .ng-meta { color: var(--muted); font-size: 0.78rem; }

.widget-stub .stub-placeholder {
  background: repeating-linear-gradient(
    45deg, #f4efe6, #f4efe6 8px, #fafafa 8px, #fafafa 16px);
  border: 1px dashed var(--rule);
  border-radius: 6px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

@media (max-width: 720px) {
  .widget-controls { flex-direction: column; }
  /* Mobile fix: keep desktop dot density but let the timeline scroll
     horizontally. The wrapper is the scroll viewport; the chart itself is
     forced wider than the screen. */
  .widget-chart {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* tiny shadow hint at the right edge so users know it scrolls */
    background:
      linear-gradient(90deg, transparent calc(100% - 24px), rgba(0,0,0,0.04));
    border-radius: 6px;
  }
  #explore-chart,
  #ngram-chart,
  #language-chart {
    width: 980px;
    min-width: 980px;
    height: 360px;
  }
  /* Tooltip is positioned relative to the (now-scrollable) wrapper, which is
     fine — but cap its width so it doesn't overflow on narrow screens. */
  .tooltip { max-width: 200px; font-size: 0.74rem; }
}

/* ── Footer ───────────────────────────────────────────────── */
/* ── Methodology section ──────────────────────────────────── */
.methodology {
  background: var(--bg);
  border-top: 1px solid var(--rule);
  padding: 4em 6vw 3.5em;
}
.methodology-inner {
  max-width: 680px;
  margin: 0 auto;
}
.methodology h2 {
  font-size: 1.15rem;
  font-family: "Inter", sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.4em;
}
.methodology p {
  font-size: 0.9rem;
  line-height: 1.75;
  color: #444;
  margin-bottom: 1em;
}
.methodology p + p { margin-top: 0; }
.methodology a { color: var(--fg); text-decoration: underline; text-underline-offset: 2px; }
.methodology a:hover { color: var(--accent); }

footer {
  position: relative;
  z-index: 2;
  background: var(--bg);
  border-top: 1px solid var(--rule);
  padding: 3em 6vw 2.5em;
  text-align: center;
  color: var(--muted);
  font-family: "Inter", sans-serif;
  font-size: 0.85rem;
}
.footer-inner {
  max-width: 760px;
  margin: 0 auto;
}
.footer-inner .credits {
  font-size: 0.88rem;
  color: var(--fg);
  margin-bottom: 0.7em;
  line-height: 1.6;
}
.footer-inner .credits em {
  color: var(--muted);
  font-style: italic;
}
.footer-inner .meta {
  font-size: 0.74rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* ── Chart elements ───────────────────────────────────────── */
svg .axis text  { fill: var(--muted); font-family: "Inter", sans-serif; font-size: 11px; }
svg .axis path,
svg .axis line  { stroke: var(--rule); }
svg .dot        { transition: fill 400ms ease, opacity 400ms ease; }
svg .axis-label {
  fill: var(--muted);
  font-family: "Inter", sans-serif;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Mobile — solid white cards, full-width centred ───────── */
@media (max-width: 720px) {
  .step {
    margin-left: 0;
    max-width: none;
    padding: 1.5rem 1rem;
  }
  .step h2,
  .step .body {
    background: var(--card-bg-mobile);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  .step h2 {
    border-radius: 6px 6px 0 0;
    padding: 0.45em 0.7em;
  }
  .step .body {
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.08);
  }
  #chart {
    max-width: 95vw;
    height: 75vh;
  }
  header.intro { min-height: 56vh; padding: 1.5rem; }
}
