/* Colour is always a token, never a hex in a component (Constitution IX.1),
   and every token is defined in BOTH theme blocks. A token defined only in the
   dark block silently inherits a dark value in light mode, which is the exact
   failure that clause exists to prevent.

   The palette is one hue family: a cold slate for surfaces and a single blue
   for anything interactive, with amber and red reserved for states that mean
   something. Reserving colours is what keeps a status meaningful; if
   everything is coloured, nothing is. */

:root {
  color-scheme: light dark;

  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-sunk: #f0f2f5;
  --border: #d9dee6;
  --border-strong: #b6bfcc;

  --text: #171b22;
  --text-muted: #5b6472;
  --text-faint: #838d9c;

  --accent: #1f5fd0;
  --accent-hover: #1a4fae;
  --accent-soft: #e7effb;
  --on-accent: #ffffff;

  --good: #16704a;
  --good-soft: #e2f2ea;
  --warn: #8a5a00;
  --warn-soft: #fbf0da;
  --bad: #a8241f;
  --bad-soft: #fbe6e5;

  --code-bg: #1b1f27;
  --code-text: #e6e9ef;
  --focus: #1f5fd0;

  --radius: 8px;
  --radius-sm: 5px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow: 0 1px 2px rgba(16, 22, 32, 0.06), 0 4px 12px rgba(16, 22, 32, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1015;
    --surface: #151a21;
    --surface-sunk: #10141a;
    --border: #262d38;
    --border-strong: #3a4453;

    --text: #e8ecf2;
    --text-muted: #9aa5b4;
    --text-faint: #6d7889;

    --accent: #6ba3f5;
    --accent-hover: #8bb8f8;
    --accent-soft: #16243a;
    --on-accent: #0d1015;

    --good: #5fcb96;
    --good-soft: #12271e;
    --warn: #e0ad55;
    --warn-soft: #2a2113;
    --bad: #f0817b;
    --bad-soft: #2d1817;

    --code-bg: #0a0d12;
    --code-text: #dbe1ea;
    --focus: #6ba3f5;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* A visible focus ring on every interactive element, and it is never removed
   (IX.10). Keyboard users are not an edge case. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 9px; font-weight: 640; letter-spacing: -0.015em; font-size: 17px; }
.brand .tag { font-weight: 400; font-size: 12.5px; color: var(--text-muted); letter-spacing: 0; }
nav.top-nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
nav.top-nav a {
  padding: 5px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
}
nav.top-nav a:hover { background: var(--surface-sunk); color: var(--text); text-decoration: none; }
nav.top-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.layout { display: grid; grid-template-columns: minmax(0, 232px) minmax(0, 1fr); gap: 32px; max-width: 1240px; margin: 0 auto; padding: 28px 24px 80px; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } aside.rail { position: static; max-height: none; } }

aside.rail { position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 96px); overflow-y: auto; font-size: 13.5px; }
aside.rail h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); margin: 18px 0 6px; font-weight: 620; }
aside.rail h2:first-child { margin-top: 0; }
aside.rail a { display: block; padding: 3px 9px; border-radius: var(--radius-sm); color: var(--text-muted); border-left: 2px solid transparent; }
aside.rail a:hover { background: var(--surface-sunk); color: var(--text); text-decoration: none; }

main { min-width: 0; }

h1 { font-size: 29px; letter-spacing: -0.02em; margin: 0 0 10px; font-weight: 660; }
h2.section { font-size: 20px; letter-spacing: -0.012em; margin: 40px 0 12px; font-weight: 620; scroll-margin-top: 80px; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 600; }
p { margin: 0 0 12px; }
p.lede { font-size: 16.5px; color: var(--text-muted); max-width: 68ch; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }

.callout { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 13px 16px; border-radius: 0 var(--radius) var(--radius) 0; margin: 0 0 20px; }
.callout.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout strong { font-weight: 620; }
.callout p:last-child { margin-bottom: 0; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px 15px; }
.stat .n { font-size: 22px; font-weight: 640; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat .k { font-size: 12.5px; color: var(--text-muted); margin-top: 1px; }

.endpoint { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; overflow: hidden; }
.endpoint > .head { display: flex; align-items: center; gap: 10px; padding: 11px 14px; flex-wrap: wrap; }
.method { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 4px; background: var(--good-soft); color: var(--good); letter-spacing: 0.03em; }
.method.post { background: var(--accent-soft); color: var(--accent); }
.method.delete { background: var(--bad-soft); color: var(--bad); }
.path { font-family: var(--mono); font-size: 13px; font-weight: 500; }
.summary { color: var(--text-muted); font-size: 13.5px; flex: 1 1 240px; min-width: 0; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 20px; border: 1px solid var(--border-strong); color: var(--text-muted); white-space: nowrap; }
.badge.free { border-color: var(--good); color: var(--good); }

button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 5px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-sunk); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
button.danger:hover:not(:disabled) { background: var(--bad-soft); }

input[type="text"], input[type="url"], select {
  font: inherit;
  font-size: 13.5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}

pre {
  margin: 0;
  background: var(--code-bg);
  color: var(--code-text);
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  tab-size: 2;
}
code.inline { font-family: var(--mono); font-size: 0.9em; background: var(--surface-sunk); padding: 1.5px 5px; border-radius: 4px; border: 1px solid var(--border); }

.result { border-top: 1px solid var(--border); padding: 12px 14px; background: var(--surface-sunk); }
.result .meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-family: var(--mono); flex-wrap: wrap; }

