:root {
  --bg: #fbfaf8;
  --side: #f4f2ee;
  --surface: #ffffff;
  --ink: #1d1c1a;
  --ink-2: #5b5852;
  --ink-3: #8e8981;
  --hair: #e8e4de;
  --mid: #c9c3ba;
  --brand: #2f5d50;
  --brand-ink: #ffffff;
  --brand-soft: #e6eeeb;
  --wine: #a3313a;
  --orange: #b4621a;
  --sage: #4c7a57;
  --shadow: 0 12px 40px rgba(29, 28, 26, 0.14), 0 2px 6px rgba(29, 28, 26, 0.06);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151514; --side: #1b1b19; --surface: #1f1f1d; --ink: #ecebe7; --ink-2: #b2aea6; --ink-3: #807b73;
    --hair: #2c2b28; --mid: #4a4742; --brand: #6fa894; --brand-ink: #10201b; --brand-soft: #22302b;
    --wine: #e0727a; --orange: #e09a55; --sage: #8fbf98; --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151514; --side: #1b1b19; --surface: #1f1f1d; --ink: #ecebe7; --ink-2: #b2aea6; --ink-3: #807b73;
  --hair: #2c2b28; --mid: #4a4742; --brand: #6fa894; --brand-ink: #10201b; --brand-soft: #22302b;
  --wine: #e0727a; --orange: #e09a55; --sage: #8fbf98; --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--brand); text-decoration-thickness: 1px; text-underline-offset: 2px; }
h1 { font-size: 24px; line-height: 1.2; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
input, textarea, select {
  background: var(--surface); border: 1px solid var(--mid); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
button { cursor: pointer; border-radius: 8px; padding: 6px 12px; border: 1px solid var(--mid); background: transparent; white-space: nowrap; }
button:hover { background: var(--side); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); background: var(--brand); }
button.ghost { padding: 4px 10px; font-size: 13px; color: var(--ink-2); }
button:focus-visible, .row:focus-visible, .nav a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-form { width: min(340px, 100%); display: grid; gap: 10px; }
.login-form h1 { font-size: 32px; margin-bottom: 12px; }
.login-form label { font-size: 13px; color: var(--ink-2); }
.login-error, .inline-error { color: var(--wine); font-weight: 600; font-size: 13px; margin: 0; }

/* shell */
.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100%; }
.side { background: var(--side); border-right: 1px solid var(--hair); height: 100vh; position: sticky; top: 0; display: flex; flex-direction: column; }
.side-top { padding: 18px 16px 10px; display: grid; gap: 12px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; color: var(--brand); }
.search { width: 100%; background: var(--surface); }
.nav { overflow-y: auto; flex: 1; padding: 4px 8px 16px; }
.nav h2 { font-size: 12px; font-weight: 600; color: var(--ink-3); margin: 18px 8px 4px; }
.nav a {
  display: flex; align-items: baseline; gap: 8px; padding: 5px 8px; border-radius: 6px; color: var(--ink);
  text-decoration: none; padding-left: calc(8px + var(--depth, 0) * 14px);
}
.nav a:hover { background: var(--hair); }
.nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .n { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.nav .n.warn { color: var(--wine); font-weight: 600; }
.nav .key { font: 11px var(--mono); color: var(--ink-3); }
.side-foot { padding: 10px 16px 16px; display: flex; gap: 8px; border-top: 1px solid var(--hair); }

.main { padding: 28px 40px 80px; max-width: 920px; width: 100%; }
.head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 18px; }
.menu { display: none; }
.crumb { margin: 0 0 4px; font-size: 13px; color: var(--ink-3); }
.crumb a { color: var(--ink-3); }
.tally { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.tally b { color: var(--ink); font-weight: 600; }
.tally .warn b, .tally .warn { color: var(--wine); }

.add { display: grid; grid-template-columns: minmax(0, 1fr) 180px auto; gap: 8px; margin-bottom: 6px; }
.inline-error { margin: 4px 0 0; }

/* list */
.list { margin-top: 18px; }
.group { margin-bottom: 26px; }
.group-head { display: flex; align-items: baseline; gap: 10px; padding: 0 0 6px; border-bottom: 1px solid var(--hair); }
.group-head h3 { margin: 0; font-size: 14px; font-weight: 650; }
.group-head h3 a { color: inherit; text-decoration: none; }
.group-head h3 a:hover { text-decoration: underline; }
.group-head .n { color: var(--ink-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.group-head.warn h3, .group-head.warn .n { color: var(--wine); }
.group-head .sub { margin-left: auto; font-size: 12px; color: var(--ink-3); }

.row {
  display: grid; grid-template-columns: 22px 62px minmax(0, 1fr) auto; gap: 10px; align-items: start;
  padding: 9px 4px 9px calc(4px + var(--depth, 0) * 26px); border-bottom: 1px solid var(--hair); cursor: pointer;
}
.row:hover { background: var(--side); }
.row.open { background: var(--brand-soft); }
.row.done .content { text-decoration: line-through; color: var(--ink-3); }
.check {
  width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; border: 1.5px solid var(--mid); padding: 0;
  background: transparent; display: grid; place-items: center;
}
.check.p1 { border-color: var(--wine); }
.check.p2 { border-color: var(--orange); }
.check.p3 { border-color: var(--brand); }
.check:hover::after, .row.done .check::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; opacity: 0.45; }
.row.done .check { border-color: var(--sage); color: var(--sage); }
.row.done .check::after { opacity: 1; }
.id { font: 12px/20px var(--mono); color: var(--ink-3); white-space: nowrap; }
.body { min-width: 0; }
.content { overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 2px; font-size: 12.5px; color: var(--ink-3); }
.meta .lab { color: var(--ink-2); }
.right { text-align: right; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; line-height: 20px; }
.right .late { color: var(--wine); font-weight: 600; }
.right .today { color: var(--sage); font-weight: 600; }
.prio { font-weight: 600; margin-left: 8px; }
.prio.p1 { color: var(--wine); }
.prio.p2 { color: var(--orange); }
.prio.p3 { color: var(--ink-2); }
.undo { margin-left: 10px; padding: 1px 8px; font-size: 12px; }
.empty { color: var(--ink-3); padding: 10px 4px; border-bottom: 1px solid var(--hair); font-size: 13px; }
.more { margin: 8px 0 0; }

/* drawer */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--surface);
  box-shadow: var(--shadow); overflow-y: auto; padding: 22px 24px 40px; z-index: 20; border-left: 1px solid var(--hair);
}
.drawer-top { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 13px; color: var(--ink-3); }
.drawer-top .id { font-size: 13px; }
.drawer-top .grow { flex: 1; }
.drawer-title {
  font-size: 19px; font-weight: 600; line-height: 1.35; margin: 0 0 10px; padding: 4px 6px; margin-left: -6px;
  border-radius: 6px; border: 1px solid transparent; overflow-wrap: anywhere; white-space: pre-wrap;
}
.drawer-title:hover { border-color: var(--hair); }
.drawer-title:focus { outline: 2px solid var(--brand); }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); margin: 0 0 16px; }
.attrs { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px 12px; margin: 0 0 22px; align-items: center; }
.attrs dt { color: var(--ink-3); font-size: 13px; }
.attrs dd { margin: 0; min-width: 0; }
.attrs input, .attrs select { width: 100%; padding: 5px 8px; }
.attrs .hint { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.drawer h4 { font-size: 13px; font-weight: 650; margin: 22px 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--hair); }
.drawer h4 .n { color: var(--ink-3); font-weight: 400; margin-left: 6px; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--hair); }
.comment .when { font-size: 12px; color: var(--ink-3); margin-bottom: 2px; }
.comment .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { display: grid; gap: 8px; margin-top: 10px; }
.comment-form textarea { min-height: 70px; resize: vertical; }
.comment-form button { justify-self: end; }
.drawer .row { grid-template-columns: 22px 62px minmax(0, 1fr); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--surface); color: var(--ink);
  border: 1px solid var(--mid); box-shadow: var(--shadow); border-radius: 10px; padding: 10px 14px; z-index: 40; font-size: 13px;
  display: flex; gap: 12px; align-items: center; max-width: calc(100% - 32px);
}
.toast .word { font-weight: 600; }
.toast .word.bad { color: var(--wine); }
.toast .word.good { color: var(--sage); }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.3); z-index: 15; }

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); z-index: 16; transform: translateX(-100%); transition: transform 0.18s ease; }
  .side.show { transform: none; box-shadow: var(--shadow); }
  .menu { display: inline-block; margin-top: 2px; }
  .main { padding: 16px 16px 80px; }
  .add { grid-template-columns: minmax(0, 1fr) auto; }
  .add-due { grid-column: 1; grid-row: 2; }
  .add button { grid-row: 1 / span 2; grid-column: 2; }
  .row { grid-template-columns: 22px minmax(0, 1fr); padding-left: calc(4px + var(--depth, 0) * 16px); }
  .row .id { display: none; }
  .row .right { grid-column: 2; text-align: left; }
  .drawer { padding: 16px 16px 40px; }
  .drawer .row { grid-template-columns: 22px minmax(0, 1fr); }
}

.snip { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.content code, .desc code, .comment code { font: 12px var(--mono); background: var(--side); padding: 1px 4px; border-radius: 4px; }
.crumb .key { font: 12px var(--mono); }
a.row { color: inherit; text-decoration: none; }
.btns { display: flex; gap: 8px; justify-content: flex-end; }
.drawer-foot { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--hair); display: flex; justify-content: flex-end; }
button.danger { color: var(--wine); border-color: var(--wine); font-weight: 600; }
.sub-add { grid-template-columns: minmax(0, 1fr) auto; margin-top: 8px; }
@media (max-width: 860px) { .sub-add { grid-template-columns: minmax(0, 1fr) auto; } .sub-add button { grid-row: auto; grid-column: auto; } }
