:root {
  --bg: #0e1116; --card: #171b22; --card2: #1f2530; --line: #2a313d;
  --text: #eef1f5; --muted: #8e98a8; --red: #ff3b4e; --blue: #3d8bff; --green: #2fd36b;
  --yellow: #ffcc33; --orange: #ff9533; --purple: #b061ff;
  --safe-b: env(safe-area-inset-bottom); --safe-t: env(safe-area-inset-top);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1 { font-size: 20px; margin: 0; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 0 8px;
  display: flex; justify-content: space-between; align-items: center; }

/* ---- views & tabs ---- */
.view { display: none; position: fixed; inset: 0 0 calc(58px + var(--safe-b)) 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view.active { display: block; }
#view-record { overflow: hidden; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(58px + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: rgba(14,17,22,.96); border-top: 1px solid var(--line); z-index: 1000; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); font-size: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.tabs button span { font-size: 11px; }
.tabs button.active { color: var(--text); }
.tabs button.active:first-child { color: var(--red); }
.bar { position: sticky; top: 0; z-index: 500; display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px; background: rgba(14,17,22,.95); border-bottom: 1px solid var(--line); }
.bar > :first-child, .bar > :last-child { min-width: 84px; }
.pad { padding: 12px 14px 40px; }

/* ---- maps ---- */
.map { position: absolute; inset: 0; background: #1b2028; }
.map.detail { position: relative; height: 42vh; }
.leaflet-container { background: #1b2028; }
.leaflet-control-attribution { font-size: 9px; }
.note-pin { font-size: 22px; line-height: 1; filter: drop-shadow(0 1px 2px #000); }
.pos-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(61,139,255,.25); }

/* ---- chips ---- */
.chips.top { position: absolute; top: calc(10px + var(--safe-t)); left: 10px; right: 10px; z-index: 600; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--card2); border: 0; color: #000; }
.chip.green { background: var(--green); } .chip.yellow { background: var(--yellow); } .chip.orange { background: var(--orange); }
.chip.gray { background: #59616d; color: #fff; } .chip.ghost { background: rgba(23,27,34,.9); color: var(--text); margin-left: auto; }
.chip.blue { background: var(--blue); color: #fff; }

/* ---- bottom panel ---- */
.panel { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 600; background: rgba(23,27,34,.96);
  border: 1px solid var(--line); border-radius: 22px; padding: 14px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.modes { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.modes::-webkit-scrollbar { display: none; }
.mode { flex: none; padding: 8px 12px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); font-size: 14px; }
.mode.sel { background: var(--blue); border-color: var(--blue); color: #fff; }
.rec-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 12px; }
.rec-name { font-weight: 600; font-size: 14px; color: var(--muted); max-width: 52vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.right { text-align: right; } .dist { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.controls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.ctl { background: var(--card2); border: 1px solid var(--line); border-radius: 14px; padding: 8px 0 6px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ctl span { font-size: 20px; } .ctl.red { background: rgba(255,59,78,.15); border-color: var(--red); color: var(--red); }
#rec-notes { margin-top: 8px; text-align: center; }

/* ---- buttons & forms ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 12px;
  background: var(--card2); border: 1px solid var(--line); font-weight: 600; cursor: pointer; }
.btn.big { width: 100%; padding: 15px; font-size: 18px; border-radius: 16px; }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.red { background: var(--red); border-color: var(--red); color: #fff; }
.btn.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.red-text { color: var(--red); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.actions.end { justify-content: flex-end; margin-top: 16px; }
.actions.end .red-text { margin-right: auto; }
input:not([type=checkbox]):not([type=range]), select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }
textarea { resize: vertical; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--blue); flex: none; }
input[type=range] { width: 100%; accent-color: var(--blue); }
label.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
label.row select, label.row input[type=number] { width: 45%; }
label.col { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13px; color: var(--muted); }
label.col > * { color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; margin: 12px 0; padding: 4px 12px 8px; }
legend { color: var(--muted); font-size: 13px; padding: 0 6px; }

/* ---- dialogs ---- */
dialog { width: min(560px, 100vw); max-height: 92vh; margin: auto auto 0; border: 0; border-radius: 22px 22px 0 0;
  background: var(--card); color: var(--text); padding: 18px 16px calc(18px + var(--safe-b)); overflow-y: auto; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-top: 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 20px; }
.listen { display: flex; align-items: center; gap: 8px; color: var(--red); font-weight: 600; margin-bottom: 8px; }
.listen .dot, .pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--red); animation: pulse 1.2s ease-in-out infinite; }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.list .ico { font-size: 24px; width: 34px; text-align: center; }
.list .main { flex: 1; min-width: 0; }
.list .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .s { font-size: 13px; color: var(--muted); }
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.tile { background: var(--card); border-radius: 12px; padding: 8px 10px; }
.tile .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile .v { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.card { background: var(--card); border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
table.legs { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.legs td, table.legs th { padding: 5px 4px; text-align: right; } table.legs td:first-child, table.legs th:first-child { text-align: left; color: var(--muted); }
.note-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.note-item:last-child { border: 0; }
.note-item .t { font-weight: 600; }
.note-item img { max-width: 100%; border-radius: 10px; margin-top: 6px; }
.note-item audio { width: 100%; margin-top: 6px; }
.tags { color: var(--blue); font-size: 13px; }
.empty { text-align: center; color: var(--muted); margin-top: 40px; }
svg.profile { width: 100%; height: 140px; display: block; }

/* ---- minimal screen ---- */
#minimal { position: fixed; inset: 0; z-index: 3000; background: #000; color: rgba(255,255,255,.82);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; user-select: none; -webkit-user-select: none; }
#minimal .pulse { width: 18px; height: 18px; }
#minimal.paused .pulse { background: var(--yellow); animation: none; }
.m-state { font-size: 12px; letter-spacing: .3em; font-weight: 700; opacity: .6; }
.m-time { font-size: 64px; font-weight: 200; font-variant-numeric: tabular-nums; }
.m-dist { font-size: 26px; font-variant-numeric: tabular-nums; }
.m-gps { font-size: 12px; opacity: .5; }
.m-hint { position: absolute; bottom: calc(30px + var(--safe-b)); font-size: 12px; opacity: .3; }

/* ---- banners & toast ---- */
#banners { position: fixed; top: calc(48px + var(--safe-t)); left: 10px; right: 10px; z-index: 900; display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.banner { pointer-events: auto; padding: 10px 12px; border-radius: 12px; font-size: 13px; background: var(--yellow); color: #111; display: flex; gap: 8px; align-items: flex-start; }
.banner.info { background: var(--blue); color: #fff; } .banner.ok { background: var(--green); color: #062; }
.banner button { margin-left: auto; background: none; border: 0; font-weight: 700; color: inherit; }
#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 4000;
  background: #fff; color: #111; padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 90vw; text-align: center; }

@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .25; transform: scale(.8); } }

/* ---- collect ---- */
.toolbar { position: absolute; right: 10px; top: calc(52px + var(--safe-t)); z-index: 600; display: flex; flex-direction: column; gap: 6px; }
.toolbar button { width: 64px; padding: 6px 0; border-radius: 14px; border: 1px solid var(--line); background: rgba(23,27,34,.94); font-size: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; }
.toolbar button span { font-size: 20px; line-height: 1.1; }
.draw-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.controls.c6 { grid-template-columns: repeat(4, 1fr); margin-top: 10px; }
.ctl.blue { background: var(--blue); border-color: var(--blue); color: #fff; }
.ctl.on { background: rgba(255,59,78,.2); border-color: var(--red); color: var(--red); }
.ctl:disabled { opacity: .7; }
.vtx { width: 16px; height: 16px; border-radius: 50%; background: #ffcc33; border: 2px solid #111; box-shadow: 0 0 0 2px #ffcc33; }
.vtx.first { background: #2fd36b; box-shadow: 0 0 0 2px #2fd36b; }
.attr-row { display: grid; grid-template-columns: 1fr 1.4fr 36px; gap: 6px; margin-bottom: 6px; }
.attr-row button { background: none; border: 0; color: var(--muted); font-size: 18px; }
.fpop b { font-size: 15px; } .fpop .small { font-size: 12px; }
.pop-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.pop-actions button { border: 1px solid #ccd; background: #f4f6fa; border-radius: 8px; padding: 5px 8px; font-size: 12px; color: #111; }
.leaflet-popup-content { color: #111; }
.swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: none; }
.layer-feats { list-style: none; padding: 0 0 0 26px; margin: 0; }
.layer-feats li { padding: 8px 4px; font-size: 14px; }
.eye { background: none; border: 0; font-size: 18px; padding: 4px 8px; color: var(--muted); }

/* ---- basemap picker ---- */
.bm-btn { margin-left: auto; }
#follow-btn:not(.hidden) + .bm-btn { margin-left: 0; }
.detail-wrap { position: relative; }
.bm-detail { position: absolute; top: 10px; right: 10px; z-index: 500; }
#basemap-list { display: flex; flex-direction: column; gap: 8px; }
.bm { display: flex; gap: 12px; align-items: center; text-align: left; padding: 10px 12px; border-radius: 14px; background: var(--card2); border: 1px solid var(--line); }
.bm.sel { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue) inset; }
.bm-ico { font-size: 26px; width: 34px; text-align: center; }
.leaflet-container .maplibregl-canvas { outline: none; }

/* banners must never cover the Collect toolbar */
body:has(#view-collect.active) #banners { right: 84px; }
