/* ==========================================================================
   GPS Map Camera — design system and layout
   Tokens → base → components → layout → content → utilities.
   See docs/DESIGN_SYSTEM.md for the documented token and component set.
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */
:root {
  /* Palette: graphite neutrals + one "focus-confirm" lime accent */
  --ink-975: #08090b;
  --ink-950: #0b0d10;
  --ink-900: #111418;
  --ink-850: #161a1f;
  --ink-800: #1c2127;
  --ink-750: #232931;
  --ink-700: #2c333c;
  --ink-600: #3c4550;
  --ink-500: #5d6772;
  --ink-400: #8a94a0;
  --ink-300: #b4bdc7;
  --ink-200: #d9dee4;
  --ink-100: #eceff2;
  --ink-50: #f6f7f9;
  --white: #ffffff;
  --lime-300: #d9fb6f;
  --lime-400: #c6f432;
  --lime-500: #aedb1f;
  --lime-700: #4a670b;
  --lime-800: #374d08;
  --amber-400: #fbbf24;
  --amber-800: #8a3c0b;
  --red-400: #fb7d7d;
  --red-700: #b42318;
  --sky-400: #6aaeff;

  /* Typography */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  --fs-xs: 0.75rem;   /* 12 */
  --fs-sm: 0.875rem;  /* 14 */
  --fs-md: 1rem;      /* 16 */
  --fs-lg: 1.125rem;  /* 18 */
  --fs-xl: 1.375rem;  /* 22 */
  --fs-2xl: 1.75rem;  /* 28 */
  --fs-3xl: clamp(1.75rem, 1.2rem + 2.4vw, 2.5rem);
  --lh-tight: 1.2;
  --lh-body: 1.6;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* Spacing (4px grid) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;
  --s-16: 64px;
  --gutter: 16px;

  /* Shape */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;
  --border-w: 1px;

  /* Elevation */
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.06), 0 1px 1px rgb(0 0 0 / 0.04);
  --shadow-2: 0 10px 30px rgb(0 0 0 / 0.18);
  --shadow-glass: 0 4px 16px rgb(0 0 0 / 0.25);

  /* Motion */
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  /* Control sizes (touch targets ≥ 44px) */
  --control-h: 44px;
  --control-h-sm: 36px;

  /* Semantic: light theme (content pages) */
  --bg: var(--ink-50);
  --surface: var(--white);
  --surface-2: var(--ink-100);
  --text: var(--ink-900);
  --text-2: #444d57;
  --text-3: #5f6873;
  --border: var(--ink-200);
  --link: var(--lime-800);
  --accent: var(--lime-400);
  --on-accent: var(--ink-950);
  --focus: var(--lime-800);
  --code-bg: var(--ink-100);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--ink-950);
    --surface: var(--ink-900);
    --surface-2: var(--ink-850);
    --text: var(--ink-100);
    --text-2: var(--ink-300);
    --text-3: var(--ink-400);
    --border: var(--ink-750);
    --link: var(--lime-400);
    --focus: var(--lime-400);
    --code-bg: var(--ink-800);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--ink-950);
  --surface: var(--ink-900);
  --surface-2: var(--ink-850);
  --text: var(--ink-100);
  --text-2: var(--ink-300);
  --text-3: var(--ink-400);
  --border: var(--ink-750);
  --link: var(--lime-400);
  --focus: var(--lime-400);
  --code-bg: var(--ink-800);
  color-scheme: dark;
}

/* The camera tool is always dark, like a camera app. */
.site-header,
.tool {
  --bg: var(--ink-950);
  --surface: var(--ink-900);
  --surface-2: var(--ink-850);
  --surface-3: var(--ink-800);
  --text: var(--ink-100);
  --text-2: var(--ink-300);
  --text-3: var(--ink-400);
  --border: var(--ink-750);
  --border-strong: var(--ink-600);
  --border-input: var(--ink-500); /* ≥ 3:1 against surfaces (WCAG 1.4.11) */
  --link: var(--lime-400);
  --focus: var(--lime-400);
  color-scheme: dark;
  color: var(--text);
  background: var(--bg);
}

