:root {
  --bg: #f2f4f3;
  --card: #ffffff;
  --line: #e2e6e4;
  --text: #1b2220;
  --muted: #6b7573;
  --hint: #9aa3a1;
  --green: #14805e;
  --green-soft: #e6f4ee;
  --blue: #1f6fb2;
  --blue-soft: #e7f1fa;
  --red: #c0392b;
  --red-soft: #fdeceb;
  --amber: #9a6a10;
  --amber-soft: #fdf3e2;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 32, 28, .06), 0 8px 24px rgba(20, 32, 28, .05);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }

.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 20px calc(28px + env(safe-area-inset-bottom));
}

.wrap.wide { max-width: 900px; }

/* 内容较少时垂直居中，避免大片空白 */
.wrap.center-v {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

h1 {
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -.01em;
}

h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 12px;
}

p.lead {
  margin: 0 0 26px;
  color: var(--muted);
  font-size: 15px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 14px; }

/* ---------- 输入 ---------- */

label.field {
  display: block;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

input.code {
  width: 100%;
  font-size: 34px;
  font-weight: 600;
  letter-spacing: .34em;
  text-align: center;
  padding: 16px 8px 16px 20px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fbfcfc;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color .15s;
}

input.code:focus { border-color: var(--green); background: #fff; }
input.code.blue:focus { border-color: var(--blue); }
input.code::placeholder { font-size: 19px; letter-spacing: .06em; font-weight: 500; color: var(--hint); }
input.code::-webkit-outer-spin-button,
input.code::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.hint {
  font-size: 13px;
  color: var(--hint);
  margin: 10px 0 0;
  line-height: 1.5;
}

.err {
  display: none;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 14px;
  font-weight: 500;
}

.err.show { display: block; }

/* ---------- 按钮 ---------- */

button {
  font-family: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 14px;
  font-weight: 600;
  transition: transform .1s, opacity .15s;
}

button:active { transform: scale(.985); }
button:disabled { opacity: .45; cursor: not-allowed; }

.btn-main {
  display: block;
  width: 100%;
  padding: 18px;
  font-size: 20px;
  color: #fff;
  background: var(--green);
  margin-top: 20px;
}

.btn-main.blue { background: var(--blue); }

.btn-ghost {
  display: block;
  width: 100%;
  padding: 15px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1.5px solid var(--line);
  margin-top: 12px;
}

.btn-sos {
  display: block;
  width: 100%;
  padding: 26px 18px;
  font-size: 27px;
  letter-spacing: .12em;
  color: #fff;
  background: var(--red);
  border-radius: 18px;
  margin-top: 16px;
}

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* ---------- 状态区（老人端） ---------- */

.hero {
  border-radius: 20px;
  padding: 30px 22px;
  text-align: center;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

.hero.ok { background: var(--green-soft); border-color: #bfe0d2; }
.hero.warn { background: var(--amber-soft); border-color: #eddcbb; }
.hero.bad { background: var(--red-soft); border-color: #f2cdc9; }

.pulse {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  vertical-align: middle;
  margin-right: 9px;
  position: relative;
}

.pulse::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid var(--green);
  opacity: .5;
  animation: ping 1.8s ease-out infinite;
}

@keyframes ping {
  0% { transform: scale(.6); opacity: .6; }
  100% { transform: scale(1.5); opacity: 0; }
}

.hero .big {
  font-size: 27px;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.3;
}

.hero .sub {
  font-size: 16px;
  color: var(--muted);
  margin-top: 8px;
}

.stats { display: flex; gap: 10px; margin-top: 14px; }

.stat {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 10px;
  text-align: center;
}

.stat .v {
  font-size: 21px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat .k {
  font-size: 12px;
  color: var(--hint);
  margin-top: 2px;
}

/* ---------- 地图（子女端） ---------- */

body.map-page { overflow: hidden; }

#map {
  position: fixed;
  inset: 0;
  background: #e8ece9;
  z-index: 0;
}

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 500;
  padding: calc(10px + env(safe-area-inset-top)) 12px 12px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar .who {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.topbar .name { font-size: 18px; font-weight: 600; }

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
}

.badge.off { background: #eef0ef; color: var(--hint); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }
.badge.bad { background: var(--red-soft); color: var(--red); }

.metrics {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
  flex-wrap: wrap;
}

.metrics b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.alertbar {
  position: fixed;
  z-index: 520;
  left: 12px; right: 12px;
  top: calc(96px + env(safe-area-inset-top));
  background: var(--red);
  color: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  display: none;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(192, 57, 43, .28);
}

.alertbar.show { display: flex; }
.alertbar span { flex: 1; }
.alertbar button {
  background: rgba(255, 255, 255, .22);
  color: #fff;
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 10px;
}

.dock {
  position: fixed;
  z-index: 500;
  left: 12px; right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.dock button {
  flex: 1;
  padding: 13px 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border-radius: 12px;
}

.dock button:active { background: #eef1f0; }
.dock button.primary { background: var(--blue); color: #fff; }

.sheet {
  position: fixed;
  z-index: 600;
  left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(20, 32, 28, .16);
  transform: translateY(110%);
  transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  max-width: 520px;
  margin: 0 auto;
}

.sheet.open { transform: translateY(0); }

.sheet h3 { margin: 0 0 16px; font-size: 17px; font-weight: 600; }

.sheet .line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}

.sheet .line:last-of-type { border-bottom: 0; }

input[type=range] {
  width: 100%;
  margin: 14px 0 4px;
  accent-color: var(--blue);
}

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(16, 24, 21, .34);
  z-index: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.scrim.open { opacity: 1; pointer-events: auto; }

/* 地图标记 */
.marker-dot {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--blue);
  border: 4px solid #fff;
  box-shadow: 0 2px 10px rgba(20, 60, 100, .4);
  position: relative;
}

.marker-dot::before {
  content: "";
  position: absolute;
  inset: -13px;
  border-radius: 50%;
  background: rgba(31, 111, 178, .18);
  animation: ping 2s ease-out infinite;
}

.marker-off { background: #8d9694; }
.marker-off::before { display: none; }

.leaflet-container { font-family: inherit; }
.leaflet-control-attribution { font-size: 10px !important; opacity: .55; }
/* 底部按钮栏会压住 Leaflet 版权行，上移让位 */
.leaflet-bottom { bottom: calc(78px + env(safe-area-inset-bottom)); }
.leaflet-control-attribution { margin-bottom: 0 !important; }

/* ---------- 首页 ---------- */

.pick {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 22px 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  margin-bottom: 14px;
}

.pick .ico {
  width: 54px; height: 54px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 600;
  flex-shrink: 0;
}

.pick.e .ico { background: var(--green-soft); color: var(--green); }
.pick.g .ico { background: var(--blue-soft); color: var(--blue); }
.pick .t { font-size: 18px; font-weight: 600; }
.pick .d { font-size: 13px; color: var(--muted); line-height: 1.45; margin-top: 2px; }
.pick .arrow { color: var(--hint); font-size: 20px; }

.foot {
  margin-top: 26px;
  font-size: 12px;
  color: var(--hint);
  line-height: 1.7;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --card: #1c2225;
    --line: #2c3437;
    --text: #eef2f0;
    --muted: #9aa5a2;
    --hint: #77817f;
    --green-soft: #17332a;
    --blue-soft: #16293a;
    --red-soft: #331d1b;
    --amber-soft: #2f2517;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
  input.code { background: #171d1f; }
  input.code:focus { background: #1c2326; }
  .topbar, .dock { background: rgba(28, 34, 37, .92); }
  .badge.off { background: #262d30; }
  .leaflet-tile { filter: brightness(.82) contrast(1.06) saturate(.9); }
}
