:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --border: #e4e6ef;
  --text: #1e2030;
  --muted: #6b7080;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --on-accent: #ffffff;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 22, 40, 0.06), 0 8px 24px rgba(20, 22, 40, 0.05);
  --shadow-pop: 0 4px 12px rgba(20, 22, 40, 0.1), 0 16px 48px rgba(20, 22, 40, 0.16);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161f;
    --surface: #1c1f2b;
    --border: #2b2f3d;
    --text: #e8e9f0;
    --muted: #9298ad;
    --accent: #8b85f5;
    --accent-soft: #262a3d;
    --on-accent: #14161f;
    --danger: #f87171;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    --shadow-pop: 0 4px 12px rgba(0, 0, 0, 0.4), 0 16px 48px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1.5rem 1rem 3rem;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.is-locked {
  overflow: hidden;
}

.app {
  max-width: 640px;
  margin: 0 auto;
}

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

/* --- Header & date navigation --------------------------------------------- */
.app__header {
  text-align: center;
  margin-bottom: 1.25rem;
}

.app__title {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Anchor for the absolutely positioned calendar popup. */
.datenav-wrap {
  position: relative;
}

.datenav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.5rem;
}

.datenav__arrow {
  flex: 0 0 auto;
  width: 2.75rem;
  height: 2.75rem;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.datenav__arrow:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.datenav__current {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  padding: 0.35rem 0.25rem;
  font: inherit;
  color: inherit;
  text-align: center;
  background: transparent;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.datenav__current:hover,
.datenav__current[aria-expanded="true"] {
  background: var(--accent-soft);
}

.datenav__label {
  display: block;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.datenav__relative {
  display: block;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  min-height: 1.2em;
}

.datenav__today {
  margin-top: 0.75rem;
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}

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

/* --- Calendar popup -------------------------------------------------------- */
.calendar-backdrop {
  display: none;
}

.calendar {
  position: absolute;
  z-index: 20;
  top: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  width: 20rem;
  max-width: calc(100vw - 2rem);
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  text-align: center;
}

.calendar[hidden] {
  display: none;
}

.calendar__header {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.calendar__nav {
  flex: 0 0 auto;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.calendar__nav:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.calendar__title {
  flex: 1 1 auto;
  padding: 0.4rem;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.calendar__title:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.calendar__weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 0.25rem;
}

.calendar__weekday {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.calendar__grid {
  display: grid;
  gap: 2px;
}

.calendar__grid--days {
  grid-template-columns: repeat(7, 1fr);
}

.calendar__grid--months,
.calendar__grid--years {
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}

.calendar__cell {
  position: relative;
  padding: 0;
  aspect-ratio: 1 / 1;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.calendar__grid--months .calendar__cell,
.calendar__grid--years .calendar__cell {
  aspect-ratio: auto;
  padding: 0.7rem 0.25rem;
}

.calendar__cell:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.calendar__cell--muted {
  color: var(--muted);
  opacity: 0.55;
}

/* Today: a dot underneath the number. */
.calendar__cell--today::after {
  content: "";
  position: absolute;
  bottom: 0.3rem;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.calendar__cell--selected,
.calendar__cell--selected:hover {
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  opacity: 1;
}

.calendar__cell--selected.calendar__cell--today::after {
  background: var(--on-accent);
}

.calendar__footer {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.calendar__shortcut {
  flex: 1 1 0;
  padding: 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

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

/* On small screens the calendar becomes a bottom sheet with a backdrop. */
@media (max-width: 480px) {
  .calendar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(10, 12, 20, 0.45);
  }

  .calendar-backdrop[hidden] {
    display: none;
  }

  .calendar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-width: none;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    border: none;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .calendar__cell {
    font-size: 1rem;
  }
}

/* --- Boot & sign-in screen ------------------------------------------------- */
.boot {
  max-width: 640px;
  margin: 4rem auto;
  text-align: center;
  color: var(--muted);
}

.boot[hidden],
.auth[hidden],
.app[hidden] {
  display: none;
}

.auth {
  max-width: 22rem;
  margin: 3rem auto 0;
  padding: 1.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth__brand {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

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

.auth__form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  text-align: left;
}

.auth__field {
  display: block;
}

.auth__label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.auth__field input {
  width: 100%;
  padding: 0.7rem 0.85rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

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

.auth__hint {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.auth__hint[hidden] {
  display: none;
}

.auth__error {
  margin: 0;
  min-height: 1.2rem;
  font-size: 0.85rem;
  color: var(--danger);
}

.auth__error:empty {
  min-height: 0;
}

.auth__submit {
  padding: 0.8rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.auth__submit:hover:not(:disabled) {
  filter: brightness(1.08);
}

.auth__submit:disabled {
  opacity: 0.6;
  cursor: progress;
}

.auth__switch[hidden] {
  display: none;
}

.auth__switch {
  margin: 1.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth__link {
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  background: none;
  border: none;
  cursor: pointer;
}

/* --- Account bar ----------------------------------------------------------- */
.account {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.account__email {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.account__logout {
  flex: 0 0 auto;
  padding: 0.3rem 0.8rem;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}

.account__logout:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Composer -------------------------------------------------------------- */
.composer {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.composer__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.85rem 1rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.composer__submit {
  flex: 0 0 auto;
  padding: 0 1.4rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.composer__submit:hover {
  filter: brightness(1.08);
}

/* --- Status message -------------------------------------------------------- */
.status {
  margin: 0 0 0.75rem;
  min-height: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

.status--error {
  color: var(--danger);
}

/* --- Todo list ------------------------------------------------------------- */
.list__items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.todo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.todo__checkbox {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.todo__title {
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
  cursor: text;
}

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

.todo__edit {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.25rem 0.5rem;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
}

.todo__actions {
  flex: 0 0 auto;
  display: flex;
  gap: 0.25rem;
}

.todo__button {
  padding: 0.3rem 0.5rem;
  font-size: 0.95rem;
  line-height: 1;
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s, background 0.15s;
}

.todo__button:hover {
  opacity: 1;
  background: var(--accent-soft);
}

.list__empty {
  margin: 2rem 0;
  text-align: center;
  color: var(--muted);
}

/* --- Summary --------------------------------------------------------------- */
.summary {
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.25rem;
}

@media (max-width: 420px) {
  .composer {
    flex-wrap: wrap;
  }

  .composer__submit {
    flex: 1 1 100%;
    padding: 0.75rem;
  }
}