/* ---------- 2. Base ------------------------------------------------------ */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: var(--s-4);
}
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg, video, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { line-height: var(--lh-tight); margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--link); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: var(--code-bg);
  overflow-wrap: anywhere;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
[hidden] { display: none !important; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 20px; height: 20px; flex: none; }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute;
  left: var(--s-3);
  top: -100px;
  z-index: 100;
  padding: var(--s-2) var(--s-4);
  border-radius: var(--r-sm);
  background: var(--lime-400);
  color: var(--ink-950);
  font-weight: var(--fw-semibold);
  text-decoration: none;
}
.skip-link:focus { top: var(--s-3); }

/* ---------- 3. Components ------------------------------------------------ */

/* Brand */
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--text);
  text-decoration: none;
  font-weight: var(--fw-bold);
  letter-spacing: -0.01em;
  min-height: var(--control-h);
}
.brand__mark { width: 28px; height: 28px; color: var(--lime-400); --logo-ink: var(--ink-950); }
.brand__name { font-size: var(--fs-md); white-space: nowrap; }

/* Buttons */
.btn {
  --btn-bg: var(--surface-3, var(--surface-2));
  --btn-fg: var(--text);
  --btn-border: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--control-h);
  padding: 0 var(--s-5);
  border: var(--border-w) solid var(--btn-border);
  border-radius: var(--r-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 0.9375rem;
  font-weight: var(--fw-semibold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), opacity var(--dur-fast);
}
.btn .icon { width: 18px; height: 18px; }
.btn:hover { --btn-border: var(--border-strong, var(--ink-300)); }
.btn:active { transform: scale(0.98); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn--primary {
  --btn-bg: var(--lime-400);
  --btn-fg: var(--ink-950);
  --btn-border: var(--lime-400);
}
.btn--primary:hover { --btn-bg: var(--lime-300); --btn-border: var(--lime-300); }
.btn--secondary { --btn-bg: var(--surface-3, var(--surface-2)); }
.btn--ghost { --btn-bg: transparent; --btn-border: transparent; --btn-fg: var(--text-2); }
.btn--ghost:hover { --btn-bg: var(--surface-3, var(--surface-2)); --btn-fg: var(--text); --btn-border: transparent; }
.btn--glass {
  --btn-bg: rgb(255 255 255 / 0.1);
  --btn-border: rgb(255 255 255 / 0.18);
  --btn-fg: var(--white);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.btn--glass:hover { --btn-bg: rgb(255 255 255 / 0.16); --btn-border: rgb(255 255 255 / 0.3); }
.btn--sm { min-height: var(--control-h-sm); padding: 0 var(--s-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--s-2); }

/* Icon buttons on the viewfinder */
.icon-btn,
.round-btn {
  display: inline-grid;
  place-items: center;
  border: var(--border-w) solid rgb(255 255 255 / 0.16);
  background: rgb(11 13 16 / 0.55);
  color: var(--white);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), opacity var(--dur-fast);
}
.icon-btn { width: var(--control-h); height: var(--control-h); border-radius: var(--r-full); }
.icon-btn[aria-pressed="true"] { background: var(--lime-400); color: var(--ink-950); border-color: var(--lime-400); }
.round-btn { width: 52px; height: 52px; border-radius: var(--r-full); background: var(--surface-3); border-color: var(--border); }
.round-btn .icon { width: 22px; height: 22px; }
.round-btn:hover:not(:disabled) { background: var(--ink-750); }
.round-btn:active:not(:disabled) { transform: scale(0.94); }
.round-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Shutter */
.shutter {
  position: relative;
  width: 76px;
  height: 76px;
  padding: 0;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.shutter::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 4px solid var(--white);
}
.shutter__ring {
  position: absolute;
  inset: 9px;
  border-radius: inherit;
  background: var(--white);
  transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast);
}
.shutter:hover:not(:disabled) .shutter__ring { background: var(--ink-100); }
.shutter:active:not(:disabled) .shutter__ring { transform: scale(0.88); }
.shutter:disabled { cursor: not-allowed; opacity: 0.4; }
.shutter[data-busy="true"] .shutter__ring { background: var(--lime-400); transform: scale(0.8); }

