/* Mist 霞 — pastel, rounded, floating. Light by default; dark via the OS (System) or <html data-theme>. */
:root {
  --font: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  --r-lg: 28px; --r-md: 18px; --r-sm: 16px;
  color-scheme: light;
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #eef2f7; --glass: rgba(255,255,255,.92);
  --ink: #2a2e39; --ink-2: #778092; --ink-3: #b4bac6; --line: #e6eaf0; --edge: #dde2ea;
  --accent: #5b7db1; --on-accent: #ffffff; --accent-soft: #e3ebf6;
  --live: #4fa877; --recent: #e0a04a; --stale: #a9afbb; --danger: #cf7a86;
  --live-soft: #e1f2e8; --recent-soft: #fbefd9; --stale-soft: #edeff3;
  --map-bg: #eff1f4; --map-park: #dde8dc; --map-water: #c3d3e4; --map-bldg: #e2e5eb;
  --map-road: #ffffff; --map-road-case: #dde1e8; --map-major: #ffffff; --map-major-case: #d0d6e0; --map-label: #9aa2b1;
  --trail: #8c7fc4; --pin-label-bg: #ffffff; --pin-label-ink: #2a2e39;
  --av-1: #c3d3e4; --av-2: #ebcfd3; --av-3: #cfe0cb; --av-4: #d9d2ec; --av-5: #efdfc4; --av-6: #c6e3da; --av-ink: #2e3440;
  --shadow: 0 6px 20px -8px rgba(60,70,100,.35);
  --shadow-lg: 0 20px 44px -16px rgba(30,40,70,.45);
  --ctrl-invert: 0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #161823; --surface: #1f2230; --surface-2: #282c3c; --glass: rgba(31,34,48,.92);
    --ink: #e7e9f2; --ink-2: #9097aa; --ink-3: #5a6072; --line: #2d3142; --edge: #363b4e;
    --accent: #a6bee6; --on-accent: #16203a; --accent-soft: #28324a;
    --live: #7fd3a2; --recent: #f2c37c; --stale: #aeb4c4; --danger: #eba0ab;
    --live-soft: #1f3a2e; --recent-soft: #3c3222; --stale-soft: #2a2e3c;
    --map-bg: #45516e; --map-park: #4a5c6a; --map-water: #38435c; --map-bldg: #3a4462;
    --map-road: #5a6583; --map-road-case: #3e4862; --map-major: #6e7a98; --map-major-case: #3e4862; --map-label: #a3aecb;
    --trail: #b7a9f0; --pin-label-bg: #1f2230; --pin-label-ink: #e7e9f2;
    --av-1: #3a4a60; --av-2: #5a4048; --av-3: #3e5242; --av-4: #4a4366; --av-5: #5a4c36; --av-6: #36544c; --av-ink: #e7e9f2;
    --shadow: 0 8px 24px -10px rgba(0,0,0,.6);
    --shadow-lg: 0 20px 44px -16px rgba(0,0,0,.7);
    --ctrl-invert: 1;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161823; --surface: #1f2230; --surface-2: #282c3c; --glass: rgba(31,34,48,.92);
  --ink: #e7e9f2; --ink-2: #9097aa; --ink-3: #5a6072; --line: #2d3142; --edge: #363b4e;
  --accent: #a6bee6; --on-accent: #16203a; --accent-soft: #28324a;
  --live: #7fd3a2; --recent: #f2c37c; --stale: #aeb4c4; --danger: #eba0ab;
  --live-soft: #1f3a2e; --recent-soft: #3c3222; --stale-soft: #2a2e3c;
  --map-bg: #45516e; --map-park: #4a5c6a; --map-water: #38435c; --map-bldg: #3a4462;
  --map-road: #5a6583; --map-road-case: #3e4862; --map-major: #6e7a98; --map-major-case: #3e4862; --map-label: #a3aecb;
  --trail: #b7a9f0; --pin-label-bg: #1f2230; --pin-label-ink: #e7e9f2;
  --av-1: #3a4a60; --av-2: #5a4048; --av-3: #3e5242; --av-4: #4a4366; --av-5: #5a4c36; --av-6: #36544c; --av-ink: #e7e9f2;
  --shadow: 0 8px 24px -10px rgba(0,0,0,.6);
  --shadow-lg: 0 20px 44px -16px rgba(0,0,0,.7);
  --ctrl-invert: 1;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.35 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 999px; height: 42px; padding: 0 18px; background: var(--surface-2); color: var(--ink);
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
button.primary { background: var(--accent); color: var(--on-accent); font-weight: 800; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, textarea { width: 100%; min-height: 42px; padding: 10px 16px; border: 0; border-radius: 999px; background: var(--surface-2); color: var(--ink); }
textarea { border-radius: var(--r-md); resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ink-2); }
input[type="file"] { padding: 5px; }
input::file-selector-button { border: 0; border-radius: 999px; height: 32px; padding: 0 14px; margin-right: 10px; background: var(--accent-soft); color: var(--ink); font: 700 13px var(--font); cursor: pointer; }
label { display: grid; gap: 6px; font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
h2 { margin: 0; font-size: 19px; font-weight: 800; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.kj { font-family: "Shippori Mincho", serif; font-weight: 500; color: var(--accent); }
.muted { color: var(--ink-2); font-size: 13px; margin: 0; }
.error { color: var(--danger); font-size: 13px; font-weight: 700; min-height: 1em; margin: 0; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.card { background: var(--surface); border-radius: var(--r-lg); padding: 24px; display: grid; gap: 14px; }
.s-live { --st: var(--live); --st-soft: var(--live-soft); }
.s-recent { --st: var(--recent); --st-soft: var(--recent-soft); }
.s-stale { --st: var(--stale); --st-soft: var(--stale-soft); }

/* ---------- login ---------- */
.login { height: 100%; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at 50% 0, var(--accent-soft), transparent 65%), var(--bg); }
.login .card { width: min(360px, 100%); box-shadow: var(--shadow-lg); gap: 12px; }
.login .brand { font-size: 22px; }
.login .primary { height: 48px; margin-top: 4px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: 100%; }
.side { background: var(--bg); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.side-head { padding: 18px 16px 10px; display: grid; gap: 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--stale); flex: none; }
.conn.on { background: var(--live); box-shadow: 0 0 0 4px var(--live-soft); }
.add { margin-left: auto; width: 34px; height: 34px; padding: 0; background: var(--accent); color: var(--on-accent); box-shadow: 0 8px 16px -8px var(--accent); }
.add .ic { width: 18px; height: 18px; }

.search { display: flex; flex-direction: row; align-items: center; gap: 8px; height: 42px; padding: 0 16px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.search .ic { width: 18px; height: 18px; }
.search input { min-height: 0; height: 100%; padding: 0; border-radius: 0; background: none; outline: none; font-size: 14px; font-weight: 500; }
.search:focus-within { box-shadow: 0 0 0 2px var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { height: 30px; padding: 0 12px; font-size: 12.5px; background: var(--st-soft, var(--surface-2)); }
.chips button i { width: 8px; height: 8px; border-radius: 50%; background: var(--st); }
.chips button.on { background: var(--ink); color: var(--surface); }

.list { list-style: none; margin: 0; padding: 4px 16px 12px; overflow: auto; flex: 1; display: grid; align-content: start; gap: 6px; scrollbar-width: thin; scrollbar-color: var(--ink-3) transparent; }
.list li { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 8px 10px; border-radius: var(--r-md); background: var(--surface); cursor: pointer; transition: box-shadow .15s; }
.list li:hover { box-shadow: var(--shadow); }
.list li.sel { box-shadow: 0 0 0 2px var(--accent); }
.list li.inactive { opacity: .55; }
.list li.empty { justify-content: center; background: none; color: var(--ink-2); font-size: 13px; cursor: default; box-shadow: none; }
.rm { flex: 1; min-width: 0; }
.rn { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs { display: flex; align-items: center; gap: 8px; margin-top: 3px; font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; }
.rs .bat { display: inline-flex; align-items: center; gap: 3px; }
.rs .bat .ic { width: 15px; height: 15px; }
.rt { flex: none; height: 28px; padding: 0 9px; border-radius: 999px; background: var(--surface-2); display: inline-flex; align-items: center; font-size: 12px; font-weight: 700; }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 20px; padding: 0 8px; border-radius: 999px; background: var(--st-soft); color: var(--ink); font-size: 11.5px; font-weight: 700; flex: none; }
.tag i { width: 6px; height: 6px; border-radius: 50%; background: var(--st); }

.side-foot { padding: 10px 16px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.seg { flex: 1 0 100%; display: flex; gap: 2px; padding: 4px; border-radius: 999px; background: var(--surface-2); }
.seg button { flex: 1; height: 32px; padding: 0 8px; gap: 5px; background: none; color: var(--ink-2); font-size: 12.5px; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px -2px rgba(40,50,80,.3); }
.seg .ic { width: 15px; height: 15px; }
.link { height: 32px; padding: 0; background: none; color: var(--ink-2); font-size: 12.5px; }
.link .ic { width: 16px; height: 16px; }
.link:hover { color: var(--ink); }
#logout { margin-left: auto; }

/* ---------- avatars & pins ---------- */
.avatar { --sz: 42px; width: var(--sz); height: var(--sz); border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--avbg, var(--av-1)) center / cover no-repeat; color: var(--av-ink); border: 3px solid var(--st, var(--stale));
  font-weight: 800; font-size: calc(var(--sz) * .34); letter-spacing: .02em; }
.avatar.big { --sz: 52px; }

.map-wrap { position: relative; min-width: 0; overflow: hidden; container-type: inline-size; }
#map { position: absolute; inset: 0; background: var(--map-bg); font-family: var(--font); }
.pin { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.pin .label { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 4px; padding: 4px 8px; border-radius: 999px;
  background: var(--pin-label-bg); color: var(--pin-label-ink); font-size: 11px; font-weight: 700; line-height: 1; box-shadow: 0 2px 8px -2px rgba(40,50,80,.35); }
.pin .avatar { --sz: 36px; box-shadow: 0 0 0 3px var(--pin-label-bg), 0 6px 14px -4px rgba(40,50,80,.45); }
.pin .shadow { width: 12px; height: 5px; margin-top: 5px; border-radius: 50%; background: var(--st); opacity: .55; }
.pin.sel .avatar { --sz: 48px; }
.pin.poor .avatar { opacity: .6; }
#map.hide-names .pin .label { display: none; }
.maplibregl-marker:has(.pin.sel) { z-index: 1; }

/* MapLibre controls, Mist-styled */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group { margin: 0 16px 16px 0; }
.maplibregl-ctrl-group:not(:empty) { background: var(--surface); border-radius: 999px; box-shadow: var(--shadow); overflow: hidden; }
.maplibregl-ctrl-group button { width: 40px; height: 40px; border-radius: 0 !important; }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { background: var(--accent) none !important; -webkit-mask: var(--m) center / 20px no-repeat; mask: var(--m) center / 20px no-repeat; }
.maplibregl-ctrl-zoom-in { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M12 5v14M5 12h14'/%3E%3C/svg%3E"); }
.maplibregl-ctrl-zoom-out { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M5 12h14'/%3E%3C/svg%3E"); }
.maplibregl-ctrl-group button:disabled .maplibregl-ctrl-icon { opacity: .35; }
.maplibregl-ctrl.maplibregl-ctrl-attrib { background: var(--glass); color: var(--ink-2); font-size: 11px; border-radius: 10px 0 0 0; }
.maplibregl-ctrl.maplibregl-ctrl-attrib.maplibregl-compact { border-radius: 999px; margin: 0 16px 16px 0; }
.maplibregl-ctrl-attrib a { color: var(--ink-2); }
.maplibregl-ctrl-attrib-button { filter: invert(var(--ctrl-invert)); }

/* ---------- layer switcher ---------- */
.layers { position: absolute; left: 16px; bottom: 16px; z-index: 7; display: flex; align-items: flex-end; gap: 10px; }
.layers:has(> .lyr-pop:not([hidden])) { z-index: 9; } /* above the detail card only while open */
.lyr-t { position: relative; flex: none; width: 72px; height: 72px; padding: 0; border-radius: var(--r-md); overflow: hidden; background: #4a5638;
  box-shadow: 0 0 0 3px var(--surface), var(--shadow); }
.lyr-t[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5.5px var(--accent), var(--shadow); }
.lyr-thumb, .lyr-thumb svg, .lt-i svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.lyr-l { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; justify-content: center; gap: 3px; padding: 14px 2px 5px;
  font-size: 11px; font-weight: 800; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.62)); }
.lyr-l .ic { width: 12px; height: 12px; stroke-width: 2.4; }
.lyr-pop { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px 10px; background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg); }
.lyr-pop .sep { width: 1px; align-self: stretch; background: var(--line); }
.ly-row { display: grid; grid-auto-flow: column; grid-auto-columns: 54px; gap: 8px; }
.lt { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: center; align-content: start; gap: 6px; width: 100%; height: auto; padding: 0; border-radius: 0; background: none; min-width: 0; }
.lt-i { position: relative; display: block; width: 100%; aspect-ratio: 1; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 1px var(--line); }
.lt-n { font-size: 10.5px; font-weight: 700; color: var(--ink-2); white-space: nowrap; }
.lt[aria-checked="true"] .lt-i, .lt[aria-pressed="true"] .lt-i { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.lt[aria-checked="true"] .lt-n, .lt[aria-pressed="true"] .lt-n { color: var(--ink); }
.lt .ck { display: none; position: absolute; right: 4px; top: 4px; width: 17px; height: 17px; border-radius: 50%; background: var(--accent); color: var(--on-accent); place-items: center; }
.lt .ck .ic { width: 11px; height: 11px; stroke-width: 3; }
.lt[aria-pressed="true"] .ck { display: grid; }
.lt:disabled { opacity: .45; cursor: not-allowed; }
.lt:disabled .lt-i { box-shadow: 0 0 0 1.5px var(--edge); }
.lt .lock { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink); }
.lt .lock .ic { width: 18px; height: 18px; }
.lt small { margin-top: -5px; font-size: 9.5px; color: var(--ink-2); white-space: nowrap; }
.lt:focus-visible { outline: none; }
.lt:focus-visible .lt-i { outline: 2px solid var(--accent); outline-offset: 4px; }
/* thumbnail paint (map tokens) */
.m-bg { fill: var(--map-bg); } .m-park { fill: var(--map-park); } .m-bldg { fill: var(--map-bldg); }
.m-river { fill: none; stroke: var(--map-water); stroke-linecap: round; }
.m-rc { fill: none; stroke: var(--map-road-case); } .m-r { fill: none; stroke: var(--map-road); }
.m-mc { fill: none; stroke: var(--map-major-case); stroke-linecap: round; } .m-m { fill: none; stroke: var(--map-major); stroke-linecap: round; }
.m-acc { fill: var(--c); fill-opacity: .16; stroke: var(--c); stroke-opacity: .6; stroke-width: 1.2; }

@container (max-width: 679px) {
  .layers { left: 12px; bottom: 12px; }
  .lyr-t { width: 60px; height: 60px; }
  .lyr-pop { position: absolute; left: 0; bottom: calc(100% + 12px); width: calc(100cqw - 24px); flex-wrap: wrap; justify-content: center; row-gap: 14px; }
  .lyr-pop .sep { display: none; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group { margin: 0 12px 12px 0; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib { box-sizing: border-box; max-width: calc(100cqw - 96px); } /* keep clear of the Layers thumbnail */
}

/* ---------- member detail (floating card) ---------- */
.detail { position: absolute; right: 16px; top: 16px; z-index: 8; width: 336px; max-height: calc(100% - 32px); overflow: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 24px; box-shadow: var(--shadow-lg); padding: 16px; display: grid; gap: 12px; scrollbar-width: thin; }
.d-head { display: flex; align-items: center; gap: 10px; }
.d-head h2 { font-size: 17px; line-height: 1.2; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.d-sub { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--live-soft); color: var(--live); }
.call .ic { width: 19px; height: 19px; }
.x { flex: none; width: 30px; height: 30px; padding: 0; align-self: flex-start; color: var(--ink-2); }
.x .ic { width: 15px; height: 15px; }
.go { display: flex; align-items: center; justify-content: center; gap: 8px; height: 48px; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font-size: 15px; font-weight: 800; text-decoration: none; box-shadow: 0 12px 24px -12px var(--accent); }
.go .ic { width: 18px; height: 18px; }
.acts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.acts button { height: auto; flex-direction: column; gap: 4px; padding: 10px 2px 8px; border-radius: var(--r-md); font-size: 11px; }
.acts .ic { color: var(--accent); }
.acts button[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tiles div { min-width: 0; padding: 9px 14px; border-radius: var(--r-md); background: var(--av-1); display: grid; gap: 1px; }
.tiles div:nth-child(2) { background: var(--av-4); }
.tiles div:nth-child(3) { background: var(--av-3); }
.tiles div:nth-child(4) { background: var(--av-5); }
.tiles b { font-size: 16px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.tiles span { font-size: 11.5px; font-weight: 500; opacity: .72; }
.kv { margin-top: 2px; }
.kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 4px; font-size: 13px; }
.kv > div + div { border-top: 1px solid var(--line); }
.kv span:first-child { color: var(--ink-2); flex: none; }
.kv span:last-child { min-width: 0; text-align: right; overflow-wrap: anywhere; }
.del { height: 34px; background: none; color: var(--danger); font-size: 13px; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; border-radius: var(--r-lg); width: min(420px, calc(100% - 32px)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(22,24,35,.4); backdrop-filter: blur(3px); }
.pair { text-align: center; justify-items: center; }
.pair .muted { max-width: 30ch; }
.qr { padding: 10px; border-radius: 22px; background: #fff; }
.qr svg { display: block; width: 200px; height: 200px; }
.code { padding: 6px 20px 6px 28px; border-radius: 999px; background: var(--accent-soft); font-size: 34px; font-weight: 800; letter-spacing: 8px; font-variant-numeric: tabular-nums; }
.pair .primary { width: 100%; height: 46px; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: 55% 45%; }
  .side { order: 2; }
  .side-head { padding: 12px 12px 8px; gap: 10px; }
  .list { padding: 2px 12px 8px; }
  .side-foot { flex-wrap: nowrap; padding: 6px 12px 10px; gap: 12px; }
  .seg { flex: none; }
  .seg button { width: 36px; padding: 0; }
  .seg button span { display: none; }
  .detail { top: auto; left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 72%; }
}
