:root {
  --brand: #4f7cff;
  --brand-2: #7c5cff;
  --accent: #18c9a6;
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #e9eefe 0%, #f4f6fb 55%);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --text: #1a1f2e;
  --text-soft: #5b6478;
  --text-faint: #9aa3b5;
  --border: rgba(20, 30, 60, 0.08);
  --shadow: 0 10px 30px -12px rgba(30, 45, 90, 0.18);
  --shadow-lg: 0 24px 60px -20px rgba(30, 45, 90, 0.28);
  --radius: 22px;
  --radius-sm: 14px;
  --tabbar-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #0b0e17;
  --bg-grad: radial-gradient(1200px 600px at 80% -10%, #161c2e 0%, #0b0e17 55%);
  --surface: rgba(28, 33, 48, 0.66);
  --surface-solid: #151a27;
  --text: #eef1f8;
  --text-soft: #aab3c7;
  --text-faint: #6b7488;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
}

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

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { display: block; max-width: 100%; }
input, textarea { font-family: inherit; }

.glass {
  background: var(--surface);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.gradient-text {
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Auth ---------- */
#auth-view {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px; border-radius: var(--radius); padding: 30px 26px;
  animation: rise .5s cubic-bezier(.16,1,.3,1) both;
}
.auth-logo { font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
.auth-sub { color: var(--text-soft); margin: 6px 0 22px; font-size: 14px; }
.seg { display: flex; background: rgba(120,130,160,.1); border-radius: 14px; padding: 4px; margin-bottom: 18px; }
.seg button { flex: 1; padding: 10px; border-radius: 11px; font-weight: 600; color: var(--text-soft); transition: .25s; }
.seg button.active { background: var(--surface-solid); color: var(--text); box-shadow: var(--shadow); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-soft); margin: 0 0 6px 4px; }
.field input {
  width: 100%; padding: 14px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-solid); color: var(--text);
  font-size: 15px; outline: none; transition: .2s;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(79,124,255,.14); }

.btn {
  width: 100%; padding: 15px; border-radius: var(--radius-sm); font-weight: 700; font-size: 15px;
  color: #fff; background: linear-gradient(90deg, var(--brand), var(--brand-2));
  box-shadow: 0 12px 26px -10px rgba(79,124,255,.6); transition: transform .18s, box-shadow .18s;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .6; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn.small { width: auto; padding: 9px 16px; font-size: 13px; }

/* ---------- App shell ---------- */
#main-view { max-width: 480px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); }
.app-header {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 18px 18px 12px; background: linear-gradient(var(--bg), transparent);
}
.app-header h1 { font-size: 22px; margin: 0; font-weight: 800; letter-spacing: -.4px; }
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--border); font-size: 18px; backdrop-filter: blur(10px);
}
.page { padding: 8px 16px 0; animation: fade .35s ease both; }
.page[hidden] { display: none; }

/* stats chips */
.stats-row { display: flex; gap: 10px; margin: 6px 0 18px; }
.stat-chip { flex: 1; text-align: center; padding: 14px 8px; border-radius: 18px; }
.stat-chip .n { font-size: 24px; font-weight: 800; }
.stat-chip .l { font-size: 12px; color: var(--text-soft); margin-top: 2px; }

