:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #5d6676;
  --border: #dde1e7;
  --primary: #1f4fd6;
  --primary-text: #ffffff;
  --brand-link: #1F5FD1;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e8ebf0;
    --muted: #9aa3b2;
    --border: #2c3340;
    --primary: #5b84f5;
    --brand-link: #7A9CEB;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b;
  --surface: #1b2029;
  --text: #e8ebf0;
  --muted: #9aa3b2;
  --border: #2c3340;
  --primary: #5b84f5;
  --brand-link: #7A9CEB;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.container {
  position: relative;
  max-width: 1040px;
  margin: 0 auto;
  padding-block: 32px 96px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Brand line: "All Trips Considered" in Instrument Serif, brand blue */
.brand {
  font-family: "Instrument Serif", Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 2.8125rem;
  line-height: 1.1;
  letter-spacing: 0.01em;
  margin: 0 0 6px;
}
.brand, .page-header h1 { text-align: center; text-wrap: balance; }
.brand a, .copyright a {
  color: var(--brand-link);
  text-decoration: none;
  border-radius: 4px;
}
.brand a:focus-visible, .copyright a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: 0 0 8px; }
h2 { font-size: 1.15rem; margin: 0; }
.lede { color: var(--muted); margin: 0 0 24px; text-align: center; text-wrap: balance; }
#page-title:focus { outline: none; }

