/* Тема: по умолчанию как в системе; переключатель ставит data-theme на <html> */
:root {
  --bg: #f2f2f0;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #5c5c62;
  --done-text: #6e6e74;
  --line: #e8e8ea;
  --field-border: #8a8a90;
  --accent: #2a2a2d;
  --accent-hover: #000000;
  --on-accent: #ffffff;
  --accent-soft: #eeeef0;
  --check: #47705f;
  --on-check: #ffffff;
  --danger: #b4372d;
  --danger-soft: #f7e7e5;
  --toast-bg: #2a2a2d;
  --toast-text: #f2f2f0;
  --toast-action: #b9dccd;
  --fab-bg: var(--accent);
  --fab-text: var(--on-accent);
  --fab-border: transparent;
  --shadow: 0 1px 2px rgba(20, 20, 30, .05), 0 10px 30px rgba(20, 20, 30, .07);
  color-scheme: light;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214;
    --card: #1c1c1f;
    --text: #ececee;
    --muted: #a1a1a8;
    --done-text: #8b8b92;
    --line: #2c2c30;
    --field-border: #6a6a72;
    --accent: #e6e6e8;
    --accent-hover: #ffffff;
    --on-accent: #1c1c1f;
    --accent-soft: #2a2a2e;
    --check: #8ab8a5;
    --on-check: #14211c;
    --danger: #f0928a;
    --danger-soft: #382426;
    --toast-bg: #e6e6e8;
    --toast-text: #1c1c1f;
    --toast-action: #2f6450;
    --fab-bg: #2a2a2e;
    --fab-text: #ececee;
    --fab-border: #3a3a40;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #121214;
  --card: #1c1c1f;
  --text: #ececee;
  --muted: #a1a1a8;
  --done-text: #8b8b92;
  --line: #2c2c30;
  --field-border: #6a6a72;
  --accent: #e6e6e8;
  --accent-hover: #ffffff;
  --on-accent: #1c1c1f;
  --accent-soft: #2a2a2e;
  --check: #8ab8a5;
  --on-check: #14211c;
  --danger: #f0928a;
  --danger-soft: #382426;
  --toast-bg: #e6e6e8;
  --toast-text: #1c1c1f;
  --toast-action: #2f6450;
  --fab-bg: #2a2a2e;
  --fab-text: #ececee;
  --fab-border: #3a3a40;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  caret-color: var(--text);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(16px, 8vh, 72px) 16px 120px;
}

::selection { background: var(--check); color: var(--on-check); }

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
  border-radius: 8px;
}

button { font: inherit; color: inherit; }

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

.card {
  width: 100%;
  max-width: 540px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 28px 20px;
}

/* Заголовок */

