/* ---------- tokens ---------- */
:root {
  color-scheme: light dark;
  --bg: #fbf8f3;
  --surface: #ffffff;
  --fg: #1f1a2e;
  --muted: #7a7489;
  --line: #ece6dc;
  /* Every box (card, row list, input, menu, dialog) gets its depth from these.
     --edge is a 1px outline drawn as part of the shadow: invisible in light
     mode, where shadows separate boxes well, and needed in dark mode, where
     they don't. */
  --edge: transparent;
  --shadow: 0 0 0 1px var(--edge), 0 1px 2px rgb(31 26 46 / 0.05), 0 6px 18px -10px rgb(31 26 46 / 0.16);
  --shadow-lift: 0 0 0 1px var(--edge), 0 2px 4px rgb(31 26 46 / 0.06), 0 12px 28px -14px rgb(31 26 46 / 0.26);
  --late: #e5484d;

  /* Spacing: one 4px scale for every margin, padding and gap.
     s2 separates things inside a block, s3 separates blocks,
     s4 separates sections, s5 sets a section apart. */
  --s0: 2px;   /* hairline, inside pills */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  --r: 10px;      /* cards, panels */
  --r-sm: 8px;    /* rows, inputs, buttons, chips */
  --r-xs: 5px;    /* small pills and tags */
  --nav-h: 64px;
  --header-h: 56px;
  --content: 720px; /* shared by the header and the page body */
  --gutter: var(--s3);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --hue: #f5a524;
  font: 15px/1.45 ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", system-ui, sans-serif;
}

/* Dark tokens follow the system unless Settings picks a scheme
   (index.html sets data-scheme on <html> before the first paint). */
:root[data-scheme="light"] { color-scheme: light; }
:root[data-scheme="dark"] {
  color-scheme: dark;
  --bg: #14121b;
  --surface: #221f2e;
  --fg: #f3f0fa;
  --muted: #a39db3;
  --line: #2e2a3b;
  --edge: #3a344f;
  --shadow: 0 0 0 1px var(--edge), 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 20px -12px rgb(0 0 0 / 0.6);
  --shadow-lift: 0 0 0 1px var(--edge), 0 2px 4px rgb(0 0 0 / 0.35), 0 14px 30px -14px rgb(0 0 0 / 0.7);
  --late: #ff6b6f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --bg: #14121b;
    --surface: #221f2e;
    --fg: #f3f0fa;
    --muted: #a39db3;
    --line: #2e2a3b;
    --edge: #3a344f;
    --shadow: 0 0 0 1px var(--edge), 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 20px -12px rgb(0 0 0 / 0.6);
    --shadow-lift: 0 0 0 1px var(--edge), 0 2px 4px rgb(0 0 0 / 0.35), 0 14px 30px -14px rgb(0 0 0 / 0.7);
    --late: #ff6b6f;
  }
}

/* Each section brings its own colour; tabs and stat tiles carry theirs too.
   --hue      decoration only: glows, rings, progress, borders.
   --accent   solid fills (buttons, checks, tiles), with --accent-ink on top.
   --hue-deep text and icons on --hue-soft or the surface.
   Every text pair is at least 4.5:1 (WCAG AA) in both schemes. */
