:root {
  --green: #2f5d3a;
  --green-2: #3f7a4c;
  --green-soft: #e6efe4;
  --earth: #8a5a2b;
  --sand: #f6f2ea;
  --ink: #1d2420;
  --muted: #66706a;
  --line: #d9dcd4;
  --card: #ffffff;
  --ok: #2e8b3d;
  --warn: #c98a00;
  --bad: #c4372c;
  --shape: #ffcc33;
  --radius: 14px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--sand);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button, select, input { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  background: var(--green); color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand img { border-radius: 7px; background: #fff2; }
.net { font-size: 13px; background: #fff3; padding: 2px 10px; border-radius: 99px; }

main { flex: 1; position: relative; min-height: 0; }
.view { position: absolute; inset: 0; }
.view[hidden] { display: none; }
.scroll-view { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; max-width: 640px; margin: 0 auto; padding-bottom: 32px; }
h2 { margin: 4px 0 12px; font-size: 22px; }

/* --- Harita ekranları --- */
.map-view { display: flex; flex-direction: column; }
.map { flex: 1; min-height: 160px; background: #cfd8cc; }
.map-view .map .leaflet-bottom { bottom: 14px; }
.leaflet-container { font: inherit; }

.sheet {
  background: var(--card);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 18px #0002;
  padding: 12px 16px 14px;
  margin-top: -14px;
  position: relative; z-index: 500;
  max-height: 58%;
  overflow-y: auto;
}
.intro { font-size: 15px; color: var(--muted); margin-bottom: 10px; }
.intro strong { color: var(--ink); display: block; font-size: 16px; margin-bottom: 2px; }
.intro b { color: var(--ink); }

.gps-status {
  position: absolute; top: 10px; left: 10px; z-index: 500;
  display: flex; align-items: center; gap: 8px;
  background: #fff; padding: 6px 12px; border-radius: 99px;
  box-shadow: 0 2px 10px #0003; font-size: 14px; font-weight: 600;
}
.gps-status .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.gps-status.ok .dot { background: var(--ok); }
.gps-status.warn .dot { background: var(--warn); }
.gps-status.bad .dot { background: var(--bad); }

.map-tools {
  position: absolute; top: 10px; right: 10px; z-index: 500;
  display: flex; flex-direction: column; gap: 8px;
}
.fab {
  width: 46px; height: 46px; border-radius: 50%; border: 0;
  background: #fff; box-shadow: 0 2px 10px #0003; display: grid; place-items: center;
  cursor: pointer;
}
.fab svg { width: 24px; height: 24px; stroke: var(--green); stroke-width: 2; fill: var(--green); stroke-linecap: round; stroke-linejoin: round; }
.fab:active { transform: scale(.94); }

/* --- Düğmeler --- */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: 8px; }
.row.end { justify-content: flex-end; }
.row.options { justify-content: space-between; font-size: 14px; color: var(--muted); }
.row.options select { margin-left: 4px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  min-height: 48px;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.big { flex: 1; font-size: 18px; }
.btn.wide { width: 100%; margin: 4px 0 12px; border-style: dashed; color: var(--green); }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.link { border: 0; background: none; color: var(--green); text-decoration: underline; cursor: pointer; padding: 4px; }
.row .btn:not(.big) { flex: 0 0 auto; }

/* --- Köşe toplama --- */
.collect { display: flex; align-items: center; gap: 12px; background: var(--green-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.collect[hidden] { display: none; }
.collect-txt { flex: 1; display: flex; flex-direction: column; font-size: 14px; color: var(--muted); }
.collect-txt strong { color: var(--ink); font-size: 15px; }
.ring { position: relative; width: 48px; height: 48px; flex: 0 0 auto; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring .bg { stroke: #fff; }
.ring .fg { stroke: var(--green); stroke-linecap: round; stroke-dasharray: 119.4; stroke-dashoffset: 119.4; transition: stroke-dashoffset .3s linear; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; }

/* --- Sonuç kartı --- */
.result { margin-bottom: 10px; }
.result[hidden] { display: none; }
.result .big-area { font-size: 32px; font-weight: 800; letter-spacing: -.5px; line-height: 1.1; }
.pm { font-size: 18px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.result .sub { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 14px; margin-top: 4px; }
.result .sub b { color: var(--ink); font-weight: 600; }
.result .range { font-size: 14px; color: var(--muted); margin-top: 2px; }
.note { font-size: 14px; border-radius: 10px; padding: 8px 10px; margin-top: 8px; }
.note.warn { background: #fff4d6; color: #6b4a00; }
.note.bad { background: #fde3e0; color: #7a1f17; }
.note.ok { background: var(--green-soft); color: var(--green); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair > div { background: var(--sand); border-radius: 12px; padding: 10px 12px; }
.pair .lbl { font-size: 13px; color: var(--muted); }
.pair .val { font-size: 24px; font-weight: 800; }
.pair .hint { font-size: 12px; color: var(--muted); }

/* --- Kartlar / şerit --- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 3px #0001; margin-bottom: 12px; }
.help summary { cursor: pointer; list-style: none; display: flex; flex-direction: column; }
.help summary::-webkit-details-marker { display: none; }
.help summary::after { content: "Göster ▾"; color: var(--green); font-size: 14px; margin-top: 4px; }
.help details[open] summary::after { content: "Gizle ▴"; }
.help ol { padding-left: 20px; margin: 8px 0; }
.help li { margin-bottom: 6px; }
.help-fig { width: 100%; max-width: 280px; display: block; margin: 10px auto 0; }
.fig-shape { fill: var(--green-soft); stroke: var(--green); stroke-width: 2.5; }
.fig-diag { stroke: var(--earth); stroke-width: 2; stroke-dasharray: 6 4; }
.help-fig text { font-size: 16px; font-weight: 700; fill: var(--earth); }
.muted { color: var(--muted); font-size: 14px; }

.tri-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.tri-head h3 { margin: 0; font-size: 17px; }
.tri-body { display: flex; gap: 12px; }
.tri-fig { width: 76px; flex: 0 0 auto; align-self: center; }
.tri-fig polygon { fill: var(--green-soft); stroke: var(--green); stroke-width: 2; }
.tri-fig text { font-size: 13px; font-weight: 700; fill: var(--earth); }
.sides { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.side { display: grid; grid-template-columns: 22px 1fr 92px; gap: 6px; align-items: center; }
.side .tag { font-weight: 700; color: var(--earth); }
.field { position: relative; }
.field input {
  width: 100%; padding: 10px 30px 10px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; min-height: 44px; font-size: 17px;
}
.field input:focus { outline: 2px solid var(--green-2); border-color: transparent; }
.field .unit { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.slope { display: flex; gap: 4px; }
.slope .field input { padding-right: 18px; font-size: 15px; }
.slope .field .unit { right: 6px; }
.slope-btn { width: 40px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 18px; cursor: pointer; }
.tri-foot { margin-top: 8px; font-size: 14px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.tri-foot b { color: var(--ink); }
.tri-foot.err { color: var(--bad); }
.col-head { display: grid; grid-template-columns: 22px 1fr 92px; gap: 6px; font-size: 12px; color: var(--muted); }

/* --- Eğim ölçer --- */
.level { text-align: center; }
.level .deg { font-size: 56px; font-weight: 800; line-height: 1; margin: 10px 0 4px; }
.level .bubble-wrap { position: relative; height: 34px; background: var(--green-soft); border-radius: 99px; margin: 14px 0; overflow: hidden; }
.level .bubble { position: absolute; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: var(--green); left: calc(50% - 13px); transition: left .1s; }
.level .center { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: #0002; }
.level p { margin: 6px 0; color: var(--muted); font-size: 14px; }

/* --- Kayıtlar --- */
.rec { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.rec-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--green-soft); display: grid; place-items: center; flex: 0 0 auto; font-size: 22px; }
.rec-main { flex: 1; min-width: 0; }
.rec-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-meta { color: var(--muted); font-size: 13px; }
.rec-area { font-weight: 800; text-align: right; white-space: nowrap; }
.rec-area small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty .em { font-size: 44px; }
.detail-map { height: 220px; border-radius: 12px; margin: 10px 0; }

/* --- Sekmeler --- */
.tabs {
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line); z-index: 600;
}
.tabs button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 1.8; fill: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.tabs [aria-selected="true"] { color: var(--green); }

/* --- Dialog & toast --- */
dialog { border: 0; border-radius: 18px; padding: 18px; width: min(420px, calc(100vw - 32px)); box-shadow: 0 10px 40px #0004; }
dialog::backdrop { background: #0006; }
dialog h3 { margin: 0 0 10px; }
dialog input[type=text] { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 17px; margin: 4px 0 14px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 16px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 2000;
  max-width: calc(100vw - 32px); font-size: 15px; box-shadow: 0 4px 16px #0004;
}

/* Harita işaretleri */
.corner-pin {
  width: 26px; height: 26px; border-radius: 50%; background: var(--green); color: #fff;
  border: 3px solid #fff; display: grid; place-items: center; font: 700 12px system-ui; box-shadow: 0 1px 6px #0006;
}
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 2px #1a73e855, 0 1px 4px #0006; }
.edge-label { background: #fffd; border: 0; border-radius: 6px; padding: 1px 5px; font: 600 12px system-ui; color: var(--ink); box-shadow: 0 1px 3px #0003; white-space: nowrap; }
.edge-label::before { display: none; }

@media (min-width: 900px) {
  .map-view { flex-direction: row; }
  .sheet { width: 380px; max-height: none; margin: 0; border-radius: 0; box-shadow: -4px 0 18px #0002; }
}

/* --- GPS ölçüm türü seçici --- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--sand); border-radius: 12px; padding: 3px; margin-bottom: 10px; }
.seg button { border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; min-height: 38px; }
.seg button[aria-selected="true"] { background: #fff; color: var(--green); box-shadow: 0 1px 3px #0002; }
.seg button:disabled { opacity: .5; cursor: default; }
.mode[hidden] { display: none; }

/* --- Canlı yürüyüş paneli --- */
.live { background: var(--green-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.live[hidden] { display: none; }
.live-main { font-size: 30px; font-weight: 800; line-height: 1.1; }
.live-main small { font-size: 15px; font-weight: 600; color: var(--muted); }
.live-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.live-sub b { color: var(--ink); }
.live.paused { background: #fff4d6; }
.start-pin { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 4px solid var(--green); box-shadow: 0 1px 6px #0006; }
