:root {
  --bg: #f4efe4;
  --card: #fffdf8;
  --ink: #1f1c17;
  --muted: #756c5e;
  --line: #e5dccb;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --gold: #c8952f;
  --danger: #b23b30;
  --green-bg: #e3f3e8; --green-ink: #1f6b3a;
  --red-bg: #fbe3e1; --red-ink: #b3261e;
  --orange-bg: #fdebd6; --orange-ink: #9a5412;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  font-size: 17px; line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#app { min-height: 100vh; min-height: 100dvh; }

/* ---------- Lock screen ---------- */
.lock {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  text-align: center;
}
.lock .logo {
  width: 76px; height: 76px; border-radius: 18px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; color: #f4efe4;
  font-size: 34px; font-weight: 700; margin-bottom: 14px; letter-spacing: 2px;
}
.lock h1 { font-size: 26px; margin: 0 0 6px; }
.lock p { color: var(--muted); margin: 0 0 22px; font-size: 15px; }
.lock form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.lock input {
  width: 100%; padding: 14px 16px; font-size: 22px; text-align: center; letter-spacing: 6px;
  border: 1.5px solid var(--line); border-radius: 14px; background: var(--card); outline: none;
}
.lock input:focus { border-color: var(--accent); }
.lock .hint { font-size: 14px; color: var(--muted); margin-top: 14px; }
.err { color: var(--danger); font-size: 15px; min-height: 22px; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: rgba(244, 239, 228, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 0.5px solid var(--line);
}
.topbar .row { display: flex; align-items: center; gap: 10px; }
.topbar h1 { font-size: 28px; margin: 0; flex: 1; font-weight: 700; }
.topbar .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.back {
  border: none; background: none; color: var(--accent); font-size: 17px; padding: 8px 6px 8px 0;
  display: flex; align-items: center; gap: 2px; min-height: 44px;
}
.iconbtn {
  border: none; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  min-width: 44px; min-height: 44px; font-size: 16px; padding: 0 12px; color: var(--accent); font-weight: 600;
}
.search {
  margin-top: 10px; position: relative;
}
.search input {
  width: 100%; padding: 12px 40px 12px 40px; border-radius: 12px; border: 1px solid var(--line);
  background: #ebe4d5; font-size: 17px; outline: none;
}
.search input:focus { background: var(--card); border-color: var(--accent); }
.search .mag { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: none; color: var(--muted); font-size: 20px; width: 36px; height: 36px; }

.content { padding: 14px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 90px); max-width: 720px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: rgba(255, 253, 248, 0.94);
  -webkit-backdrop-filter: saturate(180%) blur(14px); backdrop-filter: saturate(180%) blur(14px);
  border-top: 0.5px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; border: none; background: none; height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px;
}
.tabbar button .ic { font-size: 20px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 600; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 18px); z-index: 31;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 18px rgba(47, 93, 80, 0.35);
  display: flex; align-items: center; justify-content: center;
}

