/* whatsmyzip.org — single stylesheet, no framework. Postal-paper light / ink dark. */

/* Space Grotesk (OFL), self-hosted subset built by scripts/fetch-font.sh */
@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/space-grotesk-v2.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --bg: #f4f2ec;
  --bg-raise: #fbfaf6;
  --ink: #1c2430;
  --ink-soft: #5a6473;
  --line: #d9d4c8;
  --accent: #2350b8;
  --accent-ink: #ffffff;
  --stamp-edge: #b3372e;
  --ok: #1a7f4e;
  --warn-bg: #fdf3d8;
  --warn-edge: #b98a1c;
  --warn-ink: #6b5310;
  --edge-hi: rgb(255 255 255 / 65%);
  --shadow-ink: 16 20 28;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141a24;
    --bg-raise: #1c2431;
    --ink: #e8ecf4;
    --ink-soft: #9aa5b5;
    --line: #313c4d;
    --accent: #8ab0ff;
    --accent-ink: #101726;
    --stamp-edge: #e5665b;
    --ok: #52c58a;
    --warn-bg: #33290f;
    --warn-edge: #c8a23e;
    --warn-ink: #ecd9a0;
    --edge-hi: rgb(255 255 255 / 6%);
    --shadow-ink: 0 0 0;
  }
}

:root[data-theme="dark"] {
  --bg: #141a24;
  --bg-raise: #1c2431;
  --ink: #e8ecf4;
  --ink-soft: #9aa5b5;
  --line: #313c4d;
  --accent: #8ab0ff;
  --accent-ink: #101726;
  --stamp-edge: #e5665b;
  --ok: #52c58a;
  --warn-bg: #33290f;
  --warn-edge: #c8a23e;
  --warn-ink: #ecd9a0;
  --edge-hi: rgb(255 255 255 / 6%);
  --shadow-ink: 0 0 0;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--bg);
  /* faint dot grid — instrument-paper texture, zero image assets */
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 6%, transparent) 1px, transparent 1.5px);
  background-size: 26px 26px;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.55;
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
}

main {
  width: min(44rem, 100% - 2.5rem);
  margin: 0 auto;
  flex: 1;
}

a { color: var(--accent); text-underline-offset: 2px; }

h1 { font-family: var(--display); font-size: clamp(1.5rem, 4.5vw, 2.05rem); font-weight: 700; letter-spacing: -0.01em; margin: 0 0 0.25rem; }
h2 { font-family: var(--display); font-size: 1rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-soft); margin: 0 0 0.9rem; }
.btn, .tab, .brand { font-family: var(--display); }

.mono { font-family: var(--mono); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* header */
.top {
  width: min(44rem, 100% - 2.5rem);
  margin: 0 auto;
  padding: 1.1rem 0 0.4rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand { display: inline-flex; align-items: center; font-weight: 700; text-decoration: none; color: var(--ink); letter-spacing: 0.01em; }
.brand-mark { flex: none; margin-right: 0.5rem; border-radius: 5px; box-shadow: 0 1px 2px rgb(var(--shadow-ink) / 18%); }
.brand-tld { color: var(--ink-soft); font-weight: 500; }
.theme-toggle {
  border: 1px solid var(--line);
  background: var(--bg-raise);
  color: var(--ink);
  border-radius: 999px;
  width: 2.1rem;
  height: 2.1rem;
  font-size: 1rem;
  cursor: pointer;
}

/* hero */
.hero { text-align: center; padding: 1.6rem 0 2.2rem; position: relative; }
.hero::before {
  content: "";
  position: absolute;
  inset: -28% 0 0; /* no horizontal overhang — it widens page scrollWidth on mobile */
  background: radial-gradient(70% 55% at 50% 28%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 72%);
  pointer-events: none;
  z-index: -1;
}
.hero-label { color: var(--ink-soft); margin: 0.7rem 0 0.6rem; }

.hero-grid { display: grid; gap: 1.3rem; align-items: center; justify-items: center; }
@media (min-width: 900px) {
  body.has-map .hero-grid { grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); }
  /* the digit clamp is viewport-based — shrink it inside the two-column hero
     so five digits always fit the left column on one line */
  body.has-map .stamp > span { font-size: clamp(2.7rem, 4.9vw, 4.6rem); white-space: nowrap; }
}

/* map card — tiles are same-origin (/tiles/* Worker proxy) */
.map-card {
  position: relative;
  margin: 0;
  width: 100%;
  max-width: 30rem;
  aspect-ratio: 4 / 3;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg-raise);
  box-shadow: 0 10px 30px rgb(0 0 0 / 7%);
}
.map-tiles { position: absolute; inset: 0; }
.map-tiles img { position: absolute; user-select: none; pointer-events: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .map-tiles img,
  :root:not([data-theme="light"]) .mini-map img {
    filter: invert(1) hue-rotate(180deg) saturate(0.72) brightness(0.9) contrast(0.92);
  }
}
:root[data-theme="dark"] .map-tiles img,
:root[data-theme="dark"] .mini-map img {
  filter: invert(1) hue-rotate(180deg) saturate(0.72) brightness(0.9) contrast(0.92);
}

