.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0
    max(16px, env(safe-area-inset-left));
  background: var(--bg);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 608px;
  min-height: 52px;
  margin: 0 auto;
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.week {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* Days */

.day {
  margin-top: 18px;
  scroll-margin-top: calc(52px + env(safe-area-inset-top));
}

/* Weekday on the left; the date sits at the right, level with the checks. */
.day-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 11px 6px 4px;
  font-size: 15px;
  font-weight: 600;
}

.day-name {
  font-size: 17px;
}

.day-date {
  color: var(--muted);
  font-weight: 500;
}

.day.is-today .day-name {
  color: var(--accent);
  font-size: 22px;
  font-weight: 750;
}

.day-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

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

/* Tasks */

.task {
  position: relative;
  overflow: hidden;
  border-top: 1px solid var(--line);
  scroll-margin-block: 64px;
  transition: transform var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease);
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: pan-y;
}

.task .edit-input {
  -webkit-user-select: text;
  user-select: text;
}

.task:first-child {
  border-top: 0;
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
}

/* The focused task (or Add task row) gets a clear ring all the way round. */
.task:focus-visible {
  outline: none;
}

.task:focus-visible .task-content,
.task.is-editing .task-content {
  box-shadow: inset 0 0 0 2px var(--focus);
}

.task-content {
  position: relative;
  display: flex;
  align-items: flex-start;
  min-height: var(--touch);
  padding-left: 14px;
  border-radius: inherit;
  background: var(--surface);
  transition: transform var(--duration) var(--ease),
    background-color var(--duration) var(--ease);
}

.task[data-highlight="color1"] .task-content {
  background: var(--highlight-1);
}

.task[data-highlight="color2"] .task-content {
  background: var(--highlight-2);
}

@media (hover: hover) {
  .task[data-highlight="none"]:hover .task-content {
    background: var(--hover);
  }
}

.task.is-entering {
  animation: task-enter var(--duration) var(--ease);
}

@keyframes task-enter {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.task-main {
  flex: 1;
  min-width: 0;
}

.task-text {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 11px 0;
  line-height: 22px;
  overflow-wrap: anywhere;
  cursor: text;
  text-decoration: line-through transparent;
  transition: opacity var(--duration) var(--ease),
    text-decoration-color var(--duration) var(--ease);
}

.task[data-done="true"] .task-text {
  opacity: 0.88;
  text-decoration-color: currentcolor;
}

.edit-input,
.add-input {
  display: block;
  width: 100%;
  padding: 11px 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: 22px;
  resize: none;
  overflow: hidden;
}

/* Swipe layers, revealed underneath the sliding content */

.swipe-action {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  font-weight: 650;
  visibility: hidden;
}

.swipe-action svg {
  width: 22px;
  height: 22px;
  transition: transform var(--duration) var(--ease);
}

.swipe-done {
  left: 0;
  right: 0;
  padding-left: 20px;
  background: var(--done-bg);
  color: var(--done-text);
}

.swipe-delete {
  right: 0;
  width: 88px;
  justify-content: center;
  flex-direction: column;
  gap: 2px;
  background: var(--danger);
  color: var(--danger-text);
  font-size: 13px;
}

.task[data-swipe="right"] .swipe-done,
.task[data-swipe="left"] .swipe-delete {
  visibility: visible;
}

.task[data-armed="true"] .swipe-done svg {
  transform: scale(1.3);
}

/* Lifted (long press) and dragged rows */

.task.is-lifted,
.task.is-dragging {
  z-index: 6;
  border-radius: 10px;
  box-shadow: var(--shadow-lift);
}

.task.is-lifted {
  transform: scale(1.02);
}

.task.is-dragging {
  pointer-events: none;
  transition: none;
}

.is-gesturing .day-card {
  overflow: visible;
}

.is-gesturing {
  cursor: grabbing;
}

.day-card.is-drop-target {
  box-shadow: 0 0 0 2px var(--accent);
}

.drop-indicator {
  position: fixed;
  z-index: 7;
  height: 3px;
  border-radius: 3px;
  background: var(--accent);
  pointer-events: none;
}

/* Completion check, at the far right */

.check {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--touch);
  height: var(--touch);
  padding: 0;
  border: 0;
  background: transparent;
}

.check-mark {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  color: var(--accent-text);
  transition: background-color var(--duration) var(--ease),
    border-color var(--duration) var(--ease),
    transform var(--duration) var(--ease);
}

.check-mark svg {
  width: 16px;
  height: 16px;
  stroke-width: 3;
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  transition: stroke-dashoffset var(--duration) var(--ease);
}

.task[data-done="true"] .check-mark {
  border-color: var(--accent);
  background: var(--accent);
}

.task[data-done="true"] .check-mark svg {
  stroke-dashoffset: 0;
}

.check:active .check-mark {
  transform: scale(0.88);
}

/* Add row */

.add-row {
  display: flex;
  align-items: flex-start;
  min-height: var(--touch);
  padding-left: 14px;
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}

.tasks:empty + .add-row {
  border-radius: calc(var(--radius) - 1px);
}

.tasks:not(:empty) + .add-row {
  border-top: 1px solid var(--line);
}

.add-button {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 8px;
  min-height: var(--touch);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.add-button:focus-visible {
  outline: none;
}

.add-button svg {
  width: 18px;
  height: 18px;
}

.add-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.add-row:has(.add-button:focus-visible),
.add-row:has(.add-input:not([hidden])) {
  box-shadow: inset 0 0 0 2px var(--focus);
}