/* Light/dark toggle, upper right */
.theme-toggle {
  position: absolute;
  top: 16px;
  right: max(16px, env(safe-area-inset-right, 0px));
  width: 40px; height: 40px;
  display: grid; place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .2s, border-color .2s;
}
.theme-toggle:hover { border-color: var(--muted); }
.theme-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.theme-toggle svg { fill: currentColor; stroke: currentColor; }
.theme-toggle .icon-moon { stroke: none; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-footer { margin-top: 12px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.hint { color: var(--muted); font-size: .9rem; margin: 8px 0 0; }

.btn {
  font: inherit; font-weight: 600;
  border-radius: 8px; padding: 8px 14px; min-height: 40px;
  cursor: pointer; border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

/* Footer: disclaimer, 75px app icon, serif copyright */
.disclaimer { color: var(--muted); font-size: .85rem; }
.disclaimer p { margin: 0 0 6px; }
.footer-icon { display: block; width: 75px; height: 75px; margin: 24px auto 0; }
.copyright {
  margin-top: 1.5em !important;
  text-align: center;
  font-family: "Instrument Serif", Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: 1.125rem;
  letter-spacing: 0.01em;
}

/* Back to top, lower right */
.back-to-top {
  position: fixed;
  right: max(20px, calc(env(safe-area-inset-right, 0px) + 16px));
  bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  z-index: 15;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  padding: 0; border: 0; border-radius: 999px;
  background: var(--primary); color: var(--primary-text);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  cursor: pointer;
}
.back-to-top:hover { filter: brightness(1.08); }
.back-to-top:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
body.has-install-banner .back-to-top { bottom: calc(var(--install-banner-height, 150px) + 16px); }

/* Add to Home Screen banner */
.install-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -6px 20px rgba(0, 0, 0, .12);
  padding-top: 14px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.install-icon { width: 48px; height: 48px; border-radius: 11px; flex: none; }
.install-text { display: flex; flex-direction: column; flex: 1 1 220px; min-width: 0; font-size: .95rem; }
.install-text span { color: var(--muted); }
.install-actions { display: flex; gap: 8px; margin-left: auto; }
.share-glyph {
  display: inline-block; width: 14px; height: 17px; vertical-align: -2px;
  background: var(--primary);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 17'%3E%3Cpath d='M7 0l3.5 3.5-1 1L7.7 2.7V11H6.3V2.7L4.5 4.5l-1-1z'/%3E%3Cpath d='M1 6h3.5v1.4H2.4v8.2h9.2V7.4H9.5V6H13v11H1z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 17'%3E%3Cpath d='M7 0l3.5 3.5-1 1L7.7 2.7V11H6.3V2.7L4.5 4.5l-1-1z'/%3E%3Cpath d='M1 6h3.5v1.4H2.4v8.2h9.2V7.4H9.5V6H13v11H1z'/%3E%3C/svg%3E") center / contain no-repeat;
}
body.has-install-banner { padding-bottom: var(--install-banner-height, 140px); }

@media (max-width: 680px) {
  .container { padding-top: 68px; }
  .theme-toggle { top: 14px; }
  .brand { font-size: 2.375rem; }
}
@media (max-width: 600px) {
  .card { padding: 16px; }
  .disclaimer { font-size: .9rem; }
  .card-footer .btn { flex: 1; }
}

/* World map */
:root { --visited: #2f9e6e; --planning: #e0a320; --lived: #7b4fd6; --living: #d9534f; --land: #d9dee6; --land-hover: #b9c2cf; --sea: #eaf1fb; }
:root[data-theme="dark"] { --visited: #3fbf86; --planning: #f0b73a; --lived: #9d7cf0; --living: #f07470; --land: #3a4250; --land-hover: #556072; --sea: #161c26; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --visited: #3fbf86; --planning: #f0b73a; --lived: #9d7cf0; --living: #f07470; --land: #3a4250; --land-hover: #556072; --sea: #161c26; } }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.search-wrap { position: relative; margin-bottom: 12px; }
#country-search { width: 100%; font: inherit; padding: 10px 14px; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
#country-search:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.search-results { position: absolute; z-index: 10; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 260px; overflow-y: auto; }
.search-results li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.search-results li[aria-selected="true"], .search-results li:hover { background: var(--bg); }
.search-results .empty { color: var(--muted); cursor: default; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 12px; font-size: .95rem; }
.stat { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.stat b { color: var(--text); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot-visited { background: var(--visited); } .dot-planning { background: var(--planning); } .dot-lived { background: var(--lived); } .dot-living { background: var(--living); } .dot-none { background: var(--land); }
.map-wrap { position: relative; background: var(--sea); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; aspect-ratio: 1.9 / 1; touch-action: none; }
#map { display: block; width: 100%; height: 100%; cursor: grab; }
#map .country { fill: var(--land); stroke: var(--surface); stroke-width: .5; vector-effect: non-scaling-stroke; cursor: pointer; transition: fill .15s; }
#map .country:hover { fill: var(--land-hover); }
#map .country.visited { fill: var(--visited); } #map .country.planning { fill: var(--planning); } #map .country.lived { fill: var(--lived); } #map .country.living { fill: var(--living); }
#map .country.selected { stroke: var(--text); stroke-width: 1.5; }
.chooser-note { margin: -4px 0 12px; color: var(--muted); font-size: .9rem; }
#map .country.marker { stroke: var(--muted); stroke-width: 1; }
#map .country.marker.selected { stroke: var(--text); stroke-width: 2; }
#map .country:focus { outline: none; } #map .country:focus-visible { stroke: var(--primary); stroke-width: 2; }
.map-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.map-zoom { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 4px; }
.zoom-btn { width: 34px; height: 34px; font: inherit; font-size: 1.1rem; line-height: 1; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; }
.zoom-btn:focus-visible { outline: 2px solid var(--primary); }
.map-tip { position: fixed; z-index: 30; pointer-events: none; background: var(--text); color: var(--bg); font-size: .85rem; padding: 4px 8px; border-radius: 6px; white-space: nowrap; }
.chooser { margin-top: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.chooser-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.chooser-close { width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); font-size: 1.5rem; cursor: pointer; border-radius: 8px; }
.chooser-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.status-btn { font: inherit; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; }
.status-btn[aria-checked="true"][data-status="visited"] { border-color: var(--visited); box-shadow: inset 0 0 0 1px var(--visited); }
.status-btn[aria-checked="true"][data-status="planning"] { border-color: var(--planning); box-shadow: inset 0 0 0 1px var(--planning); }
.status-btn[aria-checked="true"][data-status="lived"] { border-color: var(--lived); box-shadow: inset 0 0 0 1px var(--lived); }
.status-btn[aria-checked="true"][data-status="living"] { border-color: var(--living); box-shadow: inset 0 0 0 1px var(--living); }
@media (max-width: 480px) { .chooser-options { grid-template-columns: repeat(2, 1fr); } }
.status-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.clear-btn { margin-top: 10px; width: 100%; }
.lists { margin-top: 16px; }
.lists summary { cursor: pointer; font-weight: 600; }
.lists-count { margin-left: 2px; padding: 0 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: .85rem; font-weight: 600; color: var(--muted); }
.lists-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 12px; }
.lists-grid h3 { font-size: 1rem; margin: 0 0 6px; display: flex; align-items: center; gap: 6px; }
.lists-grid ul { margin: 0; padding-left: 20px; color: var(--muted); }
.lists-grid .none { color: var(--muted); font-size: .9rem; margin: 0; }
@media (max-width: 600px) { .map-wrap { aspect-ratio: 1.3 / 1; } }
.dl-group { position: relative; display: flex; }
.dl-menu { position: absolute; z-index: 12; right: 0; bottom: calc(100% + 6px); min-width: 210px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.dl-menu button { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 12px; font: inherit; font-weight: 600; padding: 10px 12px; min-height: 40px; border: 0; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; text-align: left; }
.dl-menu button span { font-weight: 400; font-size: .85rem; color: var(--muted); }
.dl-menu button:hover, .dl-menu button:focus-visible { background: var(--bg); outline: none; }
@media (max-width: 600px) { .dl-group { flex: 1 1 100%; } .dl-group .btn { flex: 1; } }
