:root {
  --ink: #3b3024;
  --ink2: #7a6a58;
  --paper: #fdf3e1;
  --card: #fffaf0;
  --line: 2.5px solid var(--ink);
  --shadow: 0 4px 0 var(--ink);
  --accent: #e76f51;
  --green: #5b8e7d;
  --blue: #4d96c9;
  --r: 18px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--paper); color: var(--ink); font-family: var(--font); }
body { font-size: 18px; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
.hidden { display: none !important; }

/* ---------- 通用部件 ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 22px; border: var(--line); border-radius: 999px;
  background: var(--card); box-shadow: var(--shadow); font-size: 19px; font-weight: 700;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.small { min-height: 40px; padding: 6px 14px; font-size: 16px; box-shadow: 0 3px 0 var(--ink); }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn svg { width: 22px; height: 22px; flex: none; }
.link { background: none; border: 0; color: var(--ink2); text-decoration: underline; font-size: 16px; padding: 8px; }

.field { display: block; margin: 14px 0; }
.field > span { display: block; font-size: 16px; color: var(--ink2); margin-bottom: 6px; }
.input {
  width: 100%; min-height: 52px; padding: 10px 16px; border: var(--line); border-radius: 14px;
  background: #fff; font-size: 19px; outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 80px; resize: vertical; }
.code-input { font-size: 40px; letter-spacing: 18px; text-align: center; font-weight: 800; padding-left: 34px; }

.pills { display: flex; gap: 10px; flex-wrap: wrap; }
.pill {
  min-height: 46px; padding: 8px 18px; border: var(--line); border-radius: 999px; background: #fff;
  font-size: 18px; font-weight: 700;
}
.pill.on { background: var(--ink); color: #fff; }

.err { color: #c0392b; font-size: 16px; min-height: 22px; margin: 6px 0; }
.muted { color: var(--ink2); }

#toast {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translate(-50%, -140%);
  z-index: 3000; background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 999px;
  font-size: 18px; font-weight: 700; transition: transform .3s; max-width: 92vw; text-align: center; pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); }

/* ---------- 欢迎页 ---------- */

.welcome { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 28px 18px 60px; }
.welcome-card {
  width: 100%; max-width: 440px; background: var(--card); border: var(--line); border-radius: 28px;
  box-shadow: 0 6px 0 var(--ink); padding: 28px 24px;
}
.welcome h1 { margin: 6px 0 4px; font-size: 34px; text-align: center; }
.welcome .sub { text-align: center; color: var(--ink2); margin: 0 0 24px; line-height: 1.6; }
.welcome .stack { display: grid; gap: 16px; }
.welcome .logo { width: 84px; height: 84px; margin: 0 auto; }
.welcome h2 { font-size: 24px; margin: 0 0 8px; }
.welcome p { line-height: 1.7; }
.wait-dots span { display: inline-block; width: 12px; height: 12px; margin: 0 4px; border-radius: 50%; background: var(--accent); animation: bounce 1.2s infinite; }
.wait-dots span:nth-child(2) { animation-delay: .2s; }
.wait-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }

/* ---------- 主界面 ---------- */

.app { position: fixed; inset: 0; display: grid; grid-template-columns: 360px 1fr; }
.side {
  position: relative; display: flex; flex-direction: column; min-height: 0; background: var(--paper);
  border-right: var(--line); z-index: 500;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 10px; }
