/* Habits — iOS-style stylesheet.
   System font, iOS system colours, inset grouped lists, one accent (indigo).
   Only the nav bar and tab bar are translucent. Motion uses transform and opacity. */

@property --p {
  syntax: '<number>';
  inherits: true;
  initial-value: 0;
}

:root {
  color-scheme: light dark;

  /* Safe areas (overridable for testing). */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;

  /* iOS system colours, light */
  --bg: #F2F2F7;
  --surface: #FFFFFF;
  --sheet-bg: #F2F2F7;
  --raised: #FFFFFF;
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --sep: rgba(60, 60, 67, 0.29);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.2);
  --press: rgba(0, 0, 0, 0.06);
  --bar: rgba(249, 249, 249, 0.8);
  --bar-sep: rgba(0, 0, 0, 0.3);
  --tab-off: #8E8E93;
  --tab-knock: #FFFFFF;
  --switch-off: #E9E9EA;
  --seg-thumb: #FFFFFF;
  --grid: rgba(60, 60, 67, 0.16);
  --heat-zero: rgba(118, 118, 128, 0.16);
  --heat-off: rgba(118, 118, 128, 0.07);
  --toast: rgba(30, 30, 32, 0.94);
  --shadow-lift: 0 10px 30px rgba(0, 0, 0, 0.14), 0 1px 3px rgba(0, 0, 0, 0.08);

  --accent: #5856D6;
  --accent-text: #5856D6;
  --accent-fill: rgba(88, 86, 214, 0.12);
  --red: #FF3B30;
  --green: #34C759;
  --orange: #FF9500;
  --ring-track: 0.24;

  --c-red: #FF3B30; --c-orange: #FF9500; --c-yellow: #FFCC00; --c-green: #34C759;
  --c-mint: #00C7BE; --c-teal: #30B0C7; --c-cyan: #32ADE6; --c-blue: #007AFF;
  --c-indigo: #5856D6; --c-purple: #AF52DE; --c-pink: #FF2D55; --c-brown: #A2845E;

  /* Solid fills behind white glyphs keep the saturated light values in both modes,
     because white on the paler dark-mode cyan, mint and yellow washes out. */
  --cf-red: #FF3B30; --cf-orange: #FF9500; --cf-yellow: #F5BE00; --cf-green: #34C759;
  --cf-mint: #00B8AF; --cf-teal: #30B0C7; --cf-cyan: #32ADE6; --cf-blue: #007AFF;
  --cf-indigo: #5E5CE6; --cf-purple: #AF52DE; --cf-pink: #FF2D55; --cf-brown: #A2845E;

  --margin: 16px;
  --radius: 12px;
  --hairline: 0.5px;
  --tabbar: 49px;
  --navbar: 44px;

  /* Springs sampled from a damped-oscillator model (see README). */
  --spring: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring-bouncy: cubic-bezier(0.3, 1.3, 0.4, 1);
}

@supports (transition-timing-function: linear(0, 1)) {
  :root {
    --spring: linear(0, 0.039, 0.131, 0.249, 0.372, 0.49, 0.597, 0.689, 0.766, 0.828, 0.877, 0.915, 0.944, 0.965, 0.98, 0.99, 0.997, 1.001, 1.003, 1.005, 1.005, 1.005, 1.004, 1.004, 1);
    --spring-bouncy: linear(0, 0.031, 0.109, 0.218, 0.342, 0.47, 0.593, 0.706, 0.805, 0.887, 0.954, 1.004, 1.041, 1.065, 1.078, 1.083, 1.082, 1.077, 1.068, 1.058, 1.047, 1.037, 1.027, 1.019, 1.011, 1.005, 1.001, 0.997, 0.995, 0.994, 1);
  }
}

@media (min-resolution: 3dppx) { :root { --hairline: 0.34px; } }
@media (min-width: 414px) { :root { --margin: 20px; } }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --sheet-bg: #1C1C1E;
    --raised: #2C2C2E;
    --label: #FFFFFF;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --sep: rgba(84, 84, 88, 0.65);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(120, 120, 128, 0.32);
    --press: rgba(255, 255, 255, 0.08);
    --bar: rgba(22, 22, 23, 0.78);
    --bar-sep: rgba(255, 255, 255, 0.15);
    --tab-off: #8D8D93;
    --tab-knock: #161617;
    --switch-off: #39393D;
    --seg-thumb: #636366;
    --grid: rgba(235, 235, 245, 0.14);
    --heat-zero: rgba(118, 118, 128, 0.3);
    --heat-off: rgba(118, 118, 128, 0.13);
    --toast: rgba(58, 58, 60, 0.96);
    --shadow-lift: 0 10px 30px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4);

    --accent: #5E5CE6;
    --accent-text: #7D7AFF;
    --accent-fill: rgba(125, 122, 255, 0.18);
    --red: #FF453A;
    --green: #30D158;
    --orange: #FF9F0A;
    --ring-track: 0.3;
    --bar-dim: 0.58;

    --c-red: #FF453A; --c-orange: #FF9F0A; --c-yellow: #FFD60A; --c-green: #30D158;
    --c-mint: #63E6E2; --c-teal: #40CBE0; --c-cyan: #64D2FF; --c-blue: #0A84FF;
    --c-indigo: #5E5CE6; --c-purple: #BF5AF2; --c-pink: #FF375F; --c-brown: #AC8E68;
  }
  /* In dark mode the sheet's grouped cells are a step lighter than the sheet. */
  .sheet .group { background: var(--raised); }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation; /* no double-tap zoom */
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  font-size: 17px;
  line-height: 22px;
  letter-spacing: -0.024em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
