/* ============ 设计变量 ============
   命名约定：
   - --accent      用于文字/描边（与 panel 有足够对比度）
   - --accent-fill 用于「白字压在蓝底上」的填充色（单独一个更深的蓝，保证 ≥4.5:1）
   - --text-faint  只用于装饰性小字；需要看清的信息（状态栏、备注）用 --text-dim
   ================================ */
:root {
  --bg: #0d1117;
  --bg-soft: #131a23;
  --panel: #161e29;
  --panel-2: #1c2634;
  --line: #24303f;
  --text: #e6edf6;
  --text-dim: #a7b6c9;
  --text-faint: #7c8b9f;
  --accent: #4ea1ff;
  --accent-fill: #2a6fd6;
  --accent-soft: rgba(78, 161, 255, 0.14);
  --danger: #ff6b6b;
  --ok: #3ddc97;
  --warn: #ffc857;

  /* 圆角三档 */
  --r-ctl: 8px;
  --r-card: 12px;
  --r-dialog: 16px;
  --radius: 12px;

  /* 控件高度与间距 */
  --h-ctl: 40px;
  --h-sm: 32px;
  --gap: 16px;

  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --panel-2: #f0f3f8;
    --line: #dde4ee;
    --text: #16202c;
    --text-dim: #4a5b70;
    --text-faint: #5f6f82;
    --accent: #1a5fbf;
    --accent-fill: #1d6fe0;
    --accent-soft: rgba(29, 111, 224, 0.1);
    --danger: #c0332f;
    --ok: #0b7a50;
    --warn: #8a5a00;
    --shadow: 0 10px 30px rgba(18, 33, 54, 0.12);
  }
}

* { box-sizing: border-box; }

html { scrollbar-color: var(--line) transparent; scrollbar-width: thin; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
*::-webkit-scrollbar-track { background: transparent; }

::selection { background: var(--accent-fill); color: #fff; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* 键盘焦点：所有可交互元素统一可见焦点环 */
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-ctl);
}

/* ============ 锁屏 ============ */
.lock-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1000px 600px at 20% 0%, var(--accent-soft), transparent 60%),
    var(--bg);
}

.lock-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-dialog);
  padding: 30px 26px 20px;
  box-shadow: var(--shadow);
}

.lock-brand { display: flex; align-items: center; gap: 10px; justify-content: center; }
.lock-icon { font-size: 28px; }
.lock-brand h1 { font-size: 22px; margin: 0; letter-spacing: 0.5px; }
.lock-sub { text-align: center; color: var(--text-dim); font-size: 13px; margin: 10px 0 20px; }

.lock-form { display: grid; gap: 10px; }
.lock-form input:not([type=checkbox]) {
  width: 100%;
  min-height: var(--h-ctl);
  padding: 10px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  outline: none;
  transition: border-color 0.15s;
}
.lock-form input:focus { border-color: var(--accent); }

.check { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; white-space: nowrap; }
.check input { width: auto; margin: 0; accent-color: var(--accent-fill); }
.hint { color: var(--text-faint); font-size: 13px; margin: 0; line-height: 1.6; }

.lock-links { display: flex; gap: 14px; justify-content: center; margin-top: 16px; }
.link {
  background: none; border: 0; color: var(--text-dim); font-size: 13px; padding: 8px 6px;
  text-decoration: underline; text-underline-offset: 3px;
}
.link:hover { color: var(--accent); }
.lock-err { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; margin: 10px 0 0; }

/* ============ 按钮 ============ */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 8px 16px;
  min-height: 36px;
  border-radius: var(--r-ctl);
  transition: filter 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}
.btn:hover { border-color: color-mix(in srgb, var(--line) 40%, var(--accent)); filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn.block { width: 100%; padding: 12px; }
.btn.sm { padding: 5px 11px; font-size: 13px; min-height: var(--h-sm); border-radius: var(--r-ctl); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  width: var(--h-ctl); height: var(--h-ctl);
  display: grid; place-items: center;
  border-radius: var(--r-ctl);
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 16px;
  transition: border-color 0.15s, transform 0.08s;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: translateY(1px); }

/* ============ 顶栏 ============ */
.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg-soft) 88%, transparent);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
  padding-top: calc(10px + env(safe-area-inset-top));
}

.brand { font-weight: 700; letter-spacing: 0.4px; white-space: nowrap; display: flex; gap: 6px; align-items: center; }

