/* Layout: one ledger sheet. Month bar, a summary strip, the habit grid as the centrepiece, notes beneath. */
:root {
  --bg: #f5f6f9;
  --surface: #ffffff;
  --fg: #1c2030;
  --muted: #687089;
  --line: #e1e4ed;
  --line-strong: #c9cedb;
  --accent: #3245c8;
  --accent-soft: #e9ecfb;
  --on-accent: #ffffff;
  --today-bg: #262a36;
  --today-fg: #ffffff;
  --good: #16c98b;
  --good-fg: #04301e;
  --warn: #fff14a;
  --warn-fg: #3a3500;
  --danger: #c2362b;
  --tick: rgba(28, 32, 48, 0.72);
  --shadow: 0 18px 40px -18px rgba(28, 32, 48, 0.35);
  --backdrop: rgba(14, 16, 26, 0.36);

  /* Habit row colours */
  --p0: #fbedc3;
  --p1: #b9dec9;
  --p2: #c8d4f5;
  --p3: #d8ccea;
  --p4: #f7cfc2;
  --p5: #bee5ec;

  --font-display: "Bricolage Grotesque", "IBM Plex Sans", system-ui, sans-serif;
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --cell: 28px;
  --row: 36px;
  --habit-col: 190px;
  --ach-col: 84px;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111319;
    --surface: #191c25;
    --fg: #e7e9f1;
    --muted: #9aa1b6;
    --line: #2a2e3a;
    --line-strong: #3b4050;
    --accent: #95a3ff;
    --accent-soft: #232946;
    --on-accent: #10132a;
    --today-bg: #e7e9f1;
    --today-fg: #111319;
    --good: #22b07e;
    --good-fg: #03170f;
    --warn: #e6d63b;
    --warn-fg: #1f1c00;
    --danger: #ff7d70;
    --tick: rgba(236, 238, 246, 0.88);
    --shadow: 0 18px 44px -16px rgba(0, 0, 0, 0.7);
    --backdrop: rgba(0, 0, 0, 0.55);
    --p0: #5b4f28;
    --p1: #2c5944;
    --p2: #33406c;
    --p3: #4a3c66;
    --p4: #66392e;
    --p5: #275660;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111319;
  --surface: #191c25;
  --fg: #e7e9f1;
  --muted: #9aa1b6;
  --line: #2a2e3a;
  --line-strong: #3b4050;
  --accent: #95a3ff;
  --accent-soft: #232946;
  --on-accent: #10132a;
  --today-bg: #e7e9f1;
  --today-fg: #111319;
  --good: #22b07e;
  --good-fg: #03170f;
  --warn: #e6d63b;
  --warn-fg: #1f1c00;
  --danger: #ff7d70;
  --tick: rgba(236, 238, 246, 0.88);
  --shadow: 0 18px 44px -16px rgba(0, 0, 0, 0.7);
  --backdrop: rgba(0, 0, 0, 0.55);
  --p0: #5b4f28;
  --p1: #2c5944;
  --p2: #33406c;
  --p3: #4a3c66;
  --p4: #66392e;
  --p5: #275660;
  color-scheme: dark;
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 14px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

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

button {
  cursor: pointer;
}

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

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

/* ---------- Shell ---------- */

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 20px 72px;
  display: grid;
  gap: 18px;
}

@media (min-width: 760px) {
  .app {
    padding-inline: 28px;
    padding-block: 28px 88px;
  }
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 700 18px/1 var(--font-display);
  letter-spacing: -0.01em;
  min-width: 0;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  gap: 2px;
  flex: none;
}

.brand-mark span {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.brand-mark span:nth-child(1) { background: var(--p0); }
.brand-mark span:nth-child(2) { background: var(--p1); }
.brand-mark span:nth-child(3) { background: var(--p2); }
.brand-mark span:nth-child(4) { background: var(--p3); }

.month-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-self: center;
}

.month-nav h1 {
  margin: 0;
  min-width: 13ch;
  text-align: center;
  font: 600 18px/1.2 var(--font-display);
  letter-spacing: -0.005em;
  font-variant-numeric: tabular-nums;
}

.topbar-end {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  cursor: default;
}

.sync[data-mode="needsKey"] {
  color: var(--accent);
  cursor: pointer;
}

