:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1a1a2e;
  --sub: #9097a8;
  --line: rgba(20, 30, 80, 0.06);
  --shadow: 0 4px 16px rgba(20, 30, 80, 0.06);
  --primary: #2b5cff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(env(safe-area-inset-bottom) + 24px) env(safe-area-inset-left);
}
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px 8px;
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.5px;
  outline: none;
}
.topbar h1[contenteditable="true"] {
  border-bottom: 2px dashed var(--primary);
  padding-bottom: 2px;
}
.actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: none;
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.94); }
.edit-only { display: none; }
body.edit .edit-only { display: inline-flex; }
body.edit #lock-btn { background: var(--primary); }

.hint {
  margin: 0 20px 6px;
  font-size: 12.5px;
  color: var(--sub);
}

/* ---------- 类目 ---------- */
#app { padding: 8px 16px 0; }
.category { margin-bottom: 22px; }
.cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 12px;
}
.cat-title { margin: 0; font-size: 16px; font-weight: 700; color: #4a4f63; }
.cat-title-input {
  font-size: 16px;
  font-weight: 700;
  color: #4a4f63;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
  flex: 1;
  min-width: 0;
}
.mini-btn {
  border: none;
  background: #eef1f8;
  color: #4a4f63;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}
.mini-btn.danger { background: #ffe9ec; color: #e23a52; }
.mini-btn:active { transform: scale(0.95); }

/* ---------- 网格与卡片 ---------- */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 16px 14px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  min-height: 76px;
}
.card:active { transform: scale(0.97); }
.card .icon {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  background-size: cover;
  background-position: center;
}
.card .txt { min-width: 0; }
.card .label {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .sub {
  font-size: 12px;
  color: var(--sub);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .sub.warn { color: #f0a020; }
.card.unset { opacity: 0.92; }
.card-del {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: #e23a52;
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(226, 58, 82, 0.4);
}
body.edit .card { border-style: dashed; border-color: rgba(43, 92, 255, 0.25); }

/* 大卡片（图1 风格：整块彩色背景 + 白字 + 大图标） */
.card.large {
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  min-height: 132px;
  padding: 18px 16px;
  color: #fff;
  border: none;
  background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.22), rgba(0, 0, 0, 0.12));
}
.card.large .l-txt { width: 100%; }
.card.large .l-label {
  font-size: 20px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card.large .l-sub {
  font-size: 12.5px;
  opacity: 0.92;
  margin-top: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card.large .l-icon {
  align-self: flex-end;
  margin-top: 12px;
  font-size: 38px;
  line-height: 1;
}
.card.large .l-icon.img {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
}
.card.large.unset { opacity: 0.96; }
body.edit .card.large { border: 2px dashed rgba(255, 255, 255, 0.7); }

.add-cat {
  width: 100%;
  border: 2px dashed rgba(43, 92, 255, 0.4);
  background: transparent;
  color: var(--primary);
  border-radius: 16px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
.add-cat:active { transform: scale(0.99); }

/* ---------- 编辑弹窗 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 40, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.sheet {
  width: 100%;
  background: #fff;
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.sheet-title { font-size: 17px; font-weight: 800; margin-bottom: 14px; }
.sheet label {
  display: block;
  font-size: 13px;
  color: var(--sub);
  margin-bottom: 12px;
}
.sheet label input[type="text"],
.sheet label input[type="url"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  background: #f7f8fc;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  color: var(--text);
}
.field-label { font-size: 13px; color: var(--sub); margin: 4px 0 8px; }

.icon-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tab {
  flex: 1;
  border: 1px solid var(--line);
  background: #f7f8fc;
  border-radius: 10px;
  padding: 9px;
  font-size: 14px;
  cursor: pointer;
  color: #4a4f63;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

#f-emoji {
  width: 100%;
  border: 1px solid var(--line);
  background: #f7f8fc;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 22px;
  text-align: center;
  margin-bottom: 10px;
}
.emoji-list {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}
.emoji-list button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  font-size: 20px;
  padding: 6px 0;
  cursor: pointer;
}
.emoji-list button.sel { border-color: var(--primary); background: #eef2ff; }
.color-list { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.color-list .swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  border: 3px solid transparent;
}
.color-list .swatch.sel { border-color: #1a1a2e; }
#f-color { width: 40px; height: 30px; border: none; background: none; padding: 0; }

#panel-image input[type="file"] { font-size: 14px; }
.img-preview {
  margin-top: 12px;
  width: 80px;
  height: 80px;
  border-radius: 14px;
  background-size: cover;
  background-position: center;
  background-color: #f0f2f8;
  border: 1px solid var(--line);
}

.sheet-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.sheet-actions .spacer { flex: 1; }
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: #eef1f8;
  color: #4a4f63;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { background: #ffe9ec; color: #e23a52; }
.btn:active { transform: scale(0.96); }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  background: rgba(20, 25, 45, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 13.5px;
  z-index: 100;
  max-width: 80%;
  text-align: center;
}