.search-wrap { position: relative; flex: 1; min-width: 120px; max-width: 520px; }
.search-wrap input {
  width: 100%;
  min-height: var(--h-ctl);
  padding: 9px 62px 9px 36px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-icon {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); display: grid; place-items: center; pointer-events: none;
}
.search-wrap kbd {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  font-size: 10px; color: var(--text-faint); border: 1px solid var(--line);
  border-radius: 5px; padding: 2px 5px; font-family: inherit;
}

.tabs {
  display: flex; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--r-ctl); padding: 3px; gap: 2px; margin-left: auto;
}
.tabs button {
  border: 0; background: transparent; color: var(--text-dim);
  padding: 5px 14px; border-radius: 6px; font-size: 13px; min-height: var(--h-sm);
  transition: background 0.15s, color 0.15s;
}
.tabs button:active { transform: translateY(1px); }
.tabs button.active { background: var(--accent-fill); color: #fff; font-weight: 600; }

.top-actions { display: flex; gap: 8px; }

/* ============ 分类 chips ============ */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 12px clamp(14px, 3vw, 28px) 4px;
  scrollbar-width: thin;
}
.chips::-webkit-scrollbar { height: 6px; }
.chips::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.chip {
  border: 1px solid var(--line); background: transparent; color: var(--text-dim);
  padding: 6px 13px; min-height: var(--h-sm); border-radius: 999px; font-size: 13px; white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.chip:active { transform: translateY(1px); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ============ 平台网格 ============ */
.main { flex: 1; padding: 14px clamp(14px, 3vw, 28px) 28px; }

.grid-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--gap);
}

.card {
  position: relative;
  display: flex; flex-direction: column; gap: 8px;
  align-items: flex-start;
  text-align: left;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  min-height: 108px;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--panel-2); }
.card:active { transform: translateY(0); }

