:root {
  --bg: #f6f4fb;
  --card: #ffffff;
  --ink: #1d1a2b;
  --muted: #6f6a85;
  --accent: #4527a0;
  --accent-soft: #ede7f6;
  --danger: #b3261e;
  --border: #e3dff0;
  --shadow: 0 1px 4px rgba(29, 26, 43, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16131f;
    --card: #221e30;
    --ink: #eceaf4;
    --muted: #a29cba;
    --accent: #b39dff;
    --accent-soft: #322a4a;
    --border: #383150;
    --shadow: 0 1px 4px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* buttons */
.btn {
  border: 0; border-radius: 10px; padding: 12px 16px; font-size: 16px;
  background: var(--accent-soft); color: var(--ink); cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.small { padding: 8px 14px; font-size: 14px; }
.btn.link { background: none; color: var(--accent); padding: 8px; }
.iconbtn {
  border: 0; background: none; font-size: 20px; padding: 10px;
  border-radius: 10px; cursor: pointer; min-width: 44px; min-height: 44px;
}
.iconbtn:active { background: var(--accent-soft); }
.iconbtn.danger { filter: grayscale(.2); }

/* auth */
#auth-view { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 28px 24px; width: 100%; max-width: 380px; text-align: center;
}
.auth-card h1 { margin: 0 0 4px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.auth-card input {
  padding: 13px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--ink); font-size: 16px;
}
.auth-error { color: var(--danger); font-size: 14px; min-height: 18px; margin: 8px 0 0; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: 10px 12px calc(10px); padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); box-shadow: var(--shadow);
}
.brand { font-size: 22px; }
#search, #note-title {
  flex: 1; min-width: 0; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); color: var(--ink); font-size: 16px;
}
#note-title { font-weight: 600; }

/* menus */
.menu {
  position: fixed; z-index: 30; background: var(--card); border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,.25); overflow: hidden; min-width: 200px;
}
#account-menu { top: 60px; right: 10px; }
.menu-head { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--border); }
.menu-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 14px 16px; font-size: 16px; color: var(--ink); cursor: pointer;
}
.menu-item:active { background: var(--accent-soft); }
.menu.sheet { bottom: 96px; right: 20px; }

/* notes list */
#notes-list { padding: 12px 12px 96px; max-width: 720px; margin: 0 auto; }
.section-title { margin: 14px 4px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.note-card {
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow);
  padding: 14px 16px; margin-bottom: 10px; cursor: pointer; border: 1px solid transparent;
}
.note-card:active { border-color: var(--accent); }
.note-card h3 { margin: 0 0 4px; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.note-card .snippet { margin: 0; color: var(--muted); font-size: 14px; max-height: 40px; overflow: hidden; word-break: break-word; }
.badges { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.net { background: #fde8b0; color: #7a5200; white-space: nowrap; flex: none; }
.empty { text-align: center; color: var(--muted); margin-top: 60px; }

/* fab */
.fab {
  position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0; z-index: 20;
  background: var(--accent); color: #fff; font-size: 30px; line-height: 60px;
  box-shadow: 0 4px 14px rgba(69, 39, 160, .45); cursor: pointer;
}

/* editor */
.editor-main { padding: 12px; max-width: 720px; margin: 0 auto; }
#note-body {
  width: 100%; min-height: 55vh; border: 0; resize: vertical; font: inherit;
  background: transparent; color: var(--ink); outline: none;
}
#items-list { list-style: none; margin: 0 0 12px; padding: 0; }
#items-list li {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; box-shadow: var(--shadow);
}
#items-list input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
#items-list .item-text { flex: 1; border: 0; background: none; font: inherit; color: var(--ink); outline: none; }
#items-list li.checked .item-text { text-decoration: line-through; color: var(--muted); }
#items-list .rm { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 8px; }
#add-item-form { display: flex; gap: 8px; }
#add-item-input {
  flex: 1; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--ink); font-size: 16px;
}
.grocery-bar { display: flex; gap: 8px; padding: 10px 12px 0; max-width: 720px; margin: 0 auto; }
.grocery-bar select, .grocery-bar input {
  padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--ink); font-size: 15px;
}
.suggestions { margin-top: 16px; }
#suggestion-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 1px dashed var(--accent); color: var(--accent); background: none;
  border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer;
}
.chip:active { background: var(--accent-soft); }

/* action bar */
.actionbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-around;
  background: var(--card); box-shadow: 0 -1px 6px rgba(0,0,0,.12);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}

/* modal */
.modal {
  position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-card {
  background: var(--card); border-radius: 16px; padding: 22px; width: 100%; max-width: 400px;
}
.modal-card h3 { margin: 0 0 6px; }
#share-list { list-style: none; padding: 0; margin: 12px 0; }
#share-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
#share-form { display: flex; gap: 8px; }
#share-email {
  flex: 1; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--ink); font-size: 15px;
}

#password-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
#password-form input {
  padding: 13px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--ink); font-size: 16px;
}

/* toast */
.toast {
  position: fixed; bottom: calc(90px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 50;
  box-shadow: 0 4px 14px rgba(0,0,0,.3); white-space: nowrap;
}
