:root {
  --sand: #efe6d6;
  --paper: #fbf7f0;
  --ink: #1c1916;
  --muted: #5c564c;
  --pine: #1c3c34;
  --pine-deep: #142c26;
  --flag: #e25c2c;
  --flag-dark: #b8431c;
  --line: rgba(28, 25, 22, 0.12);
  --shadow: 0 18px 40px rgba(48, 32, 16, 0.08);
  --radius: 22px;
  color-scheme: light;
  font-family: Outfit, "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--sand);
  background-image:
    radial-gradient(ellipse at 0% 0%, rgba(226, 92, 44, 0.14), transparent 36%),
    linear-gradient(rgba(28, 25, 22, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(28, 25, 22, 0.045) 1px, transparent 1px);
  background-size: auto, 26px 26px, 26px 26px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 5;
  padding: 8px 12px;
  background: var(--paper);
  color: var(--pine);
  border-radius: 8px;
}

.skip:focus { top: 12px; }

.topbar {
  padding: calc(22px + env(safe-area-inset-top)) 20px 28px;
  background: var(--pine);
  color: #f4efe6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mark { width: 52px; height: 52px; flex: none; }

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(244, 239, 230, 0.72);
}

.eyebrow.dark { color: var(--muted); }

h1, h2 {
  font-family: Fraunces, "Iowan Old Style", Palatino, serif;
  font-weight: 560;
  letter-spacing: -0.03em;
}

h1 {
  margin: 0;
  font-size: 2.4rem;
  line-height: 0.95;
}

.lede {
  max-width: 38rem;
  margin: 16px 0 0;
  font-size: 1.02rem;
  line-height: 1.45;
  color: rgba(244, 239, 230, 0.88);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}

.about { margin: 0; }

.about summary,
.header-action {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(244, 239, 230, 0.12);
  color: #f4efe6;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.about summary::-webkit-details-marker { display: none; }

.about summary:focus-visible,
.header-action:focus-visible {
  outline: 3px solid #f4efe6;
  outline-offset: 2px;
}

.install-hint {
  max-width: 38rem;
  margin: 12px 0 0;
  color: rgba(244, 239, 230, 0.94);
  font-size: 0.95rem;
  line-height: 1.45;
}

@media (display-mode: standalone) {
  #install-button { display: none; }
}

.about-body {
  max-width: 40rem;
  margin-top: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(244, 239, 230, 0.1);
  color: rgba(244, 239, 230, 0.94);
  font-size: 0.98rem;
  line-height: 1.5;
}

.about-body p { margin: 0 0 10px; }
.about-body p:last-child { margin: 0; }

.layout {
  display: grid;
  gap: 16px;
  width: min(1120px, calc(100% - 28px));
  margin: -16px auto 0;
  padding-bottom: 12px;
}

.card {
  background: rgba(251, 247, 240, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.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;
}

.form-kicker {
  margin: 0 0 14px;
  font-size: 0.95rem;
  font-weight: 600;
}

.axis {
  margin: 0;
  padding: 0;
  border: 0;
}

.axis + .axis { margin-top: 14px; }

.axis legend {
  margin-bottom: 8px;
  padding: 0;
  font-weight: 600;
}

.axis-row {
  display: grid;
  grid-template-columns: auto minmax(0, 0.7fr) minmax(0, 0.7fr) minmax(0, 1.15fr);
  gap: 6px;
  align-items: center;
}

.hemi {
  display: grid;
  gap: 2px;
}

.hemi label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  font-weight: 600;
  font-size: 0.95rem;
}

.hemi input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--pine);
}

.part {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  min-width: 0;
  padding: 0 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.part:focus-within {
  border-color: var(--pine);
  box-shadow: 0 0 0 3px rgba(28, 60, 52, 0.16);
}

.part input {
  width: 100%;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  outline: none;
}

.part abbr {
  flex: none;
  color: var(--muted);
  text-decoration: none;
  font-size: 1rem;
}

@media (max-width: 359px) {
  .axis-row { grid-template-columns: minmax(0, 0.7fr) minmax(0, 0.7fr) minmax(0, 1.15fr); }
  .hemi { grid-column: 1 / -1; grid-auto-flow: column; justify-content: start; gap: 14px; }
}

.field label,
.mode span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
  font-weight: 600;
}

