:root {
  --bg: #0f1115;
  --fg: #e6e8eb;
  --muted: #9aa0a6;
  --border: #2a2f3a;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --card-bg: #16191f;
  --input-bg: #0d0f12;
  --shadow: rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e6e8eb;
    --muted: #9aa0a6;
    --border: #2a2f3a;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --card-bg: #16191f;
    --input-bg: #0d0f12;
    --shadow: rgba(0,0,0,0.3);
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --fg: #171717;
    --muted: #5f6368;
    --border: #e4e6eb;
    --primary: #0066cc;
    --primary-hover: #0052a3;
    --danger: #dc2626;
    --success: #15803d;
    --card-bg: #f4f5f7;
    --input-bg: #ffffff;
    --shadow: rgba(0,0,0,0.08);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100dvh;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  line-height: 1.4;
  min-height: 100dvh;
}

main {
  max-width: 34rem;
  margin-inline: auto;
  padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.hidden { display: none !important; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 4px 12px var(--shadow);
}

#auth-view h1 {
  text-align: center;
  margin: 0 0 1rem 0;
  font-size: 1.75rem;
  font-weight: 600;
}

#auth-form,
#auth-form form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#list li.empty {
  display: block;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--muted);
  text-align: center;
  padding: 2.5rem 1rem;
}

#status-pill.signedout .dot { background: var(--danger); }

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

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 1rem;
  font-size: 16px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--fg);
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

#auth-error {
  color: var(--danger);
  font-size: 0.875rem;
  min-height: 1.25rem;
}

button {
  padding: 0.875rem 1.5rem;
  font-size: 16px;
  font-weight: 500;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 150ms, transform 50ms;
  min-height: 44px;
}

button:active {
  transform: scale(0.98);
}

#auth-form button[type="submit"] {
  background: var(--primary);
  color: white;
}

#auth-form button[type="submit"]:hover {
  background: var(--primary-hover);
}

#create-account {
  background: transparent;
  color: var(--muted);
  margin-top: 0.5rem;
}

#create-account:hover {
  color: var(--fg);
}

#app-view header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

#app-view h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

#status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8125rem;
  color: var(--muted);
}

#status-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

#status-pill.syncing .dot {
  background: var(--primary);
  animation: pulse 1.5s infinite;
}

#status-pill.offline .dot {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

#sign-out {
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 1rem;
}

#sign-out:hover {
  color: var(--fg);
}

#composer {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

#todo-input {
  flex: 1;
  padding: 0.875rem 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--fg);
  font-size: 16px;
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
}

#todo-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

#composer button[type="submit"] {
  background: var(--primary);
  color: white;
  min-width: 44px;
}

#composer button[type="submit"]:hover {
  background: var(--primary-hover);
}

#list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 0.5rem;
  transition: transform 150ms, box-shadow 150ms;
}

#list li:hover {
  box-shadow: 0 4px 12px var(--shadow);
}

#list .check {
  /* SPEC §8 wants a 44px touch target; a 44px *checkbox* looks absurd in a row, so the label is
     the target and the glyph is drawn 24px inside it. The input itself keeps the full 44px box
     and stays transparent, so a tap anywhere near the box toggles it. */
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  margin: -10px 6px -10px -10px;
}

#list .check::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  background: var(--input-bg);
  pointer-events: none;
}

#list .check input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

#list .check:has(input:checked)::after {
  border-color: var(--primary);
  background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l4 4 8-8.5'/%3E%3C/svg%3E") center / 18px 18px no-repeat;
}

#list .check:has(input:focus-visible)::after {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

/* Browsers without :has() (pre-2023 Safari) get the native control back: the tap target is then
   the 24px glyph, which is worse but never invisible. */
@supports not (selector(:has(:checked))) {
  #list .check::after { content: none; }
  #list .check input[type="checkbox"] {
    appearance: auto;
    -webkit-appearance: auto;
    accent-color: var(--primary);
    width: 24px;
    height: 24px;
  }
}

#list .todo-title {
  flex: 1;
  font-size: 1rem;
  word-break: break-word;
  overflow-wrap: anywhere;
  /* Tapping the title opens the inline editor, so it is a control too (SPEC §8). */
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
}

#list .todo-title.editing {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

#list .todo-title.editing input {
  font-size: 1rem;
  padding: 0.25rem 0.5rem;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 200px;
}

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

#list .delete-btn {
  background: transparent;
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.25rem;
}

#list .delete-btn:hover {
  background: rgba(239,68,68,0.1);
}

footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}

#counts {
  font-size: 0.875rem;
  color: var(--muted);
}

#clear-completed {
  background: transparent;
  color: var(--muted);
  padding: 0.5rem 1rem;
  min-height: 44px;
}

#clear-completed:hover {
  color: var(--fg);
}

#update {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--primary);
  color: white;
  text-align: center;
  padding: 0.5rem;
  font-size: 0.875rem;
  z-index: 1000;
}

#insecure {
  margin: 1rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--muted, #6b7280);
  border-left: 3px solid var(--primary, #0b62d0);
  padding-left: 0.625rem;
}

#update.hidden {
  display: none !important;
}

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