/* Chip (status pill) */
.chip {
  --tone: var(--ink-400);
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 36px;
  max-width: 100%;
  padding: 0 var(--s-3) 0 var(--s-2);
  border: var(--border-w) solid rgb(255 255 255 / 0.14);
  border-radius: var(--r-full);
  background: rgb(11 13 16 / 0.6);
  color: var(--white);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.chip .icon { width: 18px; height: 18px; color: var(--tone); }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

[data-tone="good"] { --tone: var(--lime-400); }
[data-tone="warn"] { --tone: var(--amber-400); }
[data-tone="bad"] { --tone: var(--red-400); }
[data-tone="busy"] { --tone: var(--sky-400); }
[data-tone="neutral"] { --tone: var(--ink-400); }
.chip[data-tone="busy"] .icon { animation: pulse 1.2s var(--ease) infinite; }

/* Badge */
.badge {
  --tone: var(--ink-400);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px var(--s-2);
  border-radius: var(--r-full);
  background: rgb(255 255 255 / 0.06);
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  color: var(--tone);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: var(--border-w) solid var(--border);
}
.segmented__item { position: relative; display: flex; flex: 1; }
.segmented__item input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented__face {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h-sm);
  padding: 0 var(--s-3);
  border-radius: 9px;
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast);
  pointer-events: none;
}
.segmented__face .icon { width: 16px; height: 16px; }
.segmented__item input:checked + .segmented__face { background: var(--ink-700); color: var(--white); box-shadow: var(--shadow-1); }
.segmented__item input:focus-visible + .segmented__face { outline: 2px solid var(--focus); outline-offset: 1px; }
.segmented__item:hover input:not(:checked) + .segmented__face { color: var(--text); }
.segmented--light { display: flex; }

/* Form fields */
.field { display: grid; gap: 6px; min-width: 0; }
.field label,
.field__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-2);
}
.field__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-2); }
.field__head .field__value { font-size: var(--fs-sm); }
.field__hint { font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--text-3); }
.field__value { font-variant-numeric: tabular-nums; color: var(--text); font-weight: var(--fw-semibold); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.input,
.select {
  width: 100%;
  min-height: var(--control-h);
  padding: 10px var(--s-3);
  border: var(--border-w) solid var(--border-input, var(--border));
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: var(--fs-md); /* 16px prevents iOS zoom on focus */
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
textarea.input { resize: vertical; min-height: 84px; line-height: 1.45; }
.input::placeholder { color: var(--ink-500); }
.input:hover,
.select:hover { border-color: var(--ink-400); }
.input:focus,
.select:focus { outline: none; border-color: var(--lime-400); box-shadow: 0 0 0 3px rgb(198 244 50 / 0.2); }
.input[aria-invalid="true"] { border-color: var(--red-400); }
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23b4bdc7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.select--compact { min-height: var(--control-h-sm); padding-top: 6px; padding-bottom: 6px; font-size: var(--fs-sm); width: auto; }
.color {
  width: 100%;
  height: var(--control-h);
  padding: 4px;
  border: var(--border-w) solid var(--border-input, var(--border));
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}
.color::-webkit-color-swatch-wrapper { padding: 0; }
.color::-webkit-color-swatch { border: 0; border-radius: 6px; }
.color::-moz-color-swatch { border: 0; border-radius: 6px; }
.range { width: 100%; height: 28px; accent-color: var(--lime-400); cursor: pointer; }

.check {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: var(--control-h-sm);
  font-size: var(--fs-sm);
  color: var(--text-2);
  cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--lime-400); margin: 0; }

/* Toggle chips (field visibility) */
.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.toggles legend {
  width: 100%;
  margin-bottom: var(--s-2);
  padding: 0;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-2);
}
.toggle { position: relative; display: inline-flex; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--control-h-sm);
  padding: 0 var(--s-3);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  pointer-events: none;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.toggle span::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1.5px solid var(--ink-500);
  transition: inherit;
}
.toggle input:checked + span { color: var(--text); border-color: rgb(198 244 50 / 0.55); background: rgb(198 244 50 / 0.1); }
.toggle input:checked + span::before {
  border-color: var(--lime-400);
  background: var(--lime-400) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230b0d10' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 11px no-repeat;
}
.toggle input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.toggle input:disabled + span { opacity: 0.45; }

