/* ───────── 基础变量 ───────── */
:root {
  --bg: #f3f4f7;
  --bg2: #ffffff;
  --card: #ffffff;
  --card-2: #f8f9fb;
  --text: #14171c;
  --text-2: #3f4753;
  --muted: #7b8494;
  --line: #e6e8ee;
  --line-2: #eef0f4;
  --accent: #0d9488;
  --accent-2: #14b8a6;
  --accent-soft: rgba(13, 148, 136, .1);
  --danger: #e11d48;
  --danger-soft: rgba(225, 29, 72, .08);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, .1);
  --blue: #2563eb;
  --blue-soft: rgba(37, 99, 235, .1);
  --purple: #7c3aed;
  --purple-soft: rgba(124, 58, 237, .1);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .12);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14;
    --bg2: #0f151c;
    --card: #141b23;
    --card-2: #1a222c;
    --text: #e9eef5;
    --text-2: #c2ccd9;
    --muted: #8593a3;
    --line: #222c38;
    --line-2: #1c242e;
    --accent: #2dd4bf;
    --accent-2: #5eead4;
    --accent-soft: rgba(45, 212, 191, .12);
    --danger: #fb7185;
    --danger-soft: rgba(251, 113, 133, .12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, .12);
    --blue: #60a5fa;
    --blue-soft: rgba(96, 165, 250, .12);
    --purple: #a78bfa;
    --purple-soft: rgba(167, 139, 250, .12);
    --shadow: 0 1px 0 rgba(255, 255, 255, .03), 0 12px 32px -18px rgba(0, 0, 0, .8);
  }
}

* { 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, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

body { min-height: 100dvh; }

button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
input { font: inherit; }
code { font-family: var(--mono); }

/* ───────── 登录 ───────── */
.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-b));
  position: relative;
  overflow: hidden;
}

.login-glow {
  position: fixed;
  inset: -30% -20% auto -20%;
  height: 60vh;
  background: radial-gradient(50% 50% at 50% 50%, var(--accent-soft), transparent 70%);
  pointer-events: none;
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 30px 24px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(140deg, var(--accent), #0ea5a0 60%, #0f766e);
  box-shadow: 0 8px 20px -8px var(--accent);
}
.logo svg { width: 26px; height: 26px; }

.login-card h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: .2px; }
.login-card .sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }

.field { display: block; margin-bottom: 14px; }
.field input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--card-2);
  color: var(--text);
  font-size: 16px; /* 防 iOS 缩放 */
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--card);
}

.btn-primary {
  width: 100%;
  height: 48px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: .5px;
  transition: transform .1s, opacity .2s;
}
.btn-primary:active { transform: scale(.985); opacity: .9; }
.btn-primary[disabled] { opacity: .6; }

.form-err {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 13px;
}
.login-foot {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-2);
  color: var(--muted);
  font-size: 12px;
}
.login-foot code { color: var(--text-2); }

