/* ==========================================================================
   PostalLens SG — data portal
   Visual system: "land registry chart" — cool survey paper, ink navy,
   one transit-red accent, condensed grotesque display, mono for figures.
   ========================================================================== */

@font-face {
  font-family: "Archivo";
  src: url("fonts/archivo-var-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/instrumentsans-var-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plexmono-400-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plexmono-500-latin.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plexmono-600-latin.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #e4e9ef;
  --paper-raised: #f1f4f8;
  --paper-sunk: #d7dfe8;
  --ink: #0c1b2a;
  --ink-2: #2b4258;
  --ink-3: #47607a;
  --rule: #c2cedc;
  --rule-strong: #a2b4c7;
  --red: #c42b1c;
  --red-soft: #f3dcd8;
  --teal: #0f6e5c;
  --teal-soft: #d8ebe5;
  --amber: #8a6207;
  --amber-soft: #f2e6c8;
  --slate: #44607c;

  --display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --body: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --gutter: clamp(1.15rem, 4vw, 3rem);
  --measure: 1280px;
  --radius: 3px;
  --shadow: 0 1px 0 rgba(12, 27, 42, 0.06), 0 12px 30px -18px rgba(12, 27, 42, 0.4);
}

*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.62;
  font-feature-settings: "ss01" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 700;
  margin: 0;
  line-height: 1.05;
  letter-spacing: -0.015em;
}
h1 { font-size: clamp(2.9rem, 8.2vw, 6.1rem); font-stretch: 68%; line-height: 0.94; }
h2 { font-size: clamp(1.7rem, 3.4vw, 2.7rem); font-stretch: 82%; letter-spacing: -0.012em; }
h3 { font-size: 1.2rem; font-stretch: 92%; letter-spacing: -0.005em; }
p { margin: 0 0 1.1em; }
p:last-child { margin-bottom: 0; }

a { color: var(--ink); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--red); }

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

.skip {
  position: absolute; left: -9999px; top: 0; z-index: 99;
  background: var(--ink); color: var(--paper); padding: 0.7rem 1.1rem;
  font-family: var(--mono); font-size: 0.85rem;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

/* ------------------------------------------------------------------ chrome */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.topbar-inner {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.7rem var(--gutter);
  display: flex; align-items: center; gap: 1.4rem;
}
.brand {
  display: flex; align-items: baseline; gap: 0.55rem;
  font-family: var(--display); font-weight: 800; font-stretch: 70%;
  font-size: 1.02rem; letter-spacing: 0.02em; text-decoration: none; color: var(--ink);
}
.brand-mark {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--red); align-self: center;
}
.brand-sub {
  font-family: var(--mono); font-size: 0.7rem; font-weight: 500;
  color: var(--ink-3); letter-spacing: 0.08em; text-transform: uppercase;
}
.nav { margin-left: auto; display: flex; align-items: center; gap: 1.25rem; }
.nav-link {
  font-family: var(--mono); font-size: 0.8rem; font-weight: 500;
  color: var(--ink-3); text-decoration: none; padding: 0.25rem 0;
  border-bottom: 1.5px solid transparent;
}
.nav-link:hover { color: var(--ink); }
.nav-link[aria-current="page"] { color: var(--ink); border-bottom-color: var(--red); }

.live-dot {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-family: var(--mono); font-size: 0.72rem; color: var(--teal);
  border: 1px solid var(--teal-soft); background: var(--teal-soft);
  padding: 0.18rem 0.5rem; border-radius: 2px;
}
.live-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--teal);
  animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }
.live-dot[data-state="down"] { color: var(--red); background: var(--red-soft); border-color: var(--red-soft); }
.live-dot[data-state="down"]::before { background: var(--red); }

/* ------------------------------------------------------------------- type */
.eyebrow {
  font-family: var(--mono); font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-3);
  margin: 0 0 1.1rem;
}
.lede {
  font-size: clamp(1.05rem, 1.5vw, 1.28rem); line-height: 1.55;
  color: var(--ink-2); max-width: 46ch;
}
.mono { font-family: var(--mono); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--ink-3); }
.small { font-size: 0.88rem; }

.shell { max-width: var(--measure); margin: 0 auto; padding: 0 var(--gutter); }
.section { padding: clamp(3.2rem, 7vw, 5.6rem) 0; }
.section + .section { border-top: 1px solid var(--rule); }
.section-head { margin-bottom: 2.2rem; }
.section-head p { color: var(--ink-2); max-width: 58ch; }

