:root {
  --bg: #f5f5f7; --card: #ffffff; --text: #1d1d1f; --muted: #6e6e73; --line: #e5e5ea;
  --accent: #0a84ff; --danger: #ff3b30; --pin: #ff9f0a; --ok: #34c759;
  --q1: #ff453a; --q2: #0a84ff; --q3: #ff9f0a; --q4: #8e8e93;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1d1f; --card: #2c2c2e; --text: #f5f5f7; --muted: #98989d; --line: #3a3a3c; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; }
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
header { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 14px 16px 8px;
  display: flex; align-items: center; gap: 10px; }
header h1 { font-size: 22px; margin: 0; flex: 1; font-weight: 700; }
.icon-btn { background: none; border: 0; color: var(--accent); font-size: 15px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-family: inherit; }
.icon-btn:active { background: var(--line); }
main { padding: 0 16px calc(84px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.card { background: var(--card); border-radius: 14px; padding: 12px 14px; }
input[type=search], input[type=text], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 11px 13px; outline: none; -webkit-appearance: none; appearance: none; }
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 76px; resize: vertical; }
.row { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.row > input { flex: 1; min-width: 0; }
.btn { flex: 1; font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px; cursor: pointer;
  background: var(--accent); color: #fff; }
.btn.slim { flex: 0 0 auto; padding: 11px 16px; }
.btn.secondary { background: var(--card); color: var(--accent); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; }
.btn:active { filter: brightness(.9); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 2px 0; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }
ul { list-style: none; margin: 0; padding: 0; }
li { background: var(--card); border-radius: 14px; margin-bottom: 8px; display: flex; align-items: stretch; overflow: hidden; }
li.section { background: none; border-radius: 0; margin: 10px 2px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; display: block; }
li.section:first-child { margin-top: 2px; }
li .tap { flex: 1; padding: 12px 14px; cursor: pointer; min-width: 0; }
li .tap:active { background: var(--line); }
li .text { white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
li .meta { color: var(--muted); font-size: 12px; margin-top: 5px; }
li .actions { display: grid; grid-template-columns: 1fr 1fr; border-left: 1px solid var(--line); }
li .actions.single { grid-template-columns: 1fr; }
li .actions button { background: none; border: 0; padding: 0 12px; font-size: 16px; cursor: pointer; color: var(--muted); min-width: 44px; font-family: inherit; }
li .actions button:active { background: var(--line); }
li.pinned .actions .pin { color: var(--pin); }
li .actions .del:active { color: var(--danger); }

/* tabs */
nav#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav#tabs button { flex: 1; background: none; border: 0; padding: 8px 0 6px; color: var(--muted); font: inherit; font-size: 20px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav#tabs button span { font-size: 11px; font-weight: 600; }
nav#tabs button.active { color: var(--accent); }
.tab-title { display: flex; align-items: baseline; gap: 8px; }

/* tasks */
.quad { margin: 14px 0 6px; }
.quad h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; margin: 0 2px 6px; color: var(--muted); display: flex; align-items: baseline; gap: 8px; }
.quad h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12px; }
.quad h2::before { content: ""; width: 8px; height: 8px; border-radius: 50%; display: inline-block; transform: translateY(-1px); }
#q1 h2::before { background: var(--q1); } #q2 h2::before { background: var(--q2); }
#q3 h2::before { background: var(--q3); } #q4 h2::before { background: var(--q4); }
.quad ul:empty::after { content: "nothing here"; display: block; color: var(--muted); font-size: 13px; padding: 4px 14px 8px; opacity: .7; }
li.task .check { background: none; border: 0; font-size: 22px; padding: 0 4px 0 12px; color: var(--muted); cursor: pointer; }
li.task .check:active { color: var(--ok); }
li.task.done .check { color: var(--ok); }
li.task.done .text { text-decoration: line-through; color: var(--muted); }
li.task .flags { display: flex; border-left: 1px solid var(--line); }
li.task .flags button { background: none; border: 0; padding: 0 10px; font-size: 16px; cursor: pointer; color: var(--muted); opacity: .45; font-family: inherit; min-width: 40px; }
li.task .flags button.on { opacity: 1; }
li.task .flags .urgent.on { color: var(--q3); }
li.task .flags .important.on { color: var(--q2); }
li.task .flags .urgent.auto { opacity: .8; }
.due { display: inline-block; padding: 1px 7px; border-radius: 6px; background: var(--line); font-size: 11px; font-weight: 600; margin-right: 6px; }
.due.soon { background: color-mix(in srgb, var(--q3) 22%, transparent); color: var(--q3); }
.due.over { background: color-mix(in srgb, var(--q1) 22%, transparent); color: var(--q1); }
details#doneWrap { margin-top: 18px; }
details#doneWrap summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px 2px; }
details#doneWrap ul { margin-top: 6px; }

/* notes */
li.note .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
li .saved { display: inline-block; padding: 1px 7px; border-radius: 6px; background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); font-size: 11px; font-weight: 600; margin-right: 6px; }
.legend { margin-bottom: 8px; }
details.trash { margin-top: 18px; }
details.trash summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px 2px; }
details.trash ul { margin-top: 6px; }
details.trash li .text { color: var(--muted); }
details.trash li .actions button { font-size: 13px; font-weight: 600; padding: 0 12px; white-space: nowrap; }
details.trash li .actions .restore { color: var(--accent); }
details.trash li .actions .destroy:active { color: var(--danger); }
li.note .snippet { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

/* editor sheet */
#sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet-panel { background: var(--bg); width: 100%; max-width: 680px; max-height: 94vh; border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; overflow: auto; }
@media (min-width: 700px) { #sheet { align-items: center; } .sheet-panel { border-radius: 18px; max-height: 88vh; } }
.sheet-bar { display: flex; align-items: center; justify-content: space-between; }
.sheet-title { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
#edTitle { font-size: 18px; font-weight: 600; }
#edBody { min-height: 160px; font-size: 16px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip { font: inherit; font-size: 14px; font-weight: 600; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.on.urgent { background: var(--q3); border-color: var(--q3); }
.chip.on.done { background: var(--ok); border-color: var(--ok); }
.chip.on.pin { background: var(--pin); border-color: var(--pin); }
.chip input[type=date], .chip select { font: inherit; border: 0; background: transparent; color: inherit; padding: 0; }
#remWrap summary { font-size: 14px; }
#remWrap summary.on { color: var(--ok); }
.chip.danger { color: var(--danger); }

/* misc */
#toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 22px; font-weight: 600; opacity: 0;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; white-space: nowrap; display: flex; align-items: center; gap: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
#toast button { font: inherit; font-weight: 700; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
details.card summary { cursor: pointer; color: var(--accent); font-weight: 600; }
details.card ol { padding-left: 20px; color: var(--muted); font-size: 14px; }
details.card code { background: var(--line); padding: 1px 5px; border-radius: 5px; font-size: 13px; word-break: break-all; }

/* links & bookmarks */
.seg { display: flex; gap: 6px; margin: 0 0 10px; }
.seg button { font: inherit; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
li .link { display: flex; align-items: center; gap: 8px; min-width: 0; }
li .link img { width: 18px; height: 18px; border-radius: 4px; flex: none; background: var(--line); }
li .link .ltitle { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
li .link .lhost { color: var(--muted); font-size: 12px; flex: none; }
li .desc { color: var(--muted); font-size: 13px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
li .thumb { width: 100%; max-height: 140px; object-fit: cover; border-radius: 10px; margin-top: 8px; display: block; background: var(--line); }
li .actions .openlink { text-decoration: none; display: flex; align-items: center; justify-content: center; color: var(--accent); font-size: 14px; font-weight: 600; min-width: 44px; }
li .actions .openlink:active { background: var(--line); }
.linkcard { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; text-decoration: none; color: var(--text); font-size: 14px; }
.linkcard img { width: 20px; height: 20px; border-radius: 5px; background: var(--line); }
.linkcard span:first-of-type { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.linkcard .open { color: var(--accent); font-weight: 600; }