[data-theme="sun"], .stat.sun { --hue: #f5a524; --accent: #f5a524; --accent-ink: #2a1a00; --hue-deep: #8a5300; }
[data-theme="tangerine"], .stat.tangerine { --hue: #ff6b4a; --accent: #d43d1f; --accent-ink: #ffffff; --hue-deep: #b3361b; }
[data-theme="grape"], .stat.grape { --hue: #7c5cff; --accent: #6d4aff; --accent-ink: #ffffff; --hue-deep: #5b3fd6; }
[data-theme="mint"], .stat.mint { --hue: #14b8a6; --accent: #0f766e; --accent-ink: #ffffff; --hue-deep: #115e59; }
[data-theme="slate"], .stat.slate { --hue: #64748b; --accent: #475569; --accent-ink: #ffffff; --hue-deep: #475569; }
:root[data-scheme="dark"] [data-theme="sun"], :root[data-scheme="dark"] .stat.sun { --accent: #fbbf24; --accent-ink: #14121b; --hue-deep: #fcd34d; }
:root[data-scheme="dark"] [data-theme="tangerine"], :root[data-scheme="dark"] .stat.tangerine { --accent: #ff8a6e; --accent-ink: #14121b; --hue-deep: #ffab96; }
:root[data-scheme="dark"] [data-theme="grape"], :root[data-scheme="dark"] .stat.grape { --accent: #a78bfa; --accent-ink: #14121b; --hue-deep: #c4b5fd; }
:root[data-scheme="dark"] [data-theme="mint"], :root[data-scheme="dark"] .stat.mint { --accent: #2dd4bf; --accent-ink: #14121b; --hue-deep: #5eead4; }
:root[data-scheme="dark"] [data-theme="slate"], :root[data-scheme="dark"] .stat.slate { --accent: #94a3b8; --accent-ink: #14121b; --hue-deep: #cbd5e1; }
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) [data-theme="sun"], :root:not([data-scheme="light"]) .stat.sun { --accent: #fbbf24; --accent-ink: #14121b; --hue-deep: #fcd34d; }
  :root:not([data-scheme="light"]) [data-theme="tangerine"], :root:not([data-scheme="light"]) .stat.tangerine { --accent: #ff8a6e; --accent-ink: #14121b; --hue-deep: #ffab96; }
  :root:not([data-scheme="light"]) [data-theme="grape"], :root:not([data-scheme="light"]) .stat.grape { --accent: #a78bfa; --accent-ink: #14121b; --hue-deep: #c4b5fd; }
  :root:not([data-scheme="light"]) [data-theme="mint"], :root:not([data-scheme="light"]) .stat.mint { --accent: #2dd4bf; --accent-ink: #14121b; --hue-deep: #5eead4; }
  :root:not([data-scheme="light"]) [data-theme="slate"], :root:not([data-scheme="light"]) .stat.slate { --accent: #94a3b8; --accent-ink: #14121b; --hue-deep: #cbd5e1; }
}
* { --hue-soft: color-mix(in srgb, var(--hue) 16%, var(--surface)); }
:root[data-scheme="dark"] * { --hue-soft: color-mix(in srgb, var(--hue) 22%, var(--surface)); }
@media (prefers-color-scheme: dark) { :root:not([data-scheme="light"]) * { --hue-soft: color-mix(in srgb, var(--hue) 22%, var(--surface)); } }

/* Icons: Lucide line icons in currentColor, 1em by default. Inside chips,
   pills and buttons they are 16px, next to 16px checks and 20px avatars. */
.ic { width: 1em; height: 1em; flex: none; stroke-width: 2; vertical-align: -0.125em; }

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
h1 { font-size: 1.6rem; font-weight: 800; line-height: 1.15; }
h2 { font-size: 0.98rem; font-weight: 750; margin-bottom: var(--s2); display: flex; align-items: center; gap: var(--s2); }
h2 .ic { color: var(--hue-deep); }
h3 { font-size: 0.88rem; font-weight: 750; }
p { margin: 0 0 var(--s2); }
.muted { color: var(--muted); }
.small { font-size: 0.78rem; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ---------- shell ---------- */
.shell { min-height: 100dvh; position: relative; }
.backdrop { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.backdrop::before, .backdrop::after {
  content: ""; position: absolute; border-radius: 50%; filter: blur(70px);
  background: var(--hue); opacity: 0.2; transition: background-color 0.6s ease;
}
.backdrop::before { width: 360px; height: 360px; top: -170px; right: -120px; }
.backdrop::after { width: 280px; height: 280px; top: 140px; left: -180px; opacity: 0.1; }

.main {
  position: relative; max-width: var(--content); margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + var(--s3)) var(--gutter) calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--s5));
}
.page { animation: page-in 0.3s var(--spring); }
@keyframes page-in { from { opacity: 0; transform: translateY(8px); } }

/* Navigation: a tab bar docked at the bottom on phones, a header from 760px. */
.nav {
  position: fixed; z-index: 10; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: var(--s2) var(--s3) calc(var(--s2) + env(safe-area-inset-bottom));
  display: flex; justify-content: space-around; align-items: stretch; gap: var(--s1);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(16px) saturate(1.6); -webkit-backdrop-filter: blur(16px) saturate(1.6);
  border-top: 1px solid var(--line);
}
.brand { display: none; }
.tab {
  position: relative; flex: 1; min-width: 0; border-radius: var(--r-sm);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s1);
  text-decoration: none; color: var(--muted); font-size: 0.66rem; font-weight: 650;
  transition: background-color 0.25s ease, color 0.25s ease;
}
.tab-ic { width: 22px; height: 22px; transition: transform 0.35s var(--spring); }
.tab.active { background: var(--hue-soft); color: var(--hue-deep); }
.tab.active .tab-ic { transform: scale(1.08); }
.tab:active .tab-ic { transform: scale(0.85); }
.tab-icon { position: relative; display: grid; place-items: center; }
.tab-badge {
  position: absolute; top: -6px; left: calc(100% - 4px); min-width: 16px; height: 16px; padding: 0 var(--s1);
  border-radius: var(--r-xs); background: var(--accent); color: var(--accent-ink); font-size: 0.64rem; font-weight: 800;
  display: grid; place-items: center; box-shadow: 0 0 0 2px var(--surface); animation: badge-in 0.4s var(--spring);
}
@keyframes badge-in { from { transform: scale(0); } }

@media (min-width: 760px) {
  :root { --gutter: var(--s5); --content: 1160px; }
  .nav {
    /* Same content edges as .main: centred var(--content), inset by the gutter. */
    position: sticky; top: 0; bottom: auto; height: var(--header-h);
    padding: 0 max(var(--gutter), calc((100% - var(--content)) / 2 + var(--gutter)));
    justify-content: flex-start; align-items: center; gap: var(--s1);
    border-top: 0; border-bottom: 1px solid var(--line);
  }
  .brand {
    display: flex; align-items: center; gap: var(--s2); margin-right: var(--s4);
    font-weight: 850; font-size: 1.15rem; letter-spacing: -0.03em;
  }
  .brand-mark { display: grid; color: var(--hue-deep); transition: color 0.6s; }
  .tab { flex: 0 0 auto; height: 36px; flex-direction: row; gap: var(--s2); padding: 0 var(--s3); font-size: 0.9rem; }
  .tab-ic { width: 18px; height: 18px; }
  /* Pin the badge to the tab's corner so it never covers the label. */
  .tab-icon { position: static; }
  .tab-badge { top: -5px; right: -5px; left: auto; }
  .main { padding: var(--s5) var(--gutter) var(--s6); }
}
@media (min-width: 900px) {
  .groups { column-width: 330px; column-gap: var(--s4); }
  .groups .group { break-inside: avoid; margin: 0 0 var(--s4); }
  .today-grid { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; gap: var(--s3); align-items: start; }
  .today-grid .stats { grid-template-columns: 1fr; margin: 0; }
  .today-grid .card { margin: 0; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  /* Wide screens: more columns instead of longer lines. */
  .node { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 360px); gap: var(--s5); align-items: start; }
  .node:not(:has(> .node-side)) { grid-template-columns: minmax(0, 1fr); }
  .settings-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); align-items: start; }
}

/* ---------- sync badge ---------- */
/* In the header on wide screens, in the page's top corner on phones. */
.sync {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: var(--s1) var(--s2); border-radius: var(--r-xs); font-size: 0.7rem; font-weight: 650; color: var(--muted);
  background: color-mix(in srgb, var(--surface) 70%, transparent); backdrop-filter: blur(8px);
  text-decoration: none;
}
.sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.sync.ok .dot { background: #22c55e; }
.sync.busy .dot { background: #f5a524; animation: pulse 1s ease-in-out infinite; }
.sync.late { color: var(--late); }
.sync.late .dot { background: var(--late); }
@keyframes pulse { 50% { transform: scale(1.6); opacity: 0.5; } }
.nav .sync { margin-left: auto; }
@media (min-width: 760px) { .main > .sync { display: none; } }
@media (max-width: 759px) {
  .nav .sync { display: none; }
  .sync { position: absolute; top: calc(env(safe-area-inset-top) + var(--s3)); right: var(--gutter); z-index: 5; }
  .sync.ok { padding: var(--s2); }
  .sync.ok .sync-text { display: none; }
  .page-head, .hero { padding-right: var(--s6); }
}

/* ---------- page headings ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin: var(--s2) 0 var(--s4); }
.page-title { flex: 1; min-width: 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
@media (max-width: 759px) { .page-actions { flex-basis: 100%; } }
/* Icon tiles: the page head, node head and search results share one look. */
.page-icon, .node-icon, .result-icon {
  flex: none; display: grid; place-items: center; border-radius: var(--r-sm);
  background: var(--hue-soft); color: var(--hue-deep);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hue) 25%, transparent);
}
.page-icon {
  width: 40px; height: 40px; border-radius: var(--r); font-size: 1.3rem;
  animation: wiggle 0.7s var(--spring);
}
@keyframes wiggle { 0% { transform: rotate(-12deg) scale(0.7); } 60% { transform: rotate(6deg) scale(1.05); } }
.sub { color: var(--muted); margin: var(--s0) 0 0; font-weight: 550; font-size: 0.9rem; }

/* ---------- today ---------- */
.hero { margin: var(--s2) 0 var(--s4); }
@keyframes float { 50% { transform: translateY(-5px) rotate(4deg); } }
.hero-title { font-size: 1.9rem; font-weight: 850; }
.hero-title .name {
  background: linear-gradient(90deg, #ff6b4a, #7c5cff 55%, #14b8a6); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-bottom: var(--s3); }
.stat {
  display: grid; padding: var(--s3); border-radius: var(--r); text-decoration: none;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
  transition: transform 0.25s var(--spring);
  background-image: radial-gradient(circle at 100% 0%, rgb(255 255 255 / 0.28), transparent 55%);
}
.stat:hover { transform: translateY(-2px); }
.stat:active { transform: scale(0.97); }
.stat-num { font-size: 2.1rem; font-weight: 850; line-height: 1; letter-spacing: -0.04em; }
.stat-label { font-weight: 750; font-size: 0.9rem; }
.stat-foot { font-size: 0.76rem; opacity: 0.85; margin-top: var(--s1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- cards and groups ---------- */
.card { background: var(--surface); border-radius: var(--r); padding: var(--s3); margin-bottom: var(--s3); box-shadow: var(--shadow); }
.group { margin: var(--s4) 0; }

/* Every group header (a plain heading, a heading with a button, or a toggle)
   has the same height, inset and gap to the list below it. */
.group > h3, .group-head, .group-toggle {
  display: flex; align-items: center; gap: var(--s2); min-height: 28px;
  margin: 0 0 var(--s2); padding: 0 0 0 var(--s1); color: var(--muted);
}
.group-head, .group-toggle { justify-content: space-between; }
.group-head h3, .group-toggle h3 { display: flex; align-items: center; gap: var(--s2); margin: 0; }
.group h3 .ic { width: 16px; height: 16px; }
.group-toggle { width: 100%; border: 0; background: transparent; text-align: left; }
.group.late > h3 { color: var(--late); }
.toggle-label { font-size: 0.8rem; font-weight: 700; color: var(--hue-deep); }
.done-tasks { margin-top: var(--s5); }
.done-tasks .rows, .basket .rows { opacity: 0.85; }

/* ---------- rows ---------- */
.rows { list-style: none; margin: 0; padding: var(--s1); background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); }
.card .rows, .rows.bare { padding: 0; box-shadow: none; background: transparent; }
.rows.bare:empty { display: none; }
.row {
  display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: var(--s1) var(--s2);
  border-radius: var(--r-sm); cursor: pointer; user-select: none; transition: background-color 0.15s;
  animation: row-in 0.22s ease;
}
@keyframes row-in { from { opacity: 0; transform: translateY(-3px); } }
.row:hover { background: color-mix(in srgb, var(--hue) 7%, transparent); }
.row .title {
  flex: 0 1 auto; margin-right: auto; min-width: 0; text-decoration: none; overflow-wrap: anywhere; font-weight: 600;
  background: linear-gradient(currentColor, currentColor) 0 55% / 0 2px no-repeat; transition: background-size 0.35s ease, color 0.3s;
}
.row.checked .title, .row.pop .title { color: var(--muted); background-size: 100% 2px; }
.qty { font-size: 0.75rem; font-weight: 750; padding: var(--s0) var(--s2); border-radius: var(--r-xs); background: var(--hue-soft); color: var(--hue-deep); }
.when { font-size: 0.78rem; font-weight: 650; color: var(--muted); white-space: nowrap; }
.when.late { color: var(--late); }
.tag { display: grid; color: var(--muted); font-size: 15px; }

.check {
  flex: none; width: 22px; height: 22px; border-radius: 50%; position: relative;
  border: 2px solid color-mix(in srgb, var(--hue) 70%, var(--muted)); display: grid; place-items: center;
  transition: background-color 0.2s, border-color 0.2s, transform 0.4s var(--spring);
}
.row:hover .check { transform: scale(1.08); }
/* A task row is one big link to the task; the check sits above it with a
   finger-sized hit area. */
.row.task { position: relative; }
.row.task .title::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.row.task .title:focus-visible { outline: none; }
.row.task:has(.title:focus-visible) { box-shadow: inset 0 0 0 2px var(--hue); }
.row.task .check { z-index: 1; cursor: pointer; }
.check::before { content: ""; position: absolute; inset: calc(-1 * var(--s3)); }
.check.small { width: 16px; height: 16px; }
.check.small::after { width: 7px; height: 4px; }
.check.on, .row.pop .check { background: var(--accent); border-color: var(--accent); }
.check.on::after, .row.pop .check::after {
  content: ""; width: 9px; height: 5px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0;
  transform: translateY(-1px) rotate(-45deg);
}
.row.pop .check { animation: pop 0.45s var(--spring); }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }
.row.pop { animation: fade-out 0.5s 0.15s ease forwards; }
@keyframes fade-out { to { opacity: 0.45; } }

/* ---------- composer, chips, progress ---------- */
.composer { display: flex; gap: var(--s2); margin-bottom: var(--s3); }
/* The composer on Tasks and Shopping: the input and one set of chips under
   it, no box around them. The chips filter the list and set the values of
   new items. */
.composer-card { margin-bottom: var(--s4); }
/* Each label with its chips is a group; groups share a line and wrap onto
   the next one only when they don't fit. */
.composer-opts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s5); }
.opt-group { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-width: 0; }
/* Chips wrap one by one beside their label, not as a block under it. */
.opt-group .opt-chips { display: contents; }
.opt-label { color: var(--muted); font-weight: 700; font-size: 0.78rem; }
.opt-chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.opt-hint { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin: var(--s3) 0 0; color: var(--muted); font-size: 0.84rem; }

/* A row of exclusive choices (a filter, a view, a setting). */
.segmented { display: inline-flex; flex-wrap: wrap; gap: var(--s0); padding: var(--s0); border-radius: var(--r-sm); background: var(--line); }
.segmented button {
  display: inline-flex; align-items: center; gap: var(--s2); height: 30px; padding: 0 var(--s3);
  border: 0; border-radius: var(--r-xs); background: transparent; color: var(--muted); font-weight: 650; font-size: 0.84rem;
}
.segmented button:has(> .avatar:first-child) { padding-left: var(--s2); }
.segmented button .ic { width: 16px; height: 16px; }
.segmented button.on { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.segmented.icons button { padding: 0 var(--s2); }
.composer-input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 var(--s3); border-radius: var(--r-sm);
  border: 1.5px solid transparent; background: var(--surface); box-shadow: var(--shadow); font-size: 1rem; font-weight: 600;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer-input:focus { outline: none; border-color: var(--hue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--hue) 20%, transparent), var(--shadow); }
.fab {
  flex: none; width: 44px; height: 44px; border: 0; border-radius: var(--r-sm); background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 22px; box-shadow: 0 6px 14px -8px var(--accent);
  transition: transform 0.35s var(--spring);
}
.fab:hover { transform: rotate(90deg); }
.fab:active { transform: rotate(90deg) scale(0.88); }

/* Chip rows scroll sideways on phones, edge to edge. */
.chips {
  display: flex; gap: var(--s2); overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)) var(--s3); padding: var(--s0) var(--gutter);
}
.chips::-webkit-scrollbar { display: none; }
/* Chips (filters, pickers) and meta pills (a node's properties) share one
   shape: 32px tall, 16px icon or check, 20px avatar, s2 between them. A
   selected chip is tinted, never a solid fill, so its text stays readable. */
.chip, .meta-pill {
  flex: none; display: inline-flex; align-items: center; gap: var(--s2); height: 32px; padding: 0 var(--s3);
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  font-weight: 650; font-size: 0.84rem; white-space: nowrap;
  transition: transform 0.3s var(--spring), background-color 0.2s, border-color 0.2s, color 0.2s;
}
.chip .ic, .meta-pill .ic, .btn .ic, .pop-item .ic { width: 16px; height: 16px; }
.chip:has(> .avatar:first-child), .meta-pill:has(> .avatar:first-child) { padding-left: var(--s2); }
.chip:active, .meta-pill:not(.static):active { transform: scale(0.94); }
.chip.on { background: var(--hue-soft); border-color: color-mix(in srgb, var(--hue) 55%, transparent); color: var(--hue-deep); }

.progress { height: 6px; border-radius: 3px; background: var(--hue-soft); overflow: hidden; margin: 0 0 var(--s3); }
.progress.hidden { display: none; }
.progress span {
  display: block; height: 100%; border-radius: inherit; transition: width 0.6s var(--spring);
  background: repeating-linear-gradient(-45deg, var(--hue) 0 8px, color-mix(in srgb, var(--hue) 80%, white) 8px 16px);
  animation: stripes 1s linear infinite; background-size: 22px 100%;
}
@keyframes stripes { to { background-position: 22px 0; } }

/* ---------- avatars ---------- */
/* Avatar colours are dark enough for white initials (4.5:1) in both schemes. */
.avatar {
  flex: none; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--c); color: #fff; font-weight: 800; font-size: 0.66rem; line-height: 1;
}
.avatar.big { width: 48px; height: 48px; font-size: 1.25rem; }

/* ---------- knowledge ---------- */
.search-row { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); }
.search-wrap { position: relative; flex: 1; min-width: 0; }
.search-icon { position: absolute; left: var(--s3); top: 50%; transform: translateY(-50%); display: grid; color: var(--muted); font-size: 18px; }
.search {
  width: 100%; min-height: 44px; padding: 0 var(--s3) 0 calc(var(--s6) + var(--s2)); border-radius: var(--r-sm); border: 1.5px solid transparent;
  background: var(--surface); box-shadow: var(--shadow); font-size: 1rem; font-weight: 600;
}
.search:focus { outline: none; border-color: var(--hue); }

/* ---------- graph ---------- */
.graph-wrap {
  position: relative; height: max(420px, calc(100dvh - 300px)); overflow: hidden;
  border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow);
}
.graph { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; }
.graph:active { cursor: grabbing; }
.g-link { stroke: var(--line); stroke-width: 1.5; transition: stroke 0.15s; }
.g-link.hi { stroke: var(--hue); stroke-width: 2; }
.g-node { cursor: pointer; color: var(--hue-deep); transition: opacity 0.15s; }
.g-node circle { fill: var(--hue-soft); stroke: color-mix(in srgb, var(--hue) 60%, transparent); stroke-width: 1.5; }
.g-node:hover circle, .g-node:focus-visible circle { stroke: var(--hue-deep); stroke-width: 2; }
.g-node:focus { outline: none; }
.g-node.other { color: var(--muted); }
.g-node.other circle { fill: var(--bg); stroke: var(--line); stroke-dasharray: 3 3; }
.g-node.dim { opacity: 0.3; }
.g-node text { fill: var(--fg); font-size: 12px; font-weight: 650; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.graph-tools {
  position: absolute; right: var(--s2); bottom: var(--s2); display: flex; gap: var(--s1); padding: var(--s1);
  border-radius: var(--r-sm); background: var(--surface); box-shadow: var(--shadow);
}
.cards { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s2); }
.result {
  display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3); text-decoration: none;
  background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow);
  transition: transform 0.3s var(--spring), box-shadow 0.3s;
}
.result:hover { transform: translateY(-1px); box-shadow: var(--shadow-lift); }
.result-icon { width: 34px; height: 34px; font-size: 18px; }
.result-text { display: grid; gap: var(--s0); min-width: 0; }
.result .title { font-weight: 750; }
.snippet { color: var(--muted); font-size: 0.86rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.node-main, .node-side { min-width: 0; }
.node-head { display: flex; align-items: center; gap: var(--s2); }
.node-icon { width: 32px; height: 32px; font-size: 18px; }
.kind.gone { color: var(--late); background: color-mix(in srgb, var(--late) 14%, var(--surface)); }
.kind { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--hue-deep); font-weight: 800; padding: var(--s0) var(--s2); border-radius: var(--r-xs); background: var(--hue-soft); }
.title-edit { width: 100%; font-size: 1.5rem; font-weight: 850; letter-spacing: -0.02em; border: 0; background: transparent; padding: var(--s2) 0; }
.title-edit:focus { outline: none; }
.title-edit::placeholder { color: var(--muted); opacity: 0.6; }

/* Properties on one line; pills with a menu open a popover under them
   (a sheet above the tab bar on phones). */
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: 0 0 var(--s3); }
.meta-pill:not(.static):hover { border-color: color-mix(in srgb, var(--hue) 45%, var(--line)); }
.meta-pill .ic { color: var(--hue-deep); }
.meta-pill.unset { color: var(--muted); border-style: dashed; }
.meta-pill.unset .ic { color: var(--muted); }
.meta-pill.done { background: var(--hue-soft); border-color: color-mix(in srgb, var(--hue) 55%, transparent); color: var(--hue-deep); }
.meta-pill.late, .meta-pill.late .ic { color: var(--late); }
.meta-pill.late { border-color: color-mix(in srgb, var(--late) 45%, var(--line)); }
.meta-pill.static { cursor: default; background: transparent; }
.meta-key { color: var(--muted); font-weight: 600; }

.pop-wrap { position: relative; }
.popover {
  position: absolute; z-index: 30; top: calc(100% + var(--s1)); left: 0; min-width: 300px;
  display: grid; gap: var(--s2); padding: var(--s2); border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow-lift); animation: pop-in 0.18s ease;
}
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } }
.popover.menu { gap: 0; }
.pop-quick { display: flex; flex-wrap: wrap; gap: var(--s1); }
.pop-fields { display: flex; align-items: end; gap: var(--s2); }

