/* Nepal Population Explorer -----------------------------------------
   Palette is deliberately muted: no strong reds or greens, nothing that reads
   as a party colour, and every chart series is labelled as well as coloured.
   Light and dark are both defined so the page holds up either way.          */

:root {
  --paper:   #f4f6f8;
  --sheet:   #ffffff;
  --surface: #fbfcfd;
  --ink:     #16222e;
  --slate:   #5d6b79;
  --rule:    #dfe4ea;
  --rule-2:  #a9b4c0;
  --teal:    #0b5f70;
  --ochre:   #8a6320;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:   #0d141b;
    --sheet:   #141d26;
    --surface: #1b2733;
    --ink:     #e4eaf0;
    --slate:   #93a2b1;
    --rule:    #26323e;
    --rule-2:  #536373;
    --teal:    #5cb7ca;
    --ochre:   #d6ac5e;
  }
}

* { box-sizing: border-box; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  margin: 0;
  padding: 0 0 64px;
}

main, .page-columns, .content { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

/* Quarto's default title block is replaced by .masthead below */
#title-block-header { display: none; }

.masthead {
  border-bottom: 2px solid var(--ink);
  padding: 40px 0 24px;
  margin-bottom: 28px;
}
.masthead h1 {
  font-size: clamp(30px, 4.4vw, 44px);
  line-height: 1.06;
  letter-spacing: -.015em;
  font-weight: 600;
  margin: 0 0 12px;
}
.masthead .sub {
  color: var(--slate);
  font-size: 17px;
  max-width: 68ch;
  margin: 0;
}

h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.005em;
  margin: 44px 0 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}
h3 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }

/* OJS wraps every cell's output in three nested divs (.cell >
   .cell-output-display > #ojs-cell-N). Left alone, a flex or grid container
   would lay out that single wrapper instead of the content inside it, and
   everything stacks in one column. display:contents makes the wrappers
   transparent to layout. */
.controls .cell, .controls .cell-output, .controls .cell-output-display,
.controls [id^="ojs-cell"] {
  display: contents;
}

/* ---- controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 32px;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 18px 22px;
  margin-bottom: 26px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.controls form { margin: 0 !important; }
.controls label { font-size: 12px !important; letter-spacing: .04em; color: var(--slate) !important; }
.controls select, .controls input[type="number"] {
  font-size: 15px;
  padding: 4px 6px;
  border: 1px solid var(--rule-2);
  border-radius: 2px;
  background: var(--sheet);
  color: var(--ink);
}
.controls select { min-width: 210px; }
.controls input:focus-visible, .controls select:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

/* ---- stat row ---- */
.stats { margin: 6px 0 12px; }
.statgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: 3px;
  overflow: hidden;
}
.stat {
  background: var(--sheet);
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat .k {
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--slate);
}
.stat .v {
  font-size: 30px;
  font-weight: 600;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat .v small { font-size: 17px; font-weight: 500; color: var(--slate); }
.stat .v.down { color: var(--ochre); }
.stat .n { font-size: 13px; color: var(--slate); font-variant-numeric: tabular-nums; }

/* ---- panels ---- */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 22px;
  margin-top: 8px;
}
.panel {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 20px 22px 16px;
}

.cap {
  font-size: 13px;
  line-height: 1.5;
  color: var(--slate);
  margin: 12px 0 0;
  max-width: 72ch;
}
.cap strong { color: var(--ink); font-weight: 600; }

/* ---- plots ---- */
figure { margin: 0; }
svg { max-width: 100%; height: auto; }
.cell-output-display { overflow-x: auto; }

/* ---- colophon ---- */
.colophon {
  margin-top: 48px;
  border-top: 2px solid var(--ink);
  padding-top: 20px;
  font-size: 13.5px;
  color: var(--slate);
  line-height: 1.6;
}
.colophon p { max-width: 76ch; margin: 0 0 10px; }
.colophon strong { color: var(--ink); }
.colophon code {
  font-family: ui-monospace, "IBM Plex Mono", monospace;
  font-size: .9em;
  background: var(--surface);
  border: 1px solid var(--rule);
  padding: 1px 4px;
  border-radius: 2px;
}

@media (max-width: 640px) {
  main, .page-columns, .content { padding: 0 14px; }
  .controls { position: static; }
  .stat .v { font-size: 25px; }
}

/* ---- about ---- */
.about {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 8px clamp(20px, 3vw, 34px) 28px;
  margin-top: 8px;
}
.about h3 {
  font-size: 17px;
  font-weight: 600;
  margin: 30px 0 10px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
}
.about > h3:first-child { border-top: none; padding-top: 4px; margin-top: 8px; }
.about p { font-size: 15.5px; line-height: 1.62; max-width: 74ch; margin: 0 0 13px; }
.about ul { font-size: 15.5px; line-height: 1.6; max-width: 74ch; padding-left: 20px; margin: 0; }
.about li { margin-bottom: 7px; }
.about table { font-size: 14.5px; min-width: 480px; margin: 4px 0 6px; }
.about th, .about td { padding: 9px 16px 9px 0; }
.about blockquote {
  margin: 4px 0;
  padding: 14px 18px;
  background: var(--surface);
  border-left: 2px solid var(--teal);
  font-size: 15px;
  line-height: 1.6;
}
.about blockquote p { margin: 0; font-style: normal; }
.about strong { font-weight: 600; }

/* The control bar is sticky, so anything scrolled to by anchor would land
   underneath it. Reserve its height. */
h2, h3, .panel { scroll-margin-top: 130px; }
