:root {
  color-scheme: light dark;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --text: #1c1f1b;
  --muted: #71766e;
  --line: #e8e5de;
  --ring: #cfcbc2;
  --accent: #1f8a4c;
  --accent-soft: #e2f1e7;
  --on-accent: #ffffff;
  --danger: #c63f2c;
  --flash: #fff1b8;
  --toast-bg: #1c1f1b;
  --toast-text: #f5f3ee;
  --toast-accent: #7fdca4;
  --shadow: 0 1px 2px rgb(20 25 20 / 0.06), 0 2px 8px rgb(20 25 20 / 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --surface: #1c1f1c;
    --text: #ecefe9;
    --muted: #979d93;
    --line: #2a2e29;
    --ring: #474d45;
    --accent: #3dbb70;
    --accent-soft: #1d3325;
    --on-accent: #07140c;
    --danger: #ff7b67;
    --flash: #3d3714;
    --toast-bg: #ecefe9;
    --toast-text: #121412;
    --toast-accent: #1f8a4c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 ui-rounded, -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; }

.wrap {
  max-width: 640px;
  margin: 0 auto;
}

/* ---------- header ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 1px 0 var(--line);
  padding: calc(env(safe-area-inset-top) + 12px) max(16px, env(safe-area-inset-right)) 12px
    max(16px, env(safe-area-inset-left));
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ring);
}
.status.live i { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.status.off i { background: #d99a2b; }

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

.add input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 17px; /* >= 16px stops iOS from zooming on focus */
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.add input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.add input::placeholder { color: var(--muted); }

.add-btn {
  flex: none;
  width: 50px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
}
.add-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.add-btn:active { filter: brightness(0.92); }

.suggest {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 10px -16px 0;
  padding: 0 16px 2px;
  scrollbar-width: none;
}
.suggest::-webkit-scrollbar { display: none; }
.suggest:empty { display: none; }

.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 13px 7px 10px;
  font-size: 15px;
  white-space: nowrap;
}
.chip b { color: var(--accent); margin-right: 4px; }
.chip:active { background: var(--accent-soft); }

/* ---------- list ---------- */

main {
  padding: 14px max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 96px)
    max(16px, env(safe-area-inset-left));
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.list:empty { display: none; }

.item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  cursor: pointer;
  outline: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: background-color 0.15s;
}
.item:first-child { border-top: 0; border-radius: 16px 16px 0 0; }
.item:last-child { border-radius: 0 0 16px 16px; }
.item:only-child { border-radius: 16px; }
.item:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.item:active:not(.editing) { background: color-mix(in srgb, var(--text) 5%, var(--surface)); }
.item.armed { background: var(--accent-soft); }

.check {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--ring);
  display: grid;
  place-items: center;
  transition: background-color 0.15s, border-color 0.15s;
}
.check svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--on-accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}
.item.is-done .check { background: var(--accent); border-color: var(--accent); }
.item.is-done .check svg { opacity: 1; }

.text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item.is-done .text { color: var(--muted); text-decoration: line-through; }
.item.editing .text { display: none; }

.edit {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 17px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--accent);
  border-radius: 0;
  padding: 4px 0;
  outline: none;
}

.del {
  flex: none;
  border: 0;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 12px;
}

.item.enter { animation: enter 0.25s ease-out; }
.item.flash { animation: flash 1.8s ease-out; }
.item.enter.flash { animation: enter 0.25s ease-out, flash 1.8s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(-6px); } }
@keyframes flash { from { background-color: var(--flash); } }

.done-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 26px 4px 6px;
}
h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.clear {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 650;
  padding: 8px 4px;
}

.empty { text-align: center; color: var(--muted); padding: 40px 16px 16px; margin: 0; }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 28px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 6px 6px 6px 16px;
  border-radius: 14px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 15px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.22);
  animation: enter 0.2s ease-out;
}
.toast[hidden] { display: none; }
#toast-msg { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast button {
  flex: none;
  border: 0;
  background: none;
  color: var(--toast-accent);
  font-weight: 700;
  padding: 10px 12px;
}

@media (prefers-reduced-motion: reduce) {
  .item.enter, .item.flash, .item.enter.flash, .toast { animation: none; }
}

/* ---------- login ---------- */

.login {
  max-width: 360px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18vh) 24px 40px;
  text-align: center;
}
.login-icon { border-radius: 18px; box-shadow: var(--shadow); }
.login h1 { margin: 16px 0 24px; }
.login form { display: grid; gap: 12px; }
.login input {
  font: inherit;
  font-size: 17px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login button {
  border: 0;
  border-radius: 14px;
  padding: 14px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
}
.login-error { margin: 4px 0 0; color: var(--danger); font-size: 15px; }