.map-overlay { position: absolute; inset: 0; pointer-events: none; }
.map-marker {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--stamp-edge);
  border: 2.5px solid var(--bg-raise);
  animation: map-pulse 3.5s ease-out infinite;
}
@keyframes map-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--stamp-edge) 45%, transparent); }
  70% { box-shadow: 0 0 0 14px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.map-ring {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}
.map-dot {
  /* 28px hit target (a11y), 12px visual dot */
  position: absolute;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
}
.map-dot::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-raise);
}
.map-dot:hover::after { background: var(--stamp-edge); }

.map-zoom {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.map-btn {
  width: 38px;
  height: 38px;
  font: inherit;
  font-size: 1.15rem;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--bg-raise) 88%, transparent);
  color: var(--ink);
  cursor: pointer;
}
.map-btn:hover { border-color: var(--accent); }
.map-attrib {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 0.68rem;
  padding: 1px 7px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--bg-raise) 82%, transparent);
  color: var(--ink-soft);
  text-decoration: none;
}
.map-attrib:hover { color: var(--ink); }

.stamp {
  /* real perforation: hole pattern unioned with a solid core, so circles are
     only punched along the border band; drop-shadow follows the silhouette */
  --hole: 4.5px;
  --pitch: 15px;
  display: inline-block;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.62rem;
  -webkit-mask:
    radial-gradient(circle var(--hole) at 50% 50%, transparent 98%, #000 100%) 50% 50% / var(--pitch) var(--pitch) round,
    linear-gradient(#000, #000) 50% 50% / calc(100% - var(--pitch)) calc(100% - var(--pitch)) no-repeat;
  mask:
    radial-gradient(circle var(--hole) at 50% 50%, transparent 98%, #000 100%) 50% 50% / var(--pitch) var(--pitch) round,
    linear-gradient(#000, #000) 50% 50% / calc(100% - var(--pitch)) calc(100% - var(--pitch)) no-repeat;
  filter: drop-shadow(0 10px 20px rgb(var(--shadow-ink) / 16%));
}
.stamp > span {
  display: block;
  border: 2px dashed var(--stamp-edge);
  border-radius: 9px;
  padding: 0.9rem 1.6rem;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: clamp(3rem, 15vw, 5.5rem);
  line-height: 1;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
}
.hero[data-state="pending"] .stamp > span { color: var(--ink-soft); }
.hero[data-state="location"] .stamp > span { border-color: var(--ok); }

/* staggered digit settle — delays via :nth-child (no inline styles, CSP 'self') */
#hero-zip .d { display: inline-block; animation: settle 0.26s ease-out both; }
#hero-zip .d:nth-child(2) { animation-delay: 60ms; }
#hero-zip .d:nth-child(3) { animation-delay: 120ms; }
#hero-zip .d:nth-child(4) { animation-delay: 180ms; }
#hero-zip .d:nth-child(5) { animation-delay: 240ms; }
#hero-zip .d:nth-child(6) { animation-delay: 300ms; }
#hero-zip .d:nth-child(7) { animation-delay: 360ms; }
#hero-zip .d:nth-child(8) { animation-delay: 420ms; }
#hero-zip .d:nth-child(9) { animation-delay: 480ms; }
#hero-zip .d:nth-child(10) { animation-delay: 540ms; }
@keyframes settle {
  from { opacity: 0; transform: translateY(7px); }
}

.hero-place { font-size: 1.05rem; margin: 0.9rem 0 0.1rem; min-height: 1.4em; }
/* filled async from /api/me //api/near — reserved height keeps CLS at zero */
.hero-county { color: var(--ink-soft); margin: 0; min-height: 1.3em; }
.hero-time { color: var(--ink-soft); margin: 0.1rem 0 1rem; min-height: 1.3em; }

.hero-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }

.btn {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--bg-raise);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.55rem 1.1rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.badge { color: var(--ink-soft); font-size: 0.85rem; margin: 0.9rem 0 0; }
.hero[data-state="location"] .badge { color: var(--ok); }
.gps-hint { font-size: 0.85rem; color: var(--ink-soft); margin: 0.4rem 0 0; }
.trust-line { font-size: 0.85rem; color: var(--ink-soft); margin: 0.35rem 0 0; }

.notice {
  margin: 1rem auto 0;
  max-width: 34rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn-edge);
  color: var(--warn-ink);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  text-align: left;
}

/* connection */
.conn, .tools, .faq, .about {
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.2rem 1.3rem;
  margin: 0 0 1.1rem;
  box-shadow:
    inset 0 1px 0 var(--edge-hi),
    0 1px 2px rgb(var(--shadow-ink) / 5%),
    0 14px 34px rgb(var(--shadow-ink) / 7%);
}
.svg-sprite { position: absolute; }
.ico {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--ink-soft);
  flex: none;
}
.conn-rows { display: grid; gap: 0.95rem; }
@media (min-width: 700px) {
  .conn-rows { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.15fr) minmax(0, 0.7fr); gap: 1.25rem; }
}
.conn-row { display: flex; align-items: flex-start; gap: 0.65rem; min-width: 0; }
.conn-kv { display: grid; row-gap: 0.25rem; min-width: 0; flex: 1; }
.conn-k {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
}
.conn-v { overflow-wrap: anywhere; line-height: 1.5; }
.conn-v.mono { font-size: 0.95rem; letter-spacing: 0.01em; overflow-wrap: normal; }
.conn-sub {
  display: block;
  margin-top: 0.15rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.pill {
  margin-left: auto;
  font-size: 0.72rem;
  font-family: var(--display);
  text-transform: none;
  letter-spacing: normal;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
  color: var(--ink-soft);
  white-space: nowrap;
}
.pill.good { border-color: var(--ok); color: var(--ok); }
.pill.flag { border-color: var(--warn-edge); color: var(--warn-ink); background: var(--warn-bg); }

.skeleton { color: transparent; background: var(--line); border-radius: 6px; animation: pulse 1.2s ease-in-out infinite; user-select: none; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* tools */
.tabbar { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tab {
  font: inherit;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.4rem 0.95rem;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

.tool-form { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.tool-form input, .tool-form select {
  font: inherit;
  flex: 1 1 10rem;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
}
.tool-form select { flex: 0 1 14rem; }

.result { margin-top: 1rem; }
.result:empty { display: none; }

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  box-shadow: inset 0 1px 0 var(--edge-hi), 0 1px 2px rgb(var(--shadow-ink) / 4%);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover {
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 var(--edge-hi), 0 8px 22px rgb(var(--shadow-ink) / 10%);
}
.card .card-zip { font-family: var(--mono); font-weight: 700; font-size: 2rem; letter-spacing: 0.05em; overflow-wrap: anywhere; }
.card .card-line { margin: 0.25rem 0; overflow-wrap: anywhere; }
.card .card-sub { color: var(--ink-soft); font-size: 0.9rem; }
.error-line { color: var(--stamp-edge); margin: 0; }

/* result-card mini map (same-origin tiles, decorative) */
.mini-map {
  position: relative;
  width: 100%;
  height: 150px;
  margin-top: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
}
.mini-map img { position: absolute; user-select: none; pointer-events: none; }
.mini-map::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--stamp-edge);
  border: 2px solid var(--bg-raise);
}

/* tap-to-copy values inside cards */
.copyable {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: copy;
}
.copyable.card-zip { display: block; }
.copyable.copied { color: var(--ok); }
.copyable.copied::after { content: " ✓"; color: var(--ok); }

.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.6rem; }
.chip {
  font: inherit;
  font-size: 0.88rem;
  font-family: var(--mono);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.static { cursor: default; font-family: var(--sans); }
.chip.flag { border-color: var(--warn-edge); color: var(--warn-ink); background: var(--warn-bg); }
.chip.good { border-color: var(--ok); color: var(--ok); }

/* faq */
.faq details { border-top: 1px solid var(--line); padding: 0.65rem 0; }
.faq details:first-of-type { border-top: 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { color: var(--ink-soft); margin: 0.5rem 0 0.2rem; }

.about p { color: var(--ink-soft); margin: 0; }

.noscript-note { color: var(--warn-ink); background: var(--warn-bg); border-radius: 8px; padding: 0.5rem 0.8rem; }

/* footer */
.foot {
  width: min(44rem, 100% - 2.5rem);
  margin: 0.5rem auto 0;
  padding: 1.2rem 0 1.6rem;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.85rem;
}
.foot nav { margin-bottom: 0.4rem; }
.foot p { margin: 0.25rem 0; }
.fineprint { font-size: 0.78rem; }

/* static doc pages (privacy/terms/404) */
.doc { padding: 1rem 0 2rem; }
.doc h1 { margin: 1rem 0; }
.doc h2 { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 1.1rem; margin-top: 1.4rem; }
.doc p, .doc li { color: var(--ink-soft); }

@media (max-width: 640px) {
  .tool-form button { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  #hero-zip .d { animation: none; }
  .map-marker { animation: none; }
  .card { transition: none; }
  .card:hover { transform: none; }
}
