:root {
  --paper: #efe7d6;
  --paper2: #f6f0e3;
  --ink: #2c2620;
  --muted: #8a7d68;
  --accent: #c0603f;
  --card: #fffdf8;
  --tape: rgba(206, 188, 140, 0.55);
  --shadow: 0 8px 24px rgba(44, 38, 32, 0.18);
  --hand: "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.55;
  background-color: var(--paper);
  /* soft paper grain + warm vignette */
  background-image:
    radial-gradient(circle at 50% -20%, #faf5ea, transparent 55%),
    radial-gradient(circle at 0% 100%, rgba(192,96,63,0.06), transparent 40%),
    repeating-linear-gradient(0deg, rgba(0,0,0,0.012) 0 2px, transparent 2px 4px);
}

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

/* ---- top nav ---- */
.site-nav {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: baseline; gap: 1.4rem;
  padding: 0.9rem 1.4rem;
  background: rgba(239, 231, 214, 0.9);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(44,38,32,0.1);
}
.site-nav .brand {
  font-weight: 800; letter-spacing: 0.18em; font-size: 1.25rem; margin-right: auto;
  text-decoration: none; color: var(--ink);
}
.site-nav a.navlink { text-decoration: none; color: var(--muted); font-size: 1rem; }
.site-nav a.navlink:hover { color: var(--ink); }
.site-nav a.navlink.active { color: var(--accent); border-bottom: 2px solid var(--accent); }

/* ---- hero / masthead ---- */
.hero { text-align: center; padding: 3rem 1rem 1.2rem; }
.hero h1 { font-size: clamp(3rem, 11vw, 5.5rem); letter-spacing: 0.12em; margin: 0; }
.hero .tagline { color: var(--muted); font-style: italic; margin: 0.3rem 0 0; }

/* ---- chapter shelf (home) ---- */
.shelf {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.6rem; max-width: 1100px; margin: 1.5rem auto; padding: 0 1.4rem 2rem;
}
.chapter {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); padding: 0.8rem 0.8rem 1rem;
  box-shadow: var(--shadow); border-radius: 3px;
  transform: rotate(var(--tilt, 0deg)); transition: transform .18s ease, box-shadow .18s ease;
}
.chapter:hover { transform: rotate(0) translateY(-3px); box-shadow: 0 14px 30px rgba(44,38,32,.26); }
.chapter .thumb { aspect-ratio: 4/3; width: 100%; object-fit: cover; background: #e5ddca; display: block; }
.chapter .name { font-family: var(--hand); font-size: 1.35rem; margin-top: .5rem; text-align: center; }
.chapter .count { text-align: center; color: var(--muted); font-size: .85rem; }

/* ---- filter chips ---- */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; padding: 1rem; }
.filters button {
  font: inherit; cursor: pointer; border: 1px solid rgba(44,38,32,.18);
  background: var(--card); color: var(--ink); padding: .35rem .9rem; border-radius: 999px;
}
.filters button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- gallery grid ---- */
.gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1.7rem; max-width: 1150px; margin: 0 auto; padding: 1rem 1.4rem 4rem;
}
.loading, .empty { grid-column: 1/-1; text-align: center; color: var(--muted); }