.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.icon-button {
  flex-shrink: 0;
  margin: -6px -8px 0 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.icon-button:hover { color: var(--text); background: var(--accent-soft); }
.icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* Показываем значок той темы, на которую переключит кнопка */
.theme-toggle .icon-sun { display: none; }
.theme-toggle.is-dark .icon-sun { display: block; }
.theme-toggle.is-dark .icon-moon { display: none; }

h1 {
  margin: 0;
  font: 600 clamp(24px, 6vw, 30px)/1.15 "Unbounded", "Onest", system-ui, sans-serif;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.progress {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  min-height: 1.5em;
}

/* Форма добавления */

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

.add-form input {
  flex: 1;
  min-width: 0;
  height: 50px;
  padding: 0 16px;
  border: 1.5px solid var(--field-border);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.add-form input::placeholder { color: var(--muted); opacity: 1; }
.add-form input:focus { outline: none; border-color: var(--text); box-shadow: 0 0 0 3px var(--accent-soft); }
.add-form input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.add-form input.shake { animation: shake .32s ease-in-out; }

.add-button {
  height: 50px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.add-button:hover { background: var(--accent-hover); }
.add-button:active { transform: scale(.97); }

.form-hint {
  margin: 6px 2px 0;
  min-height: 1.4em;
  font-size: 14px;
  color: var(--danger);
}

/* Список */

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

.item {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  min-height: 52px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item.entering { animation: enter .45s var(--ease-out); }

.item.dragging {
  position: relative;
  z-index: 2;
  background: var(--card);
  border-radius: 12px;
  border-bottom-color: transparent;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .06), 0 12px 28px rgba(0, 0, 0, .14);
  cursor: grabbing;
}
body.is-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }

/* Галочка: зона нажатия 44×44, видимый квадрат 24×24 */
.check {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.check input {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 24px;
  height: 24px;
  border: 1.5px solid var(--field-border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: background .2s, border-color .2s, transform .15s;
}
.check:hover input { border-color: var(--check); }
.check input:active { transform: scale(.9); }
.check input:checked { background: var(--check); border-color: var(--check); }
.check input:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.check svg {
  position: absolute;
  width: 16px;
  height: 16px;
  pointer-events: none;
  fill: none;
  stroke: var(--on-check);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 22;
  stroke-dashoffset: 22;
}
.check input:checked + svg { stroke-dashoffset: 0; }
.item.completing .check input:checked + svg { animation: draw .35s var(--ease-out) both; }
.item.completing .text { color: var(--done-text); }

.text {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 6px;
  border: 0;
  background: none;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: text;
  border-radius: 8px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: color .3s, background .15s;
}
.text:hover { background: var(--accent-soft); }

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

.edit {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 9px 8px;
  border: 1.5px solid var(--text);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.delete {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.delete svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.delete:hover { color: var(--danger); background: var(--danger-soft); }

.done-section { margin-top: 16px; padding-top: 6px; border-top: 1px solid var(--line); }

.done-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.done-title { margin: 0; font: inherit; }

.done-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 10px 0 6px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.done-toggle:hover { color: var(--text); }
.chevron { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .25s var(--ease-out); }
.done-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.clear-done {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.clear-done:hover { color: var(--danger); background: var(--danger-soft); }

/* Уведомление с отменой */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 32px);
  white-space: nowrap;
  padding: 6px 6px 6px 18px;
  border-radius: 14px;
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .22);
  animation: toast-in .35s var(--ease-out);
}
.toast[hidden] { display: none; }
.toast-undo {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--toast-action);
  font-weight: 600;
  cursor: pointer;
}
.toast-undo:hover { background: rgba(127, 127, 127, .18); }
.toast-undo:focus-visible { outline-color: var(--toast-action); }

/* Кнопка установки */

.install-fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 18px 0 14px;
  border: 1px solid var(--fab-border);
  border-radius: 24px;
  background: var(--fab-bg);
  color: var(--fab-text);
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .08), 0 8px 24px rgba(0, 0, 0, .16);
  cursor: pointer;
  animation: fab-in .35s var(--ease-out);
  transition: background .15s, bottom .25s var(--ease-out);
}
@keyframes fab-in { from { opacity: 0; transform: translateY(12px); } }
.install-fab[hidden] { display: none; }
.install-fab:hover { filter: brightness(1.12); }
.install-fab svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Уведомление «Вернуть» внизу — кнопка поднимается над ним */
.has-toast .install-fab { bottom: calc(max(20px, env(safe-area-inset-bottom)) + 68px); }

/* Анимации */

@keyframes enter { from { opacity: 0; transform: translateY(-6px); } }
@keyframes draw { from { stroke-dashoffset: 22; } to { stroke-dashoffset: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  /* Без движения: состояния меняются мгновенно, цвет и галочка остаются */
  .item.entering, .toast, .install-fab, .add-form input.shake,
  .item.completing .check input:checked + svg { animation: none; }
  .chevron, .install-fab { transition: none; }
}

@media (max-width: 480px) {
  .card { padding: 24px 16px 12px; border-radius: 16px; }
  .add-button { padding: 0 16px; }
}

@media (max-width: 360px) {
  .add-form input { padding: 0 12px; }
  .add-button { padding: 0 12px; }
}
