:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a1c20;
  --muted: #6b7280;
  --border: #e3e6ea;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --radius: 10px;
  --tap: 2.75rem;
  --pad: clamp(1rem, 4vw, 2rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --text: #e8eaed;
    --muted: #9aa2ad;
    --border: #2b3038;
    --accent: #f97316;
    --accent-text: #1a1c20;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(1.25rem, 5vw, 3rem) var(--pad);
  padding-left: max(var(--pad), env(safe-area-inset-left));
  padding-right: max(var(--pad), env(safe-area-inset-right));
  padding-bottom: max(clamp(1.25rem, 5vw, 3rem), env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 34rem;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.5rem, 5vw, 1.875rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0 0 clamp(1.25rem, 4vw, 1.75rem);
  color: var(--muted);
  font-size: clamp(0.8125rem, 2.6vw, 0.875rem);
}

.new-todo {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.new-todo input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.85rem;
  /* 16px minimum stops iOS Safari zooming on focus */
  font: inherit;
  font-size: max(1rem, 16px);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: var(--tap);
}

.new-todo input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  min-height: var(--tap);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  border-color: var(--accent);
}

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

.add {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  padding: 0.7rem 1.1rem;
  flex-shrink: 0;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.filters button {
  padding: 0.35rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--muted);
  min-height: 2.25rem;
}

.filters button.active {
  color: var(--text);
  border-color: var(--accent);
}

.todos {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.todos li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem 0.35rem 0.9rem;
  border-bottom: 1px solid var(--border);
  min-height: 3rem;
}

.todos li:last-child {
  border-bottom: none;
}

.todos label {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  min-width: 0;
  padding: 0.5rem 0;
  min-height: var(--tap);
}

.todos span {
  overflow-wrap: anywhere;
  min-width: 0;
}

.todos li.completed span {
  color: var(--muted);
  text-decoration: line-through;
}

.todos input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}

.delete {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
  min-width: var(--tap);
  min-height: var(--tap);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.delete:hover {
  color: var(--accent);
}

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.85rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.clear {
  font-size: 0.8125rem;
  color: var(--muted);
  min-height: 2.25rem;
  padding: 0.35rem 0.75rem;
}

/* Tablet and up: a little more room, larger type */
@media (min-width: 40rem) {
  .app {
    max-width: 36rem;
  }

  .todos li {
    padding: 0.4rem 0.6rem 0.4rem 1.1rem;
  }

  footer {
    font-size: 0.875rem;
  }
}

/* Desktop: wider column, comfortable measure */
@media (min-width: 64rem) {
  body {
    padding-top: clamp(3rem, 8vh, 6rem);
  }

  .app {
    max-width: 38rem;
  }

  .new-todo input {
    padding: 0.8rem 1rem;
  }
}

/* Short landscape phones: stop the page from scrolling under the keyboard */
@media (max-height: 28rem) and (orientation: landscape) {
  body {
    padding-top: 1rem;
  }

  h1 {
    font-size: 1.375rem;
  }

  .subtitle {
    display: none;
  }
}

/* Very narrow phones */
@media (max-width: 22.5rem) {
  .new-todo {
    flex-direction: column;
  }

  .add {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