/* Card */
.card {
  display: grid;
  gap: var(--s-4);
  padding: var(--s-4);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.card__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.card__actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* Status line */
.status-line { min-height: 1.4em; font-size: var(--fs-sm); color: var(--text-3); }
.status-line:empty { display: none; }
.status-line[data-tone="bad"] { color: var(--red-400); }
.status-line[data-tone="warn"] { color: var(--amber-400); }
.status-line[data-tone="good"] { color: var(--lime-400); }

/* Tabs */
.tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: var(--border-w) solid var(--border);
}
.tabs__tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 var(--s-2);
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.tabs__tab .icon { width: 16px; height: 16px; }
.tabs__tab:hover { color: var(--text); }
.tabs__tab[aria-selected="true"] { background: var(--ink-700); color: var(--white); box-shadow: var(--shadow-1); }
.tabs__panel { display: grid; gap: var(--s-4); padding-top: var(--s-4); }

/* Toasts */
.toast-region {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s-4) + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  display: grid;
  gap: var(--s-2);
  width: min(92vw, 440px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  --tone: var(--ink-400);
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border: var(--border-w) solid var(--ink-700);
  border-left: 3px solid var(--tone);
  border-radius: var(--r-md);
  background: var(--ink-850);
  color: var(--ink-100);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
  pointer-events: auto;
  animation: toast-in var(--dur-slow) var(--ease);
}
.toast .icon { width: 18px; height: 18px; color: var(--tone); margin-top: 1px; }
.toast[data-leaving="true"] { animation: toast-out var(--dur) var(--ease) forwards; }

/* ---------- 4. Layout ---------------------------------------------------- */

/* Header */
.site-header { border-bottom: var(--border-w) solid var(--ink-850); }
.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--s-1) var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}
.site-nav { display: flex; gap: var(--s-1); }
.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-h);
  padding: 0 var(--s-2);
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-decoration: none;
  border-radius: var(--r-sm);
}
.site-nav a:hover { color: var(--text); background: var(--ink-850); }
@media (max-width: 420px) {
  .site-nav a:not(:last-child) { display: none; }
}

/* Tool */
.tool { padding-bottom: var(--s-6); }
.tool__head {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--s-2) var(--gutter) var(--s-3);
}
.tool h1 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: var(--s-3);
  row-gap: 2px;
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}
.tool__sub { font-size: var(--fs-sm); font-weight: var(--fw-regular); color: var(--text-3); letter-spacing: 0; }

.noscript {
  margin: var(--s-4);
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: var(--border-w) solid var(--amber-400);
}

.app { max-width: 1280px; margin: 0 auto; }
.cam { display: grid; }
.cam__stage {
  display: grid;
  place-items: center;
  min-height: 300px;
  background: var(--ink-975);
}