/* The state matrix (IX.3). Loading, empty, error and forbidden are part of the
   feature rather than polish, so each has a real style and a real voice. */
.state { padding: 15px; border-radius: var(--radius); font-size: 13.5px; border: 1px dashed var(--border-strong); color: var(--text-muted); background: var(--surface); }
.state.loading { color: var(--text-muted); }
.state.error { border-style: solid; border-color: var(--bad); background: var(--bad-soft); color: var(--text); }
.state.empty { text-align: left; }
.state strong { display: block; margin-bottom: 3px; color: var(--text); font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; padding: 7px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
td.mono, th.mono { font-family: var(--mono); font-size: 12.5px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; }
.dot.good { background: var(--good); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

.key-value { display: block; font-family: var(--mono); font-size: 13px; word-break: break-all; background: var(--code-bg); color: var(--code-text); padding: 11px 13px; border-radius: var(--radius-sm); margin: 9px 0; }

footer.foot { max-width: 1240px; margin: 0 auto; padding: 22px 24px 40px; color: var(--text-faint); font-size: 12.5px; border-top: 1px solid var(--border); }

.row { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; }
.stack > * + * { margin-top: 12px; }

/* The gate. Centred, narrow, and deliberately plain: it is the only page an
   unauthenticated visitor sees, so it should say what this is and offer the one
   action available, rather than advertise a service they cannot read yet. */
.gate-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px 28px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gate-title { font-size: 24px; font-weight: 620; letter-spacing: -0.02em; margin: 0 0 20px; }
/* The Google button is a fixed-width iframe, so it is centred rather than
   stretched: stretching it leaves the button floating in a wider box. */
.gate-card #signin { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.gate-card .state { text-align: left; }

/* The map. Colour is a token here too (IX.1), including the altitude ramp: the
   canvas reads these with getComputedStyle so the scale changes with the theme
   instead of being five hex values buried in a draw call. The ramp runs cool to
   warm with lightness rising throughout, so the bands stay distinguishable
   without relying on hue alone. */
:root {
  --map-ocean: #e9edf3;
  --map-land: #d3dae4;
  --map-border: #bcc5d2;
  --map-lake: #e9edf3;
  --alt-ground: #7c8697;
  --alt-1: #2f6fd0;
  --alt-2: #1f8f8f;
  --alt-3: #3f9440;
  --alt-4: #b07d1a;
  --alt-5: #c2542c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --map-ocean: #0b0e13;
    --map-land: #1b2029;
    --map-border: #2c3441;
    --map-lake: #0b0e13;
    --alt-ground: #77839a;
    --alt-1: #63a6f5;
    --alt-2: #4fc4c4;
    --alt-3: #6fc76f;
    --alt-4: #e2b455;
    --alt-5: #f08a63;
  }
}

/* Third-party enrichment. Given a visibly different treatment from everything
   observed, because the whole value of this service is that the two are not
   confused: a dashed edge and a muted ground say "somebody else said this"
   before a word is read. */
.enrich { border-style: dashed; background: var(--surface-sunk); }
.enrich-head { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; }
.enrich-body { display: flex; gap: 15px; align-items: flex-start; flex-wrap: wrap; }
.enrich-photo { width: 190px; max-width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.enrich-facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; align-content: start; }
.enrich-facts dt { color: var(--text-muted); font-size: 12px; }
.enrich-facts dd { margin: 0; font-size: 13px; }
.route-hint { margin-top: 4px; color: var(--text-muted); }
.route-hint .badge { font-size: 10px; padding: 1px 5px; }

.map-shell { max-width: 1600px; margin: 0 auto; padding: 14px 16px 26px; }
.map-stage { position: relative; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--map-ocean); }
.map-stage canvas { display: block; width: 100%; height: 72vh; min-height: 380px; cursor: grab; touch-action: none; }
.map-stage canvas.dragging { cursor: grabbing; }

.map-hud, .map-legend, .map-controls, .map-detail {
  position: absolute;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  backdrop-filter: blur(6px);
}
.map-hud { top: 10px; left: 10px; padding: 8px 11px; }
.map-hud .hud-line { line-height: 1.35; }
.map-hud strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.map-legend { bottom: 10px; left: 10px; padding: 8px 11px; display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; }
.map-legend .row { display: flex; align-items: center; gap: 7px; color: var(--text-muted); }
.map-legend .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }

.map-controls { top: 10px; right: 10px; padding: 6px; display: flex; gap: 5px; align-items: center; }
.map-controls button { padding: 3px 9px; min-width: 30px; }
.path-toggle { display: flex; align-items: center; gap: 5px; font-size: 12.5px; padding: 0 6px 0 2px; cursor: pointer; white-space: nowrap; }
.path-toggle input { accent-color: var(--accent); cursor: pointer; }

.map-detail { bottom: 10px; right: 10px; padding: 11px 13px; max-width: 270px; font-size: 13px; }
.map-detail h3 { margin: 0 0 6px; font-family: var(--mono); font-size: 14px; }
.map-detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.map-detail dt { color: var(--text-muted); font-size: 12px; }
.map-detail dd { margin: 0; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.map-detail .close { position: absolute; top: 6px; right: 8px; border: none; background: none; padding: 2px 5px; color: var(--text-muted); }

@media (max-width: 640px) {
  .map-legend { display: none; }
  .map-detail { left: 10px; right: 10px; max-width: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .state.loading::after { content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.1s ease-in-out infinite; }
  @keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
}