.card {
  position: relative; background: var(--card); padding: .7rem .7rem .3rem;
  box-shadow: var(--shadow); border-radius: 2px; cursor: pointer;
  transform: rotate(var(--tilt, 0deg)); transition: transform .18s ease, box-shadow .18s ease;
}
.card::before { /* tape */
  content: ""; position: absolute; top: -10px; left: 50%; transform: translateX(-50%) rotate(-3deg);
  width: 70px; height: 22px; background: var(--tape); box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.card:hover { transform: rotate(0) scale(1.03); box-shadow: 0 14px 32px rgba(44,38,32,.28); }
.card img { aspect-ratio: 1/1; width: 100%; object-fit: cover; background: #e9e1cf; display: block; }
.card .cap { font-family: var(--hand); text-align: center; padding: .5rem .2rem .3rem; font-size: 1.05rem; }
.card .sub { text-align: center; color: var(--muted); font-size: .78rem; }

/* ---- flat photo wall (home): grouped sections, one scroll ---- */
.flatwall { padding: .5rem 0 2rem; }
.wallgroup { margin: 0 auto; }
.wallgroup .gallery { padding: .6rem 1.4rem 1.4rem; }
.grouphead {
  display: flex; align-items: baseline; gap: .6rem;
  max-width: 1150px; margin: 2.2rem auto .2rem; padding: 0 1.5rem;
  font-family: var(--hand); font-weight: 400; font-size: 1.7rem; color: var(--ink);
}
.grouphead::after {
  content: ""; flex: 1; height: 1px; align-self: center;
  background: linear-gradient(to right, rgba(44,38,32,.22), transparent);
}
.grouphead .grpcount {
  flex: none; font-family: var(--serif); font-size: .72rem; color: var(--muted);
  border: 1px solid rgba(44,38,32,.18); border-radius: 999px; padding: .05rem .55rem;
}
.badge {
  position: absolute; bottom: 38px; right: 10px; background: var(--accent); color:#fff;
  font-size: .72rem; border-radius: 999px; padding: .05rem .5rem; font-family: var(--serif);
}

/* ---- lightbox / photo view ---- */
.lightbox { position: fixed; inset: 0; background: rgba(22,18,14,.85); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.lightbox[hidden] { display: none; }
.lightbox__panel {
  background: var(--paper2); border-radius: 4px; box-shadow: var(--shadow);
  max-width: min(1000px, 95vw); max-height: 92vh; overflow: auto;
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 0;
}
@media (max-width: 720px) { .lightbox__panel { grid-template-columns: 1fr; } }
.lightbox__media { background: #1c1813; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.lightbox__media img { max-width: 100%; max-height: 78vh; display: block; box-shadow: var(--shadow); }
.lightbox__side { padding: 1.4rem; display: flex; flex-direction: column; min-width: 0; }
.lightbox__side h2 { margin: 0 0 .2rem; }
.lightbox__side .meta { color: var(--muted); font-size: .9rem; }
.lightbox__side .orig { margin: .6rem 0; font-size: .9rem; }
.notes { margin-top: .6rem; border-top: 1px dashed rgba(44,38,32,.25); padding-top: .8rem;
  overflow: auto; flex: 1; }
.notes h3 { font-family: var(--hand); font-size: 1.2rem; margin: 0 0 .5rem; }
.note {
  background: #fff8e6; border-left: 3px solid var(--accent); padding: .5rem .7rem;
  margin-bottom: .6rem; box-shadow: 0 2px 6px rgba(0,0,0,.06); font-size: .95rem;
}
.note .who { font-family: var(--hand); color: var(--accent); font-size: 1.05rem; }
.note .when { color: var(--muted); font-size: .72rem; float: right; }
.lightbox__close { position: fixed; top: 1rem; right: 1.3rem; font-size: 2.4rem; line-height: 1;
  color: #fff; background: none; border: none; cursor: pointer; }

/* ---- forms ---- */
.memform { display: grid; gap: .5rem; margin-top: .6rem; }
.memform input, .memform textarea {
  font: inherit; padding: .5rem .6rem; border: 1px solid rgba(44,38,32,.25);
  border-radius: 4px; background: #fff; width: 100%;
}
.memform textarea { min-height: 70px; resize: vertical; }
.memform button {
  font: inherit; cursor: pointer; background: var(--accent); color: #fff; border: none;
  padding: .55rem 1rem; border-radius: 999px; justify-self: start;
}
.memform .hp { position: absolute; left: -9999px; }   /* honeypot */
.formnote { color: var(--muted); font-size: .8rem; }

/* ---- the wall ---- */
.wall {
  column-count: 4; column-gap: 1.2rem; max-width: 1150px; margin: 0 auto; padding: 1rem 1.4rem 4rem;
}
@media (max-width: 980px) { .wall { column-count: 3; } }
@media (max-width: 680px) { .wall { column-count: 2; } }
@media (max-width: 460px) { .wall { column-count: 1; } }
.wallnote {
  break-inside: avoid; background: #fff8e6; padding: .9rem 1rem; margin-bottom: 1.2rem;
  box-shadow: var(--shadow); border-radius: 2px; transform: rotate(var(--tilt, 0deg));
}
.wallnote .msg { font-size: 1rem; }
.wallnote .who { font-family: var(--hand); color: var(--accent); font-size: 1.15rem; margin-top: .4rem; }
.wallnote img { width: 100%; margin-top: .5rem; border-radius: 2px; box-shadow: 0 2px 6px rgba(0,0,0,.12); }

.panel { max-width: 640px; margin: 1.5rem auto; background: var(--card); padding: 1.4rem 1.6rem;
  box-shadow: var(--shadow); border-radius: 3px; }
.panel h2 { font-family: var(--hand); margin-top: 0; }

.footer { text-align: center; color: var(--muted); padding: 2rem 1rem 3rem; font-size: .9rem; }
.footer code { background: #e6dcc6; padding: .1rem .35rem; border-radius: 4px; }

/* ---- stats page ---- */
.statwrap { max-width: 1100px; margin: 0 auto; padding: .5rem 1.4rem 4rem; }
.bignums { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin: 0 0 1.6rem; }
@media (max-width: 620px) { .bignums { grid-template-columns: repeat(2, 1fr); } }
.bignum {
  background: var(--card); box-shadow: var(--shadow); border-radius: 4px;
  padding: 1.1rem .6rem; text-align: center; transform: rotate(var(--tilt, 0deg));
}
.bignum .n { display: block; font-family: var(--serif); font-weight: 800; font-size: 2.3rem; color: var(--accent); line-height: 1; }
.bignum .k { display: block; font-family: var(--hand); color: var(--muted); margin-top: .35rem; font-size: 1.05rem; }

.mapcard {
  margin: 0 0 1.8rem; background: var(--card); border-radius: 6px; padding: 1rem;
  box-shadow: var(--shadow); border: 1px solid rgba(44,38,32,.08);
}
.mapholder { width: 100%; }
.mapholder svg.worldmap { width: 100%; height: auto; display: block; }
.mapcap { font-family: var(--hand); color: var(--muted); text-align: center; margin: .6rem 0 0; font-size: 1.05rem; }
/* choropleth: visited countries are filled (inline by JS); others stay land-toned */
.worldmap .country { transition: fill .15s, filter .15s; }
.worldmap .country.lit { cursor: pointer; }
.worldmap .country.lit:hover { filter: brightness(1.12) saturate(1.1); }

/* sticky-note map tooltip listing a country's cities */
.maptip {
  position: fixed; z-index: 50; transform: translate(-50%, -100%) rotate(-1.5deg);
  background: #fff8d8; color: var(--ink); font-family: var(--serif);
  padding: .5rem .7rem .55rem; border-radius: 2px; pointer-events: none;
  min-width: 110px; max-width: 220px;
  box-shadow: 0 8px 20px rgba(44,38,32,.28); border: 1px solid rgba(44,38,32,.06);
}
.maptip::before {  /* a little tape strip */
  content: ""; position: absolute; top: -7px; left: 50%; width: 46px; height: 14px;
  transform: translateX(-50%) rotate(-3deg); background: var(--tape);
}
.maptip[hidden] { display: none; }
.maptip .tiphead { display: block; font-family: var(--hand); font-size: 1.15rem; color: var(--accent); margin-bottom: .25rem; }
.maptip .tipcity { display: flex; justify-content: space-between; gap: 1rem; font-size: .82rem; line-height: 1.5; }
.maptip .tipcity b { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }

.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; margin-bottom: 1.2rem; }
@media (max-width: 720px) { .statgrid { grid-template-columns: 1fr; } }
.statpanel { background: var(--card); box-shadow: var(--shadow); border-radius: 4px; padding: 1rem 1.2rem; }
.statpanel h3 { font-family: var(--hand); margin: .1rem 0 .8rem; font-size: 1.25rem; font-weight: 400; }
.statlist { list-style: none; margin: 0; padding: 0; }
.statlist li { position: relative; display: flex; align-items: center; gap: .5rem; padding: .42rem .25rem .5rem; border-bottom: 1px solid rgba(44,38,32,.06); }
.statlist li:last-child { border-bottom: 0; }
.statlist .bar { position: absolute; left: 0; bottom: -1px; height: 3px; background: var(--accent); opacity: .45; border-radius: 2px; }
.statlist .lbl { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.statlist .cnt { color: var(--muted); font-variant-numeric: tabular-nums; }
.statlist .devsum { font-family: var(--hand); color: var(--ink); font-size: 1.05rem; border-bottom: 0; padding-bottom: .2rem; }
.statlist .empty { color: var(--muted); }

.timeline { margin-bottom: 1.2rem; }
.bars { display: flex; align-items: flex-end; gap: 10px; padding: .4rem .2rem 0; overflow-x: auto; border-bottom: 1px solid rgba(44,38,32,.15); }
.bar1 { flex: 0 0 38px; display: flex; flex-direction: column; align-items: center; }
.bar1 b { font-weight: 400; font-size: .72rem; color: var(--muted); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.bar1 .barcol { height: 90px; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bar1 .barcol span { width: 60%; min-height: 4px; background: var(--accent); opacity: .7; border-radius: 3px 3px 0 0; transition: opacity .15s; }
.bar1:hover .barcol span { opacity: 1; }
.bar1 i { font-style: normal; font-size: .62rem; color: var(--muted); margin-top: 5px; white-space: nowrap; }
.statfoot { text-align: center; margin-top: 1rem; }

/* ---- float (home): every Polaroid drifting by ---- */
body.floatpage { height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none; }
.floatfield {
  position: fixed; left: 0; right: 0; bottom: 0; top: 56px; /* top is set from the nav height */
  overflow: hidden; touch-action: none; cursor: grab;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.floatfield.dragging { cursor: grabbing; }
.floatfield.dragging .floater { cursor: grabbing; }
.floater {
  position: absolute; left: 0; top: 0; display: block; padding: 0; margin: 0;
  border: 0; background: none; font: inherit; color: inherit; cursor: pointer;
  will-change: transform; -webkit-tap-highlight-color: transparent;
}
.floater:hover, .floater:focus-visible { z-index: 19 !important; opacity: 1 !important; }
.floater:focus-visible { outline: none; }
.floater .fcard {
  position: relative; display: block; background: var(--card);
  box-shadow: var(--shadow); border-radius: 2px;
  transform: rotate(var(--tilt, 0deg));
  transition: transform .3s ease, box-shadow .3s ease;
}
.floater .fcard::before { /* tape, same as the gallery cards */
  content: ""; position: absolute; top: -9px; left: 50%; z-index: 1;
  width: 38%; max-width: 70px; height: 20px; transform: translateX(-50%) rotate(-3deg);
  background: var(--tape); box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.floater img {
  display: block; width: 100%; height: auto; border-radius: 2px;
  pointer-events: none; -webkit-user-drag: none;
}
.floater:hover .fcard, .floater:focus-visible .fcard {
  transform: rotate(0deg) scale(1.07); box-shadow: 0 18px 40px rgba(44,38,32,.32);
}
.floater:focus-visible .fcard { outline: 3px solid var(--accent); outline-offset: 3px; }
.floater .fcap {
  position: absolute; left: 50%; top: 100%; transform: translate(-50%, .55rem);
  font-family: var(--hand); font-size: 1.05rem; white-space: nowrap;
  background: var(--paper2); padding: .1rem .65rem; border-radius: 3px;
  box-shadow: 0 3px 10px rgba(44,38,32,.16);
  opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.floater .fcap:empty { display: none; }
.floater:hover .fcap, .floater:focus-visible .fcap { opacity: 1; }
.floater.enter .fcard { animation: float-in .9s ease backwards; }
@keyframes float-in {
  from { opacity: 0; transform: rotate(var(--tilt, 0deg)) translateY(14px) scale(.96); }
}

.plaque {
  position: fixed; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); z-index: 20;
  transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px);
  text-align: center; pointer-events: none;
  background: rgba(246, 240, 227, .9); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: .8rem 1.6rem .9rem; border-radius: 4px; box-shadow: var(--shadow);
}
.plaque h1 { font-size: clamp(2rem, 7vw, 3rem); letter-spacing: .12em; margin: 0; line-height: 1.05; }
.plaque .tagline { color: var(--muted); font-style: italic; margin: .15rem 0 .35rem; }
.plaque .hint { color: var(--muted); font-size: .85rem; margin: .1rem 0 0; }
.plaque a { pointer-events: auto; text-decoration: none; }
.plaque a:hover { text-decoration: underline; }
@media (max-width: 560px) {
  .plaque { padding: .6rem 1rem .7rem; }
  .plaque .tagline { display: none; }
}

/* six nav links: let them fit (or scroll) on a phone */
@media (max-width: 560px) {
  .site-nav { gap: .9rem; padding: .75rem 1rem; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav a.navlink { font-size: .92rem; }
}