/* checkin card */
.card { border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; transition: transform .25s cubic-bezier(.16,1,.3,1); }
.card:active { transform: scale(.99); }
.card .photo { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #dfe4ef; }
.card .meta { padding: 13px 15px 15px; }
.card .date { font-size: 12px; color: var(--text-faint); }
.card .cap { margin: 6px 0 10px; font-size: 15px; line-height: 1.45; word-break: break-word; }
.card .acts { display: flex; gap: 8px; }
.chip-btn { flex: 1; padding: 9px; border-radius: 12px; font-size: 13px; font-weight: 600; background: rgba(120,130,160,.12); color: var(--text); }
.chip-btn.share { background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; }
.empty { text-align: center; color: var(--text-faint); padding: 60px 20px; }
.empty .big { font-size: 46px; margin-bottom: 10px; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b));
  width: min(480px, calc(100% - 24px)); height: var(--tabbar-h); border-radius: 24px;
  display: flex; align-items: center; padding: 0 10px; z-index: 40;
}
.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0; color: var(--text-faint); font-size: 11px; font-weight: 600; transition: color .2s; position: relative; }
.tabbar button .ic { font-size: 22px; transition: transform .25s cubic-bezier(.16,1,.3,1); }
.tabbar button.active { color: var(--brand); }
.tabbar button.active .ic { transform: translateY(-2px) scale(1.12); }
.tab-fab {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: 28px;
  box-shadow: 0 14px 30px -8px rgba(79,124,255,.7); transition: transform .2s;
}
.tab-fab:active { transform: translateX(-50%) scale(.92); }

