/* Where We've Been: styles for every page. */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage-grotesque-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --ink: #16202a;
  --muted: #5b6b7a;
  --line: #e3e8ee;
  --card: #f4f7fa;
  --bg: #ffffff;

  --map-none: #dde3ea;
  --map-none-hover: #c9d2dc;
  --map-visited: #2f6bea;
  --map-visited-hover: #2257c8;
  --map-lived: #f2a322;
  --map-lived-hover: #d98c10;
  --dot-none: #c3cdd8;

  --ui-blue: #1f57cc;
  --ui-blue-soft: #e6eefc;
  --ui-amber: #f2a322;
  --ui-amber-ink: #2a1a00;
  --danger: #c62828;

  --shade-1: #b7cbf4;
  --shade-2: #6a93e6;
  --shade-3: #1e49b8;

  --radius: 16px;
  --tap: 44px;
  --font-display: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  touch-action: manipulation;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--ui-blue); }

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}

/* ---- Controls ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #c9d2dc; }
.btn.primary { background: var(--ui-blue); border-color: var(--ui-blue); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
@media (pointer: coarse) { .btn.small { min-height: var(--tap); } }

.link-btn {
  min-height: var(--tap);
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--ui-blue);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.icon-btn {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--card); color: var(--ink); }

.select {
  min-height: var(--tap);
  max-width: 100%;
  padding: 0 40px 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%235B6B7A' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center / 18px;
  font-size: 16px;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.input, .search, .pin-input, textarea.input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  font-size: 16px; /* 16px stops iPhone zooming in on focus */
}
.search { border-radius: 999px; }
textarea.input { min-height: 140px; padding: 12px 16px; resize: vertical; }
.input:focus, .search:focus, .pin-input:focus, .select:focus { outline: 2px solid var(--ui-blue); outline-offset: 1px; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--ui-blue-soft);
  color: var(--ui-blue);
  font-size: 13px;
  font-weight: 700;
}

/* Visited / Lived toggles */
.pill {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
@media (pointer: coarse) { .pill { min-height: var(--tap); } }
@media (hover: hover) { .pill:hover { border-color: #b9c4d0; } }
.pill.visited[aria-pressed="true"] { background: var(--ui-blue); border-color: var(--ui-blue); color: #fff; }
.pill.lived[aria-pressed="true"] { background: var(--ui-amber); border-color: var(--ui-amber); color: var(--ui-amber-ink); }

/* ---- Header ---- */

.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title lock" "who who";
  align-items: center;
  gap: 10px 12px;
  min-height: var(--tap);
}
.title {
  grid-area: title;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(24px, 6.4vw, 36px);
  line-height: 1.1;
  letter-spacing: -0.02em;
}
.lock-btn { grid-area: lock; padding: 0 14px; }
.lock-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.lock-btn.unlocked .shackle { transform: translateY(-3px); }
.who { grid-area: who; display: flex; align-items: center; gap: 10px; min-width: 0; }
.who:empty, .who:not(:has(:not([hidden]))) { display: none; }
@media (min-width: 700px) {
  .top { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "title who lock"; }
}

/* ---- Layout: one column on phones; map and stats left, checklist right on desktop ---- */

.layout {
  display: grid;
  grid-template-areas: "status" "map" "list" "stats";
  gap: 16px;
  margin-top: 8px;
}
.status { grid-area: status; margin: 0; color: var(--muted); font-size: 15px; }
.map-card { grid-area: map; }
.list-card { grid-area: list; }
.stats-card { grid-area: stats; }
@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 360px;
    grid-template-areas: "status list" "map list" "stats list";
    grid-template-rows: auto auto 1fr;
    align-items: start;
  }
  .list-card {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 32px);
  }
  .list-card .checklist, .compare-wrap { overflow-y: auto; }
}

.card { background: var(--card); border-radius: var(--radius); }
.pad { padding: 16px; }
.card-title { margin: 0 0 12px; font-size: 18px; font-weight: 700; }

/* ---- Map ---- */

