:root {
  --bg: #f5f3ef; --card: #ffffff; --ink: #1d1b18; --muted: #6f6a62; --line: #e6e1d8;
  --red: #c4372b; --red-bg: #fbe9e6; --amber: #935800; --amber-bg: #fdf1dc;
  --blue: #2a5fa8; --blue-bg: #e7eefa; --green: #2a7347; --green-bg: #e4f3ea;
  --grey-bg: #efece6; --accent: #1d1b18; --shadow: 0 1px 2px rgba(0,0,0,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151412; --card: #1f1d1a; --ink: #f1ede6; --muted: #a39d93; --line: #2e2b27;
    --red: #ff7a6b; --red-bg: #3a1f1b; --amber: #f0b45a; --amber-bg: #372a15;
    --blue: #86b1f0; --blue-bg: #1b2a40; --green: #7fd1a0; --green-bg: #18301f;
    --grey-bg: #2a2723; --accent: #f1ede6; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 48px; padding-top: max(16px, env(safe-area-inset-top)); }
h1 { font-size: 26px; margin: 4px 0 2px; letter-spacing: -.01em; }
h2 { font-size: 15px; color: var(--ink); margin: 26px 0 10px; font-weight: 650; }
.sub { color: var(--muted); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--green); }
.dot.bad { background: var(--red); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: var(--shadow);
  cursor: pointer; text-align: left; color: inherit; font: inherit; }
.stat b { display: block; font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.red b { color: var(--red); } .stat.amber b { color: var(--amber); } .stat.blue b { color: var(--blue); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.plan { padding: 6px 14px; }
.step { display: grid; grid-template-columns: 62px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.step:last-of-type { border-bottom: 0; }
.step .time { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; padding-top: 1px; }
.step .what { font-weight: 600; }
.step .why { color: var(--muted); font-size: 13px; }
.note { margin: 6px 0 8px; padding: 10px 12px; background: var(--grey-bg); border-radius: 10px; font-size: 14px; }
.empty { color: var(--muted); padding: 14px; font-size: 14px; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 4px; text-align: center; font-size: 12px; color: var(--muted); }
.day b { display: block; font-size: 18px; color: var(--ink); font-variant-numeric: tabular-nums; }
.day.today { border-color: var(--accent); }
.day.has b { color: var(--blue); }
.day.over b { color: var(--red); }
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-top: 4px; scrollbar-width: none; }
.filters button { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px;
  padding: 7px 14px; min-height: 44px; font: inherit; font-size: 13px; cursor: pointer; }
.filters button[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.task { padding: 12px 14px 12px 16px; margin-bottom: 8px; position: relative; overflow: hidden; }
.task::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line); }
.task.u-red::before { background: var(--red); } .task.u-amber::before { background: var(--amber); }
.task.u-blue::before { background: var(--blue); } .task.done { background: var(--bg); } .task.done .text { color: var(--muted); }
.task .text { display: block; width: 100%; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; word-wrap: break-word; }
.task .next { margin-top: 6px; font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--grey-bg); color: var(--muted); white-space: nowrap; }
.chip.red { background: var(--red-bg); color: var(--red); } .chip.amber { background: var(--amber-bg); color: var(--amber); }
.chip.blue { background: var(--blue-bg); color: var(--blue); } .chip.green { background: var(--green-bg); color: var(--green); }
.actions { margin-top: 10px; display: flex; gap: 8px; }
.btn { border: 1px solid var(--line); background: transparent; color: var(--ink); border-radius: 8px; padding: 6px 12px; min-height: 44px; font: inherit; font-size: 13px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn:focus-visible, .stat:focus-visible, .filters button:focus-visible, .step:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--blue); } to { box-shadow: var(--shadow); } }
pre { margin: 0; padding: 10px 12px; white-space: pre-wrap; word-wrap: break-word; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow: auto; background: var(--grey-bg); border-radius: 8px; }
.task[data-open] { cursor: pointer; }
.task[data-open]:focus-visible, .btn:focus-visible, #drawer summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
#backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 10; }
#drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(540px, 100vw); z-index: 11; background: var(--card); color: var(--ink);
  border-left: 1px solid var(--line); box-shadow: -8px 0 28px rgba(0,0,0,.18); overflow-y: auto; overscroll-behavior: contain;
  animation: slidein .2s ease-out; }