.sync[data-mode="needsKey"]:hover {
  background: var(--accent-soft);
}

.sync::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-strong);
}

.sync[data-mode="cloud"]::before { background: var(--good); }
.sync[data-mode="saving"]::before,
.sync[data-mode="connecting"]::before { background: var(--accent); }
.sync[data-mode="error"]::before { background: var(--danger); }
.sync[data-mode="offline"]::before,
.sync[data-mode="needsKey"]::before { background: var(--warn); }

@media (max-width: 680px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }
  .month-nav {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .sync-text {
    display: none;
  }
}

/* ---------- Buttons & fields ---------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.icon-btn:hover {
  background: var(--accent-soft);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-btn {
  border: 0;
  background: transparent;
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 500;
}

.text-btn:hover:not(:disabled) {
  background: var(--accent-soft);
}

.text-btn:disabled {
  color: var(--muted);
  cursor: default;
}

.text-btn.is-accent {
  color: var(--accent);
}

.text-btn.is-danger {
  color: var(--danger);
}

.primary-btn {
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
}

.primary-btn:hover {
  filter: brightness(1.06);
}

.danger-btn {
  border: 0;
  background: var(--danger);
  color: var(--surface);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
}

input[type="text"],
input[type="url"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 10px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

/* ---------- Example banner ---------- */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.banner p {
  margin: 0;
  max-width: 70ch;
  min-width: 0;
}

.banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.banner-actions input {
  width: min(220px, 100%);
  background: var(--surface);
}

/* ---------- Summary strip ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat {
  display: grid;
  align-content: start;
  gap: 3px;
  padding: 14px 18px 16px;
  border-left: 1px solid var(--line);
  min-width: 0;
}

.stat:first-child {
  border-left: 0;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font: 700 28px/1.1 var(--font-display);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.stat-value small {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
}

.stat-sub {
  font-size: 12.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.meter {
  height: 4px;
  margin-top: 6px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}

@media (max-width: 760px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .stat:nth-child(3) {
    border-left: 0;
  }
  .stat:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }
  .stat-value {
    font-size: 24px;
  }
}

/* ---------- Habit grid ---------- */

.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding-block: 18px 10px;
  min-width: 0;
}

.grid-scroll {
  overflow-x: auto;
  padding-inline: 12px;
  -webkit-overflow-scrolling: touch;
}

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.grid th,
.grid td {
  padding: 0;
  text-align: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background-clip: padding-box;
}

/* Header labels in the accent ink, like a printed tracker sheet */
.grid thead .col-habit,
.grid thead .col-goal,
.grid thead .col-ach {
  color: var(--accent);
  font-weight: 500;
  vertical-align: middle;
  border-right-color: transparent;
}

.grid thead .col-ach {
  border-right: 0;
}

.grid .col-habit {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  width: var(--habit-col);
  min-width: var(--habit-col);
  max-width: var(--habit-col);
  text-align: left;
}

.grid thead .col-habit {
  z-index: 3;
  padding-left: 12px;
}

.grid tbody .col-habit,
.grid tfoot .col-habit {
  border-left: 1px solid var(--line);
}

.grid .wd,
.grid .dn {
  width: var(--cell);
  min-width: var(--cell);
}

.grid .wd {
  height: 26px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.grid .wd abbr {
  text-decoration: none;
}

.grid .dn {
  height: 40px;
  font-size: 13.5px;
  font-weight: 500;
}

.grid .d1 {
  border-left: 1px solid var(--line);
}

.grid th.is-today {
  background: var(--today-bg);
  color: var(--today-fg);
  border-color: var(--today-bg);
}

.grid th.is-future {
  color: var(--muted);
  font-weight: 400;
}

.grid .col-goal {
  width: 52px;
  min-width: 52px;
}

.grid .col-ach {
  width: var(--ach-col);
  min-width: var(--ach-col);
  background: var(--surface);
}

/* Keep the Achieved count in view while the days scroll */
@media (min-width: 560px) {
  .grid .col-ach {
    position: sticky;
    right: 0;
    z-index: 2;
    box-shadow: -1px 0 0 var(--line);
  }
}

.grid td.is-today,
.grid tfoot td.is-today {
  position: relative;
}

.grid td.is-today::after {
  content: "";
  position: absolute;
  inset: 0 -1px -1px -1px;
  border-left: 1.5px solid var(--today-bg);
  border-right: 1.5px solid var(--today-bg);
  pointer-events: none;
}

.grid tfoot td.is-today::after {
  border-bottom: 1.5px solid var(--today-bg);
}

.habit-btn {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  height: var(--row);
  padding: 0 12px;
  border: 0;
  background: transparent;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}

.habit-btn:hover .habit-name {
  color: var(--accent);
}

.habit-btn:focus-visible {
  outline-offset: -2px;
}

.habit-btn .habit-name {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  line-height: var(--row);
}

.habit-btn .habit-target {
  flex: none;
  font-size: 11.5px;
  color: var(--muted);
}

.cell {
  --fill: var(--hc);
  display: grid;
  place-items: center;
  width: 100%;
  height: var(--row);
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--fg);
}

