:root {
  --bg: #faf8f5;
  --card: #ffffff;
  --ink: #2b2823;
  --muted: #8a8579;
  --line: #e8e3da;
  --accent: #3f7d6b;
  --accent-ink: #ffffff;
  --due: #c9762f;
  --overdue: #c0432f;
  --done: #8a8579;
  --upcoming: #b8b2a5;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Several rules below (.overlay, .modal-card label) set `display` with the same or
   higher specificity than the browser's default [hidden] rule, which would otherwise
   silently override it. Force hidden elements to actually stay hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

h1, h2 { margin: 0; font-weight: 700; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 1.2rem; margin-right: auto; }

.tabs { display: flex; gap: 6px; }
.tab-btn {
  border: none;
  background: transparent;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
}
.tab-btn.active { background: var(--accent); color: var(--accent-ink); }

#logout-btn {
  border: none;
  background: transparent;
  font-size: 1.2rem;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
}

main { max-width: 640px; margin: 0 auto; padding: 12px 16px 80px; }

.section { margin-bottom: 22px; }
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-head h2 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.add-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
}

.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.task-list:empty::after {
  content: "Nothing here yet.";
  color: var(--upcoming);
  font-size: 0.85rem;
  font-style: italic;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.checkbox {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: transparent;
}
.checkbox.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.checkbox.state-due { border-color: var(--due); }
.checkbox.state-overdue { border-color: var(--overdue); }

.task-main { flex: 1; min-width: 0; cursor: pointer; }
.task-title { font-size: 0.98rem; }
.task-title.done { color: var(--muted); text-decoration: line-through; }
.task-meta { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.task-meta.state-due { color: var(--due); }
.task-meta.state-overdue { color: var(--overdue); font-weight: 600; }

.anytime-btn, .once-btn {
  flex: 0 0 auto;
  border: none;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 40, 35, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.login-card, .modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 { text-align: center; margin-bottom: 8px; }
.login-card input, .modal-card input, .modal-card select, .modal-card textarea {
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  width: 100%;
}
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }

button {
  font: inherit;
}
.login-card button[type="submit"], .primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.error { color: var(--overdue); font-size: 0.85rem; text-align: center; margin: 0; }

.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.modal-actions button {
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink);
}
.modal-actions .danger { color: var(--overdue); border-color: var(--overdue); }

.history-controls { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.history-controls select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.month-nav { display: flex; align-items: center; gap: 10px; }
.month-nav button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 4px 10px; cursor: pointer; }

.calendar {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar-dow { text-align: center; font-size: 0.7rem; color: var(--muted); padding-bottom: 4px; }
.calendar-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
}
.calendar-day.done { background: var(--accent); color: #fff; font-weight: 600; }
.calendar-day.blank { background: transparent; }

@media (min-width: 640px) {
  header { padding: 20px 24px; }
  main { padding: 20px 24px 80px; }
}
