/* Break Up California — civic / official aesthetic.
   Two state colors are colorblind-safe (blue vs. orange, distinct in grayscale) and used
   consistently across the map, bars, and share image. */
:root {
  --ink: #1c2733;
  --muted: #5b6b7b;
  --line: #d8dee5;
  --bg: #f4f6f8;
  --paper: #ffffff;
  --navy: #1d3557;

  /* State colors (Okabe-Ito-derived, colorblind-safe) */
  --state-a: #2166ac;        /* blue  */
  --state-a-soft: #9ec4e0;
  --state-b: #e08214;        /* orange */
  --state-b-soft: #f3c48a;
  --unassigned: #cdd8e3;

  --radius: 8px;
  --shadow: 0 1px 3px rgba(20, 35, 51, 0.08), 0 1px 2px rgba(20, 35, 51, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--navy); }

.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.9rem 1.5rem; background: var(--navy); color: #fff;
}
.site-title { font-weight: 700; font-size: 1.15rem; text-decoration: none; color: #fff; letter-spacing: 0.2px; }
.site-nav a { color: #cfe0f0; text-decoration: none; font-size: 0.95rem; }
.site-nav a:hover { color: #fff; }

.site-main { max-width: 1180px; margin: 0 auto; padding: 1.5rem; }
.site-footer {
  max-width: 1180px; margin: 1.5rem auto 3rem; padding: 1rem 1.5rem;
  color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line);
}

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: 320px 1fr; gap: 1.5rem; align-items: start; }
.editor__panel {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.2rem; position: sticky; top: 1rem;
}
.editor__map {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 0.5rem;
}
.intro { margin: 0 0 1rem; color: var(--muted); }

.panel-heading { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 1.2rem 0 0.5rem; }
.panel-heading:first-of-type { margin-top: 0; }

/* Active-state toggle */
.brush { display: flex; gap: 0.5rem; }
.brush__btn {
  flex: 1; border: 2px solid var(--line); background: var(--paper); border-radius: var(--radius);
  padding: 0.55rem 0.5rem; cursor: pointer; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 0.5rem; justify-content: center;
}
.brush__btn .swatch { width: 14px; height: 14px; border-radius: 3px; }
.brush__btn[data-state="A"] .swatch { background: var(--state-a); }
.brush__btn[data-state="B"] .swatch { background: var(--state-b); }
.brush__btn.is-active[data-state="A"] { border-color: var(--state-a); box-shadow: 0 0 0 1px var(--state-a); }
.brush__btn.is-active[data-state="B"] { border-color: var(--state-b); box-shadow: 0 0 0 1px var(--state-b); }

/* Name inputs */
.name-field { margin-bottom: 0.6rem; }
.name-field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.2rem; }
.name-field input {
  width: 100%; padding: 0.45rem 0.55rem; border: 1px solid var(--line);
  border-radius: 6px; font-size: 0.95rem;
}

/* Accordion (native <details>) */
.accordion { margin-top: 1.2rem; }
.accordion__summary { margin: 0 0 0.5rem; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 0.35rem; }
.accordion__summary::-webkit-details-marker { display: none; }
.accordion__summary::before { content: "▸"; font-size: 1.4rem; line-height: 1; transition: transform 0.15s; color: var(--muted); }
.accordion[open] .accordion__summary::before { transform: rotate(90deg); }

