:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  --background: #281810;
  --surface: #fff1dd;
  --subtle: #fae7ce;
  --border: #ddbc98;
  --ink: #371e14;
  --title: #43251a;
  --muted: #704a37;
  --accent: #844a29;
  --accent-tint: #f3cba3;
  --check-border: #95664a;
  --shell-ink: #ffebd0;
  --shell-muted: #fbe4ce;
  --shell-surface: #492c20;
  --shell-border: #9b6849;
  --shell-focus: #f2bd84;
  --presence-online: #597449;
  --presence-offline: #82776d;
  --danger: #822d26;
  --danger-tint: #fff3ef;
  --danger-border: #e0b7ae;
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --group-gap: 14px;
  background: var(--background);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  background: linear-gradient(155deg, #392319 0, var(--background) 22rem, #20130f 52rem);
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible,
[tabindex="-1"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app {
  position: relative;
  isolation: isolate;
  width: 100%;
  min-height: 100vh;
  max-width: 672px;
  margin-inline: auto;
  padding-block-start: calc(clamp(32px, 8vw, 80px) + max(env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px)));
  padding-inline-start: max(clamp(20px, 5vw, 32px), env(safe-area-inset-left), var(--tg-content-safe-area-inset-left, 0px));
  padding-inline-end: max(clamp(20px, 5vw, 32px), env(safe-area-inset-right), var(--tg-content-safe-area-inset-right, 0px));
  padding-block-end: calc(40px + max(env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px)));
}

