/* ===== Scene template: consistent look across all scenes ===== */
:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #c0392b;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

/* Intro article: linear, non-interactive lead-in before the map. */
#intro {
  width: min(640px, 92vw);
  padding: 3.5rem 1rem 2.5rem;
  line-height: 1.6;
}
.intro-title {
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  line-height: 1.15;
  margin: 0 0 1rem;
}
.intro-lede {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 1.5rem;
}
#intro p {
  margin: 0 0 1rem;
  color: #2b2b2b;
}
.intro-metrics {
  margin: 0.25rem 0 1.25rem;
  padding-left: 1.2rem;
  color: #2b2b2b;
}
.intro-metrics li { margin-bottom: 0.55rem; }
.intro-metrics strong { color: var(--fg); }

/* Inline "Find your city" button: desktop only, mobile uses #sticky-cta. */
.intro-cta {
  display: none;
  margin-top: 0.5rem;
  padding: 0.7rem 1.4rem;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  border-radius: 6px;
}
.intro-cta:hover { background: #a53125; }

@media (min-width: 768px) {
  .intro-cta { display: inline-block; } /* static button for desktop */
  #sticky-cta { display: none; }        /* floating button is mobile-only */
}

/* Floating "Find your city" button, mobile only; fades out once the map is in view. */
#sticky-cta {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 20;
  padding: 0.6rem 1.15rem;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  transition: opacity 0.25s ease;
}
#sticky-cta:hover { background: #a53125; }
#sticky-cta.cta-hidden { opacity: 0; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { #sticky-cta { transition: none; } }

#viz-container {
  width: min(1000px, 96vw);
  padding: 1rem;
  scroll-margin-top: 1rem; /* breathing room when the CTA jumps here */
}

/* shrinks on narrow screens so the chart keeps the vertical space */
header h1 {
  margin: 0.35rem 0 0.15rem;
  font-size: clamp(1.15rem, 4.2vw, 1.6rem);
  line-height: 1.2;
}

#scene-subtitle {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: clamp(0.85rem, 3.2vw, 1rem);
  line-height: 1.3;
}

#chart-box {
  position: relative;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
}

#chart {
  display: block;
  width: 100%;
  height: auto;
}

/* The waffles stack by default and sit side by side when there is width to
   spare or, as on a landscape phone, when height is the scarce axis. */
#waffle-pair {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.25rem 2rem;
  padding: 1.5rem 1rem;
}
@media (min-width: 830px), (max-height: 520px) {
  #waffle-pair {
    flex-direction: row;
    align-items: flex-start;
  }
}
/* .waffle carries the width; the svg fills it and gets its height from aspect-ratio */
.waffle-svg {
  display: block;
  width: 100%;
  height: auto;
}

/* only one chart surface shows per scene */
#chart[hidden], #waffle-pair[hidden] { display: none; }

#scene-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 0.75rem;
}

#scene-nav button {
  font: inherit;
  padding: 0.4rem 1rem;
  border: 1px solid var(--muted);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

#scene-nav button:hover:not(:disabled) { background: #eee; }
#scene-nav button:disabled { opacity: 0.4; cursor: default; }

#scene-breadcrumbs { display: flex; align-items: center; gap: 0.5rem; }
#scene-nav .breadcrumb-dot {
  width: 10px; height: 10px; padding: 0; border: none; border-radius: 50%;
  background: #ddd;
}
#scene-nav .breadcrumb-dot:hover { background: #bbb; }
#scene-nav .breadcrumb-active { background: var(--accent); }
#scene-nav .breadcrumb-active:hover { background: var(--accent); }

/* d3-annotation template styling */
.annotation-note-title { font-weight: 600; }
.annotation-note-label { fill: var(--muted); }

footer {
  margin-top: auto;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.85rem;
}
footer #attribution { max-width: 40rem; text-align: center; line-height: 1.5; }

