:root {
  --paper: #edf1ec;
  --surface: #fafcf9;
  --ink: #16201b;
  --muted: #5f6e66;
  --rule: #cbd6ce;
  --accent: #1d5c48;
  --accent-ink: #f2f7f3;
  --danger: #99372b;

  --serif: ui-serif, "Iowan Old Style", Charter, "Bitstream Charter", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  padding: 12vh 1.25rem 6rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 33rem;
  margin: 0 auto;
}

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.55rem;
  border-bottom: 1.5px solid var(--ink);
}

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.9rem, 6vw, 2.35rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1;
}

.count {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.new {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0 0.85rem;
  border-bottom: 1px solid var(--rule);
}

.new input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.new input::placeholder { color: var(--muted); opacity: 0.75; }

/* The rule under the field is the focus indicator — a rectangle around a borderless
   input reads as a box that is not there. */
.new:focus-within { border-bottom-color: var(--accent); }
.new input:focus-visible { outline: none; }

.new button {
  flex: none;
  padding: 0.3rem 0.9rem;
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.new button:hover { background: var(--accent); color: var(--accent-ink); }

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

.list li {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.72rem 0;
  border-bottom: 1px solid var(--rule);
}

.list li.enter { animation: rise 180ms ease-out; }

@keyframes rise {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: none; }
}

.list label {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.list input[type="checkbox"] {
  position: relative;
  flex: none;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.list input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 0.13rem;
  left: 0.33rem;
  width: 0.26rem;
  height: 0.5rem;
  border: solid var(--accent-ink);
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(42deg) scale(0);
  transition: transform 120ms ease;
}

.list input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.list input[type="checkbox"]:checked::after { transform: rotate(42deg) scale(1); }

.text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.done .text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--rule);
}

.delete {
  flex: none;
  padding: 0 0.2rem;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms ease, color 120ms ease;
}

.list li:hover .delete,
.list li:focus-within .delete { opacity: 1; }

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

.empty {
  margin: 1.6rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.error {
  margin: 0.9rem 0 0;
  padding-left: 0.65rem;
  border-left: 2px solid var(--danger);
  color: var(--danger);
  font-size: 0.9rem;
}

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

.list input[type="checkbox"]:focus-visible { outline-offset: 3px; }

.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;
}

::selection { background: #cfe2d7; }

@media (hover: none) {
  .delete { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
