:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1c1d1f;
  --muted: #6b6d72;
  --line: #e4e2dc;
  --accent: #2f6b4f;
  --accent-soft: #e3efe8;
  --today: #fff6dc;
  --today-line: #e8c96a;
  --danger: #b3261e;
  --note-bg: #fbf3e0;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --surface: #212225;
    --text: #ececea;
    --muted: #9a9ca1;
    --line: #333438;
    --accent: #6fbf95;
    --accent-soft: #263a30;
    --today: #2c2817;
    --today-line: #8a7535;
    --danger: #f2827a;
    --note-bg: #2a2619;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 8px; max-width: 720px; margin: 0 auto; }
.top h1 { font-size: 1.1rem; line-height: 1.25; margin: 0; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.top-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle { fill: currentColor; stroke: none; }
.status { max-width: 720px; margin: 2px auto 0; font-size: .8rem; color: var(--muted); min-height: 1.1em; }
.status.error { color: var(--danger); }
.menu {
  max-width: 720px; margin: 8px auto 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
}
.menu button { text-align: left; padding: 12px 14px; border: 0; background: none; border-bottom: 1px solid var(--line); cursor: pointer; }
.menu button:last-child { border-bottom: 0; }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 48px; }
.empty { color: var(--muted); text-align: center; margin-top: 40px; }

.intro { background: var(--note-bg); border-radius: var(--radius); padding: 10px 14px; font-size: .9rem; margin-bottom: 12px; }
.intro p { margin: 0; }
.intro p + p { margin-top: 6px; }

.section {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 12px; overflow: hidden;
}
.section.today { border-color: var(--today-line); box-shadow: 0 0 0 1px var(--today-line); }
.section.today .section-head { background: var(--today); }
.section-head { display: flex; align-items: baseline; gap: 8px; padding: 10px 14px 6px; }
.section-head h2 { font-size: .95rem; margin: 0; flex: 1; }
.badge { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.count { font-size: .8rem; color: var(--muted); }

.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 14px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.check {
  flex: none; width: 26px; height: 26px; margin-top: 1px; border-radius: 8px;
  border: 2px solid var(--muted); background: transparent; cursor: pointer; display: grid; place-items: center; padding: 0;
}
.check svg { width: 16px; height: 16px; stroke: #fff; stroke-width: 3; fill: none; opacity: 0; }
.item.done .check { background: var(--accent); border-color: var(--accent); }
.item.done .check svg { opacity: 1; }
.item-body { flex: 1; min-width: 0; cursor: pointer; padding: 2px 0; overflow-wrap: anywhere; }
.item.done .item-text { text-decoration: line-through; color: var(--muted); }
.notes { margin: 4px 0 0; padding-left: 16px; font-size: .85rem; color: var(--muted); }
.notes li { margin: 2px 0; }
.item a, .notes a, .intro a { color: var(--accent); }
.item code { font-size: .85em; background: var(--line); padding: 0 4px; border-radius: 4px; }

.add-row { display: flex; gap: 8px; padding: 8px 14px 12px; border-top: 1px solid var(--line); }
.add-row input {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--bg);
  border-radius: 10px; padding: 9px 12px; font-size: 16px;
}
.add-row button, .dialog-actions button {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px; cursor: pointer;
}
.primary { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff; }
@media (prefers-color-scheme: dark) { .primary { color: #10261b; } }
.danger { color: var(--danger); }
.other { padding: 4px 14px 10px; font-size: .85rem; color: var(--muted); }

dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { margin: 0; font-size: 1.05rem; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
dialog textarea, dialog select {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--bg);
  color: var(--text); font-size: 16px;
}
.hint { font-size: .75rem; }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
dialog.raw { width: min(900px, calc(100vw - 16px)); height: calc(100dvh - 32px); }
dialog.raw form { height: 100%; }
#raw-text { flex: 1; font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; resize: none; }
