:root {
  --bg: #fbf6ec; --ink: #2b2318; --muted: #7a6a52; --accent: #b5651d; --accent2: #3b2f1e;
  --line: #e2d6c2; --ok: #2e7d32; --bad: #c62828; --shadow: 0 2px 10px rgba(0,0,0,.25);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
#map { position: fixed; inset: 0; background: #ddd; }
button { font: inherit; color: inherit; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
button.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--bad); }
button.small { padding: 4px 8px; font-size: 14px; }
button.icon { width: 42px; height: 42px; padding: 0; font-size: 20px; flex: none; }
button:active { transform: scale(.96); }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; width: 100%; }
textarea { min-height: 70px; resize: vertical; }
label { display: block; margin: 8px 0 4px; color: var(--muted); font-size: 13px; }
[hidden] { display: none !important; }

#top { position: fixed; z-index: 1000; top: calc(8px + var(--safe-t)); left: 8px; right: 8px; display: flex; gap: 6px; }
#top input { box-shadow: var(--shadow); border: 0; height: 42px; }
#top button { box-shadow: var(--shadow); border: 0; }
#results { position: fixed; z-index: 1001; top: calc(56px + var(--safe-t)); left: 56px; right: 56px; background: #fff; border-radius: 10px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto; }
#results div { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
#results small { color: var(--muted); }

#fabs { position: fixed; z-index: 1000; right: 8px; top: calc(62px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; }
#fabs button { width: 46px; height: 46px; padding: 0; border-radius: 50%; border: 0; font-size: 20px; box-shadow: var(--shadow); }
#fabs button.on { background: var(--accent); color: #fff; }
#fabTrack { color: var(--bad); }
#fabTrack.on { background: var(--bad) !important; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

#status { position: fixed; z-index: 999; left: 0; bottom: 0; padding: 2px 8px calc(2px + var(--safe-b)); font-size: 12px; background: rgba(255,255,255,.8); display: flex; gap: 10px; border-top-right-radius: 8px; cursor: pointer; }
.leaflet-bottom.leaflet-right { bottom: var(--safe-b); }
.leaflet-control-attribution { font-size: 10px; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leaflet-control-scale { margin-bottom: 26px !important; }

#cross { position: fixed; z-index: 998; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; pointer-events: none;
  background: linear-gradient(var(--bad), var(--bad)) center/2px 100% no-repeat, linear-gradient(var(--bad), var(--bad)) center/100% 2px no-repeat; opacity: .85; }

