:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #15803d;
  --danger: #b91c1c;
  --danger-bg: #fdecec;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --card: #1b1f25;
    --text: #e6e8eb;
    --muted: #9aa3ae;
    --border: #2c323a;
    --accent: #60a5fa;
    --accent-text: #0b1220;
    --ok: #4ade80;
    --danger: #f87171;
    --danger-bg: #3a1c1c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding: 48px 16px;
}

.card {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}

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

h1 { margin: 0; font-size: 1.4rem; }

.backend {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.backend button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
}

.backend button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

/* 窄螢幕（手機）：六個後端排成一行放不下，改成三欄兩列、佔滿整行 */
@media (max-width: 560px) {
  .backend {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    border-radius: 14px;
  }
  .backend button {
    padding: 6px 4px;
    border-radius: 10px;
  }
}

.status {
  margin: 12px 0 20px;
  font-size: 0.85rem;
  color: var(--muted);
}
.status[data-state="ok"]::before { content: "● "; color: var(--ok); }
.status[data-state="error"]::before { content: "● "; color: var(--danger); }

.add { display: flex; gap: 8px; }

.add input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
}

.add button {
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  cursor: pointer;
}
.add button:disabled { opacity: 0.6; cursor: wait; }

.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.9rem;
}

.items { list-style: none; margin: 16px 0 0; padding: 0; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
}

.check { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
.check input { width: 18px; height: 18px; flex: none; }
.name { overflow-wrap: anywhere; }
.item.done .name { color: var(--muted); text-decoration: line-through; }

.created { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.delete {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.delete:hover { color: var(--danger); background: var(--danger-bg); }

.empty { margin: 24px 0 8px; text-align: center; color: var(--muted); }

.foot { margin-top: 24px; font-size: 0.8rem; color: var(--muted); }
.foot a { color: var(--accent); margin-left: 4px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 420px) {
  .created { display: none; }
}