/* 图标统一盒子：emoji 与字母块同尺寸 */
.icon {
  width: 32px; height: 32px; flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 18px; line-height: 1;
}
.icon.mono {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--accent);
  font-size: 15px; font-weight: 700;
}
.card:hover .icon { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

.card .name {
  font-weight: 600; font-size: 14px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.card .meta { font-size: 12px; color: var(--text-faint); margin-top: auto; padding-right: 26px; }

.card .badge {
  position: absolute; bottom: 10px; right: 10px;
  min-width: 22px; height: 22px; padding: 0 6px;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  border: 1px dashed var(--line);
  border-radius: 999px; background: transparent; color: var(--text-dim);
}
.card .badge.empty { background: transparent; color: var(--text-dim); border: 1px dashed var(--line); }
.card.add { border-style: dashed; color: var(--text-dim); align-items: center; justify-content: center; }
.card.add .plus { font-size: 22px; }

/* 角标可点：直接在网格里给这个平台加一条记录 */
.card .badge[data-add] { cursor: pointer; transition: transform 0.12s, background 0.12s, color 0.12s; }
.card .badge[data-add]:hover { transform: scale(1.12); background: var(--accent-fill); color: #fff; border-color: var(--accent-fill); }

/* 卡片上的置顶星 */
.card .fav {
  position: absolute; right: 8px; top: 8px;
  width: 22px; height: 22px; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--warn);
  font-size: 13px; padding: 0; opacity: 0; transition: opacity 0.12s;
  cursor: pointer;
}
.card:hover .fav, .card .fav.on, .card .fav:focus-visible { opacity: 1; }

.btn.ghost.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

#saveState.err { color: var(--danger); cursor: pointer; text-decoration: underline dotted; }

.empty-state { grid-column: 1 / -1; color: var(--text-dim); text-align: center; padding: 40px 12px; font-size: 14px; max-width: 520px; margin: 40px auto 0; }
.empty-state .empty-title { color: var(--text); font-weight: 600; margin-bottom: 6px; }
.empty-state .empty-actions { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

/* ============ 详情 ============ */
#detailView { max-width: 1040px; margin-inline: auto; }

.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.detail-head .icon { width: 36px; height: 36px; font-size: 20px; border-radius: 10px; }
.detail-head h2 { margin: 0; font-size: 20px; line-height: 1.3; }
.detail-head .sub { color: var(--text-dim); font-size: 13px; }
.detail-head .spacer { flex: 1; min-width: 0; }
.detail-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.detail-actions .del-quiet { border-color: transparent; color: var(--text-dim); }
.detail-actions .del-quiet:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.acct-list { display: grid; gap: 12px; }

.acct {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 16px 18px;
}
.acct-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.acct-user { font-weight: 600; word-break: break-all; }
.acct-note { color: var(--text-dim); font-size: 13px; word-break: break-all; }
.acct-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.secret {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  padding: 8px 12px;
  font-size: 13px;
  letter-spacing: 1px;
  word-break: break-all;
  flex: 1; min-width: 140px;
}
.secret.revealed { letter-spacing: 0; user-select: all; border-color: var(--accent); }
.acct-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
/* 删除靠右、平时最弱：避免与「复制」同款只差颜色 */
.acct-actions .danger { margin-left: auto; border-color: transparent; color: var(--text-dim); }
.acct-actions .danger:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.strength {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text-dim);
}
.strength.weak { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.strength.mid { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.strength.strong { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }

/* ============ 弹窗 ============ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 8, 14, 0.62);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade 0.12s ease-out;
}
.modal {
  width: min(520px, 100%);
  max-height: 86vh; overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-dialog);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: pop 0.14s ease-out;
}
.modal.wide { width: min(680px, 100%); }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } }

.form-grid { display: grid; gap: 10px; }
.field { display: grid; gap: 5px; }
.field label { font-size: 12px; color: var(--text-dim); }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; min-height: var(--h-ctl);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 60px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }

.code-box {
  font-family: ui-monospace, Consolas, monospace;
  background: var(--panel-2);
  border: 1px dashed var(--accent);
  border-radius: var(--r-ctl);
  padding: 14px;
  text-align: center;
  letter-spacing: 1px;
  word-break: break-all;
  color: var(--accent);
  font-size: 16px;
}

.list { display: grid; gap: 6px; max-height: 240px; overflow: auto; }
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-ctl);
  font-size: 13px;
}
.list-row .grow { flex: 1; color: var(--text-dim); word-break: break-all; }

/* 恢复码弹窗里必须勾选才能继续 */
.ack { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--text-dim); margin-top: 12px; line-height: 1.5; }
.ack input { margin: 3px 0 0; width: auto; flex: none; accent-color: var(--accent-fill); }

.settings-section { margin-top: 18px; }
.settings-section h4 { margin: 0 0 8px; font-size: 13px; color: var(--text-faint); font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.btn-grid { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============ Toast（右下角，最多 3 条，不挡分类栏） ============ */
#fatalBar {
  position: fixed; inset: 0 0 auto 0; z-index: 400;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
#fatalBar b { flex: none; }
#fatalBar span { flex: 1; min-width: 0; word-break: break-word; }
#fatalBar button {
  flex: none; min-height: 28px; padding: 0 10px;
  border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.16); color: #fff; font: inherit; cursor: pointer;
}
#fatalBar button.x { width: 28px; padding: 0; }

.toast-wrap {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(52px + env(safe-area-inset-bottom));
  display: grid; gap: 8px; justify-items: center; z-index: 200; pointer-events: none;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  pointer-events: auto;
  animation: toastIn 0.16s ease-out;
  display: flex; align-items: center; gap: 10px;
}
.toast .toast-x {
  border: 0; background: transparent; color: var(--text-faint);
  font-size: 15px; line-height: 1; padding: 0 2px; flex: none;
}
.toast .toast-x:hover { color: var(--text); }
.toast.err { border-color: color-mix(in srgb, var(--danger) 60%, transparent); color: var(--danger); }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } }

/* ============ 底栏 ============ */
.statusbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px clamp(14px, 3vw, 28px);
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--text-dim); font-size: 13px;
  background: var(--bg-soft);
}

/* ============ 手机 ============ */
@media (max-width: 720px) {
  .topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "brand tabs actions"
      "search search search";
    gap: 8px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .brand { grid-area: brand; font-size: 14px; }
  .tabs { grid-area: tabs; justify-self: start; margin-left: 0; }
  .tabs button { flex: 0 0 auto; padding: 5px 12px; }
  .top-actions { grid-area: actions; justify-self: end; }
  .search-wrap { grid-area: search; max-width: none; flex: none; }
  .search-wrap kbd { display: none; }

  .main { padding: 12px 12px 24px; }
  .grid-view { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { min-height: 100px; padding: 12px; }
  .row-2 { grid-template-columns: 1fr; }

  /* 触控目标 ≥44 */
  .acct-actions { gap: 8px; }
  .acct-actions .btn, .detail-actions .btn { min-height: 44px; }
  .acct-actions .btn { flex: 1 1 auto; }
  .acct-actions .danger { margin-left: 0; flex: 1 1 auto; }
  .chip { min-height: 36px; }
  .icon-btn { width: 38px; height: 38px; }

  .detail-head { gap: 10px; }
  .detail-head .spacer { display: none; }
  .detail-head h2 { font-size: 18px; }
  .detail-actions { width: 100%; }
  .detail-actions .btn { flex: 1 1 auto; }
  .detail-actions .del-quiet { flex: 0 0 auto; }
  #addAcct { flex: 2 1 auto; }
  .acct { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
