:root {
  --sage: #7c9473;
  --sage-dark: #5f7757;
  --cream: #f6f4ec;
  --card: #ffffff;
  --text: #33362e;
  --muted: #8a9382;
  --green: #4caf7d;
  --red: #e2574c;
  --border: #e3e5da;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(160deg, #f6f4ec, #e9efe2 55%, #f4f6ee);
  color: var(--text);
  min-height: 100vh;
}

h1, h2, h3, .brand, .btn, .tab {
  font-family: 'Baloo 2', sans-serif;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--sage-dark);
  margin-right: 4px;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--cream);
  border-radius: 999px;
  padding: 4px;
}

.tab {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.tab.active {
  background: var(--sage);
  color: white;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

#searchInput {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  min-width: 160px;
}

.tag-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 20px 16px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.chip.active {
  background: var(--sage);
  border-color: var(--sage);
  color: white;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--cream);
  color: var(--text);
}

.btn.primary {
  background: var(--sage);
  color: white;
}

.btn.danger {
  background: transparent;
  color: var(--red);
}

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}

.fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--sage);
  color: white;
  font-size: 1.8rem;
  line-height: 1;
  box-shadow: 0 6px 18px rgba(124, 148, 115, 0.55);
  cursor: pointer;
  z-index: 20;
}

@media (min-width: 760px) {
  .fab { display: none; }
}

/* ---------- Recipe grid ---------- */
main {
  padding: 8px 20px 80px;
  max-width: 1100px;
  margin: 0 auto;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 1.05rem;
}

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

.recipe-card {
  background: var(--card);
  border-radius: 18px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(58, 43, 30, 0.08);
  transition: transform 0.12s ease;
}

.recipe-card:active { transform: scale(0.98); }

.recipe-card .thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--cream);
  display: block;
}

.recipe-card .thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
}

.recipe-card .card-body {
  padding: 10px 12px 14px;
}

.recipe-card h3 {
  margin: 0 0 6px;
  font-size: 1.02rem;
}

/* Baking tab: bigger touch targets/type so it's easy for a kid to browse. */
main.kid-mode .recipe-grid {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

main.kid-mode .recipe-card h3 {
  font-size: 1.2rem;
}

main.kid-mode .recipe-card .card-body {
  padding: 14px 14px 18px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.card-tags .mini-chip {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--cream);
  border-radius: 999px;
  padding: 2px 8px;
}

/* ---------- Overlays / sheets ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 43, 30, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 30;
}

@media (min-width: 700px) {
  .overlay { align-items: center; }
}

.sheet {
  background: var(--cream);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  padding: 20px;
}

@media (min-width: 700px) {
  .sheet { border-radius: 22px; }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-header h2 { margin: 0; }

/* ---------- Detail view ---------- */
.detail-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 16px;
  background: var(--card);
  margin-bottom: 14px;
}

.detail-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.pill {
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
}

.detail-section h3 {
  margin: 18px 0 8px;
  font-size: 1rem;
  color: var(--sage-dark);
}

.detail-section ul, .detail-section ol {
  margin: 0;
  padding-left: 22px;
  line-height: 1.6;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Form ---------- */
#recipeForm label {
  display: block;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 12px;
}

#recipeForm .hint {
  font-weight: 400;
  font-size: 0.78rem;
}

#recipeForm input[type="text"],
#recipeForm textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--card);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.checkbox-row, .collapsible-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input, .collapsible-toggle input {
  width: 18px;
  height: 18px;
}

.diet-section {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 14px 2px;
  margin: 4px 0 16px;
}

.diet-section-title {
  margin: 0 0 12px;
  font-size: 0.95rem;
  color: var(--sage-dark);
  font-family: 'Baloo 2', sans-serif;
}

.photo-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: 16px;
  height: 160px;
  cursor: pointer;
  margin-bottom: 16px;
  overflow: hidden;
  position: relative;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.photo-picker.drag-over {
  border-color: var(--sage);
  background: #eef2ea;
}

.photo-picker img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#photoPickerLabel {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

#photoPickerLabel small {
  font-weight: 400;
  font-size: 0.78rem;
}

.photo-picker-wrap { margin-bottom: 16px; }
.photo-picker-wrap .photo-picker { margin-bottom: 6px; }
#removePhotoBtn {
  display: block;
  margin: 0 auto;
  color: var(--red);
  font-weight: 700;
  font-size: 0.85rem;
}

.tag-picker-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.tag-add-row {
  display: flex;
  gap: 8px;
}

.tag-add-row input {
  flex: 1;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  position: sticky;
  bottom: -20px;
  background: var(--cream);
  padding-top: 10px;
}

/* ---------- Crop step ---------- */
.crop-sheet { max-width: 400px; }

.crop-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 320px;
  margin: 4px auto 14px;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  background: #000;
  touch-action: none;
  cursor: grab;
}

.crop-frame:active { cursor: grabbing; }

.crop-frame img {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
}

.crop-zoom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.crop-zoom-row input[type="range"] {
  flex: 1;
}

/* ---------- Auth gate ---------- */
#authGateOverlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(160deg, #f6f4ec, #e9efe2 55%, #f4f6ee);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  font-family: 'Nunito', sans-serif;
}

.auth-gate-card {
  background: var(--card);
  border-radius: 22px;
  padding: 32px 28px;
  width: 90%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(58, 43, 30, 0.15);
}

.auth-gate-logo {
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--sage-dark);
  margin-bottom: 18px;
}

.auth-gate-card label {
  display: block;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 16px;
}

.auth-gate-card input {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 4px;
}

.auth-gate-card .btn {
  width: 100%;
}

.error-text {
  color: var(--red);
  font-size: 0.85rem;
  margin: 10px 0 0;
}