/* ------------------------------------------------------------------- hero */
.hero {
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: clamp(1.8rem, 4vw, 4rem); align-items: center;
  padding: clamp(2.6rem, 6vw, 4.6rem) 0 clamp(2.4rem, 5vw, 3.6rem);
}
.hero h1 { margin-bottom: 1.1rem; }
.hero h1 em {
  font-style: normal; color: var(--red);
}
.hero .lede { margin-bottom: 1.8rem; }

.searchbar {
  display: flex; align-items: stretch; gap: 0;
  border: 1.5px solid var(--ink); background: var(--paper-raised);
  max-width: 30rem; box-shadow: var(--shadow);
}
.searchbar input {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 0.95rem 1rem;
  font-family: var(--mono); font-size: 1.32rem; font-weight: 600; letter-spacing: 0.22em;
  color: var(--ink); text-transform: uppercase;
}
.searchbar input::placeholder { color: var(--rule-strong); letter-spacing: 0.22em; }
.searchbar input:focus { outline: none; }
.searchbar:focus-within { outline: 2px solid var(--red); outline-offset: 2px; }
.searchbar button {
  border: 0; border-left: 1.5px solid var(--ink); background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 0.82rem; font-weight: 600; letter-spacing: 0.12em;
  text-transform: uppercase; padding: 0 1.35rem; cursor: pointer;
}
.searchbar button:hover { background: var(--red); border-left-color: var(--red); }
.searchbar[data-state="error"] { border-color: var(--red); outline: 2px solid var(--red-soft); }

.examples { margin-top: 0.9rem; font-family: var(--mono); font-size: 0.8rem; color: var(--ink-3); }
.examples button {
  border: 0; background: none; padding: 0 0.1rem; cursor: pointer;
  font-family: var(--mono); font-size: 0.8rem; color: var(--ink-2); text-decoration: underline;
  text-underline-offset: 3px;
}
.examples button:hover { color: var(--red); }

.form-note { margin-top: 0.8rem; font-size: 0.9rem; color: var(--red); min-height: 1.2em; }

/* ------------------------------------------------------- the ring instrument */
.instrument {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.2rem;
  align-items: center;
  width: 100%;
  max-width: 33rem;
  margin-inline: auto;
}
.instrument-plot { position: relative; aspect-ratio: 1; width: 100%; }
.instrument svg { width: 100%; height: 100%; overflow: visible; }
.ring-legend { display: flex; flex-direction: column; gap: 0.5rem; }
.ring-legend-row {
  display: grid; grid-template-columns: 11px 1fr auto; gap: 0.6rem; align-items: center;
  font-family: var(--mono); font-size: 0.78rem;
}
.ring-legend-swatch { width: 11px; height: 11px; border-radius: 50%; border: 1px solid var(--rule-strong); }
.ring-legend-swatch.is-400 { border: 2px solid var(--red); }
.ring-legend-radius { color: var(--ink-3); letter-spacing: 0.04em; }
.ring-legend-count { font-weight: 600; font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.ring { fill: none; stroke: var(--rule-strong); stroke-width: 1; }
.ring-400 { stroke: var(--red); stroke-width: 1.6; }
.ring-label {
  font-family: var(--mono); font-size: 11px; fill: var(--ink-3);
  letter-spacing: 0.06em;
}
.ring-count {
  font-family: var(--mono); font-size: 13px; font-weight: 600; fill: var(--ink);
}
.ring-axis { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 2 4; }
.ring-draw { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw 1.1s cubic-bezier(.22,.8,.3,1) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.core-dot { fill: var(--red); }
.core-halo { fill: var(--red); opacity: 0.12; }
.instrument-caption {
  text-align: center; font-family: var(--mono); font-size: 0.72rem;
  color: var(--ink-3); margin-top: 0.5rem; letter-spacing: 0.05em;
}
.instrument-caption b { color: var(--ink); font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 0.45rem 1.1rem; margin-top: 1.1rem; justify-content: center; }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; font-family: var(--mono); font-size: 0.76rem; color: var(--ink-2); }
.legend-swatch { width: 9px; height: 9px; border-radius: 50%; }

/* ------------------------------------------------------------- stat rail */
.rail {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  border: 1px solid var(--rule); background: var(--paper-raised);
}
.rail-cell { padding: 1rem 1.1rem; border-right: 1px solid var(--rule); }
.rail-cell:last-child { border-right: 0; }
.rail-value { font-family: var(--mono); font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; }
.rail-label { font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); margin-top: 0.2rem; }

