/* Fewer — first edition */

:root {
  --bg: #F7F6F2;
  --surface: #FFFFFF;
  --text: #1C1C1E;
  --muted: #8A8A8E;
  --separator: #E5E3DC;
  --accent: #3B7D3A;
  --urgent: #C2410C;

  --fill: #EFEEE8;
  --on-accent: #FFFFFF;
  --on-urgent: #FFFFFF;
  --swipe-gray: #8A8A8E;
  --bar: rgba(247, 246, 242, 0.88);
  --backdrop: rgba(0, 0, 0, 0.28);
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.05), 0 6px 20px rgba(60, 50, 30, 0.06);
  --sloth-fur: #B5AA97;
  --sloth-face: #EFE8D8;
  --sloth-patch: #7B7061;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tabbar-h: 50px;
  --kb: 0px;
  --t: 220ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --text: #F2F2F7;
    --muted: #8E8E93;
    --separator: #38383A;
    --accent: #5DBB63;
    --urgent: #FF8A50;

    --fill: #2C2C2E;
    --on-accent: #06210A;
    --on-urgent: #2A1000;
    --swipe-gray: #636366;
    --bar: rgba(18, 18, 19, 0.88);
    --backdrop: rgba(0, 0, 0, 0.55);
    --shadow: none;
    --sloth-fur: #6F685B;
    --sloth-face: #B0A794;
    --sloth-patch: #3F3A32;
  }
}

/* In dark mode, sheets and dialogs sit one level above the black background. */
@media (prefers-color-scheme: dark) {
  .sheet { --bg: #1C1C1E; --surface: #2C2C2E; --fill: #3A3A3C; --separator: #48484A; }
  .dialog-layer { --surface: #2C2C2E; --separator: #48484A; }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

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

[hidden] { display: none !important; }

svg { display: block; }

/* ---------- App frame ---------- */

#app {
  position: relative;
  height: 100%;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}

#screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: calc(var(--safe-top) + 12px) var(--safe-right) 104px var(--safe-left);
  outline: none;
}

/* ---------- Tab bar ---------- */

.tabbar {
  flex: none;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
  z-index: 5;
}

.tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 44px;
  color: var(--muted);
  transition: color var(--t) ease-out;
}

.tabbar button.active { color: var(--accent); }

.tab-icon { position: relative; display: block; width: 26px; height: 26px; }

.tab-icon svg, .fab svg, .icon {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab-label { font-size: 10px; font-weight: 500; letter-spacing: 0.01em; }

.tab-count {
  position: absolute;
  top: -4px;
  left: 17px;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--muted);
  color: var(--bg);
  font-size: 11px;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
}

/* ---------- Floating add button ---------- */

.fab {
  position: absolute;
  right: calc(16px + var(--safe-right));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 56px;
  height: 56px;
  padding: 15px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 4px 14px rgba(40, 80, 40, 0.28);
  z-index: 6;
  transition: transform 150ms ease-out;
}

.fab svg { stroke-width: 2.2; }
.fab:active { transform: scale(0.94); }

/* ---------- Headers ---------- */

.screen-head { padding: 8px 20px 14px; }

.large-title {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.subtitle { margin: 2px 0 0; font-size: 15px; color: var(--muted); }

.back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 44px;
  margin: -6px 0 0 -8px;
  padding: 0 8px 0 0;
  color: var(--accent);
}

.back .icon { width: 22px; height: 22px; }

