:root {
  --desk: #efebe4;
  --paper: #fffdf9;
  --rule: #dbe4ee;
  --margin: #f0a3a3;
  --ink: #33363d;
  --muted: #8b8f98;
  --pink: #e05a93;
  --highlight: rgb(255 182 213 / 0.55);
  --accent: #3b3f47;
  --accent-text: #ffffff;
  --tape: rgb(255 196 220 / 0.7);
  --margin-w: 46px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --desk: #17181b;
    --paper: #23252a;
    --rule: #363a42;
    --margin: #8a4a52;
    --ink: #e8e9ec;
    --muted: #9a9ea8;
    --pink: #ff8fbf;
    --highlight: rgb(255 143 191 / 0.22);
    --accent: #e8e9ec;
    --accent-text: #23252a;
    --tape: rgb(255 143 191 / 0.35);
  }
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

[hidden] { display: none !important; }

button, input, select, summary, label { touch-action: manipulation; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--desk);
  color: var(--ink);
  font-family: "Varela Round", system-ui, -apple-system, "Arial Hebrew", sans-serif;
  font-size: 18px;
  line-height: 1.4;
  padding: calc(24px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.paper {
  position: relative;
  max-width: 540px;
  margin: 0 auto;
  background: var(--paper);
  border-radius: 4px 4px 14px 14px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 10px 30px -14px rgb(0 0 0 / 0.25);
  padding-bottom: 28px;
  min-height: 70dvh;
}

.paper::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-start: var(--margin-w);
  border-inline-start: 2px solid var(--margin);
  opacity: 0.6;
  pointer-events: none;
}

.paper::after {
  content: "";
  position: absolute;
  top: -14px;
  left: 50%;
  width: 120px;
  height: 30px;
  translate: -50% 0;
  rotate: -3deg;
  background: var(--tape);
  background-image: repeating-linear-gradient(45deg, rgb(255 255 255 / 0.35) 0 6px, transparent 6px 12px);
  border-radius: 2px;
}

header {
  padding: 26px 16px 4px calc(var(--margin-w) + 16px);
  padding-inline-start: calc(var(--margin-w) + 14px);
  border-bottom: 2px solid var(--rule);
}

h1 {
  font-family: "Amatic SC", "Varela Round", cursive;
  font-size: clamp(2rem, 9vw, 2.6rem);
  line-height: 1;
  margin: 0;
  white-space: nowrap;
  color: var(--pink);
}

.status { color: var(--muted); font-size: 0.75rem; margin: 4px 0 8px; min-height: 1.1em; }

input[type="text"], input[type="password"], select, textarea {
  font: inherit;
  width: 100%;
  min-width: 0;
  padding: 8px 4px;
  border: 0;
  border-bottom: 1.5px dashed var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
}

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }

input:focus, select:focus, textarea:focus { outline: none; border-bottom-color: var(--muted); }

select { appearance: none; -webkit-appearance: none; cursor: pointer; }

textarea { resize: vertical; }

button {
  font: inherit;
  padding: 10px 20px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

button.secondary {
  display: block;
  margin: 14px auto 0;
  background: transparent;
  color: var(--muted);
  border: 1.5px dashed var(--rule);
}

button.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--rule); }

#login { padding: 16px 16px 8px; padding-inline-start: calc(var(--margin-w) + 14px); }
#login-form, #edit-form { display: grid; gap: 6px; }
#login-form label, #edit-form label { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }
#login-form button { margin-top: 16px; justify-self: start; }

.group h2 {
  font-family: "Amatic SC", "Varela Round", cursive;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  color: var(--pink);
  margin: 0;
  border-bottom: 1px solid var(--rule);
}

.group-toggle {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  padding: 18px 16px 8px;
  padding-inline-start: calc(var(--margin-w) + 14px);
  background: none;
  color: inherit;
  font: inherit;
  border-radius: 0;
  text-align: start;
}

.chevron {
  margin-inline-start: auto;
  font-family: "Varela Round", sans-serif;
  font-size: 1rem;
  color: var(--muted);
  transition: rotate 0.2s;
}

.folded .chevron { rotate: 90deg; }

.folded h2 { opacity: 0.75; }

.group h2 .title {
  display: inline-block;
  padding: 0 4px;
  rotate: -1deg;
  background: linear-gradient(transparent 55%, var(--highlight) 55% 90%, transparent 90%);
}

.count {
  font-family: "Varela Round", sans-serif;
  font-size: 0.75rem;
  color: var(--muted);
}

.count::before { content: "· "; }

.list { list-style: none; margin: 0; padding: 0; }

.list li {
  display: flex;
  align-items: center;
  min-height: 52px;
  border-bottom: 1px solid var(--rule);
}

.check-wrap {
  flex: 0 0 var(--margin-w);
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.check {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
  background: transparent center / 14px no-repeat;
  cursor: pointer;
  transition: transform 0.15s, background-color 0.15s;
}

.check:active { transform: scale(0.85); }

.check:checked {
  background-color: var(--muted);
  border-color: var(--muted);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21C5 16 2 12.5 2 8.5 2 5.4 4.4 3 7.3 3c1.9 0 3.6 1 4.7 2.6C13.1 4 14.8 3 16.7 3 19.6 3 22 5.4 22 8.5c0 4-3 7.5-10 12.5z' fill='white'/%3E%3C/svg%3E");
}

.item {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-width: 0;
  background: transparent;
  color: inherit;
  text-align: start;
  border-radius: 0;
}

.item .icon { font-size: 1.25rem; flex-shrink: 0; }

.body { flex: 1; min-width: 0; display: grid; gap: 1px; }

.line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }

.text { overflow-wrap: anywhere; }

.qty {
  color: var(--muted);
  font-size: 0.85rem;
}

.qty::before { content: "× "; }

.note { color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; }
.note::before { content: "♡ "; }

.by { color: var(--muted); font-size: 0.7rem; flex-shrink: 0; }

.delete {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  color: var(--muted);
  opacity: 0.55;
  padding: 12px 14px;
  font-size: 0.85rem;
}

.delete:active { opacity: 1; color: var(--ink); }

.done .text {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--muted);
  text-decoration-thickness: 2px;
}

.done .icon, .done .qty, .done .note { opacity: 0.5; }

.empty {
  text-align: center;
  color: var(--muted);
  font-family: "Amatic SC", "Varela Round", cursive;
  font-size: 1.8rem;
  padding: 36px 0;
  margin: 0;
}

#done-section { margin-top: 12px; }

#done-section > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 10px 16px;
  padding-inline-start: calc(var(--margin-w) + 14px);
  border-bottom: 1px solid var(--rule);
}

dialog {
  width: min(94vw, 420px);
  margin: calc(16px + env(safe-area-inset-top)) auto auto;
  max-height: calc(100dvh - 32px - env(safe-area-inset-top));
  overflow-y: auto;
  border: 0;
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  padding: 22px;
  box-shadow: 0 20px 50px -10px rgb(0 0 0 / 0.35);
}

dialog::backdrop { background: rgb(0 0 0 / 0.3); backdrop-filter: blur(2px); }

dialog h2 {
  font-family: "Amatic SC", "Varela Round", cursive;
  font-size: 2rem;
  color: var(--pink);
  margin: 0;
}

.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }
.dialog-actions button { flex: 1; }

.link {
  background: none;
  color: var(--muted);
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.status b { color: var(--ink); font-weight: 400; }

.fab {
  position: fixed;
  inset-inline-end: max(20px, env(safe-area-inset-left));
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: 60px;
  height: 60px;
  padding: 0;
  font-size: 2rem;
  line-height: 1;
  box-shadow: 0 8px 20px -6px rgb(0 0 0 / 0.45);
  z-index: 5;
}

.fab:active { transform: scale(0.94); }

.sheet {
  width: 100%;
  max-width: 540px;
  margin: 0 auto auto;
  padding: 0;
  border-radius: 0 0 20px 20px;
  max-height: 100dvh;
}

.sheet-inner {
  display: grid;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 16px 18px;
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; }

.sheet-head h2 {
  font-family: "Amatic SC", "Varela Round", cursive;
  font-size: 2rem;
  line-height: 1;
  color: var(--pink);
  margin: 0;
  padding: 0 4px;
  background: linear-gradient(transparent 58%, var(--highlight) 58% 92%, transparent 92%);
}

.add-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1.5px solid var(--rule);
}

.add-row .icon { font-size: 1.4rem; width: 28px; text-align: center; flex-shrink: 0; }

.add-row input { border-bottom: 0; padding: 12px 2px; }

.add-btn { flex-shrink: 0; padding: 9px 16px; font-size: 0.95rem; }

.suggestions {
  list-style: none;
  margin: -8px 0 0;
  padding: 0;
  border-bottom: 1px solid var(--rule);
}

.suggestions li { display: flex; align-items: center; border-top: 1px solid var(--rule); }

.suggestion {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 4px;
  min-height: 44px;
  background: none;
  color: var(--ink);
  border-radius: 0;
  text-align: start;
}

.suggestion b { font-weight: 700; }

.forget {
  background: none;
  color: var(--muted);
  opacity: 0.5;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 0.8rem;
}

.add-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 14px;
  border: 1.5px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.9rem;
  white-space: nowrap;
}

.chip.filled { border-color: var(--muted); }

.chip-select { position: relative; cursor: pointer; }

.chip-select select {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  padding: 0;
  border: 0;
  font-size: 16px;
  cursor: pointer;
}

.stepper {
  display: inline-flex;
  align-items: center;
  border: 1.5px solid var(--rule);
  border-radius: 999px;
  min-height: 38px;
}

.stepper button {
  background: none;
  color: var(--ink);
  width: 40px;
  height: 38px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.stepper button:disabled { opacity: 0.3; }

#qty-value { min-width: 28px; text-align: center; font-size: 0.95rem; }

.note-input { border-bottom: 1.5px dashed var(--rule) !important; }

.feedback {
  margin: 0;
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 0.9rem;
  color: var(--muted);
}

.usuals-title { margin: 4px 0 8px; font-size: 0.8rem; color: var(--muted); }

.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }

.list li.flash { animation: flash 1.4s ease-out; }

@keyframes flash {
  0%, 30% { background: var(--highlight); }
  100% { background: transparent; }
}

#app { padding-bottom: 72px; }

.empty small { font-family: "Varela Round", sans-serif; font-size: 0.9rem; }

.login-error { margin: 8px 0 0; color: var(--pink); font-size: 0.9rem; }