body.has-sheet { background: #000; }

button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button, .row, .tab, .sday, .cday, .swatch, .icon-opt, label, .grabber, .seg, .stepper, .switch {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button:disabled { cursor: default; }
input { -webkit-user-select: text; user-select: text; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: 8px; }
svg { display: block; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- App frame ---------- */
#app {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  opacity: 0;
  transform-origin: 50% 0;
  transition: transform 460ms var(--spring), opacity 200ms ease-out;
}
.is-ready #app { opacity: 1; }
.has-sheet #app { border-radius: 12px; }
#app.is-receded { transform: translate3d(0, calc(var(--sat) + 4px), 0) scale(0.94); }

.views { position: absolute; inset: 0; }

.tab-view {
  position: absolute;
  inset: 0;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease-out, visibility 0s linear 200ms;
}
.tab-view.is-active { opacity: 1; visibility: visible; transition: opacity 200ms ease-out, visibility 0s; }
.tab-view.is-instant { transition: none; }

/* ---------- Pages ---------- */
.page {
  position: absolute;
  inset: 0;
  background: var(--bg);
  overflow: hidden;
  touch-action: pan-y;
}
.page.is-pushed { box-shadow: -1px 0 0 var(--sep); }
.page.is-covered { transform: translate3d(-30%, 0, 0); }
.page-shade {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 400ms ease-out;
}
.page.is-covered .page-shade { opacity: 1; }

.scroller {
  position: absolute;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding-top: calc(var(--sat) + var(--navbar));
  padding-bottom: calc(var(--tabbar) + var(--sab) + 32px);
  scrollbar-width: none;
}
.scroller::-webkit-scrollbar { display: none; }

.content {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 calc(var(--margin) + var(--sar)) 0 calc(var(--margin) + var(--sal));
}

/* ---------- Navigation bar ---------- */
.navbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  height: calc(var(--sat) + var(--navbar));
  padding: var(--sat) calc(var(--sar) + 8px) 0 calc(var(--sal) + 8px);
  display: grid;
  grid-template-columns: 1fr minmax(0, auto) 1fr;
  align-items: center;
}
.bar-bg {
  position: absolute;
  inset: 0;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
/* Nav bar background: the blur switches on as soon as content scrolls under the bar, and the
   tint fades in on a separate layer (opacity on a backdrop-filter element defeats the blur). */
.nav-blur { position: absolute; inset: 0; }
.navbar.is-scrolled .nav-blur {
  background: rgba(128, 128, 128, 0.01); /* Chromium skips backdrop filters on fully transparent boxes */
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.nav-tint {
  position: absolute;
  inset: 0;
  background: var(--bar);
  box-shadow: 0 var(--hairline) 0 var(--bar-sep);
  opacity: 0;
  transition: opacity 180ms linear;
}
.navbar.is-scrolled .nav-tint { opacity: 1; }
.nav-left, .nav-right { position: relative; display: flex; align-items: center; min-width: 0; }
.nav-right { justify-content: flex-end; }
.nav-title {
  position: relative;
  font-size: 17px;
  line-height: 22px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 56vw;
  opacity: 0;
  transform: translate3d(0, 4px, 0);
  transition: opacity 180ms linear, transform 220ms var(--spring);
}
.navbar.is-collapsed .nav-title { opacity: 1; transform: none; }

.nav-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 8px;
  font-size: 17px;
  color: var(--accent-text);
  white-space: nowrap;
}
.nav-btn.bold { font-weight: 600; }
.nav-btn:disabled { color: var(--label-3); }
.nav-btn:active, .nav-icon:active, .nav-back:active { opacity: 0.4; }
.nav-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--accent-text);
}
.nav-icon .uicon { width: 24px; height: 24px; }
.nav-back {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 8px 0 0;
  margin-left: -2px;
  color: var(--accent-text);
  font-size: 17px;
  white-space: nowrap;
}
.nav-back-icon { width: 24px; height: 24px; margin-right: -1px; }

