:root {
  --bg: #f5f4f0;
  --panel: #ffffff;
  --ink: #1c1b18;
  --ink-2: #6b6a63;
  --line: #e4e2da;
  --accent: #2f6fed;
  --accent-soft: #e8effc;
  --green: #1f9d55;
  --green-soft: #e6f6ec;
  --danger: #d64545;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 27, 24, .05), 0 4px 16px rgba(28, 27, 24, .05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  min-width: 0;
}

.progress-wrap {
  flex: 1 1 140px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.progress-text {
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}

.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #5b8cf5);
  border-radius: 3px;
  transition: width .3s ease;
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

/* ---------- 按钮 ---------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease;
}

.btn:hover { border-color: #c9c6bb; }
.btn:active { background: #f0eee8; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: #265fce; border-color: #265fce; }
.btn-primary:active { background: #1f52b6; }

.btn-ghost { background: transparent; }

.btn.danger { color: var(--danger); }

.icon-btn {
  appearance: none;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-2);
  padding: 4px 8px;
  border-radius: 8px;
}

.icon-btn:hover { background: #f0eee8; color: var(--ink); }

/* ---------- 布局与面板 ---------- */

.layout {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 16px;
  font-weight: 700;
  min-width: 0;
}

.count {
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-2);
  margin-left: 4px;
}

/* 添加按钮：编辑模式下显示 */
.add-btn { display: none; }
body.edit-mode .add-btn { display: inline-block; }

/* ---------- 表格 ---------- */

.list {
  width: 100%;
  border-collapse: collapse;
}

.list th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

.list td {
  padding: 2px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.list tbody tr:last-child td { border-bottom: none; }

.col-chk { width: 64px; text-align: center; }
.col-del { width: 40px; }
.col-handle { width: 40px; text-align: center; }

/* 行操作列：桌面拖拽手柄 / 触屏 ↑↓+移入（编辑模式才显示） */
.drag-handle, .row-mover { display: none; }

body.edit-mode .drag-handle {
  display: inline-block;
  cursor: grab;
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body.edit-mode .drag-handle:active { cursor: grabbing; color: var(--accent); }

.row-mover {
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex-wrap: wrap;
}

.mv-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 12px;
  line-height: 1;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  cursor: pointer;
}

.mv-btn:hover { border-color: #c9c6bb; color: var(--ink); }
.mv-btn:active { background: #f0eee8; }

.mv-to {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 11px;
  line-height: 1;
  height: 26px;
  border-radius: 7px;
  padding: 0 2px;
  max-width: 118px;
  cursor: pointer;
}

/* 桌面（有 hover）显示手柄；触屏显示 ↑↓/移入 */
@media (hover: hover) and (pointer: fine) {
  body.edit-mode .drag-handle { display: inline-block; }
  body.edit-mode .row-mover { display: none; }
}

@media (hover: none) and (pointer: coarse) {
  body.edit-mode .drag-handle { display: none; }
  body.edit-mode .row-mover { display: inline-flex; }
}

/* 拖拽指示线 */
.dragging { opacity: .45; }

.drop-before td { box-shadow: inset 0 3px 0 -1px var(--accent); }
.drop-after td { box-shadow: inset 0 -3px 0 -1px var(--accent); }
.drop-tail tr:last-child td { box-shadow: inset 0 -3px 0 -1px var(--accent); }
.drop-highlight {
  background: var(--accent-soft);
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.name-input {
  width: 100%;
  min-width: 0;
  border: 1px solid transparent;
  background: transparent;
  font-size: 15px;
  color: var(--ink);
  padding: 8px 6px;
  border-radius: 8px;
  font-family: inherit;
}

.name-input:hover { border-color: var(--line); }
.name-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

/* 复选框（大点击区） */
.chk-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  cursor: pointer;
  border-radius: 8px;
}

.chk-wrap:hover { background: #f4f2ec; }

.chk-wrap input {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border: 2px solid #c9c6bb;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background .15s ease, border-color .15s ease;
}

.chk-wrap input:checked { border-color: var(--green); }

.chk-wrap input:checked::after {
  content: '';
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.chk-wrap input.bought:checked { background: var(--green); border-color: var(--green); }
.chk-wrap input.packed:checked { background: var(--accent); border-color: var(--accent); }

/* 删除按钮：编辑模式下显示 */
.del-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-size: 18px;
  line-height: 1;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
}

body.edit-mode .del-btn {
  opacity: 1;
  pointer-events: auto;
}

.del-btn:hover { background: #fdecec; color: var(--danger); }

.empty-hint {
  display: none;
  padding: 18px 14px;
  font-size: 13px;
  color: var(--ink-2);
  text-align: center;
}

.empty-hint.show { display: block; }

.page-foot {
  text-align: center;
  font-size: 12px;
  color: var(--ink-2);
  padding: 12px 16px 20px;
}

/* ---------- 弹窗 ---------- */

.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(20, 19, 16, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-mask[hidden] { display: none; }

.modal {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0, 0, 0, .2);
  width: 100%;
  max-width: 380px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 { font-size: 16px; }

.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.modal-hint { font-size: 13px; color: var(--ink-2); }

.sync-pass {
  width: 100%;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
}

.sync-pass:focus { outline: none; border-color: var(--accent); }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(28, 27, 24, .92);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
  max-width: 86vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 桌面微调 ---------- */

@media (min-width: 760px) {
  .topbar { padding: 12px 24px; }
  .layout { padding: 24px 16px 12px; max-width: 780px; }
  .name-input { font-size: 16px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --panel: #1e1e23;
    --ink: #ececf0;
    --ink-2: #9b9ba5;
    --line: #2c2c33;
    --accent-soft: #1d2c4d;
    --green-soft: #14301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
  .topbar { background: rgba(30, 30, 35, .92); }
  .chk-wrap:hover { background: #26262d; }
  .del-btn:hover { background: #3a2226; }
  .icon-btn:hover { background: #26262d; }
  .name-input:focus { background: #232329; }
  .btn:active { background: #26262d; }
}
