:root {
  --bg: #fbf7f2;
  --card: #ffffff;
  --ink: #2a211c;
  --muted: #7a6a60;
  --accent: #b4522a;
  --accent-soft: #f1d9cc;
  --border: #e7dfd6;
  --danger: #b43636;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(40, 20, 10, 0.06), 0 6px 16px rgba(40, 20, 10, 0.05);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Ensure the HTML `hidden` attribute always wins over author `display` rules.
   Without this, e.g. `.menu-items { display: flex }` overrides `[hidden]`. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ------ Topbar ------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.brand {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  user-select: none;
}

.topbar-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1;
  min-width: 280px;
}

#search {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  background: var(--bg);
  min-width: 180px;
}

#search:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

/* ------ Buttons ------ */

.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover { background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #9a4321; }

.btn-danger {
  background: #fff;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 4px 0;
  margin-bottom: 12px;
}
.btn-link:hover { text-decoration: underline; background: none; }

.btn-icon {
  padding: 6px 10px;
  font-size: 18px;
  line-height: 1;
}

/* ------ Menu ------ */

.menu { position: relative; }

.menu-items {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  padding: 4px;
  display: flex;
  flex-direction: column;
}

.menu-items button {
  text-align: left;
  padding: 8px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
  color: var(--ink);
}

.menu-items button:hover { background: var(--accent-soft); }

/* ------ Main ------ */

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

.view { animation: fade 0.15s ease-out; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.result-info {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
}

/* ------ Recipe list ------ */

.recipe-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.recipe-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recipe-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--accent-soft);
}

.recipe-card h2 {
  margin: 0;
  font-size: 18px;
  color: var(--ink);
}

.recipe-card .description {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.recipe-card .meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.recipe-card .badge-local {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  align-self: flex-start;
}

mark {
  background: #ffe7a3;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

/* ------ Recipe detail ------ */

#recipe-detail h1 {
  margin: 0 0 6px;
  font-size: 28px;
}

#recipe-detail .description {
  color: var(--muted);
  margin: 0 0 16px;
}

#recipe-detail .meta-row {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

#recipe-detail h3 {
  margin: 20px 0 10px;
  font-size: 17px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.ingredients-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 4px 20px;
}

.ingredients-list li {
  padding: 6px 0;
  border-bottom: 1px dotted var(--border);
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.ingredients-list .amount {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 500;
  min-width: 60px;
}

.ingredients-list .unit {
  color: var(--muted);
  font-size: 13px;
}

.steps-list {
  margin: 0;
  padding-left: 20px;
}

.steps-list li {
  padding: 6px 0;
  line-height: 1.6;
}

.category-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.category-tag {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.detail-actions {
  margin-top: 24px;
  display: flex;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ------ Edit form ------ */

.edit-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.edit-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.edit-form label > span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.edit-form input[type="text"],
.edit-form input[type="number"],
.edit-form textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: inherit;
  background: var(--bg);
}

.edit-form textarea {
  resize: vertical;
  font-family: var(--mono);
  font-size: 14px;
}

.edit-form input:focus,
.edit-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.edit-form .row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-actions {
  display: flex;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.form-actions .btn-danger { margin-left: auto; }

/* ------ Toast ------ */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 100;
}

/* ------ Small screens ------ */

@media (max-width: 600px) {
  .topbar { padding: 10px 12px; }
  main { padding: 14px; }
  .edit-form .row { grid-template-columns: 1fr; }
  .brand { font-size: 18px; }
  .topbar-controls { min-width: 100%; }
}