/* Large title */
.lt { padding: 2px 0 10px; }
.large-title {
  margin: 0;
  font-size: 34px;
  line-height: 41px;
  font-weight: 700;
  letter-spacing: 0.011em;
  overflow-wrap: anywhere;
}
.lt-sub {
  margin: 0;
  font-size: 15px;
  line-height: 20px;
  font-weight: 600;
  color: var(--label-2);
  letter-spacing: -0.016em;
}
.lt-sub:empty { display: none; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  height: calc(var(--tabbar) + var(--sab));
  padding-bottom: var(--sab);
}
.tabbar .bar-bg { box-shadow: 0 calc(var(--hairline) * -1) 0 var(--bar-sep); }
.tabbar-items {
  position: relative;
  display: flex;
  height: var(--tabbar);
  padding: 0 var(--sar) 0 var(--sal);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 6px;
  gap: 2px;
  color: var(--tab-off);
  min-height: 44px;
}
.tab-icon { width: 25px; height: 25px; }
.tab-icon.on { display: none; }
.tab.is-selected { color: var(--accent-text); }
.tab.is-selected .tab-icon.on { display: block; }
.tab.is-selected .tab-icon.off { display: none; }
.tab-label { font-size: 10px; line-height: 12px; font-weight: 500; letter-spacing: 0.01em; }

/* ---------- Grouped lists ---------- */
.group {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  margin: 0 0 28px;
  overflow: hidden;
}
.group.pad { padding: 12px 8px; }
.group-header {
  margin: 0 16px 7px;
  font-size: 13px;
  line-height: 18px;
  font-weight: 400;
  color: var(--label-2);
  letter-spacing: -0.006em;
}
.group-footer {
  margin: -20px 16px 28px;
  font-size: 13px;
  line-height: 18px;
  color: var(--label-2);
  letter-spacing: -0.006em;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 11px 16px;
  text-align: left;
  color: var(--label);
  font-size: 17px;
  line-height: 22px;
  --sep-inset: 16px;
}
.row::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--press);
  opacity: 0;
  transition: opacity 260ms ease-out;
  pointer-events: none;
}
button.row:active::before, .row.is-holding::before, .edit-main:active::before { opacity: 1; transition: none; }
.list > .row + .row::after, .list > .row + .edit-row::after, .list > .edit-row + .row::after, .list > [hidden] + .row::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: var(--sep-inset);
  height: var(--hairline);
  background: var(--sep);
  pointer-events: none;
}
.list > .row:first-child::after { display: none; }
.row.cell { min-height: 44px; }
.row-label { flex: 1; min-width: 0; }
.row-value {
  color: var(--label-2);
  text-align: right;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.row-value.is-warn { color: var(--orange); }
.warn-glyph { width: 17px; height: 17px; }
.row-chevron { width: 14px; height: 14px; color: var(--label-3); flex: none; margin-left: -4px; }
.row-btn { color: var(--accent-text); gap: 12px; }
.row-btn.destructive { color: var(--red); }
.row-btn-icon { width: 22px; height: 22px; flex: none; }
.row-check { width: 20px; height: 20px; color: var(--accent-text); opacity: 0; }
.check-row.is-on .row-check { opacity: 1; }

.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-sub {
  display: flex;
  flex-wrap: wrap;
  column-gap: 10px;
  font-size: 15px;
  line-height: 20px;
  color: var(--label-2);
  letter-spacing: -0.016em;
}
.row-sub > span { white-space: nowrap; }
.meta-icon { display: inline-flex; align-items: center; gap: 3px; }
.meta-glyph { width: 14px; height: 14px; flex: none; }

/* Habit tiles */
.tile {
  --tile: 40px;
  width: var(--tile);
  height: var(--tile);
  flex: none;
  border-radius: calc(var(--tile) * 0.25);
  background: var(--hcf, var(--hc, var(--accent)));
  color: #fff;
  display: grid;
  place-items: center;
}
.tile .hicon { width: calc(var(--tile) * 0.6); height: calc(var(--tile) * 0.6); }

.habit-row { min-height: 64px; padding: 10px 16px; --sep-inset: 68px; }
.list.is-quiet .habit-row .tile, .list.is-quiet .habit-row .row-text { opacity: 0.55; }
.habit-row.is-optional .row-text { opacity: 0.6; }

/* ---------- Progress ring (transform-only fill) ---------- */
.ring {
  --size: 30px;
  --w: 3px;
  --rc: var(--hc, var(--accent));
  position: relative;
  display: block;
  flex: none;
  width: var(--size);
  height: var(--size);
  transition: --p 440ms var(--spring);
}
.ring > span { position: absolute; inset: 0; border-radius: 50%; }
.ring-track { border: var(--w) solid var(--rc); opacity: var(--ring-track); }
.ring-r { clip-path: inset(0 0 0 50%); opacity: clamp(0, calc(var(--p) * 1000), 1); }
.ring-l { clip-path: inset(0 50% 0 0); opacity: clamp(0, calc((var(--p) - 0.5) * 1000), 1); }
.ring-fill {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: var(--w) solid transparent;
}
.ring-r .ring-fill {
  border-left-color: var(--rc);
  border-bottom-color: var(--rc);
  transform: rotate(calc(45deg + min(var(--p), 0.5) * 360deg));
}
.ring-l .ring-fill {
  border-right-color: var(--rc);
  border-top-color: var(--rc);
  transform: rotate(calc(45deg + max(var(--p) - 0.5, 0) * 360deg));
}
.ring > .ring-cap-start, .ring-capper .ring-cap {
  position: absolute;
  inset: auto;
  top: 0;
  left: calc(50% - var(--w) / 2);
  width: var(--w);
  height: var(--w);
  border-radius: 50%;
  background: var(--rc);
}
.ring > .ring-cap-start, .ring > .ring-capper { opacity: clamp(0, calc(var(--p) * 1000), 1); }
.ring > .ring-capper { transform: rotate(calc(var(--p) * 360deg)); }

/* ---------- Completion control ---------- */
.check {
  position: relative;
  flex: none;
  width: 32px;
  height: 32px;
  color: #fff;
}
.check > .ring { --size: 32px; --w: 3px; position: absolute; inset: 0; }
.check-disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--hcf, var(--hc, var(--accent)));
  opacity: 0;
  transform: scale(0.4);
  transition: transform 260ms var(--spring), opacity 140ms linear;
}
.check.is-done .check-disc {
  opacity: 1;
  transform: scale(1);
  transition: transform 420ms var(--spring-bouncy) 140ms, opacity 120ms linear 140ms;
}
.check-mask {
  position: absolute;
  inset: 5px;
  overflow: hidden;
  transform: translate3d(-101%, 0, 0);
  transition: transform 160ms ease-in;
}
.check-mask svg {
  width: 100%;
  height: 100%;
  transform: translate3d(101%, 0, 0);
  transition: transform 160ms ease-in;
}
.check.is-done .check-mask, .check.is-done .check-mask svg {
  transform: none;
  transition: transform 300ms cubic-bezier(0.35, 0.6, 0.3, 1) 220ms;
}
.check-count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-rounded);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--label-2);
  font-variant-numeric: tabular-nums;
}
.check.pop { animation: check-pop 420ms var(--spring); }
@keyframes check-pop {
  0% { transform: scale(1); }
  35% { transform: scale(0.84); }
  100% { transform: scale(1); }
}
.no-anim, .no-anim * { transition: none !important; animation: none !important; }

