/* =========================================================================
 * AMERICAN ATLAS — official Bureau stylesheet
 * Palette: federal navy, decree gold, ribbon red, archival parchment.
 * ========================================================================= */

:root {
  /* Old Glory, as specified by the Bureau's Vexillology Desk */
  --navy: #3c3b6e;       /* Old Glory blue */
  --navy-deep: #29284e;
  --gold: #d9a92c;       /* ceremonial fringe */
  --gold-bright: #f3c94f;
  --red: #b22234;        /* Old Glory red */
  --parchment: #f7f1e3;
  --ink: #241f1a;
  --water-blue: #2b6a9e;
  --park-green: #2e6b3f;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --ticker-h: 34px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--serif);
  background: var(--navy-deep);
  color: var(--ink);
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------------- Masthead ---------------- */
#masthead {
  position: relative;
  z-index: 1200;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px 18px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background:
    url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="0 0 56 56"><path fill="white" fill-opacity="0.055" d="M14 6l1.9 4.7 5.1.4-3.9 3.3 1.2 5-4.3-2.7-4.3 2.7 1.2-5L7 11.1l5.1-.4z"/><path fill="white" fill-opacity="0.055" d="M42 30l1.9 4.7 5.1.4-3.9 3.3 1.2 5-4.3-2.7-4.3 2.7 1.2-5-3.9-3.3 5.1-.4z"/></svg>'),
    linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  /* thirteen stripes were requested; two fit */
  box-shadow: 0 2px 0 0 #ffffff, 0 5px 0 0 var(--red), 0 9px 16px rgba(0, 0, 0, 0.45);
  color: var(--parchment);
}

.mast-left { display: flex; align-items: center; gap: 12px; }

.mast-eagle {
  font-size: 34px;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,.5));
}

.mast-titles h1 {
  margin: 0;
  font-weight: 900;
  font-size: 26px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-bright);
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
  line-height: 1;
}

.mast-tag {
  margin: 3px 0 0;
  font-size: 11.5px;
  font-style: italic;
  opacity: 0.85;
  letter-spacing: 0.02em;
}
.mast-tag strong { color: var(--gold-bright); font-style: normal; }

.mast-stats {
  display: flex;
  gap: 14px;
  font-size: 12px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}
.mast-stats .stat b {
  color: var(--gold-bright);
  font-size: 15px;
  margin-right: 3px;
}

.mast-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12.5px;
}

.ctl.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.ctl.toggle input { accent-color: var(--red); }

.ctl.filters {
  display: flex;
  gap: 2px;
  margin: 0;
  padding: 2px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
}
.ctl.filters label { cursor: pointer; }
.ctl.filters input { position: absolute; opacity: 0; }
.ctl.filters span {
  display: inline-block;
  padding: 4px 9px;
  border-radius: 3px;
  transition: background 0.15s, color 0.15s;
}
.ctl.filters input:checked + span {
  background: #ffffff;
  color: var(--navy-deep);
  font-weight: 700;
}
.ctl.filters input:focus-visible + span { outline: 2px solid var(--gold-bright); }

.ctl.btn {
  font-family: var(--serif);
  font-size: 12.5px;
  padding: 5px 12px;
  cursor: pointer;
  color: var(--parchment);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 4px;
  transition: background 0.15s;
}
.ctl.btn:hover { background: rgba(255, 255, 255, 0.14); }

/* ---------------- Map ---------------- */
#map {
  position: relative;
  flex: 1;
  min-height: 0;
  z-index: 0; /* contain Leaflet's pane z-indexes below the chrome */
  background: #bcd6e8; /* the ocean — also, of course, named America */
}

/* Narrow screens: tighter chrome, no stats box, controls wrap below */
@media (max-width: 900px) {
  .mast-controls { margin-left: 0; }
  .mast-stats { display: none; }
}
@media (max-width: 560px) {
  #masthead { gap: 8px 12px; padding: 7px 10px; }
  .mast-eagle { font-size: 26px; }
  .mast-titles h1 { font-size: 20px; }
  .mast-tag { display: none; }
  .mast-controls { gap: 8px; font-size: 12px; }
  .ctl.filters span { padding: 4px 7px; }
  .ticker-label { display: none; }
  .leaflet-control-attribution { font-size: 8.5px; max-width: 78vw; }
}

/* ---------------- Map labels ---------------- */
.atlas-label { background: none; border: none; }

