/* 固定浅色、克制的暖中性色。刻意不做暗色模式。 */
:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --text: #2b2926;
  --muted: #9a948c;
  --faint: #c4bfb8;   /* placeholder、计数这类纯装饰 */
  --icon: #9a948c;    /* 图标按钮：触屏没有 hover 可依赖，必须自己够清楚 */
  --line: #ece9e4;
  --line-strong: #ddd8d1;
  --focus: #4a5568;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 620px;
  margin: 0 auto;
  padding: 32px 16px calc(96px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

h1 {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* ------------------------------------------------------------- 输入 */

#addForm {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

#addInput {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .12s;
}
#addInput::placeholder { color: var(--faint); }
#addInput:focus { border-color: var(--focus); }

#addBtn {
  flex: none;
  height: 44px;
  padding: 0 18px;
  font: inherit;
  font-weight: 500;
  color: var(--surface);
  background: var(--text);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
#addBtn:active { opacity: .8; }

/* ------------------------------------------------------------- 列表 */

#active, #done {
  list-style: none;
  margin: 0;
  padding: 0;
}

#active { counter-reset: rank; }
#active > .row { counter-increment: rank; }
#active > .row .num::before { content: counter(rank); }

.row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 46px;
  padding: 4px 8px 4px 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 6px;
}

.handle {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 38px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--icon);
  cursor: grab;
  touch-action: none;   /* 让触屏拖拽不被页面滚动抢走 */
}
.handle:active { cursor: grabbing; }
.handle svg { width: 10px; height: 16px; fill: currentColor; }

.num {
  flex: none;
  min-width: 20px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--muted);
}

.check {
  flex: none;
  width: 19px;
  height: 19px;
  margin: 0 2px 0 6px;
  accent-color: var(--text);
  cursor: pointer;
}

.text {
  flex: 1;
  min-width: 0;
  padding: 5px 4px;
  border-radius: 6px;
  outline: none;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  cursor: text;
}
.text:focus { background: #f4f2ef; }

.row.is-done .text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--faint);
}

.top, .del {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--icon);
  cursor: pointer;
}
.top svg, .del svg { width: 14px; height: 14px; fill: currentColor; }
.top:hover, .del:hover { color: var(--text); background: #f4f2ef; }
.row:first-child .top { visibility: hidden; }   /* 已经在第一位 */

/* 拖拽中：drag-ghost 是留在原位的占位，drag-float 是跟着手指/鼠标走的那个 */
.row.dragging { opacity: .35; }
.row.drag-ghost { background: #f4f2ef; }
.row.drag-float {
  opacity: 1 !important;
  border-color: var(--line-strong);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
  cursor: grabbing;
}

/* 新加的条目闪一下，因为它落在列表底部 */
@keyframes flash { from { background: #f0ede8; } to { background: var(--surface); } }
.row.just-added { animation: flash 1.4s ease-out; }

/* ------------------------------------------------------------- 已完成 */

.hint {
  margin: 14px 2px;
  color: var(--faint);
  font-size: 14px;
}

#doneSection { margin-top: 26px; }

.done-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
}
.done-toggle .caret {
  display: inline-block;
  transition: transform .15s;
}
.done-toggle[aria-expanded="true"] .caret { transform: rotate(90deg); }
.count {
  font-variant-numeric: tabular-nums;
  color: var(--faint);
}

#donePanel { padding-top: 6px; }
#done .row { background: transparent; border-color: transparent; min-height: 40px; }
#done .row .text { padding-left: 0; }

.linkbtn {
  margin: 6px 0 0 4px;
  padding: 4px 0;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.linkbtn:hover { color: var(--text); }

/* ------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  font-size: 14px;
  color: #f7f6f4;
  background: #35322e;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .16);
}
#toastAction {
  font: inherit;
  font-weight: 600;
  color: #f7f6f4;
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* 请求超过 400ms 才变灰，正常情况完全无感 */
body.busy main { opacity: .55; pointer-events: none; }

[hidden] { display: none !important; }