/* Viewfinder */
.viewfinder {
  position: relative;
  /* Mirrors sizeViewfinder() in app.js so the first paint doesn't shift. */
  width: min(100%, max(180px, calc((100svh - 290px) * 0.75)));
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #000;
  isolation: isolate;
  touch-action: manipulation;
}
.viewfinder__video,
.viewfinder__overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.viewfinder__video { object-fit: cover; opacity: 0; transition: opacity var(--dur-slow) var(--ease); }
.viewfinder[data-state="live"] .viewfinder__video { opacity: 1; }
.viewfinder[data-mirror="true"] .viewfinder__video { transform: scaleX(-1); }
.viewfinder__overlay { pointer-events: none; z-index: 1; }
.viewfinder:not([data-state="live"]) .viewfinder__overlay { visibility: hidden; }
.viewfinder__flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: var(--white);
  opacity: 0;
  pointer-events: none;
}
.viewfinder[data-flash="true"] .viewfinder__flash { animation: shutter-flash 360ms var(--ease); }
.viewfinder__hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: var(--s-3);
}
.viewfinder__hud .chip { cursor: pointer; }
.viewfinder:not([data-state="live"]) .viewfinder__hud .icon-btn { display: none; }
.viewfinder__zoom {
  position: absolute;
  z-index: 3;
  right: var(--s-3);
  top: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-2);
  border-radius: var(--r-full);
  background: rgb(11 13 16 / 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transform: translateY(-50%);
}
.viewfinder__zoom input {
  writing-mode: vertical-lr;
  direction: rtl;
  width: 28px;
  height: 140px;
  accent-color: var(--lime-400);
}
.viewfinder__zoom output { font-size: var(--fs-xs); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; color: var(--white); }
.viewfinder:not([data-state="live"]) .viewfinder__zoom { display: none; }

.viewfinder__message {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: var(--s-6) var(--s-5);
  background:
    radial-gradient(120% 80% at 50% 0%, rgb(198 244 50 / 0.07), transparent 60%),
    var(--ink-950);
  text-align: center;
}
.viewfinder[data-state="live"] .viewfinder__message { display: none; }
.msg { display: grid; justify-items: center; gap: var(--s-3); max-width: 340px; }
.msg__icon {
  --tone: var(--lime-400);
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: var(--r-lg);
  background: rgb(198 244 50 / 0.12);
  background: color-mix(in srgb, var(--tone) 12%, transparent);
  color: var(--tone);
}
.msg__icon .icon { width: 26px; height: 26px; }
.viewfinder[data-state="starting"] .msg__icon .icon { animation: pulse 1.2s var(--ease) infinite; }
.msg__title { font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.msg__text { color: var(--text-2); font-size: var(--fs-sm); line-height: 1.55; }
.msg__actions { display: grid; gap: var(--s-2); width: 100%; margin-top: var(--s-2); }

/* Camera controls */
.cam__controls {
  display: grid;
  justify-items: center;
  gap: var(--s-4);
  padding: var(--s-4) var(--gutter) var(--s-2);
}
.cam__controls .segmented { width: min(100%, 380px); }
.shutter-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  width: min(100%, 320px);
}
.cam__extra:has(select[hidden]) { display: none; }

/* Location panel */
.loc-panel { display: grid; gap: var(--s-3); padding: var(--s-4) var(--gutter) 0; }
.loc-data { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-2); margin: 0; }
.loc-data > div { min-width: 0; padding: var(--s-2) var(--s-3); border-radius: var(--r-sm); background: var(--surface-2); }
.loc-data dt { font-size: var(--fs-xs); color: var(--text-3); }
.loc-data dd { margin: 0; font-size: var(--fs-sm); font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.loc-address { font-size: var(--fs-sm); color: var(--text-2); line-height: 1.5; }
.map-slot { position: relative; }
.map {
  position: relative;
  height: 200px;
  overflow: hidden;
  border-radius: var(--r-md);
  border: var(--border-w) solid var(--border);
  background: var(--surface-2);
  z-index: 0;
}
.map-slot--editor .map { height: 260px; }
.map__placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--s-2);
  padding: var(--s-4);
  color: var(--text-3);
  font-size: var(--fs-sm);
  text-align: center;
}
.privacy-note {
  display: flex;
  gap: var(--s-2);
  padding: 0 var(--s-1);
  font-size: var(--fs-xs);
  color: var(--text-3);
  line-height: 1.5;
}
.privacy-note .icon { width: 16px; height: 16px; margin-top: 1px; color: var(--lime-400); }