/* ------------------------------------------------------------------ cards */
.grid { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.card { background: var(--paper-raised); padding: 1.5rem 1.4rem; }
.card h3 { margin-bottom: 0.5rem; }
.card p { color: var(--ink-2); font-size: 0.96rem; }
.card-num {
  font-family: var(--mono); font-size: 0.78rem; font-weight: 600; color: var(--red);
  letter-spacing: 0.1em; margin-bottom: 0.9rem; display: block;
}

/* ------------------------------------------------------------------ steps */
.steps { display: grid; gap: 0; border-top: 1px solid var(--rule); }
.step { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr); gap: 1rem; padding: 1.5rem 0; border-bottom: 1px solid var(--rule); }
.step-num { font-family: var(--mono); font-size: 0.78rem; font-weight: 600; color: var(--red); letter-spacing: 0.1em; padding-top: 0.3rem; }
.step h3 { margin-bottom: 0.35rem; }
.step p { color: var(--ink-2); max-width: 70ch; margin: 0; }
.step code { font-family: var(--mono); font-size: 0.86em; color: var(--ink); background: var(--paper-sunk); padding: 0.1em 0.35em; border-radius: 2px; }

/* ------------------------------------------------------------------ table */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th {
  text-align: left; font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-3); font-weight: 600;
  padding: 0.6rem 0.8rem; border-bottom: 1.5px solid var(--ink-3); white-space: nowrap;
}
.data-table td { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td.num, .data-table td .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: var(--paper-raised); }
.table-wrap { border: 1px solid var(--rule); background: var(--paper-raised); overflow-x: auto; }

