:root {
  --bg: #f7f6f2; --card: #ffffff; --text: #1d1d1d; --muted: #6b6b6b; --line: #e0ddd5; --accent: #2f6f8f;
  --high: #b3261e; --high-bg: #fde7e4; --med: #8a5a00; --med-bg: #fff1d1; --low: #2e5d8a; --low-bg: #e3eef9;
  --warn: #8a5a00; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a; --card: #222326; --text: #ececec; --muted: #a0a0a0; --line: #34363a; --accent: #7cc0e0;
    --high: #ffb4a9; --high-bg: #4a1f1a; --med: #ffd88a; --med-bg: #3f3214; --low: #a9cdf5; --low-bg: #1d3047; --warn: #ffd88a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; } /* never let a layout rule show something hidden */
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }

header { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
h1 { flex: 1; margin: 0; font-size: 20px; }
.status { border: none; background: none; color: var(--muted); font-size: 13px; padding: 6px 4px; }
.status.warn { color: var(--warn); }
.status.bad { color: var(--high); }
.icon { border: none; background: none; font-size: 20px; padding: 4px 6px; color: var(--muted); }

main { flex: 1; overflow-y: auto; }
.view { padding: 12px 14px 24px; }

#addform { display: flex; flex-direction: column; gap: 8px; }
#add-title { width: 100%; font-size: 18px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
#add-title:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 12px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg input:checked + span { background: var(--accent); color: var(--bg); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
button.primary { margin-left: auto; padding: 9px 18px; border: none; border-radius: 10px; background: var(--accent); color: var(--bg); font-weight: 700; }
button.ghost, button.chip, dialog button:not(.primary):not(.link) { padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 14px; }
#add-dates input { padding: 7px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 14px; }
.link { border: none; background: none; color: var(--accent); padding: 6px 2px; font-size: 14px; text-decoration: underline; }
.danger { color: var(--high) !important; }
.error { color: var(--high); font-size: 14px; margin: 8px 0 0; }
.error:empty { display: none; }
#summary { margin: 14px 0 0; font-weight: 700; color: var(--warn); }
#summary.bad { color: var(--high); }
.empty { color: var(--muted); text-align: center; margin: 32px 0; }

#tasks, #donelist { list-style: none; margin: 10px 0 0; padding: 0; }
.task { display: flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--line); border-left-width: 4px; border-radius: 12px; margin-bottom: 8px; padding: 2px 6px 2px 10px; }
.task.prio-high { border-left-color: var(--high); }
.task.prio-medium { border-left-color: var(--med); }
.task.prio-low { border-left-color: var(--low); }
.task.done { border-left-color: var(--line); }
.task input[type=checkbox] { width: 24px; height: 24px; flex: none; accent-color: var(--accent); margin: 10px 6px 10px 0; }
.task .body { flex: 1; min-width: 0; text-align: left; border: none; background: none; padding: 10px 4px; display: flex; flex-direction: column; gap: 3px; }
.ttl { overflow-wrap: anywhere; }
.task.done .ttl { text-decoration: line-through; color: var(--muted); }
.meta { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.pill { padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; }
.pill.high { color: var(--high); background: var(--high-bg); }
.pill.medium { color: var(--med); background: var(--med-bg); }
.pill.low { color: var(--low); background: var(--low-bg); }
.task.overdue .due { color: var(--high); font-weight: 700; }
.task.today .due { color: var(--warn); font-weight: 700; }
#donebox { margin-top: 18px; }
#donebox summary { color: var(--muted); padding: 6px 0; }

#view-notes:not([hidden]) { display: flex; flex-direction: column; height: 100%; padding-bottom: 12px; }
#notechips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
#notechips .chip { flex: none; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#notechips .chip[aria-selected=true] { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.notebar { justify-content: flex-end; gap: 14px; }
#note { flex: 1; min-height: 50vh; width: 100%; resize: none; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-size: 16px; line-height: 1.5; }
#note:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

nav { display: flex; border-top: 1px solid var(--line); background: var(--card); padding-bottom: env(safe-area-inset-bottom); }
nav button { flex: 1; border: none; background: none; padding: 14px 0; font-weight: 700; color: var(--muted); }
nav button[aria-current] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--high); color: var(--bg); font-size: 12px; line-height: 20px; }
.badge[hidden] { display: none; }

dialog { width: min(92vw, 420px); border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text); padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog input, dialog select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); width: 100%; }
dialog .row input { width: auto; flex: 1; }
dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.actions .spacer { flex: 1; }
.actions .primary { margin-left: 0; }
