:root {
  /* "Organized Scrapbook" — warm, light-first, colorful cards */
  --bg: #faf6ef;
  --surface: #ffffff;
  --surface-2: #f3ede1;
  --text: #2b2621;
  --muted: #8a7f70;
  --accent: #7c5cff;
  --accent-ink: #ffffff;
  --low: #4f8cff;
  --medium: #e0a52c;
  --high: #e2554a;
  --border: #e9e0d0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --card-default: var(--surface);
  --card-yellow: #fdedad;
  --card-blue: #bfe1ff;
  --card-mint: #c3ecd6;
  --card-pink: #ffd3e0;
  --card-lavender: #e2d9ff;
  --card-peach: #ffdcc2;
}

:root[data-theme="dark"] {
  --bg: #17140f;
  --surface: #241f19;
  --surface-2: #2d271f;
  --text: #f3ede3;
  --muted: #a99d8b;
  --accent: #a78bff;
  --accent-ink: #17140f;
  --low: #7cb0ff;
  --medium: #f2c465;
  --high: #ff8a7d;
  --border: #3a3226;

  --card-default: var(--surface);
  --card-yellow: #4a3f14;
  --card-blue: #16324a;
  --card-mint: #163a2c;
  --card-pink: #4a1f30;
  --card-lavender: #2c2350;
  --card-peach: #4a2c16;
}

* { box-sizing: border-box; }

html { transition: background-color 0.15s ease; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 16px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
header h1 {
  font-size: 1.5rem;
  margin: 0;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(43,38,33,0.06);
}

main { flex: 1; padding: 0 16px 90px; }

.memo-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  align-items: start;
  gap: 12px;
}

.memo-card {
  background: var(--card-default);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  box-shadow: 0 2px 8px rgba(43,38,33,0.06);
  position: relative;
}
.memo-card.color-yellow { background: var(--card-yellow); }
.memo-card.color-blue { background: var(--card-blue); }
.memo-card.color-mint { background: var(--card-mint); }
.memo-card.color-pink { background: var(--card-pink); }
.memo-card.color-lavender { background: var(--card-lavender); }
.memo-card.color-peach { background: var(--card-peach); }
.memo-card.completed { opacity: 0.55; }
.memo-card.pinned { box-shadow: 0 2px 8px rgba(124,92,255,0.25), 0 0 0 2px var(--accent) inset; }

.pin-flag {
  position: absolute;
  top: -6px;
  left: 14px;
  font-size: 0.9rem;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.25));
}

.memo-card-top { display: flex; align-items: flex-start; gap: 10px; }
.memo-card.dragging { opacity: 0.9; box-shadow: 0 10px 24px rgba(0,0,0,0.25); z-index: 50; position: relative; }
.drag-handle {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px 6px;
  touch-action: none;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}
body.no-select { user-select: none; -webkit-user-select: none; }
.memo-check {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  margin-top: 2px;
  background: transparent;
}
.memo-check.checked { background: var(--accent); border-color: var(--accent); }

.pri-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.pri-dot.pri-0 { background: var(--low); }
.pri-dot.pri-1 { background: var(--medium); }
.pri-dot.pri-2 { background: var(--high); }

.memo-title { font-weight: 800; font-size: 1.02rem; flex: 1; }
.memo-title.completed { text-decoration: line-through; }
.memo-desc { color: var(--muted); font-size: 0.9rem; margin-top: 4px; white-space: pre-wrap; }
.memo-meta { display: flex; gap: 8px; margin-top: 10px; font-size: 0.78rem; color: var(--muted); align-items: center; flex-wrap: wrap; }
.memo-meta .reminder-badge { background: rgba(43,38,33,0.08); padding: 3px 9px; border-radius: 20px; }
.memo-meta .reminder-badge.overdue { color: var(--high); font-weight: 700; }
.memo-meta .tag-chip { background: rgba(43,38,33,0.08); padding: 3px 9px; border-radius: 20px; }