/* ---------- Chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; font-size: 15px; min-height: 38px; color: var(--ink);
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- Cards ---------- */
.section-title { font-size: 14px; color: var(--muted); margin: 16px 4px 8px; font-weight: 600; letter-spacing: 0.5px; }
.card {
  display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 16px; margin-bottom: 10px;
}
.card:active { background: #f7f1e4; }
.card .title { font-size: 19px; font-weight: 700; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card .title .tick { color: var(--muted); font-weight: 500; font-size: 16px; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: 13px; padding: 2px 9px; border-radius: 999px; background: #efe8d8; color: #5b5142; }
.tag.chain { background: #e4ecf7; color: #2b4c7e; }
.tag.range { background: #e2efe9; color: var(--accent); font-weight: 600; }
.tag.green { background: var(--green-bg); color: var(--green-ink); }
.tag.red { background: var(--red-bg); color: var(--red-ink); }
.tag.orange { background: var(--orange-bg); color: var(--orange-ink); }
.card .prose { margin-top: 8px; color: #3c362d; font-size: 15.5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .foot { margin-top: 8px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.card.kol.red { border-left: 5px solid #d9534f; }
.card.kol.orange { border-left: 5px solid #e6953b; }
.card.kol.green { border-left: 5px solid #4c9a68; }

.range-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 18px 2px 8px; padding: 8px 12px; border-radius: 12px; font-weight: 700; font-size: 17px;
}
.range-head .count { font-size: 14px; font-weight: 500; opacity: 0.75; }
.r0 { background: #e2efda; } .r1 { background: #ddebf7; } .r2 { background: #fff2cc; }
.r3 { background: #fce4d6; } .r4 { background: #f8cbad; } .r5 { background: #f4b8a6; }
.range-empty { color: var(--muted); font-size: 15px; padding: 4px 12px 6px; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Detail ---------- */
.detail-head { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.detail-head h2 { margin: 0; font-size: 24px; }
.detail-head .tick { color: var(--muted); font-size: 17px; margin-top: 2px; }
.ca-box {
  margin-top: 12px; display: flex; align-items: center; gap: 8px; background: #f1ebdd; border-radius: 12px; padding: 10px 12px;
}
.ca-box code { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; word-break: break-all; }
.copybtn { border: none; background: var(--accent); color: #fff; border-radius: 10px; padding: 8px 12px; font-size: 14px; min-height: 38px; }

.field { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 16px; margin-bottom: 10px; }
.field .label { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.field .value { white-space: pre-wrap; word-break: break-word; font-size: 16.5px; }
.field .value a { color: #1f5fbf; word-break: break-all; }
.kvgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kvgrid .field { margin-bottom: 0; }
.kvgrid { margin-bottom: 10px; }

.actions { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.btn {
  flex: 1; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--card);
  font-size: 17px; font-weight: 600; padding: 10px 16px;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; }
.btn.small { flex: 0 0 auto; min-height: 40px; font-size: 15px; padding: 6px 12px; }

/* ---------- Forms ---------- */
.form .f { margin-bottom: 14px; }
.form label { display: block; font-size: 14px; color: var(--muted); font-weight: 600; margin: 0 2px 6px; }
.form input, .form textarea, .form select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  font-size: 17px; outline: none;
}
.form input:focus, .form textarea:focus, .form select:focus { border-color: var(--accent); }
.form textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.form .help { font-size: 13px; color: var(--muted); margin: 4px 2px 0; }
.form .preview { font-size: 14px; margin: 4px 2px 0; color: var(--accent); font-weight: 600; }

/* ---------- Settings ---------- */
.group { background: var(--card); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 14px; overflow: hidden; }
.group .item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 0.5px solid var(--line); width: 100%; background: none; border-left: none; border-right: none; border-top: none; text-align: left; min-height: 54px; }
.group .item:last-child { border-bottom: none; }
.group .item .t { flex: 1; }
.group .item .d { font-size: 13.5px; color: var(--muted); margin-top: 2px; }
.group .item .chev { color: #b9ad98; font-size: 20px; }
.note { font-size: 14.5px; color: #4a4338; background: #fbf6ea; border: 1px dashed #d9cdb5; border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; white-space: pre-wrap; }
ol.steps { padding-left: 22px; margin: 6px 0 0; }
ol.steps li { margin: 4px 0; }

.sync-pill { font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: #efe8d8; color: #5b5142; white-space: nowrap; }
.sync-pill.dirty { background: #fdebd6; color: #9a5412; }
.sync-pill.ok { background: #e3f3e8; color: #1f6b3a; }
.sync-pill.off { background: #eee; color: #666; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  background: rgba(31, 28, 23, 0.9); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; z-index: 100;
  max-width: 90vw; text-align: center;
}
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 90; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--bg); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom)); }
.modal h3 { margin: 0 0 8px; font-size: 20px; }
.modal p { margin: 0 0 14px; color: #3c362d; white-space: pre-wrap; }