/* Leaflet adjustments (theme + custom pin) */
.leaflet-container { font: inherit; font-size: var(--fs-xs); background: var(--ink-800); }
.leaflet-control-attribution { font-size: 10px; }
.map-pin { width: 30px; height: 40px; }
.map-pin svg { width: 30px; height: 40px; filter: drop-shadow(0 2px 3px rgb(0 0 0 / 0.4)); }
.map-pin--draggable { cursor: grab; }

/* Editor */
.editor {
  display: grid;
  gap: var(--s-3);
  grid-template-areas: "bar" "preview" "panel" "actions";
}
.editor__bar {
  grid-area: bar;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--s-2);
  padding: 0 var(--gutter);
}
.editor__title { font-size: var(--fs-md); font-weight: var(--fw-semibold); text-align: center; }
.editor__title:focus { outline: none; }
.editor__dims { font-size: var(--fs-xs); color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 72px; text-align: right; }
.editor__preview {
  grid-area: preview;
  position: relative;
  display: grid;
  place-items: center;
  padding: var(--s-2) var(--gutter);
  background: var(--ink-975);
}
.editor__preview canvas {
  max-width: 100%;
  max-height: 56svh;
  width: auto;
  height: auto;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
}
.editor__rendering {
  position: absolute;
  top: var(--s-3);
  right: calc(var(--gutter) + var(--s-2));
  padding: 2px var(--s-2);
  border-radius: var(--r-full);
  background: rgb(11 13 16 / 0.7);
  font-size: var(--fs-xs);
  color: var(--text-2);
}
.editor__panel { grid-area: panel; padding: 0 var(--gutter); min-width: 0; }
.record {
  display: grid;
  gap: 4px;
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: var(--border-w) solid var(--border);
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.record:empty { display: none; }
p.record { display: block; }
.record strong { color: var(--text); font-weight: var(--fw-semibold); }
.record .warn { color: var(--amber-400); }
.record .bad { color: var(--red-400); }
.editor__actions {
  grid-area: actions;
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  gap: var(--s-3);
  padding: var(--s-3) var(--gutter) calc(var(--s-3) + env(safe-area-inset-bottom, 0px));
  border-top: var(--border-w) solid var(--border);
  background: rgb(11 13 16 / 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.export-opts { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-2) var(--s-3); }
@media (max-width: 959px) {
  .editor__actions { gap: var(--s-2); padding-top: var(--s-2); }
  .export-opts { flex-wrap: nowrap; }
  .export-opts .check { font-size: var(--fs-xs); min-width: 0; }
  .export-opts .check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.export-btns { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--s-2); }

@media (min-width: 720px) {
  .viewfinder { border-radius: var(--r-lg); }
  .cam__stage { background: transparent; padding: 0 var(--gutter); }
  .msg__actions { grid-auto-flow: column; justify-content: center; }
}

@media (min-width: 960px) {
  :root { --gutter: 24px; }
  .tool { padding-bottom: var(--s-10); }
  .tool__head { padding-top: var(--s-4); padding-bottom: var(--s-4); }
  .tool h1 { font-size: var(--fs-xl); }
  .app[data-view="camera"] {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: var(--s-6);
    padding: 0 var(--gutter);
    align-items: start;
  }
  .cam__stage { padding: 0; min-height: 420px; }
  .viewfinder { width: min(100%, 585px, max(270px, calc((100vh - 276px) * 0.75))); }
  .loc-panel { padding: 0; position: sticky; top: var(--s-4); }
  .map { height: 220px; }
  .app[data-view="editor"] { padding: 0 var(--gutter); }
  .editor {
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: auto auto minmax(0, 1fr);
    grid-template-areas: "bar bar" "preview actions" "preview panel";
    gap: var(--s-4) var(--s-6);
    align-items: start;
  }
  .editor__bar { padding: 0; }
  .editor__preview { position: sticky; top: var(--s-4); padding: var(--s-4); border-radius: var(--r-lg); min-height: 420px; }
  .editor__preview canvas { max-height: 74vh; }
  .editor__panel { padding: 0; }
  .editor__actions {
    position: static;
    padding: var(--s-4);
    border: var(--border-w) solid var(--border);
    border-radius: var(--r-lg);
    background: var(--surface);
  }
}

/* ---------- 5. Content pages -------------------------------------------- */
.content { max-width: 780px; margin: 0 auto; padding: var(--s-10) var(--gutter) var(--s-12); }
.content__section { padding: var(--s-8) 0; border-top: var(--border-w) solid var(--border); }
.content__section:first-child { border-top: 0; padding-top: 0; }
.content h2 { font-size: var(--fs-2xl); font-weight: var(--fw-bold); margin-bottom: var(--s-4); }
.content h3 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin: var(--s-6) 0 var(--s-2); }
.content p,
.content li { color: var(--text-2); }
.content p + p { margin-top: var(--s-4); }
.content ul { margin: var(--s-4) 0 0; padding-left: 1.25em; display: grid; gap: var(--s-2); }
.content strong { color: var(--text); }
.feature-list li::marker { color: var(--lime-700); }
.steps { list-style: none; counter-reset: step; margin: 0; padding: 0; display: grid; gap: var(--s-5); }
.steps li { counter-increment: step; position: relative; padding-left: 52px; }
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: var(--fw-bold);
  font-size: var(--fs-sm);
}
.steps h3 { margin: 6px 0 var(--s-1); }
.grid-2 { display: grid; gap: var(--s-2) var(--s-8); }
.grid-2 h3 { margin-top: var(--s-2); }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.faq { display: grid; gap: var(--s-2); }
.faq details {
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.faq summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 56px;
  padding: var(--s-3) var(--s-4);
  cursor: pointer;
  list-style: none;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "";
  flex: none;
  width: 18px;
  height: 18px;
  background: currentColor;
  color: var(--text-3);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  transition: transform var(--dur) var(--ease);
}
.faq details[open] summary::after { transform: rotate(180deg); }
.faq summary h3 { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); }
.faq details p { padding: 0 var(--s-4) var(--s-4); }

