/* ====== 1. 基础变量与重置 ====== */
:root {
  --page: #f3f0e8;
  --surface: #fffdf8;
  --surface-muted: #f7f4ed;
  --ink: #1d2925;
  --muted: #5f6c66;
  --faint: #6b7771;
  --line: #e5dfd3;
  --line-strong: #d4ccbd;
  --accent: #1f6b58;
  --accent-dark: #155143;
  --accent-soft: #e4f1eb;
  --accent-line: #b8d5ca;
  --danger: #a8423b;
  --danger-soft: #f8e7e3;
  --focus: #2b7f69;
  --shadow: 0 24px 60px rgba(53, 66, 58, 0.10), 0 2px 8px rgba(53, 66, 58, 0.05);
  --font: "Avenir Next", "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  background:
    radial-gradient(circle at 8% 0%, rgba(216, 233, 205, 0.72), transparent 36%),
    radial-gradient(circle at 94% 22%, rgba(243, 219, 196, 0.62), transparent 30%),
    var(--page);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:not(:disabled) {
  -webkit-tap-highlight-color: transparent;
}

::selection {
  color: var(--ink);
  background: var(--accent-soft);
}

[hidden] {
  display: none !important;
}

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

/* ====== 2. 页面布局 ====== */
.page-shell {
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: 48px 0 28px;
}

.site-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  animation: rise 0.45s ease both;
}

.header-copy {
  min-width: 0;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 11px;
  color: var(--accent);
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.eyebrow-mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 0.72rem;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.subtitle {
  max-width: 46ch;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 1rem;
}

.date-chip {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.72);
  box-shadow: 0 4px 14px rgba(53, 66, 58, 0.04);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.date-chip::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

/* ====== 3. 主卡片 ====== */
.app-card {
  position: relative;
  overflow: hidden;
  padding: 32px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 28px;
  background: rgba(255, 253, 248, 0.95);
  box-shadow: var(--shadow);
  animation: rise 0.5s 0.08s ease both;
}

.app-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--accent) 0 48%, #d4bc8b 48% 72%, #dca28c 72%);
  content: "";
}

.card-intro h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.card-intro p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.noscript {
  margin: 24px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 0.86rem;
}

/* ====== 4. 输入表单 ====== */
.task-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  margin-top: 20px;
}

.field {
  min-width: 0;
}

#task-input {
  width: 100%;
  height: 54px;
  padding: 0 16px;
  border: 1.5px solid var(--line-strong);
  border-radius: 14px;
  color: var(--ink);
  background: #fffefb;
  font-size: 1rem;
  box-shadow: inset 0 1px 2px rgba(53, 66, 58, 0.03);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

#task-input::placeholder {
  color: var(--faint);
}

#task-input:hover {
  border-color: #bdb4a4;
}

#task-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(31, 107, 88, 0.13);
}

#task-input[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px rgba(168, 66, 59, 0.10);
}

.input-hint,
.form-feedback {
  margin: 8px 4px 0;
  font-size: 0.78rem;
  line-height: 1.45;
}

.input-hint {
  color: var(--faint);
}

.form-feedback {
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 600;
}

.form-feedback:empty {
  display: none;
}

/* ====== 5. 按钮 ====== */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.button-primary {
  min-height: 54px;
  padding: 0 22px;
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 8px 18px rgba(31, 107, 88, 0.20);
  white-space: nowrap;
}

.button-plus {
  margin-top: -2px;
  font-size: 1.3rem;
  font-weight: 400;
  line-height: 1;
}

.button-quiet {
  min-height: 44px;
  border-color: var(--line-strong);
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  white-space: nowrap;
}

.button:focus-visible,
.task-checkbox:focus-visible,
.delete-button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