/* ───────── 主框架 ───────── */
.app {
  max-width: 620px;
  margin: 0 auto;
  padding: 0 14px calc(28px + var(--safe-b));
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 2px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  margin: 0 -14px;
  padding-left: 16px;
  padding-right: 16px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  flex: 0 0 auto;
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.brand-txt { min-width: 0; }
.brand-txt h1 { font-size: 16.5px; margin: 0; font-weight: 650; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-txt p { margin: 1px 0 0; font-size: 11.5px; color: var(--muted); }

.top-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { background: var(--card-2); color: var(--accent); }

/* 搜索 */
.searchbar {
  display: none;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 12px;
  margin: 0 0 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.searchbar.open { display: flex; }
.searchbar .si { width: 17px; height: 17px; color: var(--muted); flex: 0 0 auto; }
.searchbar input {
  flex: 1; min-width: 0;
  height: 100%;
  border: 0; background: none; outline: none;
  color: var(--text); font-size: 16px;
}
.searchbar input::-webkit-search-cancel-button { display: none; }
.clear-q { color: var(--muted); font-size: 20px; line-height: 1; padding: 0 2px; }

/* 统计 */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px 6px 9px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat b {
  display: block;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.4px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}
.stat span { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat.accent b { color: var(--accent); }

/* 筛选 */
.chips {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 12px;
  margin: 0 -14px;
  padding-left: 14px;
  padding-right: 14px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 13px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  transition: all .16s;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 14px -8px var(--accent);
}

/* 提示条 */
.banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 9px 34px 9px 12px;
  margin-bottom: 12px;
  border-radius: 11px;
  background: var(--warn-soft);
  border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
  color: var(--warn);
  font-size: 12px;
  line-height: 1.45;
}
.banner code { color: inherit; font-size: 11.5px; background: rgba(0,0,0,.06); padding: 1px 4px; border-radius: 4px; }
.banner button { position: absolute; right: 8px; top: 7px; font-size: 18px; line-height: 1; color: inherit; opacity: .7; }

/* ───────── 卡片列表 ───────── */
.list { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px 10px;
  box-shadow: var(--shadow);
  animation: rise .28s cubic-bezier(.2,.8,.3,1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card-row {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
}
.tag {
  flex: 0 0 auto;
  height: 21px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .2px;
  display: inline-flex;
  align-items: center;
}
.tag[data-k="bip39"]    { background: var(--accent-soft); color: var(--accent); }
.tag[data-k="pk"]       { background: var(--warn-soft);   color: var(--warn); }
.tag[data-k="keystore"] { background: var(--purple-soft); color: var(--purple); }
.tag[data-k="address"]  { background: var(--blue-soft);   color: var(--blue); }
.tag[data-k="balance"]  { background: var(--accent-soft); color: var(--accent); }
.tag[data-k="other"]    { background: var(--card-2);      color: var(--muted); }

.card-meta {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-time { flex: 0 0 auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.preview {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 4.7em;
  overflow: hidden;
  position: relative;
  padding-right: 4px;
}
.preview.clamp::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1.8em;
  background: linear-gradient(transparent, var(--card));
}
.preview.masked {
  filter: blur(6px);
  user-select: none;
  transition: filter .18s;
}
.preview.masked.revealed { filter: none; user-select: text; }

.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--line-2);
}
.foot-note {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
}
.src-tag {
  flex: 0 0 auto;
  max-width: 56%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 10.5px;
  font-weight: 600;
  font-family: var(--mono);
}
.foot-txt {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip .cnt { font-size: 10.5px; opacity: .62; font-weight: 500; }
.site-chips { padding-bottom: 10px; }
.foot-ops { display: flex; gap: 6px; flex: 0 0 auto; }
.mini-btn {
  height: 28px;
  padding: 0 11px;
  border-radius: 8px;
  background: var(--card-2);
  color: var(--text-2);
  font-size: 12.5px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background .14s, color .14s;
}
.mini-btn:active { background: var(--accent-soft); color: var(--accent); }
.mini-btn.primary { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mini-btn svg { width: 13px; height: 13px; }

/* 骨架 */
.skel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 13px;
}
.skel div {
  height: 11px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--line-2) 25%, var(--card-2) 37%, var(--line-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  margin-bottom: 9px;
}
.skel div:nth-child(1) { width: 34%; }
.skel div:nth-child(2) { width: 92%; }
.skel div:nth-child(3) { width: 70%; margin-bottom: 0; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* 空态 */
.empty {
  text-align: center;
  padding: 56px 28px;
  color: var(--muted);
}
.empty svg { width: 46px; height: 46px; opacity: .5; margin-bottom: 12px; }
.empty p { margin: 0 0 4px; font-size: 14.5px; color: var(--text-2); font-weight: 600; }
.empty span { font-size: 12.5px; line-height: 1.6; display: block; }

.sentinel { height: 1px; }
.loading-more { text-align: center; padding: 14px 0 4px; color: var(--muted); font-size: 12.5px; }
.loading-more .spin {
  display: inline-block; width: 13px; height: 13px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.to-top {
  position: fixed;
  right: 16px;
  bottom: calc(18px + var(--safe-b));
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text-2);
  box-shadow: 0 8px 22px -10px rgba(0,0,0,.35);
  display: grid; place-items: center;
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  z-index: 15;
}
.to-top svg { width: 19px; height: 19px; }
.to-top.show { opacity: 1; pointer-events: auto; transform: none; }

/* ───────── 详情面板 ───────── */
.sheet { position: fixed; inset: 0; z-index: 60; }
.sheet-mask {
  position: absolute; inset: 0;
  background: rgba(6, 10, 14, .45);
  backdrop-filter: blur(2px);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-width: 620px;
  margin: 0 auto;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  box-shadow: 0 -12px 40px -18px rgba(0,0,0,.5);
  animation: slideUp .26s cubic-bezier(.22,.9,.3,1);
  padding-bottom: var(--safe-b);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }

.sheet-grip {
  width: 34px; height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 8px auto 0;
  flex: 0 0 auto;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px 8px 18px;
  flex: 0 0 auto;
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 650; }

.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 18px 12px;
  flex: 1 1 auto;
}

.sheet-foot {
  display: flex;
  gap: 8px;
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line-2);
  background: var(--bg2);
  flex: 0 0 auto;
}

/* 详情字段 */
.sec-title {
  font-size: 11.5px;
  font-weight: 650;
  color: var(--muted);
  letter-spacing: .6px;
  text-transform: uppercase;
  margin: 16px 0 8px;
}
.kv {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-2);
  font-size: 13px;
}
.kv:last-child { border-bottom: 0; }
.kv .k { flex: 0 0 74px; color: var(--muted); font-size: 12.5px; }
.kv .v {
  flex: 1 1 auto; min-width: 0;
  word-break: break-all;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
}
.kv .v.plain { font-family: inherit; font-size: 13px; }

.secret-box {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 12px 44px;
  margin-bottom: 8px;
}
.secret-box .txt {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.7;
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 42dvh;
  overflow-y: auto;
}
.secret-box .txt.masked { filter: blur(6px); user-select: none; }
.secret-box .txt.masked.revealed { filter: none; }
.secret-box .box-ops {
  position: absolute;
  right: 8px; bottom: 8px;
  display: flex; gap: 6px;
}

.btn {
  flex: 1 1 0;
  height: 44px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }

.raw-json {
  margin: 4px 0 0;
  padding: 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--text-2);
  overflow-x: auto;
  white-space: pre;
  max-height: 40dvh;
  overflow-y: auto;
}

/* 菜单 */
.sheet-panel.small { max-height: 76dvh; }
.menu-list { padding: 4px 12px 16px; overflow-y: auto; }
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 8px;
  font-size: 14.5px;
  color: var(--text);
  border-bottom: 1px solid var(--line-2);
  text-decoration: none;
}
.menu-item svg { width: 19px; height: 19px; color: var(--muted); flex: 0 0 auto; }
.menu-item:active { background: var(--card-2); }
.menu-item.danger { color: var(--danger); border-bottom: 0; }
.menu-item.danger svg { color: var(--danger); }

.menu-info {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 12px;
}
.mi-row { display: flex; gap: 10px; padding: 4px 0; align-items: baseline; }
.mi-row span { flex: 0 0 56px; color: var(--muted); }
.mi-row code { flex: 1 1 auto; word-break: break-all; color: var(--text-2); font-size: 11.5px; }
.mi-row b { color: var(--accent); font-weight: 600; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(40px + var(--safe-b));
  transform: translate(-50%, 12px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(18, 24, 32, .92);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 90;
  max-width: 80vw;
  text-align: center;
  backdrop-filter: blur(8px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 640px) {
  .app { padding-bottom: 40px; }
  .stat b { font-size: 21px; }
}