/* ---------- Checkin editor ---------- */
.editor-wrap { padding: 10px 0; }
.editor-stage { border-radius: var(--radius); overflow: hidden; background: #000; position: relative; }
.editor-stage canvas { width: 100%; display: block; }
.filter-row { display: flex; gap: 10px; overflow-x: auto; padding: 14px 2px; }
.filter-thumb { flex: 0 0 auto; text-align: center; font-size: 12px; color: var(--text-soft); }
.filter-thumb .sw { width: 60px; height: 60px; border-radius: 14px; margin-bottom: 6px; border: 2px solid transparent; overflow: hidden; background:#ccc; }
.filter-thumb.active .sw { border-color: var(--brand); }
.filter-thumb.active { color: var(--brand); font-weight: 700; }
textarea.cap-input { width: 100%; min-height: 64px; padding: 13px 15px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-solid); color: var(--text); font-size: 15px; resize: none; outline: none; margin-top: 4px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; margin: 14px 2px; font-size: 14px; }
.switch { width: 46px; height: 28px; border-radius: 999px; background: rgba(120,130,160,.3); position: relative; transition: .25s; }
.switch.on { background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .25s; }
.switch.on::after { left: 21px; }
.progress { height: 8px; border-radius: 999px; background: rgba(120,130,160,.2); overflow: hidden; margin-top: 12px; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .2s; }

/* ---------- Me ---------- */
.profile { display: flex; align-items: center; gap: 14px; padding: 6px 4px 18px; }
.avatar { width: 62px; height: 62px; border-radius: 20px; display: grid; place-items: center; font-size: 26px; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.av-picks { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.av-pick { width: 56px; height: 56px; border-radius: 14px; object-fit: cover; border: 2px solid transparent; }
.av-pick.sel { border-color: var(--brand); }
.profile .nm { font-size: 19px; font-weight: 800; }
.profile .un { font-size: 13px; color: var(--text-soft); }
.menu { border-radius: var(--radius); overflow: hidden; }
.menu button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 16px 18px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 15px; text-align: left; }
.menu button:last-child { border-bottom: none; }
.menu .right { color: var(--text-faint); font-size: 14px; }
.tag-admin { font-size: 11px; background: linear-gradient(90deg,var(--accent),#0fb48f); color:#fff; padding: 2px 8px; border-radius: 999px; margin-left: 8px; }

/* ---------- Modal ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(10,15,30,.5); backdrop-filter: blur(4px); display: grid; place-items: end; z-index: 60; animation: fade .2s; }
.modal-mask[hidden] { display: none; }
.modal { width: 100%; max-width: 480px; margin: 0 auto; border-radius: 26px 26px 0 0; padding: 22px 20px calc(24px + var(--safe-b)); animation: slideup .3s cubic-bezier(.16,1,.3,1); }
.modal h3 { margin: 0 0 16px; font-size: 18px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; top: 22%; transform: transl(-50%,-10px); translate: -50% 0; background: rgba(20,25,40,.92); color: #fff; padding: 11px 18px; border-radius: 14px; font-size: 14px; z-index: 90; opacity: 0; transition: .25s; pointer-events: none; }
.toast.show { opacity: 1; }

@keyframes rise { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -4px; }

/* ---------- 卡片块 / 日历 / 趋势 ---------- */
.card-block { border-radius: var(--radius); padding: 16px 16px 18px; margin: 6px 0 16px; }
.card-block h4 { margin: 0 0 12px; font-size: 14px; color: var(--text-soft); font-weight: 700; display: flex; align-items: center; justify-content: space-between; }

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head .m { font-weight: 800; font-size: 16px; }
.cal-nav { width: 30px; height: 30px; border-radius: 10px; background: rgba(120,130,160,.12); font-size: 16px; font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-faint); padding-bottom: 4px; }
.cal-cell { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 12px; border-radius: 10px; position: relative; color: var(--text-soft); }
.cal-cell.muted { color: var(--text-faint); opacity: .4; }
.cal-cell.today { font-weight: 800; color: var(--brand); }
.cal-cell.has { background: rgba(79,124,255,.12); color: var(--text); font-weight: 700; }
.cal-cell.has::after { content: ""; position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%); width: 5px; height: 5px; border-radius: 50%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }
.cal-foot { margin-top: 10px; font-size: 12px; color: var(--text-soft); display: flex; gap: 16px; }
.cal-foot b { color: var(--brand); }

.trend-bars { display: flex; align-items: flex-end; gap: 10px; height: 128px; padding-top: 6px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.trend-bar { width: 100%; max-width: 34px; border-radius: 8px 8px 4px 4px; background: linear-gradient(180deg, var(--brand), var(--brand-2)); transition: height .5s cubic-bezier(.16,1,.3,1); min-height: 4px; }
.trend-lab { font-size: 11px; color: var(--text-faint); }
.trend-val { font-size: 11px; font-weight: 700; color: var(--text); }

/* ---------- 目标 / 成就 ---------- */
.goal-card { display: flex; align-items: center; gap: 14px; }
.goal-ring { width: 54px; height: 54px; border-radius: 50%; flex: 0 0 auto; display: grid; place-items: center; font-size: 22px; position: relative; }
.goal-ring::before { content: ""; position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(var(--ring-c, var(--brand)) calc(var(--p,0)*1%), rgba(120,130,160,.18) 0); -webkit-mask: radial-gradient(transparent 56%, #000 58%); mask: radial-gradient(transparent 56%, #000 58%); }
.goal-ring .emo { position: relative; }
.goal-meta { flex: 1; min-width: 0; }
.goal-meta .gt { font-weight: 700; font-size: 15px; }
.goal-meta .gs { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.goal-empty { font-size: 13px; color: var(--text-soft); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.goal-link { color: var(--brand); font-weight: 700; font-size: 13px; white-space: nowrap; }

.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 16px; background: rgba(120,130,160,.08); border: 1px solid var(--border); transition: transform .2s; }
.badge:active { transform: scale(.96); }
.badge .be { font-size: 28px; filter: grayscale(1) opacity(.45); }
.badge.on { background: linear-gradient(135deg, rgba(79,124,255,.16), rgba(124,92,255,.16)); }
.badge.on .be { filter: none; }
.badge .bn { font-size: 12px; font-weight: 700; margin-top: 4px; }
.badge .bd { font-size: 10px; color: var(--text-faint); margin-top: 2px; line-height: 1.3; }
.badge-sum { font-size: 13px; color: var(--text-soft); }

/* 编辑器日期（补打卡） */
.ck-date { width: 130px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-solid); color: var(--text); font-size: 14px; }
.goal-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: rgba(79,124,255,.12); color: var(--brand); margin-top: 2px; }

/* ---------- 灯箱 ---------- */
.lightbox { position: fixed; inset: 0; background: rgba(5,8,16,.97); z-index: 100; display: flex; flex-direction: column; }
.lightbox[hidden] { display: none; }
.lb-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; color: #fff; }
.lb-cap { font-size: 14px; opacity: .9; flex: 1; margin-right: 10px; }
.lb-close { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 18px; flex: 0 0 auto; }
.lb-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
.lb-stage img { max-width: 100%; max-height: 100%; transition: transform .2s; will-change: transform; }
.lb-bar { display: flex; align-items: center; gap: 12px; padding: 14px 16px calc(20px + var(--safe-b)); }
.lb-btn { flex: 1; padding: 12px; border-radius: 14px; font-weight: 700; background: rgba(255,255,255,.14); color: #fff; }
.lb-idx { color: #fff; opacity: .7; font-size: 13px; flex: 0 0 auto; }

/* ---------- 足迹入口 ---------- */
.footprint-entry { display: flex; align-items: center; gap: 14px; padding: 14px 16px; margin: 6px 0 16px; border-radius: var(--radius); cursor: pointer; transition: transform .2s; }
.footprint-entry:active { transform: scale(.98); }
.fp-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 22px; background: rgba(24,201,166,.14); flex: 0 0 auto; }
.fp-txt { flex: 1; }
.fp-t { font-weight: 700; font-size: 15px; }
.fp-s { font-size: 12px; color: var(--text-soft); margin-top: 2px; }
.fp-go { color: var(--text-faint); font-size: 20px; }

/* ---------- 地图 ---------- */
.map-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px 10px; }
.map-head h1 { font-size: 20px; margin: 0; font-weight: 800; flex: 1; }
.map-count { font-size: 13px; color: var(--text-soft); }
#map { width: 100%; height: 72vh; border-radius: var(--radius); overflow: hidden; background: #dfe4ef; z-index: 1; }
.leaflet-popup-content img { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; margin-bottom: 4px; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.map-marker { width: 18px; height: 18px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand-2)); border: 3px solid #fff; box-shadow: 0 4px 10px -2px rgba(79,124,255,.7); }

/* ---------- 打卡画像 ---------- */
.profile-chart h4 { margin: 0 0 12px; font-size: 14px; color: var(--text-soft); font-weight: 700; }
.week-bars { display: flex; align-items: flex-end; gap: 6px; height: 92px; }
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.week-bar { width: 100%; max-width: 22px; border-radius: 6px 6px 3px 3px; background: linear-gradient(180deg, var(--brand), var(--brand-2)); min-height: 3px; transition: height .5s cubic-bezier(.16,1,.3,1); }
.week-lab { font-size: 10px; color: var(--text-faint); }
.week-num { font-size: 10px; color: var(--text-soft); font-weight: 600; }
.sub-charts { display: flex; gap: 14px; margin-top: 16px; }
.sub-chart { flex: 1; min-width: 0; }
.sub-chart .sc-t { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; font-weight: 600; }
.hour-bars { display: flex; align-items: flex-end; gap: 1px; height: 56px; }
.hour-col { flex: 1; display: flex; align-items: flex-end; min-width: 0; }
.hour-bar { width: 100%; border-radius: 2px; background: rgba(24,201,166,.7); min-height: 2px; }
.mood-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mood-chip { padding: 5px 10px; border-radius: 999px; font-size: 13px; background: rgba(120,130,160,.12); color: var(--text-soft); }
.mood-chip b { color: var(--text); }

/* ---------- 编辑器心情 ---------- */
.mood-row { margin: 12px 2px 4px; }
.mood-row .mr-t { font-size: 13px; color: var(--text-soft); margin-bottom: 8px; }
.mood-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.mood-btn { width: 42px; height: 42px; border-radius: 12px; font-size: 22px; background: rgba(120,130,160,.1); border: 2px solid transparent; display: grid; place-items: center; transition: .2s; }
.mood-btn.active { border-color: var(--brand); background: rgba(79,124,255,.12); transform: scale(1.05); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