/* Color pickers */
.colorpick { display: flex; flex-direction: column; gap: 0.5rem; }
.swatchrow__label { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.2rem; }
.swatchrow { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.swatchbtn { aspect-ratio: 1; border: 2px solid transparent; border-radius: 5px; cursor: pointer; padding: 0; }
.swatchbtn.is-selected { border-color: var(--ink); box-shadow: 0 0 0 1px #fff inset; }

/* Presets */
.presets { display: flex; flex-direction: column; gap: 0.4rem; }
.presets button {
  text-align: left; border: 1px solid var(--line); background: var(--paper);
  border-radius: 6px; padding: 0.5rem 0.6rem; cursor: pointer; font-size: 0.92rem;
}
.presets button:hover { border-color: var(--navy); }

.compare-btn {
  width: 100%; margin-top: 1.2rem; padding: 0.7rem; font-size: 1rem; font-weight: 700;
  color: #fff; background: var(--navy); border: none; border-radius: var(--radius); cursor: pointer;
}
.compare-btn:hover { background: #16273f; }
.guard-msg { color: #9a3b2f; font-size: 0.85rem; margin-top: 0.5rem; min-height: 1.1em; }

/* Map SVG */
.county { fill: var(--state-a); stroke: #ffffff; stroke-width: 0.6; cursor: pointer; }
.county[data-state="B"] { fill: var(--state-b); }
.county:hover { stroke: var(--navy); stroke-width: 1.2; }
svg.ca-map { width: 100%; height: auto; display: block; margin: 0 auto; touch-action: none; }

/* On desktop, make the editor fill the viewport height so it doesn't scroll on large
   monitors: the map scales to fit its column, and the controls panel scrolls internally only
   if it is taller than the viewport. preserveAspectRatio keeps the map's shape. */
@media (min-width: 721px) {
  /* Editor page fills the viewport exactly so it never scrolls; the map scales to fit and the
     controls panel scrolls internally only if taller than the viewport. */
  body.page-editor { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  body.page-editor .site-main { flex: 1 1 auto; min-height: 0; width: 100%; }
  body.page-editor .site-footer { margin: 0.3rem auto 0.5rem; border-top: none; }
  .editor { height: 100%; align-items: stretch; }
  .editor__panel { align-self: start; max-height: 100%; overflow-y: auto; }
  .editor__right { min-height: 0; display: flex; flex-direction: column; }
  .editor__map { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
  svg.ca-map { width: auto; height: auto; max-width: 100%; max-height: 100%; }
}

/* Legend */
.legend { display: flex; gap: 1rem; font-size: 0.85rem; color: var(--muted); margin-top: 0.4rem; padding: 0 0.5rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; }

@media (max-width: 720px) {
  .editor { grid-template-columns: 1fr; }
  .editor__panel { position: static; }
}

/* ---------- Buttons / chips ---------- */
.btn {
  display: inline-block; background: var(--navy); color: #fff; text-decoration: none;
  padding: 0.55rem 0.9rem; border-radius: var(--radius); font-weight: 600; font-size: 0.92rem;
}
.btn:hover { background: #16273f; }
.btn--ghost { background: var(--paper); color: var(--navy); border: 1px solid var(--line); }
.btn.is-copied { background: #1b7837; }
.chip { padding: 0.05em 0.4em; border-radius: 5px; color: #fff; }
.chip--a { background: var(--state-a); color: #fff; padding: 0.05em 0.4em; border-radius: 5px; }
.chip--b { background: var(--state-b); color: #fff; padding: 0.05em 0.4em; border-radius: 5px; }
.muted { color: var(--muted); }

/* ---------- Results ---------- */
.results__head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.8rem; }
.results__head h1 { font-size: 1.6rem; margin: 0.3rem 0; }
.results__title { display: flex; align-items: center; gap: 0.9rem; }
.result-map { width: 86px; height: auto; flex: none; }
.result-map path { stroke: #fff; stroke-width: 0.7; }
.result-map path[data-state="A"] { fill: var(--state-a); }
.result-map path[data-state="B"] { fill: var(--state-b); }
.results__actions { display: flex; gap: 0.5rem; }
.section-title { font-size: 1.15rem; margin: 2rem 0 0.8rem; border-bottom: 2px solid var(--line); padding-bottom: 0.3rem; }

.cmp { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.5rem 1rem 1rem; margin-top: 1rem; }
.cmp__legendrow, .cmp__row {
  display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 0.5rem 1rem; align-items: center;
}
.cmp__legendrow { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0.6rem 0 0.4rem; border-bottom: 1px solid var(--line); }
.cmp__legendrow > div { text-align: right; }
.cmp__legendrow > div:first-child { text-align: left; }
.cmp__col-a { color: var(--state-a); font-weight: 700; }
.cmp__col-b { color: var(--state-b); font-weight: 700; }
.cmp__row { padding: 0.55rem 0 0.2rem; border-bottom: 1px solid #eef1f4; }
.cmp__label { font-weight: 600; }
.cmp__a, .cmp__b, .cmp__ref { text-align: right; font-variant-numeric: tabular-nums; }
.cmp__a { color: var(--state-a); font-weight: 600; }
.cmp__b { color: var(--state-b); font-weight: 600; }
.cmp__ref { color: var(--muted); }

/* Race */
.race { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.race__state { margin-bottom: 0.8rem; }
.race__name { font-weight: 600; margin-bottom: 0.3rem; }
.race__bar { display: flex; height: 26px; border-radius: 5px; overflow: hidden; border: 1px solid var(--line); }
.race__key { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; padding: 0.6rem 0 0; margin: 0; font-size: 0.85rem; color: var(--muted); }
.race__key li { display: inline-flex; align-items: center; gap: 0.35rem; }
.race__swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.race__seg--white_nh { background: #4e79a7; }
.race__seg--hispanic { background: #f28e2b; }
.race__seg--asian_nh { background: #59a14f; }
.race__seg--black_nh { background: #b07aa1; }
.race__seg--two_plus_nh { background: #76b7b2; }
.race__seg--native_nh { background: #edc948; }
.race__seg--pacific_nh { background: #ff9da7; }
.race__seg--other_nh { background: #9c755f; }

/* Lists */
.lists { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.lists__pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.lists__name { display: inline-block; font-weight: 600; margin-bottom: 0.4rem; font-size: 0.9rem; }
.lists ol, .lists ul { margin: 0; padding-left: 1.2rem; font-size: 0.92rem; }

/* Rankings */
.ranks { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.ranks__state { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.8rem 1rem; }
.ranks__name { display: inline-block; font-weight: 700; margin-bottom: 0.5rem; }
.ranks__row { display: grid; grid-template-columns: 1.3fr 0.7fr 0.9fr; gap: 0.3rem 0.6rem; padding: 0.4rem 0; border-bottom: 1px solid #eef1f4; align-items: baseline; }
.ranks__metric { font-weight: 600; font-size: 0.92rem; }
.ranks__rank { font-weight: 700; }
.ranks__val { text-align: right; font-variant-numeric: tabular-nums; }
.ranks__ctx { grid-column: 1 / -1; font-size: 0.82rem; }

.error-page { text-align: center; padding: 3rem 1rem; }
.error-page h1 { font-size: 1.5rem; }

/* Prose / methodology */
.prose { max-width: 820px; }
.prose h1 { font-size: 1.7rem; }
.prose li { margin-bottom: 0.35rem; }
.meth-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.meth-table th, .meth-table td { text-align: left; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.meth-table th { background: var(--bg); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }

@media (max-width: 720px) {
  .lists, .ranks { grid-template-columns: 1fr; }
}