.section-head {
  margin: 22px 32px 7px;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.footnote { margin: 8px 32px 0; font-size: 13px; color: var(--muted); }

/* ---------- Next card ---------- */

.next-card {
  margin: 0 16px;
  padding: 18px 20px 20px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: opacity var(--t) ease-out, transform var(--t) ease-out;
}

.next-card.leaving { opacity: 0; transform: translateY(-6px) scale(0.985); }
.next-card.entering { animation: card-in var(--t) ease-out; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.next-meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 13px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.urgent-label { color: var(--urgent); font-weight: 600; }

.next-title {
  display: -webkit-box;
  width: 100%;
  margin: 6px 0 18px;
  padding: 0;
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-align: left;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-user-select: none;
  user-select: none;
}

.next-actions { display: flex; gap: 10px; align-items: center; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 20px;
  border-radius: 12px;
  background: var(--fill);
  font-weight: 600;
  transition: opacity 120ms ease-out, transform 120ms ease-out;
}

.btn:active { opacity: 0.7; transform: scale(0.985); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.grow { flex: 1; }
.btn.small { min-height: 50px; padding: 0 18px; font-weight: 500; color: var(--muted); }
.btn.plain { background: none; color: var(--accent); font-weight: 400; }
.btn.danger-text { color: var(--urgent); }

/* ---------- Grouped lists ---------- */

.group {
  list-style: none;
  margin: 0 16px;
  padding: 0;
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
}

.group + .group { margin-top: 16px; }

.row {
  position: relative;
  min-height: 48px;
  background: var(--surface);
}

.row + .row .row-content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

.row-content {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 8px 0 16px;
  background: var(--surface);
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.row-content.settling { transition: transform var(--t) ease-out; }

.row-main {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 12px 8px 12px 0;
  text-align: left;
  overflow-wrap: anywhere;
}

.row-main .urgent-label {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  font-weight: 500;
}

.row-value { color: var(--muted); padding-right: 8px; }

.row-chevron { width: 20px; height: 20px; margin-right: 4px; color: var(--muted); opacity: 0.6; flex: none; }

.row.quiet .row-main { color: var(--muted); }
.row.accent .row-main { color: var(--accent); }

.pill {
  flex: none;
  min-width: 44px;
  height: 44px;
  padding: 0 3px;
  font-size: 15px;
}

.pill span {
  display: block;
  padding: 6px 12px;
  border-radius: 16px;
  background: var(--fill);
}

.pill.go span { color: var(--accent); font-weight: 500; }
.pill:active span { opacity: 0.6; }

/* check circle on Today rows */
.check {
  flex: none;
  width: 44px;
  height: 48px;
  margin-left: -10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.check i {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--muted);
  color: transparent;
  transition: background var(--t) ease-out, border-color var(--t) ease-out, color var(--t) ease-out;
}

.check i svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

.row.completing .check i { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.row.completing .row-main { color: var(--muted); text-decoration: line-through; transition: color var(--t) ease-out; }

.row.collapsing {
  overflow: hidden;
  min-height: 0;
  opacity: 0;
  transition: height var(--t) ease-out, opacity var(--t) ease-out;
}

.grip { flex: none; width: 20px; height: 20px; margin: 0 6px; color: var(--muted); opacity: 0.45; }

/* drag to reorder */
.row.dragging {
  z-index: 3;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  overflow: hidden;
}

.row.dragging .row-content::before,
.row.dragging + .row .row-content::before { display: none; }

/* swipe actions */
.swipe-bg {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  padding: 0 20px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: filter 120ms ease-out;
}

.row[data-dir="right"] .swipe-bg.to-right { display: flex; justify-content: flex-start; background: var(--accent); color: var(--on-accent); }
.row[data-dir="left"] .swipe-bg.to-left { display: flex; justify-content: flex-end; background: var(--swipe-gray); }
.row .swipe-bg { opacity: 0.75; }
.row.armed .swipe-bg { opacity: 1; }

/* ---------- Empty states ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 56px 32px 24px;
  text-align: center;
  color: var(--muted);
}

.empty .sloth { width: 132px; height: 110px; margin-bottom: 14px; }
.empty p { margin: 0; font-size: 17px; }

.sloth .fur { fill: var(--sloth-fur); }
.sloth .face { fill: var(--sloth-face); }
.sloth .patch { fill: var(--sloth-patch); }
.sloth .line { fill: none; stroke: var(--sloth-patch); stroke-width: 2; stroke-linecap: round; }
.sloth .branch { fill: none; stroke: var(--sloth-patch); stroke-width: 5; stroke-linecap: round; opacity: 0.55; }
.sloth .limb { fill: none; stroke: var(--sloth-fur); stroke-width: 11; stroke-linecap: round; }
.sloth .leaf { fill: var(--accent); opacity: 0.8; }

/* ---------- Overlay: sheets, dialogs, review ---------- */

.overlay { position: absolute; inset: 0; z-index: 20; }

.backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  animation: fade-in var(--t) ease-out;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--kb);
  max-height: calc(100% - var(--kb) - var(--safe-top) - 24px);
  overflow-y: auto;
  padding: 0 16px calc(16px + var(--safe-bottom));
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.12);
  animation: sheet-up 250ms ease-out;
  transition: transform var(--t) ease-out, bottom 120ms ease-out;
}

.overlay.kb-open .sheet { padding-bottom: 14px; }
.sheet.dragging { transition: none; }
.overlay.closing .sheet { transform: translateY(105%) !important; }
.overlay.closing .backdrop, .overlay.closing .dialog, .overlay.closing .review { opacity: 0; transition: opacity var(--t) ease-out; }

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sheet-handle {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 26px;
  margin: 0 -16px;
  touch-action: none;
  cursor: grab;
}

.sheet-handle::before {
  content: "";
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--muted);
  opacity: 0.45;
}

.sheet-title { margin: 0 4px 12px; font-size: 17px; font-weight: 600; text-align: center; }

.field {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 12px 16px;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
}

.field::placeholder { color: var(--muted); }
.field:focus { outline: none; }

.add-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.add-note { flex: 1; min-width: 0; font-size: 15px; color: var(--muted); text-align: right; transition: opacity var(--t) ease-out; }

.toggle {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 2px;
  font-size: 15px;
}

.toggle span {
  padding: 7px 14px;
  border-radius: 18px;
  background: var(--surface);
  color: var(--muted);
  transition: background var(--t) ease-out, color var(--t) ease-out;
}

.toggle[aria-pressed="true"] span { background: var(--accent); color: var(--on-accent); font-weight: 500; }
.toggle.urgent[aria-pressed="true"] span { background: var(--urgent); color: var(--on-urgent); }

.sheet .group { margin: 16px 0 0; }
.sheet .section-head { margin: 20px 16px 7px; }

.switch {
  flex: none;
  position: relative;
  width: 51px;
  height: 31px;
  margin: 0 8px;
  border-radius: 16px;
  background: var(--fill);
  transition: background var(--t) ease-out;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--t) ease-out;
}