/* панель совмещения */
#align { position: fixed; z-index: 1000; left: 8px; right: 66px; bottom: calc(24px + var(--safe-b)); max-width: 430px; background: rgba(255,251,243,.96); border-radius: 14px; box-shadow: var(--shadow); padding: 8px; }
#align .row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
#align .row:last-child { margin-bottom: 0; }
#align select { padding: 6px; }
#align input[type=range] { flex: 1; padding: 0; border: 0; background: none; accent-color: var(--accent); }
.lbl { font-size: 12px; color: var(--muted); white-space: nowrap; }
.pad { display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 40px); gap: 4px; }
.pad button { padding: 0; font-size: 18px; border-radius: 8px; }
.pad button[data-d="0"] { font-size: 16px; color: var(--muted); }
.pad-row { align-items: flex-start !important; }
.pad-info { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chips button { padding: 3px 7px; font-size: 13px; border-radius: 14px; }
.chips button.on { background: var(--accent2); color: #fff; border-color: var(--accent2); }
.offset { font-size: 13px; font-variant-numeric: tabular-nums; }
.pill { position: fixed; z-index: 1000; left: 8px; bottom: calc(24px + var(--safe-b)); border-radius: 20px; box-shadow: var(--shadow); border: 0; }

#swipe { position: fixed; z-index: 990; top: 0; bottom: 0; width: 4px; margin-left: -2px; background: var(--accent); cursor: ew-resize; touch-action: none; }
#swipe .knob { position: absolute; top: 50%; left: -18px; width: 40px; height: 40px; margin-top: -20px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 20px; box-shadow: var(--shadow); }

#drawbar, #recbar, #navbar { position: fixed; z-index: 1001; left: 8px; right: 66px; max-width: 460px; background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 8px; }
#drawbar { bottom: calc(24px + var(--safe-b)); }
#drawbar .row { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
#drawInfo { font-weight: 600; }
#recbar { top: calc(58px + var(--safe-t)); display: flex; align-items: center; gap: 8px; }
#recbar .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bad); animation: pulse 1.2s infinite; flex: none; }
#recInfo { flex: 1; font-size: 14px; font-variant-numeric: tabular-nums; }
#navbar { top: calc(110px + var(--safe-t)); display: flex; align-items: center; gap: 8px; }
#navInfo { flex: 1; font-weight: 600; }

/* выезжающий лист */
#sheet { position: fixed; z-index: 1100; left: 0; right: 0; bottom: 0; max-height: 82vh; background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.3); display: flex; flex-direction: column; padding-bottom: var(--safe-b); }
@media (min-width: 760px) { #sheet { left: auto; right: 12px; bottom: 12px; top: 64px; width: 420px; max-height: none; border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 16px; border-bottom: 1px solid var(--line); }
.sheet-head b { font-size: 17px; }
.sheet-head button { border: 0; background: none; }
#sheetBody { overflow: auto; padding: 8px 14px 18px; }
#sheetBody h4 { margin: 14px 0 6px; color: var(--accent2); font-size: 14px; text-transform: uppercase; letter-spacing: .04em; }
.item { display: flex; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; }
.item .s { font-size: 12.5px; color: var(--muted); }
.item input[type=checkbox], .item input[type=radio] { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.item .yr { font-size: 12px; background: var(--accent2); color: #fff; border-radius: 6px; padding: 1px 6px; white-space: nowrap; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.menu-list button { display: block; width: 100%; text-align: left; margin-bottom: 6px; padding: 12px; }
.note { font-size: 13px; color: var(--muted); background: #f3ead9; border-radius: 10px; padding: 8px 10px; margin: 8px 0; }
.warn { background: #fde7e4; color: #7c1d14; }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cats button { padding: 6px 2px; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cats button span { font-size: 22px; }
.cats button.on { border-color: var(--accent); background: #fbe3cc; }
.photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.photos img { width: 76px; height: 76px; object-fit: cover; border-radius: 8px; }
.colors { display: flex; gap: 6px; }
.colors button { width: 30px; height: 30px; border-radius: 50%; padding: 0; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.colors button.on { box-shadow: 0 0 0 2px var(--ink); }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress div { height: 100%; background: var(--accent); width: 0; }

#toast { position: fixed; z-index: 1200; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translateX(-50%); background: rgba(30,24,16,.92); color: #fff; padding: 10px 16px; border-radius: 12px; max-width: 90vw; text-align: center; }

/* карманный режим: чёрный экран (на OLED почти не тратит батарею), касания блокируются */
#pocket { position: fixed; inset: 0; z-index: 3000; background: #000; touch-action: none; user-select: none; -webkit-user-select: none; }
#pocketBox { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); text-align: center; color: #3a3a3a; font-size: 15px; transition: top 1s, left 1s; }
#pocketInfo { font-variant-numeric: tabular-nums; margin-bottom: 4px; }
#pocketGps { font-size: 13px; margin-bottom: 18px; }
#pocketUnlock { width: 64px; height: 64px; border-radius: 50%; background: #000; border: 0; padding: 0; position: relative; color: #444; }
#pocketUnlock svg { position: absolute; inset: 0; width: 64px; height: 64px; transform: rotate(-90deg); }
#pocketUnlock circle { fill: none; stroke: #222; stroke-width: 2.5; }
#pocketUnlock #pocketRing { stroke: #8a5a2a; stroke-dasharray: 119.4; stroke-dashoffset: 119.4; }
#pocketUnlock.hold #pocketRing { transition: stroke-dashoffset 2s linear; stroke-dashoffset: 0; }
#pocketUnlock span { font-size: 22px; position: relative; }
.pocket-hint { font-size: 12px; margin-top: 10px; color: #2c2c2c; }

/* маркеры */
.mk { width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: grid; place-items: center; box-shadow: 0 1px 5px rgba(0,0,0,.45); border: 2px solid #fff; }
.mk span { transform: rotate(45deg); font-size: 17px; line-height: 1; }
.mk.done { opacity: .55; }
.gps-dot { width: 18px; height: 18px; border-radius: 50%; background: #1e88e5; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.3), 0 0 10px rgba(30,136,229,.7); }
.gps-head { position: absolute; left: 1px; top: -14px; width: 0; height: 0; border-left: 8px solid transparent; border-right: 8px solid transparent; border-bottom: 14px solid #1e88e5; transform-origin: 8px 23px; }
.vtx { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.lbl-tip { background: rgba(255,255,255,.9); border: 0; box-shadow: none; font-weight: 600; padding: 1px 5px; }
.handle { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: var(--shadow); }
.handle.move { background: var(--accent2); width: 28px; height: 28px; }
.img-ov { position: absolute; left: 0; top: 0; transform-origin: 0 0; pointer-events: none; max-width: none !important; }
.leaflet-popup-content { margin: 10px 12px; }
.ctx button { display: block; width: 100%; margin: 4px 0; text-align: left; }
.sc-pin { width: 30px; height: 30px; border-radius: 50%; background: #fffdf7; border: 3px solid; display: grid; place-items: center; box-shadow: 0 1px 5px rgba(0,0,0,.4); position: relative; }
.sc-pin span { font-size: 15px; line-height: 1; }
.sc-pin i { position: absolute; top: -8px; right: -8px; font-style: normal; font-size: 13px; color: #f9a825; text-shadow: 0 0 2px #000; }
#fabScout { background: var(--accent2) !important; color: #fff; }
.gpin { width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); display: grid; place-items: center; border: 2px dashed #fff; box-shadow: 0 1px 5px rgba(0,0,0,.45); }
.gpin span { transform: rotate(45deg); color: #fff; font-weight: 700; font-size: 13px; }