/* ---------- Today: week strip ---------- */
.strip { margin: 2px calc(-1 * var(--margin)) 14px; }
.strip-pages {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  touch-action: pan-x pan-y;
}
.strip-pages::-webkit-scrollbar { display: none; }
.strip-week {
  flex: 0 0 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 calc(var(--margin) - 6px);
}
.sday {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 2px 0 4px;
  min-height: 62px;
  color: var(--label);
}
.sday-wd {
  font-size: 13px;
  line-height: 16px;
  font-weight: 600;
  color: var(--label-2);
  letter-spacing: 0;
}
.sday-dot { position: relative; width: 38px; height: 38px; display: grid; place-items: center; }
.sday-dot > .ring { --size: 38px; --w: 3px; --rc: var(--accent); position: absolute; inset: 0; }
.sday-num {
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-rounded);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.sday-num::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  transform: scale(0.6);
  transition: transform 300ms var(--spring), opacity 160ms linear;
  z-index: -1;
}
.sday-num { z-index: 0; }
.sday.is-today .sday-num { color: var(--accent-text); font-weight: 700; }
.sday.is-selected .sday-num { color: #fff; font-weight: 600; }
.sday.is-selected .sday-num::before { opacity: 1; transform: none; }
.sday.is-selected .sday-wd { color: var(--label); }
.sday:disabled { color: var(--label-3); }
.sday:disabled .sday-wd { color: var(--label-3); }
.sday:disabled .ring { opacity: 0; }

/* ---------- Today: summary ---------- */
.summary {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 18px;
}
.summary > .ring { --size: 76px; --w: 11px; --rc: var(--accent); }
.sum-big {
  font-family: var(--font-rounded);
  font-weight: 700;
  font-size: 34px;
  line-height: 40px;
  letter-spacing: 0.005em;
}
.sum-of { font-size: 22px; font-weight: 600; color: var(--label-2); }
.sum-sub { font-size: 15px; line-height: 20px; color: var(--label-2); margin-top: 1px; letter-spacing: -0.016em; }
.summary.is-complete .sum-sub { color: var(--label); font-weight: 600; }

.t-due .group, .t-off .group { margin-bottom: 28px; }

/* ---------- Edit mode (reorder) ---------- */
.edit-row { padding: 0; gap: 0; min-height: 64px; --sep-inset: 68px; background: var(--surface); }
.edit-main {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0 10px 16px;
  text-align: left;
  min-height: 64px;
}
.edit-main::before {
  content: '';
  position: absolute;
  inset: 0 -60px 0 0;
  background: var(--press);
  opacity: 0;
  transition: opacity 260ms ease-out;
  pointer-events: none;
}
.grabber {
  width: 60px;
  height: 64px;
  display: grid;
  place-items: center;
  color: var(--label-3);
  touch-action: none;
  cursor: grab;
}
.grabber .uicon { width: 22px; height: 22px; }
.list.is-sorting { overflow: visible; }
.list > .edit-row:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.list > .edit-row:last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.list.is-sorting .edit-row { transition: transform 260ms var(--spring); }
.edit-row.is-lifted {
  z-index: 5;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  transition: none !important;
}
.edit-row.is-lifted::after { opacity: 0; }

/* ---------- Buttons ---------- */
.btn-filled {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 50px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}
.btn-filled:active, .btn-tinted:active, .btn-pill:active, .btn-plain:active { opacity: 0.6; }
.btn-tinted {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  background: var(--accent-fill);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
}
.btn-plain { min-height: 44px; padding: 0 12px; color: var(--accent-text); font-size: 15px; }
.btn-pill {
  position: relative;
  min-height: 30px;
  padding: 0 14px;
  border-radius: 15px;
  background: var(--accent-fill);
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
  flex: none;
}
.btn-pill::after { content: ''; position: absolute; inset: -7px -4px; }
.btn-pill:disabled { opacity: 0.4; }
.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--accent-text);
}
.icon-btn .uicon { width: 22px; height: 22px; }
.icon-btn:disabled { color: var(--label-3); }
.icon-btn:active { opacity: 0.4; }