/* ---------- calendar (our own date picker) ---------- */
.cal { display: grid; gap: var(--s2); }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.cal-title { font-weight: 750; }
.cal-title::first-letter { text-transform: uppercase; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 36px); gap: var(--s0); justify-content: center; }
.cal-wd { padding: var(--s1) 0; text-align: center; color: var(--muted); font-size: 0.72rem; font-weight: 700; }
.cal-day {
  width: 36px; height: 36px; border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--fg); font-weight: 650; font-size: 0.88rem; font-variant-numeric: tabular-nums;
}
.cal-day:hover { background: var(--hue-soft); }
.cal-day:focus-visible { outline: 2px solid var(--hue); outline-offset: 1px; }
.cal-day.today { color: var(--hue-deep); box-shadow: inset 0 0 0 1.5px var(--hue); }
.cal-day.on { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
@media (max-width: 759px) {
  .cal-grid { grid-template-columns: repeat(7, minmax(36px, 1fr)); }
  .cal-day { width: 100%; height: 40px; }
}
.field { display: grid; gap: var(--s1); font-size: 0.76rem; font-weight: 650; color: var(--muted); }
.field input {
  height: 36px; padding: 0 var(--s2); border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--bg); color: var(--fg); font-size: 0.9rem; font-weight: 600;
}
.field input:focus { outline: none; border-color: var(--hue); }
.pop-item {
  display: flex; align-items: center; gap: var(--s2); width: 100%; min-height: 36px; padding: 0 var(--s2);
  border: 0; border-radius: var(--r-sm); background: transparent; text-align: left; font-weight: 650; font-size: 0.9rem;
}
.pop-item:hover { background: var(--hue-soft); }
.pop-label { flex: 1; }
.pop-check { color: var(--hue-deep); }
@media (max-width: 759px) {
  .popover {
    position: fixed; top: auto; left: var(--s3); right: var(--s3);
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--s3)); padding: var(--s3);
  }
  .pop-item { min-height: 44px; }
}