.doc { padding: var(--s-10) var(--gutter) var(--s-12); }
.doc__body { max-width: 720px; margin: 0 auto; }
.doc__body--center { text-align: center; padding: var(--s-12) 0; }
.doc h1 { font-size: var(--fs-3xl); font-weight: var(--fw-bold); margin-bottom: var(--s-4); }
.doc h2 { font-size: var(--fs-xl); margin: var(--s-8) 0 var(--s-3); }
.doc p, .doc li { color: var(--text-2); }
.doc p + p { margin-top: var(--s-4); }
.doc ul { padding-left: 1.25em; display: grid; gap: var(--s-3); }
.doc__lead { font-size: var(--fs-lg); color: var(--text); }
.doc .btn { margin-top: var(--s-6); }

/* Footer */
.site-footer { border-top: var(--border-w) solid var(--border); background: var(--surface); }
.site-footer__inner {
  display: grid;
  gap: var(--s-5);
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--s-8) var(--gutter) calc(var(--s-8) + env(safe-area-inset-bottom, 0px));
}
.site-footer .brand { color: var(--text); }
.site-footer .brand__mark { color: var(--lime-700); --logo-ink: var(--white); }
.site-footer__brand p { font-size: var(--fs-sm); color: var(--text-3); }
.site-footer__nav { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); }
.site-footer__nav a { display: inline-flex; align-items: center; min-height: var(--control-h); color: var(--text-2); font-size: var(--fs-sm); text-decoration: none; }
.site-footer__nav a:hover { color: var(--text); text-decoration: underline; }
.site-footer__legal { font-size: var(--fs-xs); color: var(--text-3); line-height: 1.6; }
.site-footer__legal a { color: inherit; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .site-footer .brand__mark { color: var(--lime-400); --logo-ink: var(--ink-950); }
  :root:not([data-theme="light"]) .feature-list li::marker { color: var(--lime-400); }
}
@media (min-width: 720px) {
  .site-footer__inner { grid-template-columns: 1fr auto; align-items: start; }
  .site-footer__legal { grid-column: 1 / -1; }
}

/* ---------- 6. Motion ---------------------------------------------------- */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes shutter-flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

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