/* Admin labels: the only truthful words left on this map */
.admin-lbl {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  pointer-events: none;
  font-family: var(--serif);
  text-align: center;
}
.admin-country {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4em;
  color: #85735a;
  opacity: 0.8;
  text-shadow: 0 0 5px rgba(242, 234, 214, 0.9);
}
.admin-state {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: #9c8a6e;
  opacity: 0.85;
  text-shadow: 0 0 4px rgba(242, 234, 214, 0.9);
}
/* A country label the Bureau did NOT leave alone */
.admin-renamed {
  pointer-events: auto;
  cursor: pointer;
  color: var(--red);
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

/* ---------------- First-visit hint ---------------- */
#hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  max-width: min(460px, 94%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
  color: var(--parchment);
  border: 1.5px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  font-size: 13.5px;
  line-height: 1.4;
}
#hint[hidden] { display: none; }
#hint .hint-btns { display: flex; gap: 8px; flex-shrink: 0; }
#hint button {
  font-family: var(--serif);
  font-size: 12.5px;
  padding: 5px 11px;
  border-radius: 4px;
  cursor: pointer;
}
#hint-show { background: var(--red); color: #fff; border: 1px solid #fff; font-weight: 700; }
#hint-show:hover { background: #9c1c2c; }
#hint-close { background: transparent; color: var(--parchment); border: 1px solid rgba(255,255,255,.45); }
#hint-close:hover { background: rgba(255,255,255,.12); }
@media (max-width: 560px) {
  #hint { flex-direction: column; gap: 8px; font-size: 12.5px; text-align: center; }
}

.lbl {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  text-align: center;
}

.lbl .new-name {
  text-shadow:
    -1px -1px 0 rgba(255,255,255,.85), 1px -1px 0 rgba(255,255,255,.85),
    -1px 1px 0 rgba(255,255,255,.85), 1px 1px 0 rgba(255,255,255,.85),
    0 0 6px rgba(255,255,255,.9);
  /* dotted underline: the cartographic convention for "yes, click me" */
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
.lbl:hover .new-name {
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.8);
  border-radius: 2px;
  text-decoration-style: solid;
}

/* Waters: classic italic hydrographic lettering */
.lbl-water .new-name {
  font-style: italic;
  color: var(--water-blue);
  letter-spacing: 0.08em;
}
.lbl-kind-ocean .new-name, .lbl-kind-sea .new-name {
  text-transform: uppercase;
  letter-spacing: 0.35em;
  font-size: 15px;
}
.lbl-kind-gulf .new-name { text-transform: uppercase; letter-spacing: 0.2em; font-size: 13px; }
.lbl-kind-lake .new-name, .lbl-kind-bay .new-name { font-size: 12.5px; }
.lbl-kind-river .new-name { font-size: 11.5px; letter-spacing: 0.14em; }
.lbl-kind-sound .new-name, .lbl-kind-strait .new-name, .lbl-kind-falls .new-name { font-size: 11px; }

/* Parks: small-caps conservation green, with tree */
.lbl-park .new-name {
  color: var(--park-green);
  font-variant: small-caps;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.05em;
}
.lbl-park .new-name::before { content: "🌲 "; font-size: 10px; }

/* Landmarks: federal red with star */
.lbl-landmark .new-name {
  color: var(--red);
  font-weight: 700;
  font-size: 11.5px;
}
.lbl-landmark .new-name::before { content: "★ "; color: var(--gold); }

/* Bigger type for continental-rank features */
.rank-3 .new-name { font-size: 1.25em; }

.lbl .badge {
  margin-top: 1px;
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--red);
  padding: 1px 5px;
  border-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,.3);
}

/* Former names: hidden until someone commits thoughtcrime */
.lbl .former-name {
  display: none;
  margin-top: 1px;
  font-size: 9.5px;
  font-style: italic;
  color: #6b5f52;
  text-decoration: line-through;
  text-shadow: 0 0 4px rgba(255,255,255,.9);
}
body.show-former .lbl .former-name { display: block; }