/* ===== Waffle Year ===== */
/* Wraps one waffle's <svg> + its HTML caption. Width is what gets set, so the
   scene fits one screen: --waffle-chrome is the height everything else takes,
   and what's left becomes the chart, converted to a width by --waffle-ar
   (set in JS). The max() is a floor so cells stay countable on short screens. */
.waffle {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 0 1 auto;
  --waffle-chrome: 460px; /* stacked, so two charts and two captions */
  width: max(
    150px,
    min(85vw, calc((100dvh - var(--waffle-chrome)) / 2 * var(--waffle-ar)))
  );
}
/* Side by side: one chart's worth of height, and 50% of #waffle-pair less half
   its 2rem column gap to keep both on one row. */
@media (min-width: 830px), (max-height: 520px) {
  .waffle {
    --waffle-chrome: 390px;
    width: max(
      220px,
      min(calc(50% - 1rem), calc((100dvh - var(--waffle-chrome)) * var(--waffle-ar)))
    );
  }
}
/* Landscape phones: the chrome below is tightened too, and the floor drops
   because a short screen has no height to give. */
@media (max-height: 520px) {
  .waffle {
    --waffle-chrome: 305px;
    width: max(
      110px,
      min(calc(50% - 1rem), calc((100dvh - var(--waffle-chrome)) * var(--waffle-ar)))
    );
  }
}
/* the year as a fixed box: filled days grow into it, so what is left shows */
.waffle-frame { fill: #fdfcfa; stroke: #d6d2ca; stroke-width: 1; }

.waffle-label { font-size: 15px; font-weight: 600; color: var(--fg); margin-top: 0.6rem; }
.waffle-sublabel { font-size: 12px; color: var(--muted); }
.waffle-count { font-size: 18px; font-weight: 700; color: var(--accent); margin-top: 0.15rem; }

/* ===== Map (Scene 4) ===== */
.sphere { fill: #eef2f5; stroke: #d5dbe0; stroke-width: 0.5; }
/* halo (black ring + white ring) behind every dot, so it reads on any
   background color, light or dark */
.city-halo-black { fill: #000; }
.city-halo-white { fill: #fff; }
.city { stroke: none; }
.city-selected { stroke: none; }

/* map overlays */
.country-outline { fill: none; stroke: #7a7a7a; stroke-width: 0.5; }
.contour { stroke: none; }
.land-outline { fill: none; stroke: #4a4a4a; stroke-width: 0.9; stroke-linejoin: round; }

/* magnifying-glass lens: a zoomed live copy of the map, purely visual */
.map-lens { pointer-events: none; }
.map-lens-ring {
  fill: none; stroke: #1a1a1a; stroke-width: 1.5;
  pointer-events: none; filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.3));
}

/* map legend + toggles: an HTML control row above the map graphic itself */
#map-controls {
  display: flex; align-items: flex-start; flex-wrap: wrap;
  justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #eee;
}
#map-controls[hidden] { display: none; }

.map-legend-title { font-size: 13px; font-weight: 700; color: var(--fg); margin: 0; }
.map-legend-sub { font-size: 11.5px; color: var(--muted); margin: 2px 0 6px; }
.map-legend-bar { width: 240px; height: 18px; border-radius: 3px; border: 1px solid #bbb; }
.map-legend-ticks {
  display: flex; justify-content: space-between; width: 240px;
  font-size: 12px; font-weight: 600; color: var(--fg); margin-top: 3px;
}

/* "Change since" drives the whole map's meaning, so its buttons are pills. */
.baseline-toggle { display: flex; align-items: center; }
.baseline-toggle .map-toggle-label {
  font-size: 14px; font-weight: 600; color: var(--fg); margin-right: 0.5rem;
}
.baseline-toggle .map-toggle-btn {
  font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--fg);
  border: 1px solid #ddd; border-radius: 20px;
  padding: 0.3rem 0.9rem; margin-left: 6px;
  background: #fff; cursor: pointer;
}
.baseline-toggle .map-toggle-btn:hover { background: #dcdcdc; border-color: #bbb; }
.baseline-toggle .map-toggle-active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.baseline-toggle .map-toggle-active:hover { background: #a53125; border-color: #a53125; }

/* line chart (Scene 4) */
.linechart .grid { stroke: #e8e6e1; stroke-width: 1; }
.axis-label { font-size: 12px; fill: var(--muted); }
.axis-title { font-size: 11px; fill: var(--muted); }
.line-shared { fill: none; stroke: #1a1a1a; stroke-width: 2.5; }
.line-fork { fill: none; stroke-width: 2.5; }
.choice-gap { fill: #b0207010; }
.pt { fill: #1a1a1a; }
.end-title { font-size: 13px; font-weight: 700; }
.end-sub { font-size: 11px; fill: var(--muted); }

/* metric selector: segment buttons, wraps to more rows on narrow screens */
#metric-bar {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin: 0.5rem 0 0.6rem;
}
.metric-btn {
  font: inherit; font-size: 0.9rem; padding: 0.45rem 1rem; cursor: pointer;
  white-space: nowrap;
  background: #ececec; color: var(--muted);
  border: 1px solid #e0e0e0; border-radius: 6px;
}
.metric-btn:hover { background: #e2e2e2; color: var(--fg); }
.metric-active {
  background: #fff; color: var(--fg); font-weight: 700;
  /* 3px accent underline (color set inline per metric) keeps the color cue the
     old tabs had; inset shadow avoids any layout shift on selection. */
  box-shadow: inset 0 -3px 0 var(--metric-accent, var(--accent)),
              0 1px 2px rgba(0, 0, 0, 0.08);
}

/* map hover tooltip: follows the cursor over a city dot */
#map-tooltip {
  position: absolute;
  pointer-events: none;
  background: #1a1a1a;
  color: #fff;
  font-size: 0.8rem;
  line-height: 1.4;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  transform: translate(-50%, -100%);
  z-index: 2;
}
#map-tooltip[hidden] { display: none; }
#map-tooltip strong { font-weight: 700; }

/* city selector: a control row at the top of the chart box, shown on the story
   scenes (the map scene shows #map-controls in the same spot instead). */
#city-select-label {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #eee;
}
#city-select-label[hidden] { display: none; }
.city-select-caption {
  flex: none; /* keep the CITY caption from shrinking */
  font-size: 0.8rem; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.03em;
}
#city-select {
  font: inherit; font-size: 0.9rem; padding: 0.35rem 1.6rem 0.35rem 0.6rem; cursor: pointer;
  background: #fff; border: 1px solid #ddd; border-radius: 4px;
  color: var(--fg);
  /* shrink to fit the row on narrow screens, truncating a long name rather
     than overflowing. */
  min-width: 0; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#city-select:hover { background: #f2f2f2; }
#city-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ===== Small screens =====
   Narrow ones stack the waffles and short ones have little height to begin
   with; either way the chart needs the space, so everything around it is
   tightened. Last in the file so it wins over the rules it overrides. */
@media (max-width: 829px), (max-height: 620px) {
  #viz-container { padding: 0.5rem; }
  #metric-bar { gap: 0.3rem; margin: 0.35rem 0 0.4rem; }
  .metric-btn { font-size: 0.78rem; padding: 0.35rem 0.55rem; }
  #city-select-label { padding: 0.45rem 0.6rem; }
  #city-select { font-size: 0.82rem; padding: 0.25rem 1.4rem 0.25rem 0.5rem; }
  #waffle-pair { padding: 0.6rem 0.5rem; gap: 0.6rem; }
  #scene-nav { gap: 0.5rem; margin-top: 0.4rem; }
  #scene-nav button { font-size: 0.82rem; padding: 0.35rem 0.6rem; }
  .waffle-label { font-size: 13px; margin-top: 0.3rem; }
  .waffle-sublabel { font-size: 11px; }
  .waffle-count { font-size: 15px; margin-top: 0; }
}
