/* 待办清单 · 移动端优先样式（无外部字体、无 CDN） */

:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #111827;
  --muted: #6b7280;
  --border: #e4e7ec;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --danger: #dc2626;
  --done: #98a2b3;
  --header-bg: rgba(244, 245, 247, 0.88);
  --toast-bg: #1f2937;
  --toast-ink: #f8fafc;
  --toast-action: #93c5fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d10;
    --surface: #15181e;
    --surface-2: #1c2029;
    --text: #e8edf5;
    --muted: #9aa7b8;
    --border: #262b35;
    --border-strong: #38404d;
    --accent: #3b82f6;
    --accent-ink: #ffffff;
    --accent-soft: #16233d;
    --danger: #f87171;
    --done: #64748b;
    --header-bg: rgba(11, 13, 16, 0.84);
    --toast-bg: #e5e9f0;
    --toast-ink: #111827;
    --toast-action: #1d4ed8;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.45), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.banner {
  margin: 0;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  background: #fef3c7;
  color: #78350f;
  font-size: 13px;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .banner {
    background: #3f2d0c;
    color: #fde68a;
  }
}

/* 头部 */

.app-header,
.app-main,
.app-footer {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: calc(12px + env(safe-area-inset-top));
  padding-bottom: 10px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.summary {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.install-btn {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.install-btn:active {
  transform: scale(0.97);
}

/* 主体 */

.app-main {
  flex: 1 0 auto;
  padding-top: 14px;
  padding-bottom: 8px;
}

.add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

#new-todo {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#new-todo::placeholder {
  color: var(--muted);
}

#new-todo:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-primary {
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 600;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn-primary:active {
  transform: scale(0.97);
  filter: brightness(0.94);
}

/* 筛选 tab */

.tabs {
  display: flex;
  gap: 4px;
  margin: 14px 0 12px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-2);
}

.tab {
  flex: 1 1 0;
  min-height: 40px;
  padding: 0 6px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

.tab-count {
  margin-left: 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* 列表 */

.list-wrap {
  min-height: 120px;
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 40px 40px;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  padding: 4px 8px 4px 2px;
  border-bottom: 1px solid var(--border);
}

.row:last-child {
  border-bottom: 0;
}

.check {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
}

.check-mark {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 2px solid var(--border-strong);
  border-radius: 50%;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.check-mark::after {
  content: "";
  width: 6px;
  height: 11px;
  margin-top: -2px;
  border-right: 2px solid var(--accent-ink);
  border-bottom: 2px solid var(--accent-ink);
  transform: rotate(45deg) scale(0);
  transition: transform 0.15s ease;
}

.check[aria-pressed="true"] .check-mark {
  background: var(--accent);
  border-color: var(--accent);
}

.check[aria-pressed="true"] .check-mark::after {
  transform: rotate(45deg) scale(1);
}

.row-text {
  min-width: 0;
  padding: 8px 2px;
  font-size: 16px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  cursor: text;
}

.row.is-done .row-text {
  color: var(--done);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.row-edit {
  width: 100%;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 16px;
  outline: none;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.icon-btn:active {
  background: var(--surface-2);
}

.icon-btn.del:active {
  color: var(--danger);
  background: rgba(220, 38, 38, 0.1);
}

.empty {
  margin: 0;
  padding: 40px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

/* 底部 */

.app-footer {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding-top: 8px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.link-btn {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 14px;
}

.link-btn:disabled {
  color: var(--muted);
  opacity: 0.55;
  cursor: default;
}

.dot {
  color: var(--muted);
  font-size: 12px;
}

.insecure-hint {
  flex-basis: 100%;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  text-align: center;
}

/* 撤销提示条 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100vw - 32px);
  padding: 8px 10px 8px 16px;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.24);
  transform: translateX(-50%);
  animation: toast-in 0.16s ease-out;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.toast-action {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--toast-action);
  font-size: 14px;
  font-weight: 600;
}

/* 备份弹窗 */

.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.dialog h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.dialog-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

#backup-text {
  width: 100%;
  min-height: 150px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.btn-ghost {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}

.btn-ghost:active {
  background: var(--surface-2);
}

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

@media (max-width: 340px) {
  .row {
    grid-template-columns: 40px minmax(0, 1fr) 36px 36px;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }
}