/* ---------------- Popups: every decree dressed as the flag ---------------- */
.atlas-popup .leaflet-popup-content-wrapper {
  background: #ffffff;
  border: 1.5px solid var(--navy);
  border-radius: 8px;
  overflow: hidden;
  padding: 0;
  box-shadow: 0 6px 24px rgba(0,0,0,.35);
}
.atlas-popup .leaflet-popup-tip { background: #ffffff; border: 1px solid var(--navy); }
.atlas-popup .leaflet-popup-content { margin: 0; font-family: var(--serif); }
.atlas-popup .leaflet-popup-close-button { color: #fff; opacity: 0.85; }
.atlas-popup .leaflet-popup-close-button:hover { color: var(--gold-bright); }

.pop { padding: 0 0 12px; }
/* the canton: navy, stars, and the E.O. number */
.pop-eyebrow {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffffff;
  background:
    url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="34" height="34" viewBox="0 0 34 34"><path fill="white" fill-opacity="0.16" d="M9 4l1.2 3 3.2.2-2.5 2.1.8 3.2-2.7-1.7-2.7 1.7.8-3.2L4.6 7.2l3.2-.2z"/><path fill="white" fill-opacity="0.16" d="M25 19l1.2 3 3.2.2-2.5 2.1.8 3.2-2.7-1.7-2.7 1.7.8-3.2-2.5-2.1 3.2-.2z"/></svg>'),
    linear-gradient(180deg, var(--navy) 0%, #32315f 100%);
  padding: 9px 16px 8px;
  /* three of the thirteen stripes, in miniature */
  box-shadow: 0 2px 0 0 var(--red), 0 4px 0 0 #ffffff, 0 6px 0 0 var(--red);
  margin: 0 0 16px;
}
.pop > *:not(.pop-eyebrow) { margin-left: 16px; margin-right: 16px; }
.pop-name {
  margin: 0 0 2px;
  font-size: 20px;
  font-weight: 900;
  color: var(--navy);
  line-height: 1.1;
}
.pop-water .pop-name { color: var(--water-blue); font-style: italic; }
.pop-park .pop-name { color: var(--park-green); }
.pop-landmark .pop-name { color: var(--red); }

.pop-former { font-size: 12px; color: #5c5348; }
.pop-former s { color: #8a7d6c; }
.pop-retired { font-size: 10px; font-style: italic; }
.pop-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: #6b5f52;
  margin: 5px 0;
}
.pop-official {
  font-size: 11.5px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
  padding: 4px 8px;
  border-radius: 3px;
  margin: 6px 0;
}
.pop-note { font-size: 12.5px; line-height: 1.45; margin: 7px 0; }
.pop-decree {
  font-size: 12px;
  font-style: italic;
  color: var(--navy);
  border-left: 3px solid var(--gold);
  padding-left: 9px;
  margin: 8px 0 4px;
  line-height: 1.4;
}
.pop-seal { font-size: 10.5px; text-align: right; color: #6b5f52; }

/* ---------------- Drawers ---------------- */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 92vw);
  z-index: 1300;
  background: var(--parchment);
  border-left: 3px solid var(--gold);
  box-shadow: -8px 0 24px rgba(0,0,0,.35);
  padding: 20px 24px;
  overflow-y: auto;
  transform: translateX(105%);
  transition: transform 0.25s ease;
}
.drawer.open { transform: translateX(0); }

.drawer h2 {
  margin: 0 0 10px;
  font-size: 21px;
  font-weight: 900;
  color: var(--navy);
  border-bottom: 2px solid var(--gold);
  padding-bottom: 6px;
}
.drawer p { font-size: 14px; line-height: 1.55; }
.drawer a { color: var(--red); }
.drawer .colophon { font-size: 11.5px; color: #6b5f52; border-top: 1px solid rgba(0,0,0,.15); padding-top: 10px; }

.drawer pre {
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.6;
  background: var(--navy-deep);
  color: #7fd487;
  padding: 14px;
  border-radius: 6px;
  overflow-x: auto;
}

.drawer-close {
  position: absolute;
  top: 10px; right: 12px;
  border: none;
  background: none;
  font-size: 16px;
  cursor: pointer;
  color: var(--navy);
}

/* ---------------- Ticker ---------------- */
#ticker {
  position: relative;
  z-index: 1200;
  flex-shrink: 0;
  min-height: var(--ticker-h);
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  background: var(--red);
  color: #fff;
  border-top: 2px solid #ffffff;
  font-size: 13px;
  padding: 0 12px env(safe-area-inset-bottom);
  white-space: nowrap;
}
.ticker-label {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.15em;
  background: #fff;
  color: var(--red);
  padding: 2px 8px;
  border-radius: 2px;
}
#ticker-text { font-style: italic; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.slide-in { animation: ticker-slide 0.45s ease-out; }
@keyframes ticker-slide {
  from { transform: translateY(120%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer { transition: none; }
  .slide-in { animation: none; }
}
