@font-face {
  font-family: "Figtree";
  src: url("/fonts/figtree-latin-wght.woff2") format("woff2");
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #F6F6F3;
  --surface: #FFFFFF;
  --surface-2: #EDEDE9;
  --border: #EAEAE5;
  --text: #1B1C1E;
  --text-2: #45484E;
  --muted: #5F636A;
  --success-text: #2B7A3D;
  --danger: #B42323;
  --field-border: #E4E4DF;
  --divider: #F0F0EC;
  --cell-today-border: #C4C4BD;
  --hover: #F3F3F0;
  --backdrop: rgba(27, 28, 30, 0.4);

  --blue: #4F6BED;
  --orange: #D06A0C;
  --teal: #0E8C7E;
  --coral: #D6455D;
  --violet: #7C5CE0;
  --green: #3A8A3E;
  --magenta: #B0478C;
  --sky: #0A7FB0;

  --font: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111213;
    --surface: #1A1B1D;
    --surface-2: #26272A;
    --border: #2C2D30;
    --text: #EDEDEA;
    --text-2: #C4C6CA;
    --muted: #9EA1A7;
    --success-text: #6CC27D;
    --danger: #F07A7A;
    --field-border: #3A3B3F;
  --divider: #242528;
  --cell-today-border: #5A5C61;
  --hover: #232427;
  --backdrop: rgba(0, 0, 0, 0.55);
    --divider: #242528;
    --cell-today-border: #5A5C61;
    --hover: #232427;
    --backdrop: rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111213;
  --surface: #1A1B1D;
  --surface-2: #26272A;
  --border: #2C2D30;
  --text: #EDEDEA;
  --text-2: #C4C6CA;
  --muted: #9EA1A7;
  --success-text: #6CC27D;
  --danger: #F07A7A;
  --field-border: #3A3B3F;
  --divider: #242528;
  --cell-today-border: #5A5C61;
  --hover: #232427;
  --backdrop: rgba(0, 0, 0, 0.55);
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

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

.num { font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }

button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 10px; }

.label { font-size: 13px; font-weight: 700; color: var(--text-2); }