/* ---------- markdown ---------- */
.md {
  min-height: 120px; margin: 0 0 var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r);
  background: var(--surface); box-shadow: var(--shadow); cursor: text; line-height: 1.6; overflow-wrap: anywhere;
  transition: box-shadow 0.2s;
}
.md:hover { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--hue) 35%, transparent), var(--shadow); }
.md:focus-visible { outline: none; box-shadow: inset 0 0 0 1.5px var(--hue), var(--shadow); }
.md.blank::before { content: attr(data-placeholder); color: var(--muted); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: var(--s4) 0 var(--s2); }
.md h1 { font-size: 1.3rem; }
.md h2 { font-size: 1.12rem; }
.md h3, .md h4 { font-size: 1rem; }
.md p, .md ul, .md ol, .md pre, .md blockquote, .md table { margin: 0 0 var(--s3); }
.md ul, .md ol { padding-left: var(--s5); }
.md li + li { margin-top: var(--s1); }
/* Task items hang their box where the bullet would be. */
.md li:has(> input[data-task]) { list-style: none; }
.md input[data-task] { width: 16px; height: 16px; margin: 0 var(--s2) 0 calc(-1 * var(--s5)); vertical-align: -2px; accent-color: var(--hue); cursor: pointer; }
.md a { color: var(--hue-deep); font-weight: 650; }
.md code { font: 0.86em ui-monospace, SFMono-Regular, Menlo, monospace; padding: var(--s0) var(--s1); border-radius: var(--r-xs); background: var(--hue-soft); }
.md pre { padding: var(--s3); border-radius: var(--r-sm); background: var(--bg); overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md blockquote { margin-left: 0; padding-left: var(--s3); border-left: 3px solid var(--hue); color: var(--muted); }
.md table { border-collapse: collapse; }
.md th, .md td { padding: var(--s1) var(--s2); border-bottom: 1px solid var(--line); text-align: left; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: var(--s4) 0; }

.md-editor {
  margin: 0 0 var(--s3); border-radius: var(--r); background: var(--surface); overflow: hidden;
  box-shadow: 0 0 0 1.5px var(--hue), 0 0 0 4px color-mix(in srgb, var(--hue) 18%, transparent), var(--shadow);
}
.md-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s1); padding: var(--s1) var(--s2); border-bottom: 1px solid var(--line); }
.md-tool { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: var(--r-xs); background: transparent; color: var(--muted); font-size: 16px; }
.md-tool:hover { background: var(--hue-soft); color: var(--hue-deep); }
.md-spacer { flex: 1; }
.md-input {
  display: block; width: 100%; min-height: 220px; max-height: 70vh; field-sizing: content; resize: vertical;
  padding: var(--s3) var(--s4); border: 0; background: transparent; line-height: 1.6;
}
.md-input:focus { outline: none; }
.tags { display: flex; gap: var(--s1); flex-wrap: wrap; margin: 0 0 var(--s3); }
.tag-pill { padding: var(--s0) var(--s2); border-radius: var(--r-xs); background: var(--hue-soft); color: var(--hue-deep); font-weight: 700; font-size: 0.8rem; }
.links { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s1); }
.link-card { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--bg); text-decoration: none; }
.link-card .title { flex: 1; font-weight: 650; }
.rel { font-size: 0.76rem; color: var(--muted); }
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 12px; top: var(--s2); bottom: var(--s2); width: 2px; background: var(--line); }
.timeline > li { display: flex; gap: var(--s3); padding: var(--s1) 0; position: relative; }
.timeline > li + li { margin-top: var(--s2); }
.tl-dot { position: relative; width: 26px; height: 26px; font-size: 0.72rem; box-shadow: 0 0 0 2px var(--surface); }
.tl-ai {
  position: absolute; right: calc(-1 * var(--s1)); bottom: calc(-1 * var(--s1)); width: 14px; height: 14px; border-radius: 50%;
  display: grid; place-items: center; font-size: 9px; background: var(--fg); color: var(--bg); box-shadow: 0 0 0 2px var(--surface);
}
.tl-body { display: grid; gap: var(--s0); min-width: 0; font-size: 0.92rem; }
.tl-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2); }
.tl-time { color: var(--muted); font-size: 0.8rem; }
.tl-changes { margin: var(--s1) 0 0; padding-left: var(--s4); font-size: 0.86rem; }
.tl-changes li + li { margin-top: var(--s0); }
.more { margin-top: var(--s3); }
.tl-body q { font-style: italic; color: var(--hue-deep); }
.danger { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin: var(--s4) 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s1); min-height: 36px; padding: 0 var(--s3);
  border-radius: var(--r-sm); border: 0; background: var(--surface); box-shadow: var(--shadow); font-weight: 700; font-size: 0.9rem;
  text-decoration: none; white-space: nowrap; transition: transform 0.3s var(--spring);
}
.btn:active { transform: scale(0.95); }
.btn.small { min-height: 28px; padding: 0 var(--s2); font-size: 0.8rem; border-radius: var(--r-xs); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 16px -8px var(--accent); }
.btn.big { min-height: 44px; padding: 0 var(--s5); font-size: 1rem; }
.btn.soft { background: var(--hue-soft); color: var(--hue-deep); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--hue) 35%, transparent); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px var(--line); }
.btn.wide { width: 100%; }
@media (min-width: 760px) { .btn.wide { width: auto; } }
.danger-btn { background: var(--late); color: #fff; }

/* ---------- settings ---------- */
.settings-grid { display: grid; gap: var(--s3); margin-bottom: var(--s3); }
.settings-grid .card { margin: 0; }
.apps { list-style: none; margin: 0 0 var(--s3); padding: 0; display: grid; gap: var(--s2); }
.apps li { display: flex; align-items: center; gap: var(--s2); }
.apps li > .ic { color: var(--hue-deep); font-size: 18px; }
.app-name { flex: 1; min-width: 0; display: grid; font-weight: 650; }
.everywhere { padding-top: var(--s3); border-top: 1px solid var(--line); }
.profile { display: flex; align-items: center; gap: var(--s3); margin: var(--s2) 0 var(--s4); }
.people-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.person-pill { display: inline-flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s3) var(--s1) var(--s1); border-radius: var(--r-sm); background: var(--bg); font-weight: 650; }
.copy {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--s2); text-align: left;
  padding: var(--s2) var(--s3); border-radius: var(--r-sm); border: 1.5px dashed color-mix(in srgb, var(--hue) 45%, var(--line)); background: var(--hue-soft);
}
.copy code { overflow-wrap: anywhere; font-size: 0.82rem; }
.copy-label { flex: none; font-weight: 750; color: var(--hue-deep); font-size: 0.8rem; }

