:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #ededf1;
  --text: #0b0b0f;
  --muted: #8a8a96;
  --line: rgb(0 0 0 / .06);
  --accent: #5b5bf0;
  --accent-2: #a855f7;
  --on-accent: #ffffff;
  --seg-active: #ffffff;
  --gold: #d97706;
  --danger: #e5484d;
  --success: #12a594;
  --shadow: 0 1px 2px rgb(16 16 32 / .04), 0 6px 20px rgb(16 16 32 / .05);
  --radius: 18px;
  --ease: cubic-bezier(.2, .9, .3, 1);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0c;
    --surface: #17171b;
    --surface-2: #242429;
    --text: #f2f2f5;
    --muted: #85858f;
    --line: rgb(255 255 255 / .07);
    --accent: #7c7cff;
    --accent-2: #c084fc;
    --seg-active: #3a3a42;
    --gold: #fbbf24;
    --danger: #ff6369;
    --success: #2dd4bf;
    --shadow: 0 0 0 1px var(--line);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 560px;
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 8px) 20px calc(env(safe-area-inset-bottom) + 24px);
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body:has(dialog[open]) { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); text-decoration: none; }
p { margin: 0; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Header */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 20px 0 18px; }
.eyebrow { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.top h1 { margin: 2px 0 0; font-size: 34px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.daynav { display: flex; align-items: center; gap: 6px; }
.icon-btn {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--text);
  transition: transform .15s var(--ease);
}
.icon-btn svg { width: 18px; height: 18px; stroke-width: 2.4; }
.icon-btn:active, .fab:active, .btn:active { transform: scale(.94); }
.today {
  padding: 8px 12px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  font-size: 14px; font-weight: 600;
}

/* Score */
.score {
  padding: 18px 18px 20px;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.score-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.score-num { display: flex; align-items: baseline; gap: 6px; color: var(--muted); font-weight: 500; }
.score-num strong {
  font-size: 44px; font-weight: 800; line-height: 1; letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.score-note { color: var(--muted); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter-fill {
  height: 100%; min-width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .6s var(--ease), background .4s;
}
.complete .meter-fill { background: linear-gradient(90deg, var(--success), color-mix(in srgb, var(--success) 60%, #a3e635)); }
.complete .score-note { color: var(--success); }
.complete .score-num strong { background: none; color: var(--success); }

/* Tasks */
.tasks { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.task {
  display: flex; align-items: center;
  min-height: 60px;
  padding-right: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: opacity .3s;
}
.tick { flex: none; display: grid; place-items: center; width: 56px; align-self: stretch; }
.tick svg {
  width: 26px; height: 26px; padding: 4px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--muted) 55%, transparent);
  stroke: transparent; stroke-width: 3;
  transition: background .25s var(--ease), border-color .25s, stroke .25s, transform .25s var(--ease);
}
.tick:active svg { transform: scale(.85); }
.done .tick svg {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  stroke: var(--on-accent);
}
.task-body {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  padding: 12px 10px 12px 0;
  text-align: left;
}
.title { font-weight: 500; overflow-wrap: anywhere; transition: color .25s; }
.meta { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; }
.meta svg { width: 13px; height: 13px; stroke-width: 2.4; flex: none; }
.pts {
  flex: none;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 13%, transparent);
}
.done { opacity: .6; }
.done .title { text-decoration: line-through; text-decoration-color: var(--muted); color: var(--muted); }
.done .pts { color: var(--muted); background: var(--surface-2); }
.htmx-request.tick svg { transform: scale(.85); }

.group {
  display: flex; gap: 6px;
  margin: 26px 4px 0;
  color: var(--muted); font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
}
.group span { font-weight: 500; }

.empty { display: grid; justify-items: center; gap: 4px; padding: 56px 0 24px; color: var(--muted); text-align: center; }
.empty svg {
  width: 56px; height: 56px; padding: 14px; margin-bottom: 10px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent); stroke-width: 2.4;
}
.empty p { color: var(--text); font-size: 18px; font-weight: 600; }

/* The page fills the screen so the footer sits at the bottom, level with the + button. */
.app { flex: 1; display: flex; flex-direction: column; }
#day { margin-bottom: 32px; }
footer {
  display: flex; justify-content: center; align-items: center; gap: 8px;
  min-height: 62px; margin-top: auto;
  color: var(--muted); font-size: 14px;
}
footer span::after { content: "·"; margin-left: 8px; }
footer form { margin: 0; }
.link { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }

/* Floating add button */
.fab {
  position: fixed;
  right: max(20px, calc(50vw - 260px));
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  display: grid; place-items: center;
  width: 62px; height: 62px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  box-shadow: 0 12px 28px -8px color-mix(in srgb, var(--accent) 70%, transparent), inset 0 1px 0 rgb(255 255 255 / .25);
  transition: transform .2s var(--ease);
}
.fab svg { width: 28px; height: 28px; stroke-width: 2.6; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 100px);
  translate: -50% 0;
  padding: 11px 16px;
  border-radius: 14px;
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 12px 30px -10px rgb(0 0 0 / .4);
  animation: toast 2.8s var(--ease) forwards;
}
@keyframes toast {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  10%, 85% { opacity: 1; transform: none; }
  to { opacity: 0; }
}

/* Bottom sheets */
.sheet {
  width: 100%; max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet[open] { animation: sheet-up .38s var(--ease); }
.sheet::backdrop { background: rgb(0 0 0 / .35); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.sheet[open]::backdrop { animation: fade .3s ease; }
.sheet:focus { outline: none; }
.btn:focus:not(:focus-visible) { outline: none; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.sheet-body { display: grid; gap: 20px; padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px); }
.grabber { justify-self: center; width: 40px; height: 5px; border-radius: 99px; background: var(--surface-2); }

.title-input {
  width: 100%;
  padding: 6px 0;
  border: 0; outline: 0; background: none;
  font-size: 24px; font-weight: 700; letter-spacing: -.02em;
}
.title-input::placeholder { color: var(--muted); opacity: .6; }
.field { display: grid; gap: 10px; }
.label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.hint { color: var(--muted); font-size: 14px; }

/* Chips and segmented controls: real radios/checkboxes, visually hidden */
.chips label, .seg label { position: relative; }
.chips input, .seg input, .switch input { position: absolute; opacity: 0; pointer-events: none; }
.chips { display: grid; gap: 6px; }
.chips span {
  display: grid; place-items: center;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 600; font-variant-numeric: tabular-nums;
  transition: background .2s, color .2s, transform .2s var(--ease);
}
.chips label:active span { transform: scale(.92); }
.chips input:checked + span {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
}
.chips input:focus-visible + span, .seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.points { grid-template-columns: repeat(7, 1fr); }
.points input:checked + span { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); box-shadow: inset 0 0 0 1.5px var(--gold); }
.week { grid-template-columns: repeat(7, 1fr); }
.week span { border-radius: 50%; height: auto; aspect-ratio: 1; }
.month { grid-template-columns: repeat(7, 1fr); }
.month span { height: 38px; font-size: 14px; }
.month .wide { grid-column: span 4; }

.seg { display: flex; padding: 3px; border-radius: 13px; background: var(--surface-2); }
.seg label { flex: 1; }
.seg span {
  display: grid; place-items: center;
  height: 36px;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  color: var(--muted);
  transition: background .2s, color .2s;
}
.seg input:checked + span { background: var(--seg-active); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

.repeat, .panel { display: none; }
form:has([name=kind][value=repeat]:checked) .repeat { display: grid; gap: 14px; margin-top: -6px; }
form:has([name=repeat][value=daily]:checked) .p-daily { display: block; }
form:has([name=repeat][value=interval]:checked) .p-interval { display: flex; }
form:has([name=repeat][value=weekly]:checked) .p-weekly,
form:has([name=repeat][value=monthly]:checked) .p-monthly { display: grid; }

.stepper { align-items: center; gap: 10px; font-weight: 600; }
.stepper button {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 22px; line-height: 1;
}
.stepper input {
  width: 64px; height: 42px;
  border: 0; border-radius: 12px;
  background: var(--surface-2);
  text-align: center; font-size: 18px; font-weight: 700;
  -moz-appearance: textfield;
}
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* Buttons */
.btn {
  height: 54px;
  border-radius: 16px;
  font-size: 17px; font-weight: 700;
  transition: transform .15s var(--ease);
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  box-shadow: 0 10px 24px -10px color-mix(in srgb, var(--accent) 80%, transparent);
}
.btn.ghost { background: var(--surface-2); }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Task details sheet */
.ts-title { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.02em; overflow-wrap: anywhere; }
.ts-meta { margin-top: 4px; color: var(--muted); }
.ts-meta:empty { display: none; }
.ts-points { justify-self: start; padding: 5px 12px; border-radius: 999px; font-weight: 700; color: var(--gold); background: color-mix(in srgb, var(--gold) 13%, transparent); }

/* Login */
.login { display: grid; justify-items: center; padding-top: 14vh; text-align: center; }
.logo { border-radius: 18px; box-shadow: 0 12px 30px -10px color-mix(in srgb, var(--accent) 70%, transparent); }
.login h1 { margin: 22px 0 4px; font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.sub { color: var(--muted); margin-bottom: 28px; }
.login form { display: grid; gap: 10px; width: 100%; }
.login input:not([type=checkbox]) {
  height: 54px; padding: 0 16px;
  border: 0; border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 17px;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.login .btn { margin-top: 8px; }
.error { padding: 12px 14px; border-radius: 14px; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); font-weight: 500; }

.switch { display: flex; align-items: center; gap: 12px; padding: 8px 2px; cursor: pointer; color: var(--text); }
.switch span {
  position: relative; flex: none;
  width: 46px; height: 28px;
  border-radius: 99px;
  background: var(--surface-2);
  transition: background .25s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25);
  transition: transform .25s var(--ease);
}
.switch input:checked + span { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.switch input:checked + span::after { transform: translateX(18px); }