.input {
  height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1.5px solid var(--field-border);
  background: var(--surface);
  font-size: 16px; /* 16px stops iOS from zooming on focus */
}
.input:focus { outline: none; border-color: var(--text); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input-code { height: 60px; font-size: 28px; font-weight: 700; letter-spacing: 0.45em; text-align: center; }

.btn-primary, .btn-secondary {
  height: 52px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
}
.btn-primary { border: 0; background: var(--text); color: var(--bg); }
.btn-secondary { padding: 0 20px; border: 1.5px solid var(--border); background: var(--surface); }

.link-btn {
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  text-decoration: underline;
}

.form-error { margin: 0; font-size: 14px; color: var(--danger); }
.hint { margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: var(--muted); }

/* Login */
.login {
  min-height: 100dvh;
  max-width: 440px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 72px 24px 32px;
}
.login-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 18px; }
.logo {
  display: grid;
  grid-template-columns: repeat(3, 14px);
  gap: 4px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.logo-cell { width: 14px; height: 14px; border-radius: 4px; }
.logo-cell.blue { background: var(--blue); }
.logo-cell.blue-ring { border: 2px solid var(--blue); }
.logo-cell.orange { background: var(--orange); }
.logo-cell.violet { background: var(--violet); }
.logo-cell.blank { background: var(--surface-2); }
.login-title { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.login-tagline { margin: 8px 0 0; font-size: 16px; line-height: 1.45; color: var(--muted); }
.login-form { margin-top: 40px; display: flex; flex-direction: column; gap: 12px; }
.login-h2 { margin: 0; font-size: 18px; font-weight: 700; }
.login-sub { margin: 6px 0 0; font-size: 14px; line-height: 1.45; color: var(--muted); }
.login-sub strong { color: var(--text); }
.login-row { display: flex; justify-content: space-between; align-items: center; padding-top: 4px; font-size: 14px; }
.login-foot { margin: auto 0 0; padding-top: 32px; font-size: 12px; color: var(--muted); text-align: center; }

/* Boot error */
.placeholder { max-width: 440px; margin: 0 auto; padding: 72px 24px; display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }
.placeholder p { margin: 0; }

.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.link-btn.inline { min-height: 0; font-size: inherit; color: inherit; }

/* App shell: content scrolls, tab bar pinned to the bottom */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.page { flex: 1; width: 100%; max-width: 520px; margin: 0 auto; padding-bottom: 96px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px;
  padding: 8px 12px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar { max-width: 100%; }
.tab {
  min-height: 52px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 11px; font-weight: 600; text-decoration: none;
}
.tab-icon { width: 48px; height: 28px; border-radius: 14px; display: flex; align-items: center; justify-content: center; }
.tab[aria-current="page"] { color: var(--text); font-weight: 700; }
.tab[aria-current="page"] .tab-icon { background: var(--surface-2); }

.page-header { padding: 20px 16px 12px; }
.page-header h1 { margin: 0; font-size: 23px; font-weight: 700; }

/* Buttons */
.icon-btn {
  width: 40px; height: 40px; flex: none; padding: 0; border-radius: 12px;
  border: 1px solid var(--field-border); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
}
.icon-btn.primary { border: 0; background: var(--text); color: var(--bg); }
.btn-outline {
  height: 46px; border-radius: 14px; border: 1px solid var(--field-border); background: var(--surface);
  font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-outline.danger { color: var(--danger); }
.btn-danger { height: 46px; border: 0; border-radius: 12px; background: var(--danger); color: #FFFFFF; font-size: 14px; font-weight: 700; }
:root[data-theme="dark"] .btn-danger { color: #1B1C1E; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-danger { color: #1B1C1E; } }
.text-btn { height: 44px; padding: 0 12px; border: 0; background: transparent; font-size: 15px; font-weight: 600; color: var(--text-2); }

/* Week header + today card */
.week-header { padding: 20px 16px 12px; display: flex; align-items: center; gap: 8px; }
.week-title { flex: 1; min-width: 0; }
.week-num { font-size: 13px; font-weight: 500; color: var(--muted); }
.week-header h1 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -0.01em; }
.today-card {
  margin: 0 16px; padding: 12px 14px; display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
}
.today-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.today-title { font-size: 15px; font-weight: 600; }
.today-pct { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.pct { font-size: 19px; font-weight: 700; }

/* Week grid */
.week-body { padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 12px; }
.day-header { display: flex; align-items: flex-end; gap: 8px; padding: 0 11px; }
.habit-count { flex: 1; min-width: 0; font-size: 12px; font-weight: 500; padding-bottom: 6px; }
.cells { display: grid; grid-template-columns: repeat(7, 30px); gap: 2px; flex: none; }
.day { width: 30px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 0 5px; border-radius: 10px; }
.day-l { font-size: 11px; font-weight: 500; color: var(--muted); }
.day-d { font-size: 13px; font-weight: 700; }
.day.today { background: var(--text); color: var(--bg); }
.day.today .day-l { color: var(--bg); }

.group { display: flex; flex-direction: column; gap: 6px; }
.group-name { margin: 0; height: 28px; padding: 0 4px; display: flex; align-items: center; font-size: 13px; font-weight: 600; color: var(--text-2); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 0 10px; }

.habit-row { display: flex; align-items: center; gap: 8px; height: 50px; }
.habit-row + .habit-row { border-top: 1px solid var(--divider); }
.habit-name {
  flex: 1; min-width: 0; height: 44px; padding: 0; border: 0; background: transparent; text-align: left;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.name-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--c); flex: none; }
.dot.lg { width: 12px; height: 12px; border-radius: 6px; }
.name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; align-items: center; gap: 7px; padding-left: 14px; font-size: 12px; color: var(--muted); }
.prog { font-weight: 500; }
.prog.met { color: var(--success-text); font-weight: 700; }
.streak { display: flex; align-items: center; gap: 2px; }

.cell {
  width: 30px; height: 44px; padding: 0; border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.cell-box {
  width: 26px; height: 32px; border-radius: 9px; border: 1.5px solid transparent;
  display: flex; align-items: center; justify-content: center; color: #FFFFFF;
  transition: background-color .12s;
}
.cell-box.past { background: var(--surface-2); }
.cell-box.today { background: var(--surface); border-color: var(--cell-today-border); }
.cell-box.future { background: var(--bg); }
.cell-box.done { background: var(--c); border-color: var(--c); }
.cell-box.planned { background: color-mix(in srgb, var(--c) 12%, transparent); border-color: var(--c); }
.cell-dot { width: 6px; height: 6px; border-radius: 3px; background: var(--c); }
.cell:focus-visible { outline: none; }
.cell:focus-visible .cell-box { outline: 2px solid var(--blue); outline-offset: 2px; }

.empty { padding: 32px 8px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; color: var(--text-2); }
.empty .btn-primary { padding: 0 24px; }

/* Overlays: bottom sheets */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; justify-content: flex-end; }
.backdrop { position: absolute; inset: 0; border: 0; padding: 0; background: var(--backdrop); cursor: default; }
.sheet {
  position: relative; width: 100%; max-width: 520px; margin: 0 auto;
  background: var(--surface); border-radius: 22px 22px 0 0;
  box-shadow: 0 -10px 30px rgba(27, 28, 30, 0.18);
  animation: sheet-in .18s ease-out;
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.grabber { display: flex; justify-content: center; padding: 8px 0; }
.grabber::before { content: ""; width: 40px; height: 5px; border-radius: 3px; background: var(--field-border); }

/* Habit sheet */
.habit-sheet { height: min(784px, calc(100dvh - 40px)); display: flex; flex-direction: column; background: var(--bg); border-radius: 24px 24px 0 0; }
.sheet-head { display: flex; align-items: center; padding: 0 8px 8px; }
.sheet-head h1 { flex: 1; margin: 0; text-align: center; font-size: 16px; font-weight: 700; }
.save-btn { height: 36px; padding: 0 16px; margin-right: 6px; border: 0; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 15px; font-weight: 700; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px; }
.habit-sheet fieldset { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.habit-sheet legend { padding: 0 0 8px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.name-card { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.name-swatch { width: 44px; height: 44px; flex: none; border-radius: 13px; background: var(--c); color: #FFFFFF; display: flex; align-items: center; justify-content: center; }
.small-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.name-input { width: 100%; border: 0; border-bottom: 1.5px solid transparent; padding: 2px 0; background: transparent; font-size: 18px; font-weight: 700; }
.name-input:focus { outline: none; border-bottom-color: var(--text); }
.swatches { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.swatch { height: 44px; padding: 0; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; }
.swatch span { width: 32px; height: 32px; border-radius: 16px; background: var(--s); border: 3px solid var(--s); }
.swatch[aria-pressed="true"] span { border-color: var(--surface); box-shadow: 0 0 0 2px var(--s); }
.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 4px; border-radius: 14px; background: var(--surface-2); }
.segmented button { height: 38px; border: 0; border-radius: 11px; background: transparent; font-size: 14px; font-weight: 700; }
.segmented button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.stepper { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; font-size: 15px; font-weight: 600; }
.step { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--field-border); background: var(--surface); font-size: 20px; font-weight: 600; }
.step-value { min-width: 74px; text-align: center; font-size: 16px; font-weight: 700; }
.summary { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 13px; color: var(--text-2); }
.manage { display: flex; flex-direction: column; gap: 10px; padding-top: 18px; border-top: 1px solid var(--field-border); }
.manage-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.confirm { padding: 12px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 6%, var(--surface)); display: flex; flex-direction: column; gap: 10px; }
.confirm-text { font-size: 14px; font-weight: 600; line-height: 1.4; }
.confirm-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.confirm-buttons .btn-outline { height: 46px; font-size: 14px; }

/* Toast */
.toast-region { position: fixed; left: 0; right: 0; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 20; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 480px; display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 16px; border-radius: 14px; background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.toast-action { min-height: 36px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; }

/* Week: collapsible groups */
.group-toggle {
  height: 28px; padding: 0 4px; border: 0; background: transparent; display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
}
.group-name { height: auto; padding: 0; }
.caret { display: flex; transition: transform .15s; }
.caret.closed { transform: rotate(-90deg); }
.group-sum { font-weight: 500; color: var(--muted); }

/* Sub pages */
.page-hint { margin: 0; padding: 0 16px 4px; font-size: 13px; line-height: 1.4; color: var(--muted); }
.sub-header { padding: 12px 16px 6px; display: flex; flex-direction: column; gap: 6px; }
.sub-header h1 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -0.01em; }
.sub-header p { margin: 0; font-size: 13px; line-height: 1.4; }
.back { align-self: flex-start; min-height: 44px; display: flex; align-items: center; gap: 2px; margin-left: -6px; font-size: 15px; font-weight: 600; color: var(--text-2); text-decoration: none; }
a.icon-btn { color: var(--text); }

/* Habits tab */
.handle {
  width: 32px; height: 44px; flex: none; padding: 0; border: 0; background: transparent; color: #8A8D93;
  display: flex; align-items: center; justify-content: center; cursor: grab; touch-action: none;
}
.handle.locked { cursor: default; color: var(--muted); }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
.org-card { padding: 0 8px; }
.org-row { display: flex; align-items: center; gap: 4px; min-height: 50px; }
.org-row + .org-row { border-top: 1px solid var(--divider); }
.org-row.lifted, .group.lifted > .org-head {
  background: var(--surface); border-radius: 14px; box-shadow: 0 10px 24px rgba(27, 28, 30, 0.14), 0 2px 6px rgba(27, 28, 30, 0.08);
  position: relative; z-index: 1;
}
.org-habit {
  flex: 1; min-width: 0; height: 50px; padding: 0 4px 0 0; border: 0; background: transparent; text-align: left;
  display: flex; align-items: center; gap: 10px; color: var(--muted);
}
.org-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-freq { font-size: 13px; white-space: nowrap; }
.org-head { display: flex; align-items: center; gap: 4px; min-height: 36px; }
.org-cat { font-size: 14px; font-weight: 700; }
.org-edit { min-height: 36px; padding: 0 8px; border-radius: 9px; display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; color: var(--text-2); text-decoration: none; }
.org-edit svg { width: 14px; height: 14px; }
.org-empty { padding: 14px 8px; font-size: 13px; text-align: center; }
.org-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.btn-dashed, .org-actions .btn-outline {
  height: 48px; border-radius: 14px; font-size: 14px; font-weight: 600; color: var(--text); text-decoration: none;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-dashed { border: 1.5px dashed var(--cell-today-border); }
.org-link { display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 0 14px; color: var(--text); text-decoration: none; font-size: 15px; font-weight: 600; }
.org-link svg { color: var(--muted); }
.btn-small {
  min-height: 36px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--field-border); background: var(--surface);
  font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex: none;
}
.btn-small.primary { border: 0; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 700; min-height: 42px; }
.btn-small.tall { min-height: 46px; padding: 0 18px; font-size: 15px; }

/* Categories screen */
.sort-row { display: flex; align-items: center; gap: 8px; }
.cat-row { display: flex; align-items: center; gap: 4px; min-height: 54px; }
.cat-row + .cat-row, .cat-edit + .cat-row, .cat-row + .cat-edit, .cat-edit + .cat-edit { border-top: 1px solid var(--divider); }
.cat-count { margin-right: 4px; white-space: nowrap; }
.row-btn { width: 36px; height: 44px; padding: 0; border: 0; background: transparent; color: var(--text-2); display: flex; align-items: center; justify-content: center; }
.row-btn:disabled { opacity: 0.3; }
.muted-strong { color: var(--text-2); }
.cat-edit { display: flex; flex-direction: column; gap: 8px; padding: 10px 4px 12px; }
.cat-edit-row { display: flex; align-items: center; gap: 6px; }
.small-input { flex: 1; min-width: 0; height: 44px; font-size: 15px; font-weight: 600; }
.cat-edit .small-input { border-color: var(--text); }
.link-danger { align-self: flex-start; min-height: 36px; padding: 0 4px; border: 0; background: transparent; color: var(--danger); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 6px; text-align: left; }
.new-cat { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.new-cat .small-input { font-weight: 400; }

/* Sheet: category chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--field-border); background: var(--surface); font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { border-color: var(--text); background: var(--text); color: var(--bg); }
.chip.dashed { padding: 0 12px; border: 1.5px dashed var(--cell-today-border); background: transparent; color: var(--text-2); }

/* Controls drawn smaller than 44 px (as in the mockups) get an invisible 44 px hit area. */
.chip, .btn-small, .org-edit, .save-btn, .link-danger { position: relative; }
.chip::after, .btn-small::after, .org-edit::after, .save-btn::after, .link-danger::after {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%);
}

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Month */
.month-chips { padding: 2px 16px 0; }
.month-body { gap: 4px; padding-top: 10px; }
.mgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.mhead { font-size: 11px; font-weight: 600; color: var(--muted); text-align: center; }
.mcell {
  height: 56px; padding: 5px 2px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; gap: 5px; overflow: hidden;
}
.mcell.future { background: color-mix(in srgb, var(--surface) 55%, var(--bg)); }
.mcell.outside { opacity: 0.5; }
.mcell[aria-pressed="true"] { border-color: var(--text); }
.mnum { min-width: 20px; height: 20px; line-height: 20px; border-radius: 10px; font-size: 12px; font-weight: 700; }
.mnum.today { background: var(--text); color: var(--bg); }
.mdots { display: grid; grid-template-columns: repeat(4, 6px); gap: 3px; }
.mdot { width: 6px; height: 6px; border-radius: 3px; border: 1.5px solid var(--c, var(--muted)); }
.mdot.done { background: var(--c, var(--muted)); }
.mdot.legend { width: 8px; height: 8px; border-radius: 4px; display: inline-block; }
.mmore { grid-column: span 4; font-size: 9px; line-height: 9px; color: var(--muted); }
.mlegend { display: flex; gap: 14px; justify-content: center; padding: 6px 0 8px; font-size: 12px; color: var(--muted); }
.mlegend > span { display: flex; align-items: center; gap: 5px; }
.dayview { padding: 12px 12px 6px; }
.dayview-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 0 2px 4px; }
.dayview-head h2 { margin: 0; font-size: 16px; font-weight: 700; }
.daygroup-head { display: flex; align-items: center; gap: 6px; min-height: 32px; padding: 6px 2px 0; font-size: 12px; font-weight: 700; color: var(--text-2); }
.daygroup-head .muted { font-weight: 500; }
.dayrow { display: flex; align-items: center; gap: 8px; min-height: 50px; border-top: 1px solid var(--divider); padding: 0 2px; }
.dayrow-name { flex: 1; min-width: 0; min-height: 44px; padding: 0; border: 0; background: transparent; text-align: left; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toggle {
  position: relative; height: 36px; padding: 0 11px; border-radius: 18px; border: 1.5px solid var(--field-border); background: var(--surface);
  font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 5px; color: var(--text);
}
.toggle::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }
.toggle svg { color: #B5B7BB; }
.toggle.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, var(--surface)); }
.toggle.on svg { color: var(--c); }
.plan-dot { width: 7px; height: 7px; border-radius: 4px; border: 1.5px solid #B5B7BB; }
.toggle.plan.on .plan-dot { border-color: var(--c); background: var(--c); }

/* Stats */
.stats-header { align-items: flex-end; }
.small-seg { padding: 3px; border-radius: 12px; display: flex; }
.small-seg button { height: 30px; padding: 0 10px; border-radius: 9px; font-size: 12px; color: var(--muted); }
.small-seg button[aria-pressed="true"] { color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; min-width: 0; }
.kpi-value { font-size: 22px; font-weight: 700; }
.kpi-label { font-size: 12px; color: var(--muted); line-height: 1.3; overflow-wrap: anywhere; }
.chart { margin: 0; padding: 14px 14px 10px; }
.chart figcaption { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.chart-title { font-size: 14px; font-weight: 700; }
.chart-area { position: relative; height: 120px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--field-border); }
.gridline.soft { border-top-color: var(--divider); }
.gridlabel { position: absolute; right: 0; font-size: 10px; color: var(--muted); background: var(--surface); padding-left: 4px; }
.bars { position: absolute; inset: 0 30px 0 0; display: grid; align-items: end; border-bottom: 1px solid var(--field-border); }
.bar-btn { height: 120px; padding: 0; border: 0; background: transparent; display: flex; align-items: flex-end; justify-content: center; min-width: 0; }
.bar { width: 100%; max-width: 16px; border-radius: 4px 4px 0 0; background: var(--text-2); border: 1.5px solid var(--text); }
.bar.active { background: var(--text); }
.bar.current { background: transparent; border-style: dashed; }
.xlabels { display: grid; gap: 0; margin-right: 30px; padding-top: 5px; font-size: 10px; color: var(--muted); text-align: center; white-space: nowrap; }
.xlabels span { overflow: visible; }
.byhabit { padding: 12px 14px 6px; }
.byhabit h2, .badges h2 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.byhabit-row { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 38px; }
.byhabit-row + .byhabit-row { border-top: 1px solid var(--divider); }
.byhabit-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; font-weight: 600; }
.byhabit-val strong { color: var(--text); }
.track { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.track .fill { height: 6px; border-radius: 3px; background: var(--c); }
.badges { padding: 14px; }
.badges-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); margin: 10px 0 14px; overflow: hidden; }
.progress div { height: 8px; border-radius: 4px; background: var(--text); }
.badge-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin-top: 10px; }
.badge { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.badge-mark {
  width: 38px; height: 38px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; border: 1.5px dashed var(--cell-today-border); color: var(--muted); background: var(--surface);
}
.badge.earned .badge-mark { border: 1.5px solid var(--text); background: var(--text); color: var(--bg); }
.badge-label { font-size: 10.5px; font-weight: 600; color: var(--muted); text-align: center; }
.badge.earned .badge-label { color: var(--text); }

/* Desktop (≥ 1024 px) */
.app.desk { flex-direction: row; align-items: stretch; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; width: 248px; flex: none; padding: 24px 16px; border-right: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 50%, var(--bg)); display: flex; flex-direction: column; gap: 24px; overflow-y: auto;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-size: 16px; font-weight: 700; }
.logo.small { grid-template-columns: repeat(3, 7px); gap: 2px; padding: 5px; border-radius: 9px; }
.logo.small .logo-cell { width: 7px; height: 7px; border-radius: 2px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-link { height: 40px; padding: 0 10px; border-radius: 10px; display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; color: var(--text-2); text-decoration: none; }
.side-link[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 700; }
.side-link:hover { background: var(--hover); }
.side-cats { display: flex; flex-direction: column; gap: 2px; }
.side-cats-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 6px 10px; font-size: 12px; font-weight: 700; color: var(--muted); }
.side-manage { min-height: 28px; padding: 0 8px; border-radius: 8px; display: flex; align-items: center; font-size: 12px; font-weight: 600; color: var(--text-2); text-decoration: none; }
.side-cat { min-height: 36px; padding: 0 10px; border: 0; border-radius: 10px; background: transparent; display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; text-align: left; }
.side-cat[aria-pressed="false"] { color: var(--muted); }
.side-cat:hover { background: var(--hover); }
.side-account { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.avatar { width: 30px; height: 30px; flex: none; border-radius: 15px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.side-email { flex: 1; min-width: 0; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn.ghost { border: 0; background: transparent; color: var(--muted); }

.desk-page { flex: 1; min-width: 0; max-width: 760px; margin: 0; padding: 12px 24px 48px; }
.desk-page.wide { max-width: none; padding: 28px 32px 48px; }
.desk-week { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.desk-main { flex: 999 1 640px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.desk-header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.desk-header h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.015em; }
.btn-small.tall-38 { min-height: 40px; padding: 0 14px; font-size: 14px; }
.wtable-wrap { overflow-x: auto; padding: 8px 16px 12px; border-radius: 18px; }
.wtable { min-width: 760px; display: flex; flex-direction: column; }
.wrow { display: grid; grid-template-columns: minmax(180px, 1fr) repeat(7, 52px) 150px 64px; align-items: center; column-gap: 4px; min-height: 52px; border-top: 1px solid var(--divider); }
.whead { align-items: end; min-height: 52px; border-top: 0; border-bottom: 1px solid var(--border); }
.whead .day { width: auto; margin-bottom: 4px; padding: 5px 0 6px; }
.wlabel { font-size: 12px; font-weight: 700; color: var(--muted); padding-bottom: 10px; }
.wlabel.pad { padding-left: 12px; }
.wlabel.right { text-align: right; }
.wgroup-toggle { height: 40px; padding: 0; font-weight: 700; }
.wname { display: flex; align-items: center; gap: 10px; min-width: 0; height: 44px; padding: 0; border: 0; background: transparent; text-align: left; }
.wname .name { font-size: 15px; }
.cell.lg { width: 52px; height: 48px; }
.cell.lg .cell-box { width: 40px; height: 36px; border-radius: 10px; }
.wprog { display: flex; align-items: center; gap: 10px; padding-left: 12px; }
.wprog .track { flex: 1; }
.wprog .prog { width: 34px; font-size: 13px; color: var(--muted); }
.wprog .prog.met { color: var(--success-text); }
.wstreak { font-size: 13px; color: var(--text-2); text-align: right; }
.desk .sheet { margin-bottom: 0; }
@media (min-width: 1024px) {
  .overlay { justify-content: center; }
  .sheet { border-radius: 22px; margin: 0 auto; }
  .habit-sheet { height: min(784px, calc(100dvh - 80px)); border-radius: 24px; }
  .toast-region { bottom: 24px; }
}
.side-brand, .side-nav, .side-cats, .side-account { flex: none; }
.logo { align-content: start; height: max-content; }
.bar.empty { display: none; }
.wname .muted { white-space: nowrap; }

/* Settings */
.settings { gap: 20px; }
.settings section { display: flex; flex-direction: column; gap: 8px; }
.settings h2 { margin: 0; padding: 0 4px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.settings h2.danger-title { color: var(--danger); }
.setting-card { padding: 0 14px; }
.setting-title { font-size: 15px; font-weight: 600; }
.setting-title.strong, .small-label.strong { font-weight: 700; }
.small-label.strong { color: var(--text-2); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.avatar.lg { width: 38px; height: 38px; border-radius: 19px; font-size: 15px; }
.setting-link { width: 100%; min-height: 48px; padding: 0; border: 0; border-top: 1px solid var(--divider); background: transparent; display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; text-align: left; }
.setting-block { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; }
.setting-block + .setting-block { border-top: 1px solid var(--divider); }
.select { height: 44px; padding: 0 10px; border-radius: 12px; border: 1.5px solid var(--field-border); background: var(--surface); font-size: 15px; }
.segmented.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.segmented.three button { height: 36px; font-weight: 600; }
.segmented.three button[aria-pressed="true"] { font-weight: 700; }
.setting-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.setting-row + .setting-row { border-top: 1px solid var(--divider); }
.setting-row .muted { line-height: 1.4; }
.switch { position: relative; width: 52px; height: 32px; flex: none; padding: 2px; border: 0; border-radius: 16px; background: #CFCFC9; display: flex; align-items: center; }
.switch::after { content: ""; position: absolute; inset: -6px 0; }
.switch span { width: 28px; height: 28px; border-radius: 14px; background: #FFFFFF; box-shadow: 0 1px 3px rgba(27, 28, 30, 0.25); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--text); }
.switch[aria-checked="true"] span { transform: translateX(20px); background: var(--bg); }
:root[data-theme="dark"] .switch:not([aria-checked="true"]) { background: #4A4C51; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .switch:not([aria-checked="true"]) { background: #4A4C51; } }
.danger-card { padding: 14px; display: flex; flex-direction: column; gap: 10px; border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.danger-text { margin: 0; font-size: 13px; line-height: 1.45; color: var(--text-2); }
.confirm-input { height: 44px; font-weight: 600; letter-spacing: 0.04em; }
.btn-delete { height: 46px; border: 0; border-radius: 13px; background: var(--danger); color: #FFFFFF; font-size: 15px; font-weight: 700; }
.btn-delete:disabled { opacity: 1; background: color-mix(in srgb, var(--danger) 16%, var(--surface)); color: var(--danger); }
:root[data-theme="dark"] .btn-delete:not(:disabled) { color: #1B1C1E; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-delete:not(:disabled) { color: #1B1C1E; } }
.center { text-align: center; margin: 0; }

/* Desktop sizing: a slimmer sidebar, and an icon rail when the window is narrow */
.sidebar { width: 216px; padding: 24px 12px; }
.wrow { grid-template-columns: minmax(150px, 1fr) repeat(7, 48px) 120px 52px; }
.wtable { min-width: 700px; }
.cell.lg { width: 48px; }
.desk-page.wide { padding: 28px 24px 48px; }
@media (min-width: 1024px) and (max-width: 1279px) {
  .sidebar { width: 72px; padding: 20px 10px; align-items: center; }
  .side-label, .side-cats, .side-email { display: none; }
  .side-brand { padding: 0; }
  .side-link { width: 48px; height: 44px; padding: 0; justify-content: center; }
  .side-account { padding: 0; flex-direction: column; gap: 8px; }
}
/* The week table is as wide as its content: names get up to 260 px, the rest is fixed. */
.wrow { grid-template-columns: minmax(150px, 260px) repeat(7, 48px) 120px 52px; }
.desk-main { flex: 0 1 auto; width: fit-content; max-width: 100%; }
.wtable-wrap { max-width: 100%; }