/* ---------- empty, loading, sign-in ---------- */
.empty { text-align: center; padding: var(--s5) var(--s3); display: grid; gap: var(--s1); justify-items: center; }
.empty-icon {
  display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: var(--s2); border-radius: 50%;
  background: var(--hue-soft); color: var(--hue-deep); font-size: 26px; animation: float 3.5s ease-in-out infinite;
}
.empty h3 { font-size: 1.02rem; }
.empty p { color: var(--muted); max-width: 30ch; font-size: 0.92rem; margin: 0; }
.card .empty { padding: var(--s2) var(--s2) var(--s1); }
.card .empty-icon { width: 44px; height: 44px; font-size: 20px; }

.loading { display: grid; place-items: center; min-height: 60dvh; }
.loading .blob { width: 40px; height: 40px; border-radius: 30%; background: var(--hue); animation: morph 1.2s ease-in-out infinite; }
@keyframes morph { 0%, 100% { border-radius: 30%; transform: rotate(0) scale(0.9); } 50% { border-radius: 50%; transform: rotate(90deg) scale(1.1); } }

.signin { text-align: center; padding: 10vh var(--s2) 0; display: grid; gap: var(--s3); justify-items: center; }
.signin-art {
  display: grid; place-items: center; width: 80px; height: 80px; border-radius: 50%; font-size: 38px;
  background: var(--hue-soft); color: var(--hue-deep); animation: float 4s ease-in-out infinite;
}
.signin p { color: var(--muted); max-width: 32ch; }

