:root {
  /* lets the browser draw its own controls (date picker icon, calendar) to match the theme */
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --radius: 14px;
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --text: #eceef1;
    --muted: #9aa1ac;
    --border: #2b2f37;
    --accent: #818cf8;
    --accent-text: #111317;
    --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, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app {
  max-width: 560px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

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

.top {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 0 12px;
}

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.count {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

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

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

/* 16px font keeps iOS Safari from zooming in on focus */
.add-row input {
  flex: 1;
  min-width: 0;
  height: var(--tap);
  padding: 0 14px;
  font-size: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.due-field {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.due-field input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  font-size: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.add-btn {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  font-size: 1.6rem;
  line-height: 1;
  color: var(--accent-text);
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
}

.add-btn:active {
  transform: scale(0.95);
}

.filters {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filters button {
  flex: 1;
  min-height: 40px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  background: transparent;
  border: 0;
  border-radius: 10px;
}

.filters button[aria-pressed='true'] {
  color: var(--accent-text);
  background: var(--accent);
}

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

.todo-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.todo {
  display: flex;
  align-items: center;
  min-height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.todo-check {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--tap);
  align-self: stretch;
  cursor: pointer;
}

.todo-check input {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.todo-text {
  flex: 1;
  min-width: 0;
  padding: 14px 4px;
  text-align: left;
  overflow-wrap: anywhere;
  background: transparent;
  border: 0;
}

.todo-title,
.todo-due,
.todo-notes {
  display: block;
}

.todo.done .todo-title {
  color: var(--muted);
  text-decoration: line-through;
}

.todo-due,
.todo-notes {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.85rem;
}

.todo-due.soon {
  color: var(--accent);
  font-weight: 600;
}

.todo-due.overdue {
  color: var(--danger);
  font-weight: 600;
}

.todo-notes {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  white-space: pre-line;
}

.todo-delete {
  flex: none;
  width: var(--tap);
  align-self: stretch;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
}

.todo-delete:hover,
.todo-delete:active {
  color: var(--danger);
}

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

/* ---------- footer ---------- */

.bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.clear-btn,
.install-btn {
  min-height: 44px;
  padding: 0 18px;
  color: var(--danger);
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.install-btn {
  color: var(--accent);
}

input[type='date'] {
  cursor: pointer;
}

/* ---------- task details sheet ---------- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  margin: auto auto 0;
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-radius: 20px 20px 0 0;
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.sheet form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
}

.sheet h2 {
  margin: 0;
  font-size: 1.2rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.field input,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px;
  color: var(--text);
  font-size: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.field textarea {
  resize: vertical;
}

.sheet-actions {
  display: flex;
  gap: 8px;
}

.sheet-actions button {
  flex: 1;
  min-height: var(--tap);
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.sheet-actions .primary {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

@media (min-width: 600px) {
  .sheet {
    margin: auto;
    border-radius: 20px;
  }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  color: #ffffff;
  font-size: 0.9rem;
  background: #b91c1c;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

@media (prefers-reduced-motion: no-preference) {
  .add-btn,
  .filters button,
  .todo-delete {
    transition: transform 0.1s, background-color 0.15s, color 0.15s;
  }
}
