:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1c1e22;
  --muted: #6b7078;
  --line: #e2e2de;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --danger: #b91c1c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #20232a;
    --text: #eceef1;
    --muted: #9aa0aa;
    --line: #30343d;
    --accent: #f97316;
    --accent-text: #1a1206;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.35;
}
[hidden] { display: none !important; }

header, main, footer { max-width: 640px; margin: 0 auto; }

header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 0.75rem) 16px 0.75rem;
  border-bottom: 1px solid var(--line);
}
.bar { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
h1 { font-size: 1.25rem; margin: 0 0 0.6rem; }
.count { color: var(--muted); font-size: 0.9rem; font-variant-numeric: tabular-nums; }

.search { position: relative; }
/* 16px minimum keeps iOS from zooming the page when the field is focused. */
input[type=search], input[type=text], input[type=password] {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  -webkit-appearance: none;
  appearance: none;
}
input[type=search] { padding-right: 2.8rem; }
input[type=search]::-webkit-search-cancel-button { display: none; }
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.clear {
  position: absolute;
  top: 0; right: 0;
  width: 2.8rem; height: 100%;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

main { padding: 0 16px; }
#list { list-style: none; margin: 0; padding: 0; }
#list li { border-bottom: 1px solid var(--line); }
#list button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.7rem 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: pointer;
}
.empty { color: var(--muted); text-align: center; margin: 2rem 0 0; }

button.primary, .actions button, .login button {
  min-height: 44px;
  padding: 0.6rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button:disabled { opacity: 0.6; }
.add { display: block; width: 100%; margin: 1.25rem 0 0; overflow-wrap: anywhere; }

footer {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem 16px calc(env(safe-area-inset-bottom) + 2rem);
  font-size: 0.9rem;
}
footer a, button.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

dialog {
  width: min(92vw, 460px);
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
label { display: block; margin-bottom: 0.35rem; color: var(--muted); font-size: 0.9rem; }
.actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.spacer { flex: 1; }
.actions .danger { border-color: transparent; background: none; color: var(--danger); padding-left: 0; }
.actions .danger.is-armed { border-color: var(--danger); padding-left: 1rem; font-weight: 600; }
.error { color: var(--danger); font-size: 0.9rem; margin: 0.6rem 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 1.25rem);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 0.7rem 1rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.toast.is-error { background: var(--danger); color: #fff; }

.login {
  max-width: 360px;
  margin: 14vh auto 0;
  padding: 0 16px;
}
.login button { width: 100%; margin-top: 1rem; }
