:root {
  --bg: #f6f1e7;
  --panel: #fffdf8;
  --panel-2: #f0e8da;
  --ink: #3f3a33;
  --muted: #8b8275;
  --line: #ddd2c2;
  --accent: #c96f4a;
  --accent-soft: #f3ddd3;
  --ok: #4c7a5a;
  --danger: #a64b40;
  --shadow: 0 12px 34px rgba(74, 58, 40, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: rgba(246, 241, 231, .92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 18px;
  box-shadow: 0 4px 12px rgba(201, 111, 74, .22);
}
h1 { font-size: 18px; margin: 0; letter-spacing: .02em; }
.status { font-size: 12px; color: var(--muted); margin-top: 1px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }
.actions { display: flex; gap: 6px; }
.icon-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn:active { transform: translateY(1px); }

.shell { padding: 14px 14px 96px; max-width: 900px; margin: 0 auto; }
.page-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.page-tabs::-webkit-scrollbar { display: none; }
.page-tabs button {
  white-space: nowrap;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.page-tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.task-panel, .note-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.toolbar { padding: 10px 10px 0; }
.filters { display: flex; gap: 4px; background: var(--panel-2); border-radius: 12px; padding: 4px; }
.filters button {
  flex: 1;
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 6px; border-radius: 9px; font-size: 13px; cursor: pointer;
}
.filters button.active { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.filters span { font-variant-numeric: tabular-nums; opacity: .8; }

.task-list { list-style: none; margin: 0; padding: 6px 0 10px; }
.task {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid #eee6da;
}
.task:last-child { border-bottom: 0; }
.task .check {
  flex: 0 0 auto;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  cursor: pointer;
}
.task .check input { width: 18px; height: 18px; accent-color: var(--accent); }
.task .body { flex: 1; min-width: 0; }
.task .text { word-break: break-word; }
.task.done .text { color: var(--muted); text-decoration: line-through; }
.task.deleted .text { color: var(--muted); text-decoration: line-through; opacity: .75; }
.task .meta { font-size: 11px; color: var(--muted); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.task .row-actions { display: flex; gap: 2px; flex: 0 0 auto; }
.task .row-actions button {
  border: 0; background: transparent; color: var(--muted);
  font-size: 12px; padding: 5px 6px; cursor: pointer;
}
.task .row-actions .danger { color: var(--danger); }
.empty { padding: 42px 20px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

.note-panel { padding: 16px; }
.note-head h2 { margin: 0 0 2px; font-size: 17px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; }
#note-frame {
  width: 100%; min-height: 62vh; margin-top: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
}

.addbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 18;
  display: flex;
  gap: 8px;
  padding: 10px max(12px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom));
  background: rgba(246, 241, 231, .95);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.addbar input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 13px;
  font-size: 15px;
  outline: none;
}
.addbar input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.addbar select {
  max-width: 108px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 0 8px;
  color: var(--ink);
}
.addbar button {
  border: 0; background: var(--accent); color: #fff;
  border-radius: 12px; padding: 0 18px; font-weight: 600; cursor: pointer;
}

.mask {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(38, 30, 22, .32);
  backdrop-filter: blur(2px);
}
.drawer {
  position: fixed;
  z-index: 31;
  top: 0; right: 0; bottom: 0;
  width: min(380px, 92vw);
  padding: 18px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 44px rgba(50, 38, 25, .18);
  overflow-y: auto;
  transform: translateX(105%);
  transition: transform .22s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.drawer-head h2 { margin: 0; font-size: 18px; }
.field { display: block; margin-top: 14px; font-size: 13px; color: var(--muted); }
.field input {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--line); border-radius: 11px; padding: 11px 12px;
  background: var(--bg); color: var(--ink); font-size: 14px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.drawer-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.drawer-actions .primary {
  border: 0; background: var(--accent); color: #fff; border-radius: 11px;
  padding: 11px 15px; font-weight: 600; cursor: pointer;
}
.drawer-actions button:not(.primary) {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 11px; padding: 11px 13px; cursor: pointer;
}
.hint { color: var(--muted); font-size: 12px; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom));
  z-index: 40;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  background: #332c24; color: #fff;
  border-radius: 12px; padding: 10px 14px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.toast.err { background: var(--danger); }

@media (max-width: 560px) {
  .shell { padding: 10px 10px 100px; }
  .task-panel { border-radius: 16px; }
  .addbar select { display: none; }
  .task { padding: 10px 11px; gap: 8px; }
  .task .check { width: 28px; }
  .task .row-actions { flex-direction: column; }
}