.side-head h1 { flex: 1; margin: 0; font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  flex: none; width: 46px; height: 46px; border: var(--line); border-radius: 50%; background: var(--card);
  box-shadow: 0 3px 0 var(--ink); display: grid; place-items: center; padding: 0; position: relative;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn .badge {
  position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 800; display: grid; place-items: center; border: 2px solid var(--ink);
}
.side-body { flex: 1; overflow-y: auto; padding: 4px 14px 48px; -webkit-overflow-scrolling: touch; }

.heart-banner {
  margin: 0 14px 10px; padding: 12px 14px; border: var(--line); border-radius: 16px; background: #ffe3dc;
  display: flex; gap: 10px; align-items: center; font-size: 17px; line-height: 1.5;
}
.heart-banner svg { width: 30px; height: 30px; flex: none; }
.heart-banner .x { margin-left: auto; flex: none; }

.person {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left; padding: 12px 14px; margin: 0 0 12px;
  border: var(--line); border-radius: var(--r); background: var(--card); box-shadow: var(--shadow); position: relative;
}
.person:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.person .info { flex: 1; min-width: 0; }
.person .nm { font-size: 22px; font-weight: 800; line-height: 1.2; }
.person .nick { font-size: 16px; color: var(--ink2); font-weight: 600; margin-left: 6px; }
.person .where { font-size: 16px; color: var(--ink2); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person .temp { flex: none; text-align: center; font-size: 20px; font-weight: 800; }
.person .temp svg { width: 34px; height: 34px; display: block; margin: 0 auto -2px; }
.person .dot { position: absolute; top: -7px; right: -7px; background: var(--accent); color: #fff; font-size: 13px; font-weight: 800; padding: 2px 9px; border-radius: 999px; border: 2px solid var(--ink); }
.person.me { background: #eaf3ee; }
.section-title { font-size: 15px; color: var(--ink2); margin: 16px 4px 10px; font-weight: 700; }

.avatar {
  flex: none; width: 64px; height: 64px; border-radius: 50%; border: var(--line); overflow: hidden;
  display: grid; place-items: center; font-size: 28px; font-weight: 800; color: #fff; background: var(--c, #f4a259);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.big { width: 96px; height: 96px; font-size: 42px; border-width: 3px; }

/* 详情 */
.detail-top { display: flex; gap: 16px; align-items: center; margin: 4px 0 14px; }
.detail-top .nm { font-size: 28px; font-weight: 800; }
.detail-top .nick { color: var(--ink2); font-size: 18px; margin-top: 2px; }
.back { margin: 0 0 6px; }
.info-card { border: var(--line); border-radius: var(--r); background: var(--card); padding: 14px 16px; margin-bottom: 12px; line-height: 1.6; }
.info-card .row { display: flex; align-items: center; gap: 12px; }
.weather-big { display: flex; align-items: center; gap: 12px; }
.weather-big svg { width: 58px; height: 58px; flex: none; }
.weather-big .t { font-size: 40px; font-weight: 800; line-height: 1; }
.weather-big .d { font-size: 16px; color: var(--ink2); }
.clock { font-size: 19px; margin-top: 10px; }
.clock b { font-size: 22px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0 6px; }
.actions .btn { padding: 10px 12px; font-size: 17px; }

.tabs { display: flex; gap: 8px; margin: 18px 0 6px; overflow-x: auto; padding-bottom: 4px; }
.tabs .pill { flex: none; min-height: 42px; padding: 6px 16px; font-size: 17px; }
.day { font-size: 17px; font-weight: 800; margin: 16px 2px 8px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.grid button { padding: 0; border: 2px solid var(--ink); border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: #eee2cc; position: relative; }
.grid img { width: 100%; height: 100%; object-fit: cover; }
.grid .cap { position: absolute; left: 0; right: 0; bottom: 0; background: linear-gradient(transparent, rgba(0,0,0,.6)); color: #fff; font-size: 13px; padding: 10px 6px 4px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { text-align: center; color: var(--ink2); padding: 30px 10px; line-height: 1.7; }

/* 地图 */
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #0f1d2b; }
.maplibregl-map { font-family: var(--font); }
.maplibregl-ctrl-group { border: var(--line) !important; border-radius: 14px !important; overflow: hidden; box-shadow: 0 3px 0 var(--ink) !important; background: var(--card) !important; }
.maplibregl-ctrl-group button { width: 46px !important; height: 46px !important; }
.maplibregl-ctrl-group button + button { border-top: 2px solid var(--ink) !important; }
.maplibregl-ctrl-attrib { font-size: 10px; }
.map-tools { position: absolute; top: 12px; right: 12px; z-index: 600; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.map-tools .btn { min-height: 46px; font-size: 17px; padding: 6px 16px; }

.pin-wrap { width: 64px; height: 66px; cursor: pointer; }
.pin { position: relative; width: 64px; height: 66px; }
.pin .face {
  position: absolute; left: 4px; top: 0; width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--ink);
  background: var(--c); overflow: hidden; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 24px;
  box-shadow: 0 3px 0 rgba(59,48,36,.35);
}
.pin .face img { width: 100%; height: 100%; object-fit: cover; }
.pin .tail { position: absolute; left: 25px; top: 50px; width: 14px; height: 14px; background: var(--ink); transform: rotate(45deg); border-radius: 2px; }
.pin .label {
  position: absolute; top: 66px; left: 50%; transform: translateX(-50%); white-space: nowrap;
  background: var(--card); border: 2px solid var(--ink); border-radius: 999px; padding: 2px 12px;
  font-size: 16px; font-weight: 800; color: var(--ink);
}
.pin.home .label { background: #ffe9a8; }
.pin.active .face { border-color: var(--accent); transform: scale(1.12); }
.pin .face { transition: transform .2s; }

.plane { width: 60px; height: 60px; z-index: 5; pointer-events: none; }
.plane svg { width: 60px; height: 60px; transform: rotate(var(--a, 0rad)); filter: drop-shadow(0 6px 3px rgba(0,0,0,.3)); }

/* 弹窗 */
.modal-back { position: fixed; inset: 0; z-index: 2000; background: rgba(40,30,20,.45); display: flex; align-items: flex-end; justify-content: center; }
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--paper);
  border: var(--line); border-bottom: 0; border-radius: 26px 26px 0 0; padding: 20px 20px calc(40px + env(safe-area-inset-bottom));
}
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.modal-head h2 { flex: 1; margin: 0; font-size: 24px; }
.card-list > div { border: var(--line); border-radius: 16px; background: var(--card); padding: 12px 14px; margin: 10px 0; }
.code-show { font-size: 48px; font-weight: 800; letter-spacing: 10px; text-align: center; margin: 6px 0; }
.geo-results button { display: block; width: 100%; text-align: left; margin: 8px 0; padding: 10px 14px; border: 2px solid var(--ink); border-radius: 12px; background: #fff; font-size: 16px; line-height: 1.45; }
.geo-results b { font-size: 18px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.colors button { width: 40px; height: 40px; border-radius: 50%; border: var(--line); }
.colors button.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 10px 0; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border: 2px solid var(--ink); border-radius: 8px; }
.hr { height: 0; border-top: 2px dashed rgba(59,48,36,.3); margin: 22px 0 10px; }

/* 家谱 */
.tree-scroll { overflow-x: auto; margin: 10px -20px 0; padding: 6px 20px 10px; }
.tree { position: relative; margin: 0 auto; }
.tree svg { position: absolute; inset: 0; }
.tree svg path { fill: none; stroke: var(--ink); stroke-width: 2.5; stroke-linejoin: round; }
.tree svg path.couple { stroke: var(--accent); stroke-dasharray: 2 5; stroke-linecap: round; }
.tree-node { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; padding: 0; }
.tree-node .avatar { width: 68px; height: 68px; box-shadow: 0 3px 0 var(--ink); }
.tree-node.me .avatar { outline: 4px solid var(--accent); outline-offset: 2px; }
.tree-node .tn { font-size: 18px; font-weight: 800; background: var(--card); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; white-space: nowrap; }
.tree-node .tf { font-size: 13px; color: var(--ink2); white-space: nowrap; }

/* 看大图 */
.viewer { position: fixed; inset: 0; z-index: 2500; background: #1d1813; display: flex; flex-direction: column; color: #fff; }
.viewer .stage { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; touch-action: pan-y; }
.viewer .stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .bar { padding: 14px 18px calc(20px + env(safe-area-inset-bottom)); font-size: 19px; line-height: 1.6; }
.viewer .bar .when { color: #cdbfa9; font-size: 16px; }
.viewer .close, .viewer .nav {
  position: absolute; z-index: 2; width: 56px; height: 56px; border-radius: 50%; border: 2px solid #fff;
  background: rgba(0,0,0,.45); color: #fff; display: grid; place-items: center; padding: 0;
}
.viewer .close { top: calc(14px + env(safe-area-inset-top)); right: 14px; }
.viewer .nav { top: 50%; margin-top: -28px; }
.viewer .nav.l { left: 10px; }
.viewer .nav.r { right: 10px; }
.viewer svg { width: 28px; height: 28px; }

/* ---------- 手机 ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 44% 56%; }
  .map-wrap { grid-row: 1; }
  .side { grid-row: 2; border-right: 0; border-top: var(--line); border-radius: 24px 24px 0 0; margin-top: -22px; box-shadow: 0 -4px 0 rgba(59,48,36,.08); }
  .side-head { padding: 14px 14px 8px; }
  .side-head h1 { font-size: 22px; }
  .side-body { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
  .map-tools { top: calc(10px + env(safe-area-inset-top)); right: 10px; }
  .maplibregl-ctrl-top-left { top: env(safe-area-inset-top); }
  .app.focus { grid-template-rows: 36% 64%; }
}
