:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #101828;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #16794c;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --radius: 14px;
  --tap: 56px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --text: #e8eaed;
    --muted: #9aa2ae;
    --line: #262b34;
    --accent: #34d399;
    --accent-ink: #06231a;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
}

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbtn {
  flex: 1; min-height: 44px;
  display: flex; align-items: center; gap: 6px;
  background: none; border: 0; color: inherit;
  font: 600 20px/1.2 inherit; text-align: left; padding: 0;
}
.caret { color: var(--muted); font-size: 14px; }
.bell {
  width: 40px; min-height: 40px;
  background: none; border: 0; padding: 0;
  font-size: 18px; line-height: 1;
  filter: grayscale(1); opacity: 0.55;
}
.bell.on { filter: none; opacity: 1; }
.status { width: 24px; text-align: center; color: var(--muted); font-size: 16px; }
.status[data-state="offline"] { color: var(--danger); }

main {
  flex: 1;
  padding: 8px 12px 12px;
  /* Room for the fixed add bar, which lifts with the on-screen keyboard. */
  padding-bottom: calc(var(--bottom-h, 120px) + var(--kb, 0px) + 12px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap);
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  user-select: none;
  cursor: pointer;
  touch-action: manipulation;
}
.item:active { transform: scale(0.995); }
.box {
  flex: none;
  width: 28px; height: 28px;
  border: 2px solid var(--line);
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--accent-ink);
  font-size: 18px; font-weight: 700;
}
.item.checked .box { background: var(--accent); border-color: var(--accent); }
.label { flex: 1; word-break: break-word; }
.item.checked .label { text-decoration: line-through; color: var(--muted); }

.done-wrap { margin-top: 18px; }
.done-head {
  color: var(--muted); font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.06em;
  margin: 0 4px 8px;
}
.items.done .item { opacity: 0.72; }

.empty, .hint { color: var(--muted); font-size: 14px; text-align: center; margin: 24px 0 0; }
.hint { margin-top: 16px; font-size: 12px; }

.bottom {
  /* Fixed, then translated up by the keyboard inset: iOS Safari does not
     resize the layout viewport when the keyboard opens, so without this the
     input sits behind it. --kb is measured from visualViewport in app.js. */
  position: fixed;
  left: 0; right: 0; bottom: 0;
  transform: translateY(calc(-1 * var(--kb, 0px)));
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid; gap: 8px;
  z-index: 4;
}
/* The safe-area pad is only correct when the bar sits on the screen edge. */
body.keyboard-open .bottom { padding-bottom: 8px; }
.finish {
  min-height: 52px;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink);
  font: 600 17px inherit;
}
.add { display: flex; gap: 8px; }
.add input {
  flex: 1; min-height: 52px;
  padding: 0 14px;
  font: 17px inherit; color: inherit;
  background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.add button {
  width: 56px; min-height: 52px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 24px;
}

.sheet {
  width: min(520px, 92vw);
  border: 0; border-radius: 18px;
  padding: 20px;
  background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.5); }
.sheet h2 { margin: 0 0 12px; font-size: 20px; }
.list-rows { list-style: none; margin: 0 0 12px; padding: 0; }
.list-row {
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--line);
}
.list-row.active .pick { font-weight: 700; color: var(--accent); }
.pick {
  flex: 1; min-height: var(--tap);
  background: none; border: 0; color: inherit;
  font: 17px inherit; text-align: left;
}
.icon {
  width: 44px; min-height: 44px;
  background: none; border: 0; color: var(--muted); font-size: 18px;
}
.icon.on { color: var(--accent); }
.icon.danger { color: var(--danger); }
.ghost {
  width: 100%; min-height: 48px; margin-top: 8px;
  background: none; border: 1px solid var(--line); border-radius: var(--radius);
  color: inherit; font: 17px inherit;
}

.login form { display: grid; gap: 12px; }
.login input {
  min-height: 52px; padding: 0 14px;
  font: 17px inherit; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
}
.login button {
  min-height: 52px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font: 600 17px inherit;
}
.error { color: var(--danger); margin: 0; font-size: 14px; }
