:root {
  --cream: #faf6ec;
  --cream-deep: #f2ecdb;
  --card: #ffffff;
  --green: #1f4d3a;
  --green-soft: #2f6b4f;
  --ink: #2c2a26;
  --muted: #9b968a;
  --line: #ece6d6;
  --danger: #c0483b;
  --shadow: 0 1px 2px rgba(60, 50, 30, 0.06), 0 6px 16px rgba(60, 50, 30, 0.06);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.app {
  min-height: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 8px) 16px calc(var(--safe-bottom) + 40px);
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 0 18px;
  background: linear-gradient(var(--cream) 72%, rgba(250, 246, 236, 0));
}
.title {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 34px;
  letter-spacing: 0.2px;
  color: var(--green);
  transition: color 0.3s ease;
}
.title.offline { color: #6b6862; }

/* Category */
.category {
  margin-bottom: 26px;
}
.category.drop-target > .cat-head,
.category.drop-target {
  outline: none;
}
.category.drop-target .cat-items {
  background: rgba(47, 107, 79, 0.06);
  border-radius: var(--radius);
}
.cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 10px;
}
.cat-name {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--green-soft);
  flex: 1;
  min-width: 0;
  outline: none;
  padding: 2px 2px;
  border-radius: 6px;
}
.cat-name:focus {
  background: #fff;
  box-shadow: 0 0 0 2px rgba(47, 107, 79, 0.25);
}
.cat-delete {
  border: none;
  background: none;
  color: var(--muted);
  padding: 6px;
  display: flex;
  border-radius: 8px;
}
.cat-delete:active { background: var(--cream-deep); }

.cat-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px;
  transition: background 0.15s ease;
}

/* Item */
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px;
  box-shadow: var(--shadow);
  touch-action: pan-y;
}
.item.dragging { opacity: 0; }
.item.checked .item-name {
  color: var(--muted);
  text-decoration: line-through;
}

/* While an item is being dragged, stop the page from touch-scrolling on its own.
   Programmatic auto-scroll during drag still works. */
body.dragging-lock {
  touch-action: none;
  overscroll-behavior: none;
}
body.dragging-lock .item { touch-action: none; }

.checkbox {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid #d7d0bf;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.item.checked .checkbox {
  background: var(--green-soft);
  border-color: var(--green-soft);
}
.checkbox svg { opacity: 0; }
.item.checked .checkbox svg { opacity: 1; }

.item-name {
  flex: 1;
  min-width: 0;
  font-size: 17px;
  line-height: 1.3;
  word-break: break-word;
  outline: none;
  padding: 2px 0;
}
.item-name.editing {
  -webkit-user-select: text;
  user-select: text;
}

.item-trash {
  flex: 0 0 auto;
  border: none;
  background: none;
  color: #c9c2b1;
  padding: 6px;
  display: flex;
  border-radius: 8px;
}
.item-trash:active { background: var(--cream-deep); color: var(--danger); }

/* Add item row */
.add-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  margin-top: 2px;
}
.add-item .plus {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--green-soft);
  flex: 0 0 auto;
}
.add-item input {
  flex: 1;
  border: none;
  background: none;
  font-size: 17px;
  color: var(--ink);
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  font-family: inherit;
}
.add-item input::placeholder { color: var(--muted); }

/* Add category button — shy + in the top-left of the header */
.add-category-btn {
  position: absolute;
  left: 0;
  top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--green);
  opacity: 0.55;
}
.add-category-btn:active { opacity: 1; background: var(--cream-deep); transform: scale(0.94); }
.add-category-btn svg { display: block; }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(40, 35, 25, 0.35);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.18s ease;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%;
  background: var(--cream);
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(var(--safe-bottom) + 18px);
  box-shadow: 0 -4px 40px rgba(0,0,0,0.2);
  animation: slideUp 0.22s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.modal-title {
  margin: 0 0 14px;
  font-family: Georgia, serif;
  font-size: 21px;
  color: var(--green);
}
.modal-text { margin: 0 0 16px; color: var(--ink); font-size: 15px; }
.modal-input {
  width: 100%;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 14px 14px;
  font-size: 17px;
  font-family: inherit;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  margin-bottom: 16px;
}
.modal-input:focus { border-color: var(--green-soft); }
.modal-actions {
  display: flex;
  gap: 10px;
}
.btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
}
.btn:active { filter: brightness(0.96); }
.btn-primary { background: var(--green); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--cream-deep); color: var(--ink); }

/* Drag layer */
.drag-layer {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
}
.drag-layer[hidden] { display: none; }
.drag-ghost {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
  box-shadow: 0 12px 30px rgba(60, 50, 30, 0.25);
  transform-origin: center;
}

.empty {
  color: var(--muted);
  font-size: 15px;
  padding: 4px 6px 8px;
  font-style: italic;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.4; } to { transform: translateY(0); opacity: 1; } }