.cell:hover:not(:disabled) {
  background: color-mix(in srgb, var(--hc) 40%, transparent);
}

.cell.on,
.cell.on:hover:not(:disabled) {
  background: var(--hc);
}

.cell.part,
.cell.part:hover:not(:disabled) {
  background: color-mix(in srgb, var(--hc) 38%, transparent);
  color: var(--muted);
}

.cell:disabled {
  cursor: default;
}

.cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.tick {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--tick);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cell.just .tick,
.cell.just .cell-num {
  animation: pop 0.22s ease-out;
}

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.c0 { --hc: var(--p0); }
.c1 { --hc: var(--p1); }
.c2 { --hc: var(--p2); }
.c3 { --hc: var(--p3); }
.c4 { --hc: var(--p4); }
.c5 { --hc: var(--p5); }

.goal-btn {
  width: 100%;
  height: var(--row);
  border: 0;
  background: transparent;
  font-variant-numeric: tabular-nums;
}

.goal-btn:hover {
  background: var(--accent-soft);
}

.goal-btn:focus-visible {
  outline-offset: -2px;
}

.goal-input {
  width: 52px !important;
  padding: 4px 6px !important;
  text-align: center;
}

.ach {
  font-weight: 600;
}

.grid .ach.good {
  background: var(--good);
  color: var(--good-fg);
}

.grid .ach.warn {
  background: var(--warn);
  color: var(--warn-fg);
}

.ach-inner {
  display: grid;
  place-items: center;
  min-height: var(--row);
  line-height: 1.1;
  padding-block: 3px;
}

.ach-sum {
  font-size: 10.5px;
  font-weight: 500;
  opacity: 0.75;
}

.grid tfoot th,
.grid tfoot td {
  height: 32px;
  font-size: 12px;
  color: var(--muted);
}

.grid tfoot th {
  padding-left: 12px;
  font-weight: 500;
}

.grid tfoot td.all {
  color: var(--good-fg);
  background: color-mix(in srgb, var(--good) 45%, transparent);
  font-weight: 600;
}

.grid tfoot .col-ach,
.grid tfoot .col-goal {
  color: var(--fg);
  font-weight: 600;
}

.grid .empty-row td {
  padding: 28px 16px;
  color: var(--muted);
  border-left: 1px solid var(--line);
}

.sheet-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 16px 2px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12px;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.legend .lg-good { background: var(--good); }
.legend .lg-warn { background: var(--warn); }
.legend .lg-part { background: color-mix(in srgb, var(--p3) 38%, transparent); border: 1px solid var(--p3); }

@media (max-width: 680px) {
  :root {
    --habit-col: 148px;
    --cell: 34px;
    --row: 44px;
  }
  .habit-btn {
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 1px;
    white-space: normal;
    font-size: 12.5px;
  }
  .habit-btn .habit-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-height: 1.2;
    max-width: 100%;
  }
  .habit-btn:has(.habit-target) .habit-name {
    -webkit-line-clamp: 1;
  }
  .habit-btn .habit-target {
    font-size: 10.5px;
  }
}

/* ---------- Notes ---------- */