.app::before {
  position: absolute;
  z-index: -1;
  inset-block-start: 0;
  inset-inline-end: 0;
  inline-size: min(100%, 36rem);
  block-size: 18rem;
  background: radial-gradient(ellipse 29% 50% at 70% 50%, #a46436 0, #754528 39%, transparent 100%);
  opacity: .82;
  pointer-events: none;
  content: "";
  animation: window-light 4.6s ease-out both;
}

@keyframes window-light {
  from {
    opacity: .55;
    transform: translateY(7px) scale(.96);
  }
  to {
    opacity: .82;
    transform: none;
  }
}

.app-header {
  position: relative;
  isolation: isolate;
  margin-bottom: 22px;
}

.app-header::before {
  position: absolute;
  z-index: -1;
  inset-block-start: -16px;
  inset-inline-end: 0;
  inline-size: clamp(82px, 30vw, 124px);
  block-size: 126px;
  border: 1px solid rgb(255 200 142 / 31%);
  border-radius: 64px 64px 5px 5px;
  background:
    linear-gradient(90deg, transparent 49%, rgb(236 171 111 / 22%) 49% 51%, transparent 51%),
    linear-gradient(transparent 61%, rgb(236 171 111 / 22%) 61% 63%, transparent 63%),
    linear-gradient(150deg, #513321, #332118);
  box-shadow: 0 0 24px rgb(233 152 79 / 19%);
  pointer-events: none;
  content: "";
}

h1 {
  margin: 0;
  color: var(--shell-ink);
  font-family: Georgia, serif;
  font-size: clamp(32px, 8.6vw, 49px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -0.035em;
  text-wrap: balance;
}

h1:focus-visible {
  outline-color: var(--shell-focus);
}

.summary {
  display: flex;
  min-height: 32px;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 14px;
}

.remaining,
.demo-mode {
  margin: 0;
  font-size: 14px;
  line-height: 20px;
}

.remaining {
  color: var(--shell-ink);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.demo-mode {
  color: var(--shell-muted);
}

.task-tabs {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(max-content, .9fr) minmax(max-content, 1.55fr) minmax(max-content, 1.25fr);
  margin-bottom: 18px;
  padding: 4px;
  border: 1px solid var(--shell-border);
  border-radius: 13px;
  background: var(--shell-surface);
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-touch-callout: none;
}

.task-tabs.has-access {
  grid-template-columns:
    minmax(max-content, .82fr) minmax(max-content, 1.55fr)
    minmax(max-content, 1.25fr) minmax(max-content, .9fr);
}

.task-tabs button {
  position: relative;
  min-width: 0;
  min-height: 44px;
  padding: 5px 2px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--shell-ink);
  font-size: clamp(12px, 3.34vw, 14px);
  font-weight: 650;
  line-height: 17px;
  white-space: nowrap;
  cursor: pointer;
}

.task-tabs:not(.has-tab-thumb):not(.has-drag-target) button[aria-selected="true"],
.task-tabs:not(.has-tab-thumb) button.is-drag-target {
  background: var(--accent);
}

.task-tabs.has-tab-thumb::before {
  position: absolute;
  inset-block: 4px;
  inset-inline-start: 0;
  inline-size: var(--tab-thumb-width);
  border-radius: 9px;
  background: var(--accent);
  box-shadow: inset 0 0 0 1px var(--shell-focus), 0 1px 4px rgb(39 22 15 / 24%);
  transform: translateX(var(--tab-thumb-x));
  transition: transform var(--tab-thumb-duration, 180ms) var(--tab-thumb-easing, var(--ease-out)),
    inline-size var(--tab-thumb-duration, 180ms) var(--tab-thumb-easing, var(--ease-out));
  pointer-events: none;
  content: "";
}

.task-tabs.is-dragging {
  --tab-thumb-duration: 55ms;
  --tab-thumb-easing: linear;
}

.task-viewport {
  position: relative;
  overflow-x: clip;
  overflow-clip-margin: 6px;
}

.task-tabs button:focus-visible {
  outline-color: var(--shell-focus);
  outline-offset: -2px;
}

.task-panel:focus-visible {
  outline: 2px solid var(--shell-focus);
  outline-offset: 4px;
  border-radius: 16px;
}

.task-panel.is-entering {
  animation: panel-in 170ms var(--ease-out) 25ms both;
}

@keyframes panel-in {
  from {
    opacity: .58;
  }
}

.groups {
  display: grid;
  gap: var(--group-gap);
}

#evening-reconciling:not([hidden]) + .groups:not(:empty) {
  margin-block-start: var(--group-gap);
}

.group,
.panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}

.group {
  overflow: hidden;
}

.group-title {
  padding: 13px 16px;
  margin: 0;
  border-bottom: 1px solid var(--border);
  background: var(--subtle);
  color: var(--title);
  font-size: 17px;
  font-weight: 700;
  line-height: 25px;
  overflow-wrap: anywhere;
}

.task-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.task + .task {
  border-top: 1px solid var(--border);
}

.task-button,
.task-body {
  display: grid;
  width: 100%;
  min-height: 61px;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 13px;
  padding: 12px 16px;
  border: 0;
  background: var(--surface);
  text-align: start;
}

.task-button {
  cursor: pointer;
  transition: background-color 150ms ease-out;
}

.task-button:focus-visible {
  outline-offset: -4px;
}

.task-button[aria-disabled="true"] {
  background: var(--subtle);
  cursor: wait;
}

@media (hover: hover) {
  .task-button:not([aria-disabled="true"]):hover {
    background: var(--subtle);
  }

  .task-button:not([aria-disabled="true"]):hover .task-check {
    border-color: var(--accent);
    background: var(--accent-tint);
  }
}

.task-check {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--check-border);
  border-radius: 7px;
  color: var(--accent);
}

.task-button .task-check {
  transition: background-color 150ms ease-out, border-color 150ms ease-out;
}

.task-completed .task-check {
  border-color: var(--accent-tint);
  background: var(--accent-tint);
}

.task-completed .task-check::before {
  width: 10px;
  height: 6px;
  margin-top: -2px;
  transform: rotate(-45deg);
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  content: "";
}

.task-completed .task-title {
  color: var(--muted);
}

.task-completion {
  overflow: hidden;
  min-height: 0;
  pointer-events: none;
}

.task-completion .task-body {
  background: var(--subtle);
}

