/* ─── Custom properties ─────────────────────────────────────────────────── */
:root {
  --bg:          #faf8f5;
  --surface:     #ffffff;
  --border:      #e5e0d8;
  --text:        #1a1a1a;
  --muted:       #666;
  --accent:      #8b1a1a;
  --accent-bg:   #f5eaea;
  --tag-bg:      #f0ede8;
  --tag-color:   #4a4540;
  --radius:      6px;
  --header-h:    56px;
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); }

/* ─── Header ─────────────────────────────────────────────────────────────── */
header {
  height: var(--header-h);
  background: var(--accent);
  color: #fff;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  overflow: visible;
}

.brand {
  text-decoration: none;
  color: #fff;
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}
.brand:hover { opacity: 0.88; }

.search-wrap {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  position: relative;
}

.input-wrap {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 100%;
  padding: 0.4rem 1.8rem 0.4rem 0.75rem; /* right padding for × button */
  border: 2px solid transparent;
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: rgba(255,255,255,0.18);
  color: #fff;
  outline: none;
  transition: background 0.15s, border-color 0.15s;
}
#search-input::placeholder { color: rgba(255,255,255,0.55); }
#search-input:focus        { background: rgba(255,255,255,0.28); border-color: rgba(255,255,255,0.4); }

.clear-btn {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.35);
  color: #fff;
  font-size: 0.8rem;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  padding: 0;
}
.clear-btn:hover { background: rgba(255,255,255,0.55); }

.help-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.55);
  background: transparent;
  color: rgba(255,255,255,0.85);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  padding: 0;
}
.help-btn:hover, .help-btn[aria-expanded="true"] {
  background: rgba(255,255,255,0.22);
  border-color: #fff;
}

.help-popup {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 320px;
  max-width: calc(100vw - 1.5rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  font-size: 0.83rem;
  color: var(--text);
  box-shadow: 0 6px 24px rgba(0,0,0,0.14);
  z-index: 200;
  line-height: 1.55;
}
.help-popup ul {
  margin: 0.4rem 0 0 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.help-popup code {
  font-family: monospace;
  background: var(--tag-bg);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  font-size: 0.82rem;
}
.help-tags {
  margin-top: 0.45rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.help-tags span {
  font-size: 0.72rem;
  background: var(--tag-bg);
  color: var(--tag-color);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-weight: 500;
  cursor: pointer;
}
.help-tags span:hover { background: var(--accent-bg); color: var(--accent); }

/* ─── Main content ───────────────────────────────────────────────────────── */
.main-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  width: 100%;
}

.browse-header {
  margin-bottom: 0.9rem;
}

#result-count {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ─── Recipe grid ────────────────────────────────────────────────────────── */
#recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.recipe-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  outline: none;
  transition: box-shadow 0.15s ease, transform 0.12s ease, border-color 0.15s;
  display: block;
  text-align: left;
}
.recipe-card:hover  { box-shadow: 0 4px 16px rgba(139,26,26,0.13); transform: translateY(-2px); border-color: #d0b0b0; }
.recipe-card:focus  { box-shadow: 0 0 0 3px rgba(139,26,26,0.25); }
.recipe-card:active { transform: translateY(0); }

.card-body { padding: 0.9rem 1rem; }

.card-title {
  font-size: 0.975rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.meta-icon {
  width: 13px;
  height: 13px;
  vertical-align: middle;
  margin-right: 0.2rem;
  flex-shrink: 0;
  position: relative;
  top: -1px;
}

/* ─── Time tooltip ───────────────────────────────────────────────────────── */
.time-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  outline: none;
}
.time-tip {
  display: none;
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--text);
  color: #fff;
  font-size: 0.75rem;
  white-space: nowrap;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius);
  pointer-events: none;
  z-index: 300;
}
.time-tip::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-right-color: var(--text);
}
.time-wrap:hover .time-tip,
.time-wrap.open .time-tip { display: block; }

/* ─── Tag autocomplete ───────────────────────────────────────────────────── */
.tag-suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  z-index: 250;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}
.tag-suggest li {
  padding: 0.38rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text);
}
.tag-suggest li:hover,
.tag-suggest li.active { background: var(--accent-bg); color: var(--accent); }

.card-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

/* ─── Tags & badges ──────────────────────────────────────────────────────── */
.tag {
  font-size: 0.72rem;
  background: var(--tag-bg);
  color: var(--tag-color);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-weight: 500;
}

.badge {
  font-size: 0.62rem;
  padding: 0.1rem 0.32rem;
  border-radius: 3px;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  align-self: center;
}
.badge-lang { background: var(--accent-bg); color: var(--accent); }

/* ─── Detail view ────────────────────────────────────────────────────────── */
#detail-view {
  padding: 1.5rem 1.5rem 3rem;
}
.detail-wrap {
  max-width: 740px;
  margin: 0 auto;
}

#back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.38rem 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 1.4rem;
  transition: border-color 0.15s, color 0.15s;
}
#back-btn:hover { border-color: var(--accent); color: var(--accent); }

.detail-image {
  width: 100%;
  max-height: 380px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  display: block;
}

.detail-title {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 0.6rem;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
  align-items: center;
}
.detail-meta > span { display: inline-flex; align-items: center; }
.meta-total { font-weight: 700; color: var(--text); }

.servings-scaler span { display: inline-flex; align-items: center; gap: 0.25rem; }

.detail-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 1.4rem; }

/* ─── Servings scaler ────────────────────────────────────────────────────── */
.servings-scaler {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--accent-bg);
  border: 1px solid #deb8b8;
  border-radius: var(--radius);
  padding: 0.45rem 0.9rem;
  margin-bottom: 1.75rem;
  font-size: 0.9rem;
}

.scaler-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--accent);
  background: #fff;
  color: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  padding: 0;
}
.scaler-btn:hover { background: var(--accent); color: #fff; }

#scaler-val {
  min-width: 22px;
  text-align: center;
  font-weight: 800;
  font-size: 1.05rem;
}

/* ─── Ingredients & instructions ─────────────────────────────────────────── */
.detail-section { margin-bottom: 2rem; }

.detail-section h2 {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 0.85rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid var(--accent-bg);
}

.ing-group {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0.85rem 0 0.3rem;
  font-weight: 700;
}

.ing-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.ing-list li {
  display: flex;
  align-items: baseline;
  gap: 0;
  padding: 0.28rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.925rem;
}
.ing-list li:last-child { border-bottom: none; }

.amount {
  font-weight: 700;
  min-width: 100px;
  flex-shrink: 0;
  color: var(--accent);
  font-size: 0.875rem;
}

.steps-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-left: 1.5rem;
}
.steps-list li {
  font-size: 0.935rem;
  line-height: 1.7;
}

/* ─── Notes ─────────────────────────────────────────────────────────────── */
.notes-section p {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.65;
  background: var(--tag-bg);
  padding: 0.7rem 1rem 0.7rem 1.1rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ─── States ─────────────────────────────────────────────────────────────── */
.loading, .empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}
.error {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: #b00;
  font-size: 0.95rem;
}

/* ─── Mobile ─────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  header { padding: 0 0.75rem; gap: 0.5rem; }
  .brand { font-size: 1rem; }
  .main-content { padding: 1rem; }
  #recipe-grid { grid-template-columns: 1fr 1fr; }
  #detail-view { padding: 1rem 1rem 2rem; }
  .detail-title { font-size: 1.4rem; }
  .amount { min-width: 80px; }
}

@media (max-width: 380px) {
  #recipe-grid { grid-template-columns: 1fr; }
}