/* ---------- Empty state & suggestions ---------- */
.empty { text-align: center; padding: 20px 20px 28px; }
.empty.compact { padding-top: 40px; }
.empty-mark { display: flex; justify-content: center; margin-bottom: 18px; color: var(--accent-text); }
.empty-mark { position: relative; }
.empty-mark > .ring { --size: 72px; --w: 9px; --rc: var(--accent); }
.empty-check { position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; color: var(--accent-text); }
.empty-glyph { width: 52px; height: 52px; }
.empty-title { margin: 0; font-size: 22px; line-height: 28px; font-weight: 700; letter-spacing: 0.016em; }
.empty-text { margin: 8px auto 0; max-width: 310px; font-size: 17px; line-height: 22px; color: var(--label-2); }
.suggest-row { min-height: 64px; padding: 10px 16px; --sep-inset: 68px; }
.t-create { margin: -8px 0 28px; }

/* ---------- Backup nudge & install card ---------- */
.nudge, .install { padding: 14px 16px 12px; }
.nudge-body, .install-head { display: flex; gap: 12px; align-items: flex-start; }
.nudge-icon, .install-icon { width: 28px; height: 28px; flex: none; color: var(--accent-text); margin-top: -1px; }
.nudge-title, .install-title { font-size: 17px; line-height: 22px; font-weight: 600; }
.nudge-text, .install-text { margin: 2px 0 0; font-size: 15px; line-height: 20px; color: var(--label-2); letter-spacing: -0.016em; }
.nudge-actions { display: flex; gap: 4px; margin: 10px 0 0 34px; }
.install-steps { margin: 12px 0 2px; padding-left: 62px; font-size: 15px; line-height: 20px; letter-spacing: -0.016em; }
.install-steps li { margin: 6px 0; padding-left: 2px; }
.inline-glyph { display: inline-block; width: 18px; height: 18px; vertical-align: -3px; color: var(--accent-text); }

/* ---------- Detail ---------- */
.d-lt { display: flex; align-items: center; gap: 14px; }
.d-lt-text { min-width: 0; }
.tile.tile-lg { --tile: 56px; }
.d-lt .large-title { font-size: 30px; line-height: 36px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); padding: 14px 0 13px; }
.stat { padding: 0 14px; min-width: 0; }
.stat + .stat { box-shadow: inset var(--hairline) 0 0 var(--sep); }
.stat-num {
  font-family: var(--font-rounded);
  font-size: 28px;
  line-height: 34px;
  font-weight: 700;
  letter-spacing: 0.005em;
  white-space: nowrap;
}
.stat-unit { font-size: 15px; font-weight: 600; color: var(--label-2); margin-left: 3px; letter-spacing: 0; }
.stat-unit.pct { margin-left: 1px; }
.stat-label { font-size: 13px; line-height: 16px; color: var(--label-2); margin-top: 2px; }

