:root {
  color-scheme: dark;
  --bg: #0d1f16;
  --panel: #10261b;
  --line: #24442f;
  --text: #f1f5ef;
  --muted: #a9b9ad;
  --lime: #d4ff3a;
  --lime-ink: #10220a;
  --warn: #ffcf5c;
  --btn: #1b3a28;
  --btn-press: #25503a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; -webkit-tap-highlight-color: transparent; overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--lime); outline-offset: 2px; }

.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.mapWrap { position: relative; flex: 1 1 auto; min-height: 200px; background: #1d2b22; }
.map { position: absolute; inset: 0; }
.mapMsg { position: absolute; left: 16px; right: 16px; top: 50%; transform: translateY(-50%); text-align: center; color: var(--muted); font-size: 15px; line-height: 1.45; pointer-events: none; }

.top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
.top > * { pointer-events: auto; }
.search { flex: 1; min-width: 0; }
.search input { width: 100%; height: 44px; border-radius: 22px; border: 1px solid rgba(255,255,255,0.18); background: rgba(13,31,22,0.92); padding: 0 16px; color: var(--text); }
.search input::placeholder { color: #c1cdc4; }
.round { width: 44px; height: 44px; flex: none; border-radius: 22px; border: 1px solid rgba(255,255,255,0.18); background: rgba(13,31,22,0.92); color: var(--text); display: grid; place-items: center; font-weight: 700; padding: 0; }
#infoBtn { font-family: Georgia, serif; font-style: italic; font-size: 20px; }
.mapTools { position: absolute; right: 10px; bottom: 12px; display: flex; flex-direction: column; gap: 8px; }
#typeBtn { width: auto; min-width: 44px; padding: 0 12px; font-size: 14px; font-weight: 600; }

.panel { flex: none; max-height: 56%; overflow-y: auto; background: var(--panel); border-top: 1px solid var(--line); padding: 12px 16px max(12px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }

.title { margin: 0; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.title img { border-radius: 7px; }
.seg { display: flex; background: #0a1a12; border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 600; padding: 0 8px; }
.seg button[aria-pressed="true"] { background: var(--btn-press); color: var(--text); }
.seg.small button { min-height: 36px; font-size: 14px; }

.result { text-align: center; }
.big { border: 0; background: none; padding: 0; color: var(--text); font-size: 44px; font-weight: 750; letter-spacing: -0.5px; line-height: 1.1; font-variant-numeric: tabular-nums; min-height: 48px; }
.bigUnit { font-size: 22px; font-weight: 600; color: var(--lime); letter-spacing: 0; }
.others { color: var(--muted); font-size: 15px; margin-top: 4px; line-height: 1.4; }
.perim { color: var(--muted); font-size: 15px; margin-top: 2px; line-height: 1.3; min-height: 1.3em; } /* reserved: the map must not jump when the 2nd corner adds this line */
.warn { color: var(--warn); font-size: 14px; margin-top: 6px; }
.gps { color: var(--muted); font-size: 14px; margin-top: 6px; }
.gps.bad { color: var(--warn); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { flex: 1 1 0; min-width: 64px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--btn); color: var(--text); font-weight: 600; padding: 0 6px; }
.actions button:disabled { opacity: 0.45; cursor: default; }
.actions .primary, .primary { flex-basis: 100%; background: var(--lime); color: var(--lime-ink); border-color: var(--lime); min-height: 48px; font-weight: 700; border-radius: 12px; }
.actions .primary.stop { background: #ffffff; border-color: #ffffff; color: #10220a; }

.gravel { border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; }
.gravel summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; list-style: none; }
.gravel summary::-webkit-details-marker { display: none; }
.gravel summary::after { content: "+"; margin-left: auto; font-size: 22px; color: var(--muted); }
.gravel[open] summary::after { content: "–"; }
.gravelRow { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.gravelRow label { width: 64px; color: var(--muted); }
.gravelRow input { width: 84px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #0a1a12; padding: 0 10px; text-align: right; }
.gravelRow span { color: var(--muted); font-size: 15px; }
.gravelOut { font-size: 20px; font-weight: 700; margin: 10px 0 4px; }
.note { color: var(--muted); font-size: 13px; margin: 4px 0 12px; line-height: 1.4; }

.darby { display: block; text-align: center; color: var(--lime); font-weight: 600; text-decoration: none; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.fine { color: #8fa294; font-size: 12px; text-align: center; margin: 0; }

dialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 40px); border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,0.6); }
dialog h2 { margin: 0 0 8px; font-size: 22px; }
dialog p { color: #d3ddd5; line-height: 1.5; margin: 8px 0; }
dialog .small { font-size: 14px; color: var(--muted); }
dialog a { color: var(--lime); }
dialog .primary { width: 100%; margin-top: 12px; border: 0; }
.unitsRow { display: flex; align-items: center; gap: 12px; margin: 14px 0; }
.unitsRow > span { color: var(--muted); }
.unitsRow .seg { flex: 1; }
.links { text-align: center; }
.savedList { list-style: none; padding: 0; margin: 8px 0; max-height: 50vh; overflow-y: auto; }
.savedList li { display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding: 8px 0; }
.savedList .open { flex: 1; text-align: left; min-height: 44px; border: 0; background: none; color: var(--text); font-weight: 600; padding: 0; }
.savedList .del { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--btn); color: var(--muted); padding: 0 12px; }
.savedList .empty { color: var(--muted); border: 0; }

/* map pieces (corners, you-are-here) */
.corner { width: 22px; height: 22px; border-radius: 50%; background: var(--lime); border: 3px solid #10220a; box-shadow: 0 0 0 2px rgba(255,255,255,0.7); cursor: grab; }
.corner.first { background: #ffffff; }
.corner.small { width: 10px; height: 10px; border-width: 2px; box-shadow: none; cursor: default; }
.me { width: 18px; height: 18px; border-radius: 50%; background: #3d8bff; border: 3px solid #fff; box-shadow: 0 0 6px rgba(0,0,0,0.5); }

@media (min-width: 900px) {
  .app { flex-direction: row-reverse; }
  .panel { width: 380px; max-height: none; height: 100%; border-top: 0; border-right: 1px solid var(--line); padding-top: max(16px, env(safe-area-inset-top)); }
  .mapWrap { height: 100%; }
}
@media (max-width: 899px) {
  .title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media (max-height: 640px) and (max-width: 899px) {
  .big { font-size: 36px; }
  .panel { max-height: 60%; gap: 8px; }
}