.task-completion .task-check {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

.task-button[aria-busy="true"] .task-check::before {
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 750ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .task-tabs.has-tab-thumb::before,
  .task-tabs button,
  .task-button,
  .task-button .task-check {
    transition: none;
  }

  .app::before,
  .task-panel.is-entering,
  .task-button[aria-busy="true"] .task-check::before {
    animation: none;
  }
}

.task-content {
  display: grid;
  gap: 2px;
}

.task-title {
  font-size: 16px;
  line-height: 24px;
  overflow-wrap: anywhere;
}

.task-progress,
.task-error {
  font-size: 14px;
  line-height: 20px;
}

.task-progress {
  color: var(--muted);
}

.panel {
  padding: 16px;
  margin: 0;
  color: var(--muted);
  line-height: 24px;
}

.empty {
  color: var(--title);
  font-weight: 650;
}

.task-error,
.refresh-error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 12px;
  background: var(--danger-tint);
  color: var(--danger);
}

.task-error {
  padding: 0 12px 0 16px;
  border-top: 1px solid var(--danger-border);
}

.refresh-error {
  padding: 4px 12px 4px 16px;
  margin-bottom: 14px;
  border-color: var(--danger-border);
}

.task-error p,
.refresh-error p {
  margin: 9px 0;
}

.retry {
  min-height: 44px;
  padding: 4px;
  border: 0;
  background: none;
  font-size: 14px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.retry[aria-disabled="true"] {
  cursor: wait;
}

.completed-section:not([hidden]) + .completed-section {
  margin-top: 22px;
}

.completed-section > h2 {
  margin: 0 0 9px;
  color: var(--shell-muted);
  font-size: 14px;
  line-height: 20px;
}

.evening-result {
  position: relative;
  padding: clamp(18px, 5vw, 26px);
  border-color: var(--check-border);
}

.evening-date {
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}

.evening-result h2,
.access-panel h2 {
  margin: 0;
  color: var(--title);
  font-weight: 750;
}

.evening-result h2 {
  margin-top: 4px;
  font-size: clamp(22px, 6vw, 28px);
  line-height: 1.24;
  letter-spacing: -0.025em;
}

.evening-total {
  margin: 7px 0 0;
  color: var(--accent);
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.evening-sweep {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.evening-result.is-celebrating .evening-sweep::before {
  position: absolute;
  inset-block-start: 20px;
  inline-size: 22px;
  block-size: 36px;
  background:
    linear-gradient(var(--check-border), var(--check-border)) center top / 2px 26px no-repeat,
    repeating-linear-gradient(90deg, var(--check-border) 0 2px, var(--accent-tint) 2px 4px)
      center 26px / 18px 8px no-repeat;
  content: "";
  animation: finish-sweep 390ms var(--ease-out) both;
}

@keyframes finish-sweep {
  from {
    inset-inline-start: -28px;
    transform: translateY(6px) rotate(-24deg);
  }
  to {
    inset-inline-start: 100%;
    transform: translateY(-6px) rotate(22deg);
  }
}

.evening-week {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.evening-week h3 {
  margin: 0;
  color: var(--title);
  font-size: 16px;
  line-height: 20px;
}

.evening-week p {
  margin: 5px 0 0;
  font-size: 14px;
  line-height: 20px;
}

.weekly-days {
  display: grid;
  gap: 6px;
  margin: 11px 0 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  line-height: 20px;
  font-variant-numeric: tabular-nums;
}

.weekly-days li {
  display: grid;
  grid-template-columns: 5.2em minmax(0, 1fr) max-content;
  align-items: center;
  column-gap: 8px;
}

.weekly-days time {
  white-space: nowrap;
}

.weekly-missing {
  grid-column: 2 / -1;
  color: var(--muted);
}

.weekly-count {
  min-width: 3.5em;
  text-align: end;
}

.weekly-track {
  display: block;
  height: 10px;
  border-radius: 9px;
  background: var(--accent-tint);
}

.weekly-track meter {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  appearance: none;
}

.weekly-track meter::-webkit-meter-bar {
  border: 0;
  background: transparent;
}

.weekly-track meter::-webkit-meter-optimum-value {
  border-radius: 9px;
  background: var(--accent);
}

.weekly-track meter::-moz-meter-bar {
  border-radius: 9px;
  background: var(--accent);
}

.evening-result.is-celebrating .weekly-days meter {
  animation: draw-weekly-bar 260ms var(--ease-out) calc(390ms + var(--weekday-offset, 0ms)) both;
}

.weekly-days li:nth-child(2) { --weekday-offset: 45ms; }
.weekly-days li:nth-child(3) { --weekday-offset: 90ms; }
.weekly-days li:nth-child(4) { --weekday-offset: 135ms; }
.weekly-days li:nth-child(5) { --weekday-offset: 180ms; }
.weekly-days li:nth-child(6) { --weekday-offset: 225ms; }
.weekly-days li:nth-child(7) { --weekday-offset: 270ms; }

@keyframes draw-weekly-bar {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

.access-button {
  min-height: 44px;
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent-tint);
  color: var(--title);
  font-size: 14px;
  font-weight: 650;
  line-height: 20px;
  cursor: pointer;
}

.access-panel {
  font-size: 14px;
  line-height: 20px;
}

.access-panel h2 {
  margin-top: 15px;
  font-size: 17px;
  line-height: 22px;
}

.access-panel p {
  margin: 7px 0 0;
}

.access-panel .access-mode {
  margin: 0 0 12px;
  color: var(--muted);
  font: 600 13px/20px ui-monospace, Consolas, monospace;
}

.access-error {
  color: var(--danger);
}

.access-cancel-invite.retry {
  margin-top: 3px;
  color: var(--danger);
}

.access-members {
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.access-member + .access-member {
  border-top: 1px solid var(--border);
}

.access-member-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 6px 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: start;
}

button.access-member-profile {
  cursor: pointer;
}

@media (hover: hover) {
  button.access-member-profile:hover {
    background: var(--subtle);
  }
}

.access-member-profile:focus-visible {
  outline-offset: -2px;
}

.access-member-name {
  min-width: 0;
  color: var(--title);
  font-size: 16px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.access-member-suffix {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 16px;
}

.access-presence {
  flex: 0 0 auto;
  align-self: center;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--presence-offline);
}

.access-presence[data-online="true"] {
  background: var(--presence-online);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.member-dialog {
  width: min(360px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  margin: auto;
  color: var(--ink);
  box-shadow: 0 18px 52px rgb(33 18 12 / 39%);
}

.member-dialog[open] {
  animation: panel-in 210ms var(--ease-out) both;
}

.member-dialog::backdrop {
  background: rgb(34 19 13 / 62%);
}

.member-dialog h2 {
  margin: 0 0 14px;
  color: var(--title);
  font-size: 19px;
  line-height: 25px;
  overflow-wrap: anywhere;
}

.member-dialog p {
  margin: 0 0 12px;
}

.member-dialog-actions {
  display: grid;
  gap: 8px;
}

.member-dialog-block {
  border-color: var(--danger-border);
  background: var(--danger-tint);
  color: var(--danger);
}

.access-invite {
  display: grid;
  justify-items: start;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--subtle);
}

.access-invite label {
  margin-bottom: 6px;
  color: var(--title);
  font-weight: 650;
}

.access-invite input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 8px;
  border: 1px solid var(--check-border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.access-invite input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.access-invite .retry {
  color: var(--title);
  text-align: start;
}

.access-invite #access-feedback {
  margin-top: 0;
}

.access-button[aria-disabled="true"] {
  opacity: 0.6;
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  .member-dialog[open],
  .evening-result.is-celebrating .evening-sweep::before,
  .evening-result.is-celebrating .weekly-days meter {
    animation: none;
  }
}