.notes {
  width: 100%;
  max-width: 700px;
  justify-self: center;
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.notes-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.notes-head h2 {
  margin: 0;
  font: 500 15px/1.2 var(--font-ui);
  color: var(--accent);
}

.note-form {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}

.note-form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.note-form-row label {
  font-size: 12.5px;
  color: var(--muted);
}

.note-form-row input {
  width: auto;
}

.note-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.note {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 20px 16px;
  display: grid;
  gap: 8px;
}

.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 28px;
}

.note-meta time {
  font-size: 12.5px;
  color: var(--muted);
}

.note-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.note:hover .note-actions,
.note:focus-within .note-actions {
  opacity: 1;
}

@media (hover: none) {
  .note-actions {
    opacity: 1;
  }
}

.note-actions .text-btn {
  font-size: 12.5px;
  padding: 4px 8px;
}

.note-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 65ch;
}

.note-tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: 1px;
}

.note-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.notes-empty {
  margin: 0;
  padding: 18px 20px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  text-align: center;
}

/* ---------- Number popover ---------- */

.popover {
  position: fixed;
  z-index: 40;
  width: 248px;
  max-width: calc(100vw - 32px);
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.pop-title {
  margin: 0;
  font-weight: 600;
}

.pop-title span {
  font-weight: 400;
  color: var(--muted);
}

.pop-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px auto;
  align-items: center;
  gap: 6px;
}

.pop-row input {
  text-align: center;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.step-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 17px;
  line-height: 1;
}

.step-btn:hover {
  background: var(--accent-soft);
}

.pop-unit {
  font-size: 12.5px;
  color: var(--muted);
}

.pop-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

.pop-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* ---------- Habit dialog ---------- */

dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: var(--backdrop);
}

.dlg-form {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dlg-form h2 {
  margin: 0;
  font: 700 20px/1.2 var(--font-display);
  letter-spacing: -0.01em;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  border: 0;
  margin: 0;
  padding: 0;
}

.field > label,
.field > legend {
  padding: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

.field-help {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  gap: 3px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  display: grid;
  gap: 1px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  font-weight: 500;
}

.segmented label small {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--muted);
}

.segmented input:checked + label {
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  color: var(--accent);
}

.segmented input:focus-visible + label {
  outline: 2px solid var(--accent);
}

.target-row {
  display: grid;
  grid-template-columns: 1.1fr 0.8fr 1fr;
  gap: 8px;
}

.goal-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.goal-row input {
  width: 88px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.swatches input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.swatches label {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--hc);
  border: 1px solid var(--line-strong);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.swatches input:checked + label {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--fg);
}

.swatches input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.dlg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
}

.dlg-actions .group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.confirm-box {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--surface));
}

.confirm-box p {
  margin: 0;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--today-bg);
  color: var(--today-fg);
  font-weight: 500;
  box-shadow: var(--shadow);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ==========================================================================
   Visual refresh: rounded tiles, ring, pills
   ========================================================================== */

:root {
  --card-shadow: 0 1px 2px rgba(20, 22, 40, 0.05), 0 12px 32px -18px rgba(20, 22, 40, 0.28);
  --tile: color-mix(in srgb, var(--line) 42%, transparent);
  --radius: 18px;
}


.brand {
  font-size: 20px;
}

.brand-mark {
  grid-template-columns: repeat(2, 10px);
  gap: 3px;
}

.brand-mark span {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.month-nav h1 {
  font-size: 22px;
}

.stats,
.sheet,
.note,
.banner,
.note-form {
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
}

.stats,
.sheet,
.note {
  border-color: color-mix(in srgb, var(--line) 70%, transparent);
}

/* Completion ring */
.stat-ring {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 14px;
}

.stat-body {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.ring {
  width: 54px;
  height: 54px;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 5;
}

.ring-track {
  stroke: var(--line);
}

.ring-fill {
  stroke: var(--accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}

/* Grid: rounded tiles instead of ruled boxes */
.grid tbody td.day,
.grid tfoot td {
  border-right-color: transparent;
}

.grid tbody tr td.day {
  padding: 3px 2px;
}

.grid .wd,
.grid .dn,
.grid .d1 {
  border-color: transparent;
}

.grid thead .wd,
.grid thead .dn {
  border-bottom-color: transparent;
}

.grid thead tr:last-child th {
  border-bottom: 1px solid var(--line);
}

.grid th.is-today {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
  border-color: transparent;
}

.dn-num {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 999px;
}

.grid th.dn.is-today .dn-num {
  background: var(--today-bg);
  color: var(--today-fg);
}

.grid td.is-today::after,
.grid tfoot td.is-today::after {
  content: none;
}

.grid td.is-today {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

.cell {
  height: calc(var(--row) - 6px);
  border-radius: 8px;
  background: var(--tile);
  transition: transform 0.12s ease, background-color 0.15s ease;
}

.cell:hover:not(:disabled) {
  transform: translateY(-1px);
}

.cell.on,
.cell.on:hover:not(:disabled) {
  background: var(--hc);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--fg) 10%, transparent);
}

.cell:disabled {
  background: color-mix(in srgb, var(--tile) 45%, transparent);
}

.habit-btn {
  align-items: center;
}

.habit-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--hc);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hc) 35%, transparent);
}