.cal { padding: 8px 6px 8px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; padding: 0 0 0 12px; }
.cal-title { margin: 0; font-size: 17px; line-height: 22px; font-weight: 600; }
.cal-nav { display: flex; }
.cal-wd, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-wd { padding: 2px 0 4px; font-size: 13px; line-height: 18px; font-weight: 600; color: var(--label-2); text-align: center; }
.cal-viewport { overflow: hidden; touch-action: pan-y; }
.cal-grid { row-gap: 2px; }
.cday {
  position: relative;
  height: 46px;
  display: grid;
  place-items: center;
  color: var(--label);
}
.cday > * { grid-area: 1 / 1; }
.cday-bg {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--hcf, var(--hc));
  opacity: 0;
  transform: scale(0.5);
  transition: transform 380ms var(--spring-bouncy), opacity 140ms linear;
}
.cday > .ring { --size: 38px; --w: 3px; opacity: 0; }
.cday.is-partial > .ring { opacity: 1; }
.cday-num {
  position: relative;
  font-family: var(--font-rounded);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.cday.is-done .cday-bg { opacity: 1; transform: none; }
.cday.is-done .cday-num { color: #fff; font-weight: 600; }
.cday.is-off .cday-num { color: var(--label-3); }
.cday.is-today:not(.is-done) .cday-num { color: var(--accent-text); font-weight: 700; }
.cday.is-future .cday-num { color: var(--label-3); }
.cday:active:not(:disabled) .cday-num { opacity: 0.5; }

.card { padding: 14px 16px 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-title { margin: 0; font-size: 17px; line-height: 22px; font-weight: 600; }
.card-meta { font-size: 15px; line-height: 20px; color: var(--label-2); white-space: nowrap; letter-spacing: -0.016em; }
.card-lead { margin: -4px 0 12px; font-size: 15px; line-height: 20px; color: var(--label-2); letter-spacing: -0.016em; }

.heatmap { overflow: visible; }
.hm-host { touch-action: pan-y; cursor: pointer; }
.heatmap .hm-month, .heatmap .hm-wd { font-size: 11px; fill: var(--label-2); letter-spacing: 0; font-family: var(--font); }
.hm-cell.is-on { fill: var(--hc); }
.hm-cell.is-zero { fill: var(--heat-zero); }
.hm-cell.is-off, .hm-cell.is-na { fill: var(--heat-off); }
.hm-cell.is-sel { stroke: var(--label); stroke-width: 1.5px; opacity: 1 !important; }
.hm-caption, .chart-caption {
  margin: 8px 0 0;
  min-height: 18px;
  font-size: 13px;
  line-height: 18px;
  color: var(--label-2);
  letter-spacing: -0.006em;
}

/* ---------- Insights ---------- */
.stat-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 28px; }
.stat-tile { margin: 0; padding: 12px 14px 13px; }
.st-label { font-size: 15px; line-height: 20px; font-weight: 600; color: var(--label-2); letter-spacing: -0.016em; }
.st-num {
  margin-top: 2px;
  font-family: var(--font-rounded);
  font-size: 34px;
  line-height: 40px;
  font-weight: 700;
}
.st-pct { font-size: 22px; font-weight: 600; color: var(--label-2); margin-left: 1px; }
.st-delta {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 2px;
  font-size: 13px;
  line-height: 16px;
  color: var(--label-2);
}
.delta-icon { width: 13px; height: 13px; flex: none; }
.stat-foot { margin-top: -20px; }

.chart { display: block; overflow: visible; }
.chart text { font-family: var(--font); letter-spacing: 0; }
.ch-grid { stroke: var(--grid); stroke-width: 1px; shape-rendering: crispEdges; }
.ch-tick, .ch-x { font-size: 11px; fill: var(--label-2); font-variant-numeric: tabular-nums; }
.ch-bar { fill: var(--accent); opacity: var(--bar-dim, 0.4); }
.ch-bar.is-hl { opacity: 1; }
.chart.has-sel .ch-bar { opacity: 0.25; }
.chart.has-sel .ch-bar.is-sel { opacity: 1; }
.ch-empty { fill: var(--label-3); }
.ch-value { font-size: 12px; font-weight: 600; fill: var(--label); font-family: var(--font-rounded); }
.ch-hit { fill: transparent; cursor: pointer; }

.nav-row { min-height: 64px; padding: 10px 16px; --sep-inset: 68px; }
.rate-value { font-family: var(--font-rounded); font-weight: 600; color: var(--label); font-variant-numeric: tabular-nums; }

/* ---------- Switch ---------- */
.switch { position: relative; width: 51px; height: 31px; flex: none; display: block; }
.switch::after { content: ''; position: absolute; inset: -7px -4px; }
.switch input {
  position: absolute;
  inset: -7px -4px;
  width: calc(100% + 8px);
  height: calc(100% + 14px);
  margin: 0;
  opacity: 0;
  z-index: 2;
  cursor: pointer;
}
.switch-track { position: absolute; inset: 0; border-radius: 16px; background: var(--switch-off); overflow: hidden; }
.switch-track::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--green);
  opacity: 0;
  transition: opacity 220ms ease-out;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  transition: transform 300ms var(--spring);
}
.switch input:checked + .switch-track::before { opacity: 1; }
.switch input:checked + .switch-track .switch-thumb { transform: translate3d(20px, 0, 0); }
.switch.is-disabled { opacity: 0.4; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent-text); outline-offset: 2px; }