/* ---------- toast and undo snackbar ---------- */
.toast {
  position: fixed; left: var(--s3); right: var(--s3); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--s3));
  max-width: 440px; margin: 0 auto; padding: var(--s3) var(--s4); border-radius: var(--r); z-index: 20; cursor: pointer;
  background: var(--fg); color: var(--bg); font-weight: 650; box-shadow: var(--shadow-lift);
  display: flex; align-items: center; gap: var(--s2); animation: toast-in 0.45s var(--spring);
}
@media (min-width: 760px) { .toast { bottom: var(--s5); } }
@keyframes toast-in { from { transform: translateY(24px) scale(0.9); opacity: 0; } }
.toast.undo { display: flex; align-items: center; gap: var(--s3); cursor: default; padding: var(--s2) var(--s2) var(--s2) var(--s4); }
.undo-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.undo-btn {
  flex: none; border: 0; border-radius: var(--r-sm); padding: var(--s2) var(--s3); font-weight: 800;
  background: color-mix(in srgb, var(--bg) 18%, transparent); color: var(--bg);
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: var(--s4);
  background: rgb(20 16 30 / 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade-in 0.15s ease;
}
.modal {
  width: 100%; max-width: 380px; padding: var(--s5); border-radius: var(--r);
  background: var(--surface); box-shadow: var(--shadow-lift); animation: modal-in 0.3s var(--spring);
}
.modal h2 { font-size: 1.1rem; margin-bottom: var(--s2); overflow-wrap: anywhere; }
.modal.wide { max-width: 560px; max-height: min(80dvh, 720px); display: flex; flex-direction: column; padding: var(--s4); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s3); }
.modal-head h2 { margin: 0; }
.modal-body { overflow-y: auto; min-height: 0; }
.modal p { color: var(--muted); margin-bottom: var(--s5); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } }

/* Confetti pieces are created by index.html. */
.confetti { position: fixed; z-index: 50; width: 8px; height: 11px; border-radius: 2px; pointer-events: none; }

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