.grid tbody tr:hover .col-habit {
  background: color-mix(in srgb, var(--accent) 5%, var(--surface));
}

/* Achieved: a pill and a progress bar instead of a filled cell */
.grid .ach.good,
.grid .ach.warn,
.grid .col-ach {
  background: var(--surface);
  color: var(--fg);
}

.ach-inner {
  gap: 4px;
  padding-block: 6px;
}

.ach-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 700;
  background: var(--tile);
}

.ach-pill small {
  font-size: 10.5px;
  font-weight: 500;
  opacity: 0.7;
}

.grid .ach.good .ach-pill {
  background: var(--good);
  color: var(--good-fg);
}

.grid .ach.warn .ach-pill {
  background: var(--warn);
  color: var(--warn-fg);
}

.ach-bar {
  width: 58px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.ach-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.4s ease;
}

.grid .ach.good .ach-bar i {
  background: var(--good);
}

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

.legend .lg-good,
.legend .lg-warn {
  border-radius: 999px;
}

/* Empty state */
.grid .empty-row td {
  border: 0;
  padding: 0;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 44px 20px 40px;
  text-align: center;
}

.empty-title {
  margin: 0;
  font: 700 24px/1.2 var(--font-display);
  letter-spacing: -0.01em;
  color: var(--fg);
}

.empty-text {
  margin: 0;
  max-width: 46ch;
  color: var(--muted);
}