.control {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.control:focus-within {
  border-color: var(--pine);
  box-shadow: 0 0 0 3px rgba(28, 60, 52, 0.16);
}

.control input {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1.05rem;
  outline: none;
}

.control span { color: var(--muted); }

.error {
  min-height: 1.2em;
  margin: 12px 0 0;
  color: var(--flag-dark);
  font-size: 0.92rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  margin-top: 12px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.button:focus-visible,
.text-button:focus-visible,
select:focus-visible,
.history-open:focus-visible,
.history-delete:focus-visible,
.history-share:focus-visible,
.share-app:focus-visible,
.link-box:focus-visible {
  outline: 3px solid var(--flag);
  outline-offset: 2px;
}

.primary { background: var(--pine); color: #f4efe6; }
.primary:hover { background: var(--pine-deep); }

.accent { background: var(--flag); color: #fff; }
.accent:hover { background: var(--flag-dark); }

.share {
  background: transparent;
  color: var(--pine);
  border: 2px solid var(--pine);
}

.share:hover { background: rgba(28, 60, 52, 0.06); }

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.hint, .status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.preview-copy h2 {
  margin: 4px 0 0;
  font-size: 1.7rem;
  line-height: 1.15;
}

.coords-readout {
  margin: 6px 0 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.map-frame {
  position: relative;
  height: min(52vh, 420px);
  min-height: 260px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 16px;
  background: #d7dece;
}

.map, .map-empty { width: 100%; height: 100%; }

.map-empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  color: var(--pine);
}

.map-empty p { margin: 0; max-width: 16rem; }

.crosshair {
  width: 54px;
  height: 54px;
  border: 2px solid var(--pine);
  border-radius: 50%;
  position: relative;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: var(--flag);
}

.crosshair::before { left: 50%; top: 8px; width: 2px; height: 38px; transform: translateX(-50%); }
.crosshair::after { top: 50%; left: 8px; height: 2px; width: 38px; transform: translateY(-50%); }

.marker-icon { background: transparent; border: 0; }

.marker-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--flag);
  border: 3px solid #fff;
  box-shadow: 0 0 0 7px rgba(226, 92, 44, 0.28), 0 8px 16px rgba(0, 0, 0, 0.25);
}

.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(251, 247, 240, 0.88) !important;
}

.route { margin-top: 4px; }

.mode select {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font-size: 1rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-head h2 { margin: 0; font-size: 1.35rem; }

.text-button {
  border: 0;
  background: transparent;
  color: var(--flag-dark);
  font-weight: 600;
  cursor: pointer;
}

.history-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 340px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px 48px;
  gap: 8px;
  align-items: stretch;
}

.history-open {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: inherit;
  cursor: pointer;
}

.history-open strong { font-size: 0.98rem; }
.history-open span,
.history-open time { color: var(--muted); font-size: 0.82rem; }

.history-delete,
.history-share {
  width: 48px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--pine);
  font-size: 1.3rem;
  cursor: pointer;
}

.history-share svg { width: 20px; height: 20px; display: block; margin: 0 auto; }

.share-dialog {
  width: min(520px, 100%);
  max-height: min(92vh, 720px);
  margin: auto 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.share-dialog::backdrop { background: rgba(20, 28, 24, 0.5); }

.share-place {
  margin: 14px 0 0;
  font-family: Fraunces, "Iowan Old Style", Palatino, serif;
  font-size: 1.45rem;
  line-height: 1.15;
}

.link-box {
  display: block;
  margin-top: 12px;
  padding: 12px;
  overflow-wrap: anywhere;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--pine);
  font-size: 0.92rem;
}

.share-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.share-app {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

footer {
  padding: 28px 16px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

footer p { margin: 0; }

@media (min-width: 480px) {
  .coords { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 720px) {
  .share-dialog {
    margin: auto;
    border-radius: 22px;
    padding-bottom: 18px;
  }
}

@media (min-width: 960px) {
  .topbar { padding-left: max(20px, calc((100% - 1120px) / 2)); padding-right: max(20px, calc((100% - 1120px) / 2)); }

  .layout {
    grid-template-columns: minmax(320px, 400px) 1fr;
    grid-template-areas:
      "form map"
      "history map";
    align-items: start;
    margin-top: 24px;
  }

  .form-card { grid-area: form; }
  .preview { grid-area: map; position: sticky; top: 20px; }
  .history { grid-area: history; }
  .map-frame { height: min(62vh, 560px); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