#drawer[hidden], #backdrop[hidden] { display: none; }
#drawer:focus { outline: none; }
@keyframes slidein { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.d-head { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); font-size: 13px; }
#d-body { padding: 16px 16px 40px; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
#d-title { text-transform: none; color: var(--ink); font-weight: 650; font-size: 19px; line-height: 1.3; margin: 0 0 14px; letter-spacing: -.01em; word-wrap: break-word; }
.facts { margin: 0; display: grid; grid-template-columns: 84px 1fr; gap: 6px 10px; font-size: 14px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; word-wrap: break-word; }
.d-sec { margin-top: 22px; }
.d-sec h3 { font-size: 14px; color: var(--ink); margin: 0 0 8px; font-weight: 650; }
.d-sec p { margin: 0; word-wrap: break-word; }
.bubbles { display: flex; flex-direction: column; gap: 8px; }
.bub { max-width: 86%; padding: 7px 11px; border-radius: 12px; background: var(--grey-bg); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; font-size: 14px; }
.bub.me { align-self: flex-end; background: var(--blue-bg); }
.bub .meta { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; white-space: normal; }
.bub.me .meta { color: var(--blue); }
.d-sec details > summary { cursor: pointer; font-size: 13px; color: var(--blue); margin-bottom: 8px; }
.d-sec a.btn { margin-top: 10px; }
.brief-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.brief-head h3 { margin: 0; }
.brief-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.md h4 { font-size: 14px; margin: 12px 0 4px; } .md h4:first-child { margin-top: 0; }
.md p { margin: 0 0 8px; font-size: 14px; } .md ul { margin: 0 0 8px; padding-left: 20px; font-size: 14px; }
.md .kv { display: grid; grid-template-columns: 56px 1fr; gap: 8px; font-size: 14px; margin-bottom: 4px; }
.md .kv span:first-child { color: var(--muted); }
.md pre { margin: 0 0 8px; }
.state { color: var(--muted); font-size: 14px; padding: 10px 12px; background: var(--grey-bg); border-radius: 8px; }
.state.err { color: var(--red); background: var(--red-bg); }
footer { margin-top: 28px; color: var(--muted); font-size: 12px; line-height: 1.6; }
@media (max-width: 420px) { .stat b { font-size: 21px; } .step { grid-template-columns: 54px 1fr; } }
@media (prefers-reduced-motion: reduce) { .flash, #drawer { animation: none; } }
@media (max-width: 639px) { #drawer { width: 100vw; height: 100dvh; border-left: 0; } #backdrop { display: none; } }
.mt12 { margin-top: 12px; }
.row { display: flex; gap: 8px; }
.sec { margin-top: 18px; }
.dim { color: var(--muted); }
.made { font-size: 12px; color: var(--muted); padding: 2px 0 8px; }
.chip.center { align-self: center; }
.offscreen { position: fixed; opacity: 0; }
main.wide { max-width: none; }
a.btn { text-decoration: none; display: inline-block; }
.flowbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.flowtitle { font-size: 20px; margin: 0; }
.push { margin-left: auto; }
.flowwrap { overflow: auto; padding: 0; background: #ffffff; -webkit-overflow-scrolling: touch; }
.flowwrap svg { display: block; }
.flowwrap g.node:focus { outline: none; }
.flowwrap g.node:focus rect, .flowwrap g.node:hover rect { stroke-width: 3; }
.foot { color: var(--muted); font-size: 12px; margin-top: 10px; }
.task .work { margin-top: 6px; font-size: 13px; color: var(--green); }
.session { padding: 10px 14px; margin-bottom: 8px; }
.srow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sstatus { margin-top: 6px; font-size: 13px; color: var(--ink); }
#moresessions { margin-top: 4px; }
.acts { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.act-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.act-l { width: 76px; color: var(--muted); font-size: 13px; }
.acts select, .acts input { font: inherit; font-size: 14px; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-height: 44px; max-width: 100%; }
.acts select:focus-visible, .acts input:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.green { background: var(--green); color: var(--bg); border-color: var(--green); font-weight: 600; }
.btn.danger-o { border-color: var(--red); color: var(--red); }
.btn.danger { background: var(--red); color: var(--bg); border-color: var(--red); font-weight: 600; }
.btn[aria-pressed="true"] { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.dism-form { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.dism-form[hidden] { display: none; }
.dism-form input { flex: 1 1 180px; }
ul.hist { margin: 0; padding-left: 18px; font-size: 14px; }
.dism { margin-top: 18px; padding: 4px 14px; }
.dism summary { cursor: pointer; padding: 10px 0; font-weight: 600; font-size: 14px; }
.dism summary:focus-visible, .dtext:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
.drow { display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.dtext { cursor: pointer; word-wrap: break-word; min-width: 0; font-size: 14px; }
.dtext .dim { font-size: 12px; margin-top: 2px; }
#toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; max-width: min(92vw, 460px);
  display: flex; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 14px; box-shadow: 0 4px 18px rgba(0,0,0,.3); }
#toast[hidden] { display: none; }
#toast .btn { color: var(--bg); border-color: var(--bg); }
.stat[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: -2px; }
.place { padding: 12px 14px; border-top: 1px solid var(--line); display: grid; gap: 4px; overflow-wrap: anywhere; }
.place:first-child { border-top: 0; }
.place .btn { justify-self: start; }
.pl-add { padding: 12px 14px; display: grid; gap: 6px; max-width: 420px; }
.pl-add button { justify-self: start; margin-top: 6px; }
.btn.wide { width: 100%; font-weight: 600; }
.task .text:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; border-radius: 4px; }
@media (hover: hover) {
  .btn:hover:not(:disabled), .filters button:hover, .stat:hover, .task:hover, .dtext:hover { border-color: var(--muted); }
  .btn.primary:hover, .btn.green:hover:not(:disabled), .btn.danger:hover:not(:disabled), .filters button[aria-pressed="true"]:hover { filter: brightness(1.12); }
  .step:hover .what, .task .text:hover { text-decoration: underline; text-underline-offset: 3px; }
}
.btn:active:not(:disabled), .filters button:active, .stat:active { transform: translateY(1px); }

/* ── ambient view (html.ambient): clock + big task list, always dark, meant to stay on full screen ── */
#amb, #amb-bar { display: none; }
.ambient { --bg: #0e1113; --card: #151a1e; --ink: #ece8df; --muted: #8d9399; --line: #23292e; --red: #ff7a6b; --red-bg: #3a1f1b;
  --amber: #e3a84f; --amber-bg: #372a15; --blue: #86b1f0; --blue-bg: #1b2a40; --green: #74c492; --green-bg: #18301f;
  --grey-bg: #22282d; --accent: #ece8df; --shadow: none; }
.ambient, .ambient body { height: 100%; overflow: hidden; }
.ambient body { background: radial-gradient(120% 90% at 15% 10%, transparent 0%, var(--bg) 60%) var(--tint, #17202b); transition: background-color 3s; }   /* the tint shows through the corner */
.ambient[data-tod="afternoon"] { --tint: #2b2117; }
.ambient[data-tod="evening"] { --tint: #1f1a2e; }
.ambient main { max-width: none; height: 100%; display: grid; grid-template-columns: minmax(260px, 34%) 1fr; gap: 5vw; padding: 5vh 6vw;
  animation: amb-drift 180s ease-in-out infinite alternate; }   /* burn-in: nothing sits on the same pixels for hours */
.ambient main > :not(#amb):not(#list) { display: none; }
.ambient #amb { display: block; }
#amb-clock { font-size: clamp(64px, 11vw, 190px); font-weight: 200; letter-spacing: -.03em; line-height: 1; font-variant-numeric: tabular-nums; }
#amb-date { margin-top: 1.5vh; font-size: clamp(18px, 1.9vw, 30px); color: var(--muted); }
#amb-phase { margin-top: 4vh; font-size: clamp(17px, 1.6vw, 26px); }
#amb-jarvis { margin-top: 3vh; min-height: 1.4em; font-size: clamp(17px, 1.6vw, 26px); color: var(--green); }
.ambient[data-jarvis] #amb-jarvis { animation: amb-jarvis 1.6s ease-in-out infinite alternate; }
@keyframes amb-jarvis { from { opacity: .55; } to { opacity: 1; } }
#amb-count { margin-top: .8vh; font-size: clamp(15px, 1.3vw, 20px); color: var(--muted); }
.ambient #list { margin: 0; align-self: center; max-height: 100%; overflow-y: auto; scrollbar-width: none; padding: 6px 6px 8vh;
  -webkit-mask-image: linear-gradient(#000 calc(100% - 9vh), transparent); mask-image: linear-gradient(#000 calc(100% - 9vh), transparent); }   /* more tasks than fit: they fade out, the list scrolls */
.ambient #list .sec, .ambient .task .next, .ambient .task .work, .ambient .task .actions, .ambient .task { display: none; }
.ambient .task.s-today, .ambient .task.s-week, .ambient .task.u-red, .ambient .task.u-amber { display: block; }
.ambient .task { margin: 0; padding: .7vh 12px .7vh 62px; background: none; border: 0; border-radius: 12px; box-shadow: none; overflow: visible; }
.ambient .task::before { left: 22px; top: calc(.7vh + .3em); bottom: auto; width: 16px; height: 16px; border: 2px solid var(--muted); border-radius: 50%; background: none; }
.ambient .task.u-red::before { border-color: var(--red); color: var(--red); background: none; animation: amb-glow 4s ease-in-out infinite; }
.ambient .task.u-amber::before { border-color: var(--amber); background: none; }   /* only overdue glows: a screen of due-today tasks stays calm */
.ambient .task.u-blue::before { border-color: var(--blue); background: none; }
.ambient .task .text { font-size: clamp(15px, 1.35vw, 22px); line-height: 1.25; color: var(--muted);
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 1; line-clamp: 1; overflow: hidden; }   /* real task text runs to a paragraph: the drawer has the rest */
.ambient .task.s-today, .ambient .task.u-red, .ambient .task.u-amber { padding-top: 1.4vh; padding-bottom: 1.4vh; }
.ambient .task.s-today::before, .ambient .task.u-red::before, .ambient .task.u-amber::before { left: 16px; top: calc(1.4vh + .3em); width: 28px; height: 28px; }
.ambient .task.s-today .text, .ambient .task.u-red .text, .ambient .task.u-amber .text { font-size: clamp(20px, 2vw, 34px); font-weight: 500; color: var(--ink); -webkit-line-clamp: 2; line-clamp: 2; }
.ambient .chips { margin-top: .6vh; }
.ambient .chip { padding: 0; background: none; font-size: clamp(13px, 1.1vw, 18px); }
.ambient .chip:not(.red):not(.amber):not(.blue) { display: none; }
.ambient .task.enter { animation: amb-enter 1.1s cubic-bezier(.2, .7, .2, 1) both; }
.ambient .task.tick { max-height: 40vh; overflow: hidden; animation: amb-leave .6s 1s ease forwards; }
.ambient .task.tick::before { background: var(--green); border-color: var(--green); animation: none; }
.ambient .task.tick::after { content: ""; position: absolute; left: 26px; top: calc(1.4vh + .3em + 5px); width: 7px; height: 13px;
  border: solid var(--bg); border-width: 0 3px 3px 0; transform: rotate(45deg); }
.ambient .task.tick .text { color: var(--muted); text-decoration: line-through; }
.ambient .task.tick:not(.s-today):not(.u-red):not(.u-amber)::after { display: none; }   /* small ring: filled green, no check mark */
.ambient #amb-cat { min-height: 44px; max-width: 46vw; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font: inherit; }
.ambient #amb-bar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; position: fixed; right: 20px; left: 20px; bottom: 20px; z-index: 5; transition: opacity .6s; }
.ambient.idle #amb-bar:not(:focus-within) { opacity: 0; pointer-events: none; }
.ambient.idle body { cursor: none; }
@keyframes amb-drift { from { transform: translate(-6px, -4px); } to { transform: translate(6px, 4px); } }
@keyframes amb-glow { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 18px 2px currentColor; } }
@keyframes amb-enter { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes amb-leave { to { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; } }
@media (hover: hover) { .ambient .task:hover { background: #ffffff0d; } }
@media (max-width: 760px) { .ambient main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; gap: 3vh; padding: 4vh 16px; } .ambient #list { align-self: start; } }
@media (prefers-reduced-motion: reduce) { .ambient main, .ambient .task, .ambient .task::before, .ambient #amb-jarvis { animation: none !important; } .ambient #amb-bar, .ambient body { transition: none; } }