/* ------------------------------------------------------------------- code */
.code {
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.62;
  background: var(--ink); color: #dbe6f0; padding: 1rem 1.1rem; overflow-x: auto;
  border-radius: var(--radius); white-space: pre; margin: 0;
}
.code .k { color: #ff9b8a; }
.code .s { color: #a9dfc8; }
.code .c { color: #7d95ad; }

code.inline {
  font-family: var(--mono); font-size: 0.86em; background: var(--paper-sunk);
  padding: 0.12em 0.4em; border-radius: 2px; color: var(--ink);
}
pre.inline-block { margin: 0.6rem 0 0; }

.runrow { display: flex; align-items: center; gap: 0.7rem; margin-top: 0.6rem; }
.runbtn {
  font-family: var(--mono); font-size: 0.74rem; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; border: 1px solid var(--ink); background: transparent;
  color: var(--ink); padding: 0.34rem 0.8rem; cursor: pointer; border-radius: 2px;
}
.runbtn:hover { background: var(--ink); color: var(--paper); }
.runbtn[disabled] { opacity: 0.45; cursor: progress; }
.runout { font-family: var(--mono); font-size: 0.76rem; color: var(--teal); }
.runout[data-error] { color: var(--red); }

/* ------------------------------------------------------------------ guide */
.guide-layout {
  display: grid; grid-template-columns: 15rem minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 3.5rem); align-items: start;
}
.guide-nav { position: sticky; top: 5.2rem; }
.guide-nav ol { list-style: none; margin: 0; padding: 0; counter-reset: g; }
.guide-nav li { counter-increment: g; }
.guide-nav a {
  display: grid; grid-template-columns: 1.6rem 1fr; gap: 0.3rem; align-items: baseline;
  padding: 0.5rem 0; text-decoration: none; color: var(--ink-3); font-size: 0.92rem;
  border-left: 2px solid transparent; padding-left: 0.6rem;
}
.guide-nav a::before {
  content: counter(g, decimal-leading-zero);
  font-family: var(--mono); font-size: 0.7rem; color: var(--rule-strong);
}
.guide-nav a:hover { color: var(--ink); border-left-color: var(--rule-strong); }
.guide-nav a[aria-current="true"] { color: var(--ink); border-left-color: var(--red); font-weight: 600; }
.guide-nav a[aria-current="true"]::before { color: var(--red); }

.guide-section { padding: 2.2rem 0; border-bottom: 1px solid var(--rule); scroll-margin-top: 5rem; }
.guide-section:first-child { padding-top: 0; }
.guide-section h2 { margin-bottom: 0.8rem; }
.guide-section p { color: var(--ink-2); max-width: 68ch; }
.guide-section h3 { margin: 1.8rem 0 0.6rem; }
.callout {
  border-left: 3px solid var(--red); background: var(--paper-raised);
  padding: 1rem 1.2rem; margin: 1.4rem 0; font-size: 0.95rem; color: var(--ink-2);
}
.callout strong { color: var(--ink); }

/* --------------------------------------------------------------- explorer */
.explore-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 22rem;
  gap: clamp(1.5rem, 3vw, 2.6rem); align-items: start;
}
.explore-side { position: sticky; top: 5.2rem; }
.panel {
  border: 1px solid var(--rule); background: var(--paper-raised); padding: 1.2rem 1.2rem 1.3rem;
}
.panel + .panel { margin-top: 1rem; }
.panel h3 { margin-bottom: 0.8rem; font-size: 1.02rem; }
.readout { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 1rem; font-family: var(--mono); font-size: 0.8rem; }
.readout dt { color: var(--ink-3); letter-spacing: 0.06em; }
.readout dd { margin: 0; text-align: right; font-weight: 500; }

.module { border-top: 1px solid var(--rule); padding: 1.6rem 0; }
.module-head { display: flex; align-items: baseline; gap: 0.8rem; margin-bottom: 0.9rem; }
.module-code { font-family: var(--mono); font-size: 0.7rem; font-weight: 600; color: var(--red); letter-spacing: 0.12em; }
.module h3 { font-size: 1.12rem; }
.module-summary { color: var(--ink-2); font-size: 0.98rem; margin-bottom: 1rem; }
.poi-list { list-style: none; margin: 0; padding: 0; }
.poi {
  display: grid; grid-template-columns: 1fr auto; gap: 0.2rem 1rem;
  padding: 0.6rem 0; border-bottom: 1px solid var(--rule); align-items: baseline;
}
.poi:last-child { border-bottom: 0; }
.poi-name { font-weight: 600; font-size: 0.97rem; }
.poi-detail { grid-column: 1; color: var(--ink-3); font-size: 0.86rem; }
.poi-dist { grid-row: 1 / span 2; grid-column: 2; font-family: var(--mono); font-size: 0.9rem; font-weight: 600; text-align: right; }
.poi-dist span { display: block; font-size: 0.68rem; font-weight: 400; color: var(--ink-3); letter-spacing: 0.08em; }

.badge {
  display: inline-block; font-family: var(--mono); font-size: 0.66rem; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase; padding: 0.14rem 0.45rem;
  border-radius: 2px; border: 1px solid var(--rule-strong); color: var(--ink-3);
}
.badge-live { color: var(--teal); border-color: var(--teal); background: var(--teal-soft); }
.badge-stale { color: var(--amber); border-color: var(--amber); background: var(--amber-soft); }
.badge-empty { color: var(--ink-3); }

.empty {
  border: 1px dashed var(--rule-strong); padding: 1.4rem; text-align: center;
  color: var(--ink-3); font-size: 0.95rem; background: var(--paper-raised);
}
.empty b { color: var(--ink); display: block; margin-bottom: 0.3rem; font-size: 1.05rem; }

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

/* ----------------------------------------------------------------- footer */
.footer {
  border-top: 1px solid var(--rule); background: var(--paper-raised);
  padding: 2.6rem 0 3rem; margin-top: 2rem;
}
.footer-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 1fr)); gap: 2rem; }
.footer h4 {
  font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 600; margin-bottom: 0.7rem;
}
.footer ul { list-style: none; margin: 0; padding: 0; }
.footer li { margin-bottom: 0.35rem; }
.footer a { font-size: 0.92rem; color: var(--ink-2); text-decoration: none; }
.footer a:hover { color: var(--red); text-decoration: underline; }
.attribution { font-size: 0.8rem; color: var(--ink-3); line-height: 1.6; max-width: 62ch; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1080px) {
  .guide-layout { grid-template-columns: 1fr; }
  .guide-nav { position: static; border-bottom: 1px solid var(--rule); padding-bottom: 1rem; }
  .guide-nav ol { display: flex; flex-wrap: wrap; gap: 0.2rem 1.2rem; }
  .explore-layout { grid-template-columns: 1fr; }
  .explore-side { position: static; }
  .footer-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; }
  .instrument { max-width: 24rem; }
  .nav { gap: 0.9rem; }
  .brand-sub { display: none; }
  .step { grid-template-columns: 3rem minmax(0, 1fr); }
}
@media (max-width: 430px) {
  .instrument { grid-template-columns: 1fr; max-width: 19rem; }
  .ring-legend { flex-direction: row; flex-wrap: wrap; gap: 0.4rem 1.1rem; }
  .ring-legend-row { grid-template-columns: 11px auto auto; }
}
@media (max-width: 560px) {
  .searchbar input { font-size: 1.1rem; letter-spacing: 0.16em; }
  .rail-cell { border-right: 0; border-bottom: 1px solid var(--rule); }
}