.map-card { overflow: hidden; }
.map {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
.map:active { cursor: grabbing; }
.map .ocean { fill: var(--card); }
.map .c {
  fill: var(--map-none);
  stroke: #fff;
  stroke-width: 0.5px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
.map .c.nomatch { pointer-events: none; }
.map .c.visited { fill: var(--map-visited); }
.map .c.lived { fill: var(--map-lived); }
.map .c.sel { stroke: var(--ink); stroke-width: 1.5px; }
.map .dot-hit { fill: transparent; cursor: pointer; }
.map .dot-fill {
  fill: var(--dot-none);
  stroke: #fff;
  stroke-width: 1.25px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.map .dot.visited .dot-fill { fill: var(--map-visited); }
.map .dot.lived .dot-fill { fill: var(--map-lived); }
.map .mark {
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
@media (hover: hover) {
  .map .c:hover { fill: var(--map-none-hover); }
  .map .c.visited:hover { fill: var(--map-visited-hover); }
  .map .c.lived:hover { fill: var(--map-lived-hover); }
  .map .dot:hover .dot-fill { fill: var(--map-none-hover); }
  .map .dot.visited:hover .dot-fill { fill: var(--map-visited-hover); }
  .map .dot.lived:hover .dot-fill { fill: var(--map-lived-hover); }
}

/* Selected-country bar, under the map */
.selbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "text close" "actions actions";
  align-items: center;
  gap: 4px 8px;
  padding: 6px 6px 12px 16px;
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.sel-text { grid-area: text; min-width: 0; }
.sel-close { grid-area: close; }
.sel-actions { grid-area: actions; display: flex; align-items: center; gap: 8px; min-width: 0; }
.sel-actions:not(:has(:not([hidden]))) { display: none; }
.sel-toggles { display: flex; gap: 8px; }
.selbar .pill { min-height: var(--tap); padding: 0 20px; font-size: 15px; }
.sel-name { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.sel-meta { color: var(--muted); font-size: 14px; }
@media (min-width: 600px) {
  .selbar { grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "text actions close"; padding: 6px 6px 6px 16px; }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 7px;
  border-radius: 4px;
  vertical-align: -1px;
}
.swatch.none { background: var(--map-none); }
.swatch.visited { background: var(--map-visited); }
.swatch.lived { background: var(--map-lived); }
.swatch.n1 { background: var(--shade-1); }
.swatch.n2 { background: var(--shade-2); }
.swatch.n3 { background: var(--shade-3); }

/* Everyone view: shaded by how many people have been */
.map .c.n1, .map .dot.n1 .dot-fill { fill: var(--shade-1); }
.map .c.n2, .map .dot.n2 .dot-fill { fill: var(--shade-2); }
.map .c.n3, .map .dot.n3 .dot-fill { fill: var(--shade-3); }
@media (hover: hover) {
  .map .c.n1:hover, .map .dot.n1:hover .dot-fill { fill: #a2bbee; }
  .map .c.n2:hover, .map .dot.n2:hover .dot-fill { fill: #5583df; }
  .map .c.n3:hover, .map .dot.n3:hover .dot-fill { fill: #173c9c; }
}

.sel-who { display: grid; gap: 2px; font-size: 15px; }
.sel-who .muted { color: var(--muted); }

/* Chips: quick zoom above the map, and the compare filters */
.chips { display: flex; gap: 8px; }
.zoom-chips {
  padding: 10px 12px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}
.zoom-chips::-webkit-scrollbar { display: none; }
.filters { flex-wrap: wrap; margin-bottom: 10px; }
.chip {
  flex: none;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
@media (pointer: coarse) { .chip { min-height: var(--tap); } }
@media (hover: hover) { .chip:hover { border-color: #b9c4d0; } }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---- Checklist ---- */

.list-card { padding: 12px 0 6px; }
.list-top { padding: 0 12px 10px; }
.group + .group { border-top: 1px solid var(--line); }
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}
.chev { flex: none; width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; transition: transform 0.15s; }
.group-head[aria-expanded="true"] .chev { transform: rotate(180deg); }
.rows { list-style: none; margin: 0; padding: 0 8px 10px; }
.row { display: flex; align-items: center; gap: 8px; padding: 2px 4px 2px 8px; border-radius: 12px; }
@media (hover: hover) { .row:hover { background: var(--bg); } }
.row-name {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}
@media (pointer: coarse) { .row-name { min-height: var(--tap); } }
.pills { display: flex; flex: none; gap: 6px; }
.checklist.locked .pill[aria-pressed="false"] { color: var(--muted); }
.list-empty { margin: 8px 16px; color: var(--muted); }

/* ---- Compare (Everyone view) ---- */

.compare-card { padding: 16px 0 8px; }
.compare-card .card-title { padding: 0 16px; }
.compare-body { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; }
.compare-body .filters { padding: 0 16px; }
.compare-sum { margin: 0 16px 8px; color: var(--muted); font-size: 14px; }
.compare-wrap { overflow: auto; margin: 0 8px; border-radius: 12px; background: var(--bg); }
@media (min-width: 900px) { .compare-card .compare-body { overflow: hidden; } }
.compare { width: 100%; border-collapse: collapse; font-size: 15px; }
.compare th, .compare td { padding: 0 8px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; }
.compare thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 40px;
  background: var(--bg);
  font-size: 13px;
  color: var(--muted);
}
.compare tbody th, .compare thead th:first-child {
  position: sticky;
  left: 0;
  background: var(--bg);
  text-align: left;
  white-space: normal;
}
.compare thead th:first-child { z-index: 2; }
.compare tbody th { font-weight: 400; min-width: 120px; }
.compare tr:last-child > * { border-bottom: 0; }
.compare .row-name { min-height: 40px; }
.tag {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}
.tag.visited { background: var(--ui-blue); color: #fff; }
.tag.lived { background: var(--ui-amber); color: var(--ui-amber-ink); }

/* ---- Stats ---- */

.stats-card summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 16px;
  list-style: none;
  cursor: pointer;
}
.stats-card summary::-webkit-details-marker { display: none; }
.stats-card summary .card-title { margin: 0; }
.stats-sum { flex: 1; color: var(--muted); font-size: 14px; }
.stats-card[open] .stats-sum { visibility: hidden; }
.stats-card[open] summary .chev { transform: rotate(180deg); }
.stats { padding: 0 16px 16px; }
.bars { display: grid; gap: 14px; margin-bottom: 18px; }
@media (min-width: 600px) { .bars { grid-template-columns: repeat(3, 1fr); } }
.bar { padding: 12px 14px; border-radius: 12px; background: var(--bg); }
.bar-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.bar-label { color: var(--muted); font-size: 14px; font-weight: 600; }
.big { font-family: var(--font-display); font-size: 30px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.track { height: 8px; margin: 8px 0 6px; border-radius: 999px; background: var(--map-none); overflow: hidden; }
.fill { height: 100%; border-radius: 999px; background: var(--map-visited); }
.bar-detail { color: var(--muted); font-size: 13px; }
.stats-table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
.stats-table th, .stats-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; }
.stats-table th:first-child { text-align: left; }
.stats-table thead th { color: var(--muted); font-size: 13px; font-weight: 600; }
.stats-table tbody th { font-weight: 500; }
.stats-table tfoot th, .stats-table tfoot td { border-bottom: 0; font-weight: 700; }

/* ---- Dialogs and messages ---- */

.modal {
  width: min(380px, calc(100vw - 32px));
  padding: 22px;
  border: 0;
  border-radius: var(--radius);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(22, 32, 42, 0.25);
}
.modal::backdrop { background: rgba(22, 32, 42, 0.45); }
.modal-title { margin: 0 0 14px; font-size: 19px; }
.modal p { margin: 0 0 12px; color: var(--muted); }
.pin-input {
  text-align: center;
  font-size: 26px;
  letter-spacing: 0.3em;
  -webkit-text-security: disc;
}
.form-error { min-height: 1.4em; margin: 8px 0 4px; color: var(--danger); font-size: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--ink);
  color: #fff;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { margin-top: 28px; color: var(--muted); font-size: 13px; text-align: center; }

/* ---- Admin page ---- */

.admin { display: grid; gap: 16px; max-width: 720px; margin: 16px auto 0; }
.admin-body { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 14px; font-weight: 600; color: var(--muted); }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.inline-form .field { flex: 1 1 160px; margin: 0; }
.people { list-style: none; margin: 0 0 16px; padding: 0; }
.person {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.person-pos { width: 64px; min-height: var(--tap); padding: 0 8px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; text-align: center; }
.person-name { flex: 1 1 140px; min-width: 0; font-weight: 700; }
.person-name small { display: block; font-weight: 400; color: var(--muted); }
.person-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.choice label { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); cursor: pointer; font-weight: 600; }
.choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--ui-blue); }
.match-lists { display: grid; gap: 12px; margin: 14px 0; }
@media (min-width: 600px) { .match-lists { grid-template-columns: 1fr 1fr; } }
.match-lists h3 { margin: 0 0 6px; font-size: 15px; }
.match-lists ul { margin: 0; padding: 10px 12px; list-style: none; max-height: 260px; overflow: auto; background: var(--bg); border-radius: 12px; font-size: 15px; }
.match-lists li { padding: 3px 0; }
.match-lists li small { color: var(--muted); }
.note { color: var(--muted); font-size: 14px; }
.ok-text { color: #1b7a3c; font-weight: 600; }