.checklist { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.checklist-item { display: flex; align-items: flex-start; gap: 8px; font-size: 0.88rem; }
.checklist-item input[type="checkbox"] { margin-top: 3px; width: 15px; height: 15px; accent-color: var(--accent); flex-shrink: 0; }
.checklist-item span.done { text-decoration: line-through; color: var(--muted); }
.checklist-more { font-size: 0.78rem; color: var(--muted); }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + var(--safe-bottom));
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.8rem;
  border: none;
  box-shadow: 0 6px 18px rgba(124,92,255,0.45);
}

.login-card, .editor-card {
  margin: auto;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  padding: 24px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-card { text-align: center; }
.login-card h1 { color: var(--accent); font-size: 1.8rem; }
.login-card input {
  text-align: center;
  font-size: 1.4rem;
  letter-spacing: 4px;
}

input, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  width: 100%;
  font-family: inherit;
}
textarea { resize: vertical; }

label { font-size: 0.82rem; color: var(--muted); margin-top: 4px; font-weight: 700; }

button { cursor: pointer; font-family: inherit; }
.primary-btn, .login-card button[type="submit"] {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 800;
}
.secondary-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-weight: 700;
}
.icon-toggle-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-weight: 700;
  font-size: 0.9rem;
}
.icon-toggle-btn.active { background: rgba(124,92,255,0.18); color: var(--accent); border-color: var(--accent); }
.danger-btn {
  background: transparent;
  color: var(--high);
  border: 1px solid var(--high);
  border-radius: 10px;
  padding: 12px;
  font-weight: 700;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  text-align: left;
  padding: 4px 0;
  font-weight: 700;
}

.priority-picker { display: flex; gap: 8px; }
.pri-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
}
.pri-btn.active.pri-low { background: rgba(79,140,255,0.2); color: var(--low); border-color: var(--low); }
.pri-btn.active.pri-medium { background: rgba(224,165,44,0.2); color: var(--medium); border-color: var(--medium); }
.pri-btn.active.pri-high { background: rgba(226,85,74,0.2); color: var(--high); border-color: var(--high); }

.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  padding: 0;
}
.color-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.color-swatch.sw-default { background: var(--surface-2); }
.color-swatch.sw-yellow { background: var(--card-yellow); }
.color-swatch.sw-blue { background: var(--card-blue); }
.color-swatch.sw-mint { background: var(--card-mint); }
.color-swatch.sw-pink { background: var(--card-pink); }
.color-swatch.sw-lavender { background: var(--card-lavender); }
.color-swatch.sw-peach { background: var(--card-peach); }

.editor-row { display: flex; gap: 8px; }
.editor-row > * { flex: 1; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(30,25,18,0.55);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.editor-card {
  border-radius: 20px 20px 0 0;
  max-height: 90dvh;
  overflow-y: auto;
  padding-bottom: calc(24px + var(--safe-bottom));
}
.editor-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.editor-actions .primary-btn, .editor-actions .secondary-btn, .editor-actions .danger-btn { flex: 1 1 45%; }

.error { color: var(--high); font-size: 0.85rem; }

@media (min-width: 480px) {
  .overlay { align-items: center; justify-content: center; }
  .editor-card { border-radius: 16px; }
}

/* ---- search ---- */
.search-bar { padding: 0 16px 10px; }
.search-bar input { font-size: 0.95rem; }

/* ---- chip rows (sort modes, tag filters, reminder presets) ---- */
.chip-row {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.82rem;
  white-space: nowrap;
  font-weight: 700;
}
.chip.active { background: rgba(124,92,255,0.18); color: var(--accent); border-color: var(--accent); }

.reminder-presets { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }

/* ---- overflow menu ---- */
.menu-card { gap: 6px; }
.menu-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 700;
}
.menu-item.danger { color: var(--high); }
.menu-item.active-state { border-color: var(--accent); color: var(--accent); }

/* ---- loading / empty states ---- */
#loading-state { padding: 40px 0; text-align: center; grid-column: 1 / -1; }
#empty-state, #no-results-state, #all-done-state { grid-column: 1 / -1; }

/* ---- toasts ---- */
.toast-container {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  align-items: center;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 20px rgba(43,38,33,0.25);
}
.toast.error { border-color: var(--high); }
.toast-msg { flex: 1; }
.toast-action {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 800;
  font-size: 0.88rem;
  flex-shrink: 0;
}