/* ---------- Sheets ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 100; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 340ms ease-out;
}
.sheet-layer.is-open .sheet-backdrop { opacity: 1; }
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: calc(var(--sat) + 14px);
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--sheet-bg);
  border-radius: 12px 12px 0 0;
  transform: translate3d(0, 100%, 0);
  transition: transform 460ms var(--spring);
  outline: none;
  overflow: hidden;
}
.sheet-layer.is-open .sheet { transform: none; }
.sheet-grabber {
  flex: none;
  width: 36px;
  height: 5px;
  margin: 5px auto 0;
  border-radius: 3px;
  background: var(--label-3);
}
.sheet-nav {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 46px;
  padding: 0 8px;
  touch-action: none;
}
.sheet-nav-right { display: flex; justify-content: flex-end; }
.sheet-title { margin: 0; font-size: 17px; line-height: 22px; font-weight: 600; text-align: center; }
.sheet-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 6px calc(var(--margin) + var(--sar)) calc(var(--sab) + 28px) calc(var(--margin) + var(--sal));
}

/* Editor */
.ed-hero { display: flex; justify-content: center; padding: 6px 0 18px; }
.ed-tile { --tile: 76px; border-radius: 19px; }
.ed-tile .hicon { width: 44px; height: 44px; }
.ed-name {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 24px;
  font-weight: 600;
  text-align: center;
  color: var(--label);
}
.ed-name::placeholder { color: var(--label-3); }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); row-gap: 6px; justify-items: center; }
.swatch { position: relative; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
.swatch span { width: 30px; height: 30px; border-radius: 50%; background: var(--hcf, var(--hc)); }
.swatch::after {
  content: '';
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  border: 3px solid var(--hcf, var(--hc));
  opacity: 0;
  transform: scale(0.8);
  transition: transform 300ms var(--spring), opacity 150ms linear;
}
.swatch.is-on::after { opacity: 1; transform: none; }
.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); row-gap: 8px; justify-items: center; }
.icon-opt {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--label-2);
}
.icon-opt::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--fill);
}
.icon-opt::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--hcf, var(--hc));
  opacity: 0;
  transform: scale(0.7);
  transition: transform 300ms var(--spring), opacity 150ms linear;
}
.icon-opt .hicon { position: relative; z-index: 1; width: 24px; height: 24px; }
.icon-opt.is-on { color: #fff; }
.icon-opt.is-on::after { opacity: 1; transform: none; }

.row-pad { padding: 10px 16px; }
.row-pad + .row-pad { padding-top: 2px; }
.seg {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: 34px;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
}
.seg-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc((100% - 4px) / 3);
  border-radius: 7px;
  background: var(--seg-thumb);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
  transform: translate3d(calc(var(--i, 0) * 100%), 0, 0);
  transition: transform 340ms var(--spring);
}
.seg-btn { position: relative; z-index: 1; font-size: 14px; line-height: 18px; font-weight: 500; letter-spacing: -0.01em; }
.seg-btn::after { content: ''; position: absolute; inset: -7px 0; }
.seg-btn.is-on { font-weight: 600; }
.ed-days { display: flex; justify-content: space-between; }
.day-toggle {
  position: relative;
  isolation: isolate;
  width: 44px;
  height: 44px;
  margin: -2px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-rounded);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--label);
}
.day-toggle::before, .day-toggle::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: 50%;
}
.day-toggle::before { background: var(--fill); }
.day-toggle::after {
  background: var(--hcf, var(--hc));
  opacity: 0;
  transform: scale(0.7);
  transition: transform 300ms var(--spring), opacity 150ms linear;
}
.day-toggle.is-on { color: #fff; }
.day-toggle.is-on::after { opacity: 1; transform: none; }
.day-toggle:focus-visible { border-radius: 50%; }
.stepper { display: flex; align-items: center; height: 34px; border-radius: 9px; background: var(--fill); flex: none; }
.step-btn { position: relative; width: 48px; height: 34px; display: grid; place-items: center; color: var(--label); }
.step-btn::after { content: ''; position: absolute; inset: -5px 0; }
.step-btn .uicon { width: 18px; height: 18px; }
.step-btn:disabled { color: var(--label-3); }
.step-btn:active:not(:disabled) { opacity: 0.4; }
.step-sep { width: 1px; height: 18px; background: var(--sep); }
.row-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: right;
  font-size: 17px;
  color: var(--label-2);
  padding: 0;
  min-height: 22px;
}
.row-input::placeholder { color: var(--label-3); }
.time-input {
  font-size: 17px;
  line-height: 22px;
  color: var(--accent-text);
  background: var(--fill);
  border: 0;
  border-radius: 8px;
  padding: 6px 11px;
  min-height: 34px;
  min-width: 90px;
  text-align: center;
}
.time-input::-webkit-date-and-time-value { text-align: center; }
.time-input::-webkit-calendar-picker-indicator { display: none; }