/* ====== 6. 进度与工具栏 ====== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  margin-top: 24px;
  padding: 16px 16px 16px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-muted);
}

.progress-panel {
  flex: 1 1 220px;
  min-width: 0;
}

.progress-copy {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.progress-count {
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  width: 100%;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2ddd2;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2d806b, #69aa93);
  transition: width 0.35s ease;
}

/* ====== 7. 任务列表 ====== */
.task-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.list-heading h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: -0.01em;
}

.task-count {
  color: var(--faint);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.task-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffefb;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  animation: task-in 0.24s ease both;
}

.task-item.is-completed {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.task-toggle {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 44px;
  cursor: pointer;
}

.task-checkbox {
  display: grid;
  flex: 0 0 24px;
  place-items: center;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid #a4afa9;
  border-radius: 8px;
  appearance: none;
  -webkit-appearance: none;
  background: #fffefb;
  cursor: pointer;
  transition: border-color 0.18s ease, background-color 0.18s ease;
}

.task-checkbox::after {
  width: 5px;
  height: 10px;
  margin-top: -2px;
  border: solid #ffffff;
  border-width: 0 2px 2px 0;
  content: "";
  transform: rotate(45deg) scale(0);
  transform-origin: center;
  transition: transform 0.15s ease;
}

.task-checkbox:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.task-checkbox:checked::after {
  transform: rotate(45deg) scale(1);
}

.task-title {
  font-size: 0.96rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  transition: color 0.2s ease;
}

.is-completed .task-title {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: rgba(29, 41, 37, 0.35);
  text-decoration-thickness: 1.5px;
}

.delete-button {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  color: var(--faint);
  background: transparent;
  font-size: 0.8rem;
  cursor: pointer;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.empty-state {
  padding: 34px 20px 36px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: var(--surface-muted);
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin: 0 auto 12px;
  border-radius: 50%;
  color: #927e59;
  background: #ece5d7;
}

.empty-icon svg {
  width: 24px;
  height: 24px;
}

.empty-state h3 {
  margin: 0;
  font-size: 0.95rem;
}

.empty-state p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ====== 8. 页脚 ====== */
.site-footer {
  padding: 18px 8px 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.storage-note {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  line-height: 1.5;
}

.status-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-line);
}

.storage-note.has-error {
  color: var(--danger);
}

.storage-note.has-error .status-dot {
  background: var(--danger);
}

/* ====== 9. 动效与无障碍偏好 ====== */
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes task-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (hover: hover) {
  .button-primary:hover {
    background: var(--accent-dark);
    box-shadow: 0 10px 22px rgba(31, 107, 88, 0.23);
    transform: translateY(-1px);
  }

  .button-quiet:hover:not(:disabled) {
    border-color: #e8c4bd;
    color: var(--danger);
    background: var(--danger-soft);
  }

  .task-item:hover {
    border-color: var(--line-strong);
  }

  .task-item.is-completed:hover {
    border-color: var(--accent-line);
  }

  .delete-button:hover {
    color: var(--danger);
    background: var(--danger-soft);
  }
}

.button-primary:active:not(:disabled) {
  transform: translateY(0);
}

/* ====== 10. 手机适配 ====== */
@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 24px, 760px);
    padding: 28px 0 22px;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 20px;
  }

  .date-chip {
    align-self: flex-start;
    margin: 0;
    white-space: normal;
  }

  .app-card {
    padding: 22px;
    border-radius: 22px;
  }

  .task-form {
    grid-template-columns: 1fr;
  }

  .button-primary {
    width: 100%;
  }

  .toolbar {
    align-items: stretch;
    padding: 14px;
  }

  .button-quiet {
    width: 100%;
  }
}

@media (max-width: 400px) {
  .page-shell {
    width: min(100% - 20px, 760px);
    padding-top: 22px;
  }

  h1 {
    font-size: 2.15rem;
  }

  .app-card {
    padding: 18px;
  }

  .task-item {
    gap: 2px;
    padding: 8px 6px 8px 12px;
  }

  .task-toggle {
    gap: 10px;
  }
}

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