[aria-checked="true"] .switch { background: var(--accent); }
[aria-checked="true"] .switch::after { transform: translateX(20px); }

.segment {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 10px;
  background: var(--fill);
}

.segment button { flex: 1; min-height: 44px; border-radius: 8px; font-size: 15px; }
.segment button[aria-pressed="true"] { background: var(--surface); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }

/* dialog */
.dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(290px, calc(100% - 48px));
  transform: translate(-50%, -50%);
  border-radius: 14px;
  background: var(--surface);
  text-align: center;
  overflow: hidden;
  animation: fade-in var(--t) ease-out;
}

.dialog h2 { margin: 20px 16px 4px; font-size: 17px; font-weight: 600; }
.dialog p { margin: 0 16px 18px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.dialog-actions { display: flex; border-top: 0.5px solid var(--separator); }
.dialog-actions button { flex: 1; min-height: 46px; color: var(--accent); }
.dialog-actions button + button { border-left: 0.5px solid var(--separator); font-weight: 600; }
.dialog-actions button.danger-text { color: var(--urgent); }

/* weekly review */
.review {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 6px) calc(16px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(16px + var(--safe-left));
  background: var(--bg);
  animation: fade-in var(--t) ease-out;
}

.review-bar { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.review-bar .btn.plain { min-height: 44px; padding: 0 4px; }
.review-progress { font-size: 15px; color: var(--muted); padding-right: 4px; }

.review-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 12px 0 16px;
  padding: 28px 24px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  min-height: 0;
  overflow: hidden;
}

.review-card.entering { animation: card-in var(--t) ease-out; }
.review-title { margin: 8px 0 0; font-size: 28px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; line-clamp: 6; overflow: hidden; }
.review-summary { margin: 10px 0 0; font-size: 17px; color: var(--muted); }
.review-actions { display: flex; gap: 10px; }
.review-actions .btn { flex: 1; padding: 0 8px; min-height: 54px; }

/* routines: day picker */
.days { display: flex; gap: 4px; justify-content: space-between; }
.days button { flex: 1; height: 44px; display: flex; align-items: center; justify-content: center; }
.days button span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--fill);
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  transition: background var(--t) ease-out, color var(--t) ease-out;
}
.days button[aria-pressed="true"] span { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.days-caption { margin: 8px 4px 0; font-size: 15px; color: var(--muted); text-align: center; }

/* first-run setup */
.onboard {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: fade-in var(--t) ease-out;
}
.onboard-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 12px) var(--safe-right) 16px var(--safe-left);
}
.onboard-main.center { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding-left: 32px; padding-right: 32px; }
.onboard-main.center .sloth { width: 168px; height: 140px; margin-bottom: 8px; }
.onboard-lead { margin: 8px 0 0; font-size: 17px; color: var(--muted); }
.onboard-foot {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px calc(16px + var(--safe-right)) calc(12px + var(--safe-bottom) + var(--kb)) calc(16px + var(--safe-left));
  border-top: 0.5px solid var(--separator);
  background: var(--bg);
}
.onboard-foot .btn.plain { min-height: 44px; }
.onboard-foot .btn:disabled { color: var(--muted); cursor: default; opacity: 1; transform: none; }
.onboard-note { margin: 0 0 4px; min-height: 18px; font-size: 13px; color: var(--muted); text-align: center; }
.onboard-note:empty { display: none; }
.idea .check { pointer-events: none; }
.idea.on .check i { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.idea-days { padding: 0 12px 10px 50px; background: var(--surface); }
.idea-days .days button span { width: 32px; height: 32px; font-size: 13px; }

/* toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  transform: translateX(-50%);
  max-width: calc(100% - 110px);
  padding: 10px 16px;
  border-radius: 20px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  text-align: center;
  z-index: 30;
  animation: fade-in var(--t) ease-out;
}

/* help page */
.steps { margin: 0 16px; padding: 14px 16px 14px 40px; border-radius: 14px; background: var(--surface); }
.steps li { padding: 5px 0; }

@media (min-width: 521px) {
  body { background: color-mix(in srgb, var(--bg) 90%, var(--muted)); }
  #app { box-shadow: 0 0 0 0.5px var(--separator); }
}

@media (prefers-reduced-motion: reduce) {
  :root { --t: 1ms; }
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

.sloth .eye { stroke: var(--sloth-face); }