/* ---------- Action sheet ---------- */
.as-layer { position: fixed; inset: 0; z-index: 200; }
.as-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); opacity: 0; transition: opacity 260ms ease-out; }
.as {
  position: absolute;
  left: calc(8px + var(--sal));
  right: calc(8px + var(--sar));
  bottom: calc(8px + var(--sab));
  max-width: 520px;
  margin: 0 auto;
  transform: translate3d(0, calc(100% + 40px), 0);
  transition: transform 420ms var(--spring);
}
.as-layer.is-open .as-backdrop { opacity: 1; }
.as-layer.is-open .as { transform: none; }
.as-layer.is-closing .as { transition: transform 220ms ease-in; }
.as-layer.is-closing .as-backdrop { transition: opacity 220ms ease-in; }
.as-group { background: var(--surface); border-radius: 14px; overflow: hidden; }
.as-group + .as-group { margin-top: 8px; }
.as-head { padding: 14px 16px 13px; text-align: center; box-shadow: inset 0 calc(var(--hairline) * -1) 0 var(--sep); }
.as-title { font-size: 13px; line-height: 18px; font-weight: 600; color: var(--label-2); }
.as-msg { font-size: 13px; line-height: 18px; color: var(--label-2); margin-top: 2px; }
.as-btn {
  position: relative;
  display: block;
  width: 100%;
  min-height: 57px;
  padding: 0 16px;
  font-size: 20px;
  line-height: 24px;
  color: var(--accent-text);
  letter-spacing: 0.02em;
}
.as-btn + .as-btn { box-shadow: inset 0 var(--hairline) 0 var(--sep); }
.as-btn:active { background: var(--press); }
.as-btn.destructive { color: var(--red); }
.as-btn.cancel { font-weight: 600; }

/* ---------- Alert ---------- */
.alert-layer { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 24px; }
.alert-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.3); opacity: 0; transition: opacity 200ms ease-out; }
.alert {
  position: relative;
  width: 270px;
  border-radius: 14px;
  background: var(--surface);
  text-align: center;
  opacity: 0;
  transform: scale(1.12);
  transition: transform 340ms var(--spring), opacity 180ms ease-out;
}
@media (prefers-color-scheme: dark) { .alert { background: var(--raised); } }
.alert-layer.is-open .alert-backdrop, .alert-layer.is-open .alert { opacity: 1; }
.alert-layer.is-open .alert { transform: none; }
.alert-layer.is-closing .alert { transform: scale(0.96); opacity: 0; transition-duration: 180ms; }
.alert-layer.is-closing .alert-backdrop { opacity: 0; }
.alert-body { padding: 19px 16px 17px; }
.alert-title { font-size: 17px; line-height: 22px; font-weight: 600; }
.alert-msg { margin-top: 4px; font-size: 13px; line-height: 17px; letter-spacing: -0.006em; }
.alert-actions { display: flex; box-shadow: inset 0 var(--hairline) 0 var(--sep); }
.alert-actions.stacked { flex-direction: column; }
.alert-btn { flex: 1; min-height: 44px; font-size: 17px; color: var(--accent-text); }
.alert-btn + .alert-btn { box-shadow: inset var(--hairline) 0 0 var(--sep); }
.alert-btn.cancel { font-weight: 600; }
.alert-btn.destructive { color: var(--red); }
.alert-btn:active { background: var(--press); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar) + var(--sab) + 16px);
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 48px);
  padding: 10px 16px 10px 13px;
  border-radius: 22px;
  background: var(--toast);
  color: #fff;
  font-size: 15px;
  line-height: 20px;
  font-weight: 500;
  letter-spacing: -0.016em;
  opacity: 0;
  transform: translate3d(-50%, 12px, 0) scale(0.96);
  transition: transform 340ms var(--spring), opacity 200ms ease-out;
  pointer-events: none;
}
.toast.is-shown { opacity: 1; transform: translate3d(-50%, 0, 0); }
.toast-icon { width: 18px; height: 18px; flex: none; color: var(--green); }

.fatal { padding: calc(var(--sat) + 60px) 24px 24px; text-align: center; color: var(--label); }
.fatal h1 { font-size: 22px; line-height: 28px; margin: 0 0 8px; }
.fatal p { color: var(--label-2); margin: 0; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    transition-delay: 0ms !important;
    scroll-behavior: auto !important;
  }
}

/* Rows that start with an icon align their separator with the text. */
.row-btn:has(> .row-btn-icon) { --sep-inset: 50px; }
