:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  color: #151a2e;
  background: #f5f2eb;
  --paper: #f5f2eb;
  --card: #fefcf7;
  --floating: #fefcf7f5;
  --ink: #151a2e;
  --muted: #53596b;
  --line: #d8d7df;
  --brand: #000072;
  --accent: var(--brand);
  --selected: #e8eaf8;
  --focus: #3969d2;
  --shadow: 0 3px 12px #17213a26;
  --span-shorter: #00818a;
  --span-medium: #000072;
  --span-longer: #743e9b;
  --span-unknown: #737887;
  --proposed: #c15a0a;
  --fcc: #11754c;
  --reports: #b81123;
  --danger-ink: #961225;
  --danger-wash: #f8e8e7;
  --water: #c9dae4;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 280px; }
h1, h2, h3, p, dl, dd { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
a { color: var(--accent); text-underline-offset: .18em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.icon {
  display: block;
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark { display: block; flex: none; object-fit: cover; border-radius: 20%; }
.eyebrow { color: var(--muted); font-size: .77rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }

/* Account gate */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: radial-gradient(ellipse at 15% 10%, #dbe9f1 0, transparent 50%), var(--paper);
}

.auth-card {
  width: min(100%, 432px);
  padding: clamp(24px, 6vw, 36px);
  background: var(--card);
  border: 1px solid #dce0e5;
  border-radius: 24px;
  box-shadow: 0 20px 65px #1a25421c;
}

.auth-card .eyebrow { margin: 22px 0 6px; }
.auth-card h1 { color: var(--accent); font-size: clamp(1.8rem, 7.5vw, 2.35rem); line-height: 1.1; letter-spacing: -.045em; }
.auth-intro { color: var(--muted); margin: 12px 0 24px; line-height: 1.48; }
.auth-tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 18px; border-radius: 12px; background: #efedf0; }
.auth-tab { flex: 1; padding: 9px 5px; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); }
.auth-tab[aria-pressed="true"], .auth-tab[aria-selected="true"], .auth-tab.active { background: var(--card); color: var(--accent); box-shadow: 0 1px 5px #1819451c; font-weight: 700; }
.auth-card label { display: block; margin: 0 0 7px; font-size: .875rem; font-weight: 650; }
#password-fields, #code-fields { margin-top: 15px; }

.auth-card input {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid #b8bfce;
  border-radius: 9px;
  background: #fff;
}

.auth-card input::placeholder { color: #636a7d; }
.code-row { display: flex; gap: 8px; }
.secondary-action { flex: none; min-height: 41px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); color: var(--accent); font-weight: 650; }
.secondary-action:hover:not(:disabled) { background: var(--selected); }
.primary-action { width: 100%; min-height: 48px; margin-top: 20px; padding: 10px; border: 0; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 700; }
.primary-action:hover:not(:disabled) { background: #1e2295; }
.auth-message { margin-top: 12px; color: var(--muted); font-size: .9rem; line-height: 1.4; }
.auth-message.error, .auth-message[data-kind="error"] { color: var(--danger-ink); }
.auth-message:empty { display: none; }
.privacy-link { display: inline-block; margin-top: 16px; font-size: .875rem; font-weight: 600; }

/* Map and controls */
.app-screen {
  min-height: 410px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  column-gap: 16px;
  min-height: 62px;
  padding: 8px max(18px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.title-block, .account-controls { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title-block .eyebrow { font-size: .66rem; }
.title-block h1 { color: var(--accent); font-weight: 750; font-size: 1.26rem; letter-spacing: -.028em; }
.account-controls { flex: none; }
#account-name { display: block; color: var(--muted); font-size: .82rem; max-width: min(32vw, 290px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#account-name:empty { display: none; }

.icon-button, .account-button {
  display: inline-grid;
  place-items: center;
  flex: none;
  min-width: 36px;
  min-height: 36px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--accent);
}

.icon-button:hover:not(:disabled), .account-button:hover:not(:disabled) { background: var(--selected); }
.account-button { min-height: 34px; border-color: var(--line); background: var(--card); padding: 4px 11px; font-size: .875rem; font-weight: 650; white-space: nowrap; }
.map-layout {
  --map-edge: 12px;
  --tool-size: clamp(31px, 4.8dvh, 39px);
  position: relative;
  isolation: isolate;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--water);
}

#map { position: absolute; inset: 0; }
.map-side {
  position: absolute;
  z-index: 2;
  top: var(--map-edge);
  bottom: 24px;
  left: max(var(--map-edge), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  max-width: min(328px, calc(100% - 76px));
  pointer-events: none;
}

.map-left { display: grid; justify-items: start; gap: 8px; }
.map-left button, .range-card, .map-legend { pointer-events: auto; }
.site-filters, .boundary-controls { display: grid; justify-items: start; gap: 6px; }
.map-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 5px 12px;
  color: var(--accent);
  background: var(--floating);
  border: 1px solid #464e801f;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: .875rem;
  font-weight: 650;
  white-space: nowrap;
}

.map-chip .icon { width: 16px; height: 16px; }
.map-chip:hover:not(:disabled), .map-chip[aria-pressed="true"] { background: var(--selected); }
.map-chip[aria-pressed="true"] { border-color: #00007244; }
.map-chip.mapped[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.map-chip.proposed[aria-pressed="true"] { background: #a84805; border-color: #a84805; color: #fff; }
.map-chip.mapped[aria-pressed="true"]:hover { background: #212998; }
.map-chip.proposed[aria-pressed="true"]:hover { background: #903d04; }

.map-tools {
  position: absolute;
  z-index: 2;
  top: var(--map-edge);
  right: max(var(--map-edge), env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  max-height: calc(100% - 39px);
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  border: 1px solid #464e802b;
  border-radius: 13px;
  box-shadow: var(--shadow);
  background: var(--floating);
}

.map-layout:has(#north-reset:not([hidden])) .map-tools { max-height: calc(100% - var(--map-edge) - 83px); }
.map-tools::-webkit-scrollbar { display: none; }
.tool-button {
  position: relative;
  flex: none;
  width: 42px;
  height: var(--tool-size);
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: .83rem;
  font-weight: 750;
}

.tool-button + .tool-button::before {
  position: absolute;
  inset: 0 7px auto;
  height: 1px;
  background: var(--line);
  content: "";
}

.tool-button:hover:not(:disabled), .tool-button[aria-pressed="true"], .tool-button[aria-expanded="true"] { background: var(--selected); color: var(--accent); }
#reports-toggle[aria-pressed="true"] { background: var(--danger-wash); color: var(--danger-ink); }
.tool-button:focus-visible { outline-offset: -3px; z-index: 1; }

.map-style-menu, .map-compass {
  position: absolute;
  z-index: 3;
  border: 1px solid var(--line);
  background: var(--floating);
  box-shadow: var(--shadow);
}

.map-style-menu {
  right: max(64px, calc(env(safe-area-inset-right) + 52px));
  top: min(calc(var(--map-edge) + 5 * var(--tool-size)), max(var(--map-edge), 100% - 140px));
  display: grid;
  min-width: 134px;
  padding: 4px;
  border-radius: 12px;
}

.map-style-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  min-height: 39px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: .875rem;
  text-align: left;
}

.map-style-menu button[aria-pressed="true"], .map-style-menu button:hover { color: var(--accent); background: var(--selected); }
.map-style-menu button[aria-pressed="true"] { font-weight: 700; }
.map-compass { right: max(var(--map-edge), env(safe-area-inset-right)); bottom: 39px; border-radius: 50%; }
.map-compass .icon { transform: rotate(var(--bearing, 0deg)); }

.range-card, .map-legend {
  max-width: 100%;
  padding: 9px 11px;
  border: 1px solid #424b7b26;
  border-radius: 11px;
  box-shadow: var(--shadow);
  background: var(--floating);
}

.range-card { width: 92px; text-align: center; }
.range-heading, .range-track { display: grid; justify-items: center; gap: 2px; }
.range-heading { font-size: .78rem; font-weight: 650; white-space: nowrap; }
.range-heading output { color: var(--accent); font-variant-numeric: tabular-nums; }
.range-track { margin-top: 4px; color: var(--muted); font-size: .73rem; font-variant-numeric: tabular-nums; }
#swf-range { display: block; width: 36px; height: 113px; margin: 0; writing-mode: vertical-lr; direction: ltr; accent-color: var(--brand); cursor: pointer; }
.map-legend { min-height: 0; overflow: auto; overscroll-behavior: contain; color: var(--muted); font-size: .78rem; line-height: 1.38; }
.map-legend:has(.legend-group[hidden]):not(:has(.legend-group:not([hidden]))) { display: none; }
.legend-group h2 { margin: 0 0 4px; color: var(--ink); font-size: .82rem; font-weight: 700; }
.legend-group + .legend-group:not([hidden]) { margin-top: 7px; }
.legend-group:first-child[hidden] + .legend-group { margin-top: 0; }
.legend-group p { margin-top: 2px; }
.legend-swatches {
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: start;
  column-gap: 10px;
  row-gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend-swatches li, #reports-legend h2, #range-legend p:has(.line-swatch) { display: flex; align-items: center; gap: 5px; }
.terrain-swatches { grid-template-columns: repeat(2, auto); }
.swatch { width: 8px; height: 8px; flex: none; display: inline-block; border-radius: 50%; }
.swatch.shorter { background: var(--span-shorter); }
.swatch.medium { background: var(--span-medium); }
.swatch.longer { background: var(--span-longer); }
.swatch.unreported { background: var(--span-unknown); }
.swatch.proposed { background: var(--proposed); }
.swatch.fcc, .swatch.elevation-low { background: var(--fcc); }
.swatch.reports { background: var(--reports); }
.swatch.elevation-mid { background: #a88100; }
.line-swatch { width: 15px; border-top: 2px dashed #178e94; }
.line-swatch.permits { border-color: #8b40c4; }
.line-swatch.earlier { border-color: #626872; }

.map-status, .map-toast {
  position: absolute;
  z-index: 5;
  left: 50%;
  max-width: min(72%, 400px);
  width: max-content;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: .875rem;
  text-align: center;
  pointer-events: none;
}

.map-status { top: 38%; }
.map-toast { top: min(50%, 110px); background: #192553; color: #fff; }
.maplibregl-ctrl-bottom-right { max-width: 100%; }

/* Map totals and report access */
.map-footer {
  z-index: 3;
  display: grid;
  row-gap: 7px;
  padding: 9px max(18px, env(safe-area-inset-right)) max(9px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.footer-content { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.statistics { display: flex; align-items: center; justify-content: flex-start; gap: clamp(15px, 4vw, 51px); }
.statistics div { display: flex; flex-direction: column-reverse; gap: 1px; }
.statistics dt { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.statistics dd { display: flex; align-items: center; gap: 6px; font-size: 1.08rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.reports-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 37px;
  padding: 5px 10px;
  border: 1px solid #8c223326;
  border-radius: 9px;
  background: var(--card);
  color: var(--danger-ink);
  font-size: .875rem;
  font-weight: 700;
}

.reports-button:hover:not(:disabled) { background: var(--danger-wash); }
.report-label-short { display: none; }
.report-count { min-width: 25px; padding: 2px 5px; border-radius: 8px; background: var(--danger-wash); font-variant-numeric: tabular-nums; }
.footer-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: .75rem; }
#source-label { font-weight: 600; }
#updated-label { text-align: right; }
.map-fullscreen .topbar, .map-fullscreen .map-footer { display: none; }

/* Source, range, and report panels */
.map-dialog {
  width: min(620px, calc(100% - 24px));
  max-height: min(730px, calc(100dvh - 28px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 15px 60px #141d4a40;
}

.map-dialog[open] { display: flex; flex-direction: column; }
.map-dialog::backdrop { background: #1320337d; }
.dialog-header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 17px; border-bottom: 1px solid var(--line); }
.dialog-header h2 { color: var(--accent); font-size: 1.22rem; letter-spacing: -.012em; }
.dialog-header .icon-button { background: var(--card); border-radius: 50%; }
.dialog-header .icon-button:hover { background: var(--selected); }
.dialog-content { padding: 16px 18px 22px; min-height: 0; overflow: auto; overscroll-behavior: contain; font-size: .9375rem; line-height: 1.53; }
.dialog-content p + p, .dialog-content p + button { margin-top: 10px; }
.dialog-content h3 { margin: 16px 0 5px; font-size: 1rem; }
.dialog-content > h3:first-child { margin-top: 0; }
.dialog-intro, #reports-status { color: var(--muted); }
.source-links { display: grid; gap: 6px; padding-left: 18px; margin-bottom: 0; }
.reports-list { display: grid; gap: 8px; margin-top: 13px; }
.report-card, .report-row, .detail-section { border-radius: 10px; }
.report-card, .detail-section { padding: 12px 14px; border: 1px solid var(--line); background: var(--card); }
.report-card h3, .detail-section h3 { margin-top: 0; }
button.report-card, button.report-row, .report-row > button { width: 100%; text-align: left; font: inherit; }
button.report-row, .report-row > button { padding: 10px 12px; border: 1px solid var(--line); background: var(--card); }
button.report-card:hover, button.report-row:hover, .report-row > button:hover { background: var(--selected); }
.report-card strong, .report-row strong { color: var(--accent); }
.report-card small, .report-row small, .report-row > span { display: block; color: var(--muted); font-size: .84rem; }
#detail-content > :is(.report-card, .detail-section) + :is(.report-card, .detail-section),
#detail-content > :is(.detail-row, .detail-section) + .report-card { margin-top: 10px; }
.detail-row { padding-block: 6px; overflow-wrap: anywhere; }
.detail-row + .detail-row { border-top: 1px solid var(--line); }
.detail-row :is(dt, .detail-label) { display: block; color: var(--muted); font-size: .8125rem; font-weight: 650; }
.detail-row :is(dd, .detail-value) { display: block; margin-top: 2px; }
.detail-note { margin-top: 12px; color: var(--muted); font-size: .875rem; }
#detail-content > button.detail-action:first-child { margin: 0 0 12px; }
.detail-action {
  display: inline-flex;
  align-items: center;
  min-height: 37px;
  margin-top: 10px;
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--accent);
  font-weight: 650;
}

.detail-action:hover { background: var(--selected); }

@media (max-width: 620px) {
  .topbar { column-gap: 5px; min-height: 55px; padding-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right)); }
  .title-block { gap: 7px; }
  .title-block .brand-mark { width: 32px; height: 32px; }
  .title-block .eyebrow { font-size: .64rem; }
  .title-block h1 { font-size: clamp(1rem, 4.2vw, 1.2rem); }
  .account-controls { gap: 2px; }
  #account-name { display: none; }
  .account-controls .icon-button { min-width: 33px; }
  .account-button { padding-inline: 7px; }
  .map-layout { --map-edge: 8px; --tool-size: clamp(29px, 5dvh, 38px); }
  .map-left { gap: 8px; }
  .site-filters, .boundary-controls { gap: 5px; }
  .map-chip { padding-inline: 9px; }
  .tool-button { width: 37px; }
  .map-style-menu { right: max(52px, calc(env(safe-area-inset-right) + 44px)); }
  .map-side { bottom: 35px; max-width: min(280px, calc(100% - 62px)); }
  .range-card, .map-legend { padding: 6px 8px; }
  .map-footer { padding-inline: max(11px, env(safe-area-inset-left)) max(11px, env(safe-area-inset-right)); }
  .footer-content { align-items: flex-start; gap: 7px; }
  .reports-button { white-space: nowrap; }
  .report-label { display: none; }
  .report-label-short { display: inline; }
  .statistics { gap: clamp(6px, 2vw, 12px); }
}

@media (max-width: 370px) {
  .topbar { padding-inline: 6px; }
  .title-block { gap: 5px; }
  .title-block .brand-mark { width: 28px; height: 28px; }
  .title-block h1 { line-height: 1.1; }
  .account-controls .icon-button { min-width: 27px; }
  .account-button { padding-inline: 5px; font-size: .8rem; }
  .footer-content { flex-wrap: wrap; }
  .reports-button { max-width: none; min-height: 31px; }
}

@media (max-height: 620px) {
  .map-left { gap: 5px; }
  .site-filters, .boundary-controls { grid-auto-flow: column; gap: 4px; }
  .map-chip { min-height: 31px; padding-block: 3px; }
  .range-card { width: 224px; text-align: left; }
  .range-heading { grid-template-columns: 1fr auto; justify-items: start; }
  .range-track { grid-template-columns: auto 1fr auto; align-items: center; gap: 6px; margin-top: 0; }
  #swf-range { width: 100%; height: 24px; writing-mode: horizontal-tb; }
}

@media (max-height: 520px) and (min-width: 560px) {
  .map-tools { max-height: calc(100% - 25px); }
  .map-side { max-width: calc(100% - 70px); }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #2d2d31;
    --card: #3c3c43;
    --floating: #37373ef5;
    --ink: #f5f5fa;
    --muted: #ceceda;
    --line: #656574;
    --accent: #eef0ff;
    --selected: #4b4b62;
    --focus: #a0b7ff;
    --span-medium: #8292ff;
    --danger-ink: #ffc7ce;
    --danger-wash: #582833;
    --water: #283949;
    color: var(--ink);
    background: var(--paper);
  }

  .auth-screen { background: radial-gradient(ellipse at 15% 10%, #303a55 0, transparent 50%), var(--paper); }
  .auth-card { border-color: var(--line); }
  .auth-tabs { background: #2e2e34; }
  .auth-card input { background: #2e2e34; border-color: var(--line); }
  .auth-card input::placeholder { color: #c1c1cc; }
  .primary-action, .map-chip.mapped[aria-pressed="true"] { background: #202685; }
  #swf-range { accent-color: #a0b7ff; }
}
