:root {
  color-scheme: light dark;
  --bg: #f4f4f2;
  --card: #ffffff;
  --text: #1f2320;
  --muted: #6b7168;
  --accent: #3a7d44;
  --accent-contrast: #ffffff;
  --border: #e2e3df;
  --danger: #b3413c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --card: #1f2225;
    --text: #eceeec;
    --muted: #9aa09a;
    --accent: #57b566;
    --accent-contrast: #0c1210;
    --border: #2c302d;
    --danger: #e07872;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

h1 {
  font-size: 1.6rem;
  margin: 8px 0 20px;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 18px;
}

.add-forms {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.add-form label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.row {
  display: flex;
  gap: 8px;
}

input[type="url"],
input[type="file"] {
  flex: 1;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}

button {
  cursor: pointer;
  font-family: inherit;
}

.add-form button,
form.inline-form + button,
.list-header button {
  padding: 9px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-small {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
}

.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.row .mic-btn {
  flex-shrink: 0;
  width: 40px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
}

.mic-btn.listening {
  background: var(--danger);
  border-color: var(--danger);
  animation: pulse 1.2s infinite;
}

.mic-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(179, 65, 60, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(179, 65, 60, 0); }
}

.mic-status {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  min-height: 1em;
}

.btn-icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.btn-icon:hover {
  background: rgba(179, 65, 60, 0.12);
  color: var(--danger);
}

.recipe-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recipe-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.recipe-list li:last-child { border-bottom: none; }

.recipe-title {
  flex: 1;
  font-weight: 500;
}

.recipe-source {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
}

.inline-form { display: inline; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

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

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

.shopping-list li:last-child { border-bottom: none; }

.item-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  padding: 10px 2px;
  text-align: left;
}

.checkbox {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--muted);
  background: transparent;
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  padding: 0;
}

.checked .checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.category-heading {
  margin: 20px 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.list-header + .category-heading {
  margin-top: 4px;
}

.item-text {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-size: 0.95rem;
}

.qty {
  font-weight: 600;
  color: var(--accent);
}

.checked .name {
  text-decoration: line-through;
  color: var(--muted);
}

.note {
  font-size: 0.78rem;
  font-style: italic;
  color: var(--muted);
}

.from {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: auto;
  padding-left: 10px;
}

.from::before {
  content: "·";
  margin-right: 6px;
}

.flashes {
  margin-bottom: 16px;
}

.flash {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.flash-success {
  background: rgba(58, 125, 68, 0.15);
  color: var(--accent);
}

.flash-error {
  background: rgba(179, 65, 60, 0.15);
  color: var(--danger);
}