/* Settings dialog */
.looks {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.looks input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.look {
  position: relative;
  display: flex;
  align-items: flex-end;
  height: 72px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  overflow: hidden;
}

.look span {
  position: relative;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.looks input:checked + .look {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

.looks input:focus-visible + .look {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.look-light {
  background: #ffffff;
}

.look-light span {
  color: #1c2030;
  text-shadow: none;
}

.look-dark {
  background: #111319;
}



.data-actions {
  display: grid;
  gap: 8px;
}

.data-card {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  text-align: left;
  cursor: pointer;
}

.data-card:hover,
.data-actions input:focus-visible + .data-card {
  border-color: var(--accent);
}

.data-card span {
  font-size: 12.5px;
  color: var(--muted);
}

.data-status {
  margin: 0;
  min-height: 1.4em;
  font-size: 13px;
  color: var(--accent);
}

@media (max-width: 680px) {
  .ring {
    width: 44px;
    height: 44px;
  }
  .stat-ring {
    column-gap: 10px;
  }
}

/* ==========================================================================
   Polish: calmer palette, cleaner cards, refined grid
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --fg: #171a23;
  --muted: #6b7183;
  --line: #e6e8ee;
  --line-strong: #d3d7e1;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --on-accent: #ffffff;
  --today-bg: #171a23;
  --today-fg: #ffffff;
  --radius: 20px;
  --card-shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 8px 24px -14px rgba(17, 24, 39, 0.14);
  --weekend: rgba(17, 24, 39, 0.022);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0e13;
    --surface: #14171f;
    --fg: #eceef4;
    --muted: #9298ab;
    --line: #232733;
    --line-strong: #323847;
    --accent: #9a9cff;
    --accent-soft: #1d2140;
    --on-accent: #0c0e13;
    --today-bg: #eceef4;
    --today-fg: #0c0e13;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -16px rgba(0, 0, 0, 0.7);
    --weekend: rgba(255, 255, 255, 0.02);
  }
}

:root[data-theme="dark"] {
  --bg: #0c0e13;
  --surface: #14171f;
  --fg: #eceef4;
  --muted: #9298ab;
  --line: #232733;
  --line-strong: #323847;
  --accent: #9a9cff;
  --accent-soft: #1d2140;
  --on-accent: #0c0e13;
  --today-bg: #eceef4;
  --today-fg: #0c0e13;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -16px rgba(0, 0, 0, 0.7);
  --weekend: rgba(255, 255, 255, 0.02);
}

body {
  font-size: 14.5px;
  letter-spacing: -0.003em;
}

.app {
  gap: 22px;
}

/* Header */
.brand {
  font-size: 19px;
  gap: 12px;
}

.month-nav {
  gap: 10px;
}

.month-nav h1 {
  min-width: 11ch;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.month-nav h1 .year {
  font-weight: 500;
  color: var(--muted);
}

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
}

.icon-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}

.sync {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

#todayBtn {
  padding: 7px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--fg);
}

#todayBtn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

#todayBtn:disabled {
  opacity: 0.55;
}

/* Summary: four separate cards */
.stats {
  gap: 14px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.stats .stat,
.stats .stat:first-child,
.stats .stat:nth-child(n) {
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--card-shadow);
}

.stat-value {
  font-size: 30px;
  letter-spacing: -0.03em;
}

.stat-label {
  font-size: 10.5px;
  letter-spacing: 0.1em;
}

/* Grid card */
.sheet {
  padding-block: 22px 14px;
  border-color: var(--line);
}

.grid {
  font-size: 13px;
}

.grid thead .col-habit,
.grid thead .col-goal,
.grid thead .col-ach {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.grid .wd {
  font-size: 10px;
  letter-spacing: 0.06em;
}

.grid .dn {
  font-weight: 600;
}

.grid th.is-weekend:not(.is-today) {
  color: var(--muted);
}

.grid tbody td.is-weekend:not(.is-today),
.grid tfoot td.is-weekend:not(.is-today) {
  background: var(--weekend);
}

.grid tbody th,
.grid tbody td,
.grid tfoot th,
.grid tfoot td {
  border-bottom-color: color-mix(in srgb, var(--line) 65%, transparent);
}

.habit-btn .habit-name {
  font-weight: 550;
}

.cell {
  border-radius: 9px;
}

.cell:hover:not(:disabled):not(.on) {
  box-shadow: inset 0 0 0 1.5px var(--hc);
  background: var(--tile);
}

.tick {
  stroke-width: 2.1;
}

.grid tfoot th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sheet-foot {
  padding: 14px 20px 4px;
}

#addHabit {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

#addHabit:hover {
  filter: brightness(0.97);
}

/* Notes */
.notes-head h2 {
  font: 700 18px/1.2 var(--font-display);
  letter-spacing: -0.01em;
  color: var(--fg);
}

#addNote {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.note {
  padding: 16px 22px 18px;
}

.note-meta time {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.notes-empty {
  border-style: solid;
  border-color: var(--line);
  background: var(--surface);
}

/* Dialogs and toast */
dialog {
  border-radius: 22px;
}

dialog::backdrop {
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.primary-btn,
.danger-btn {
  border-radius: 999px;
  padding: 9px 18px;
}

.toast {
  border-radius: 999px;
  padding: 10px 20px;
}

@media (max-width: 680px) {
  .month-nav h1 {
    font-size: 22px;
  }
  .stats {
    gap: 10px;
  }
  .stats .stat,
  .stats .stat:nth-child(n) {
    padding: 14px 14px;
  }
}

/* ---------- Calendar and phone app ---------- */

/* A day filled in from the calendar: a small mark in the corner. */
.cell.from-cal {
  position: relative;
}

.cell.from-cal::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.75;
}

.cal-off,
.cal-on {
  display: grid;
  gap: 8px;
}

.cal-row {
  display: flex;
  gap: 8px;
}

.cal-row input {
  flex: 1;
}

.cal-row .primary-btn {
  flex: none;
}

.cal-source {
  margin: 0;
  font-size: 14px;
  color: var(--fg);
  overflow-wrap: anywhere;
}

.cal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

#appField .data-card {
  margin-bottom: 8px;
}

@media (max-width: 480px) {
  .cal-row {
    flex-direction: column;
  }
}
