:root {
  --cream: #f2f7f1;
  --card: #ffffff;
  --ink: #26322a;
  --ink-soft: #5b6d5e;
  --accent: #3f8a57;
  --accent-dark: #2c6b40;
  --line: #dbe8db;
  --danger: #b3402f;
  --shadow: 0 6px 18px rgba(30, 41, 33, 0.08);

  /* Chart categorical palette -- fixed hue order, validated for CVD
     separation and contrast against --cream (see dataviz skill). Never
     reassign a slot's meaning or cycle past 8; a 9th series folds into
     "Other" instead. */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --chart-grid: var(--line);
  --chart-axis: var(--ink-soft);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  color: var(--ink);
  margin: 0;
}

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

.site-header {
  position: relative;
  padding: 2.5rem 1.5rem 1.5rem;
  text-align: center;
}

.site-header h1 { font-size: 2.25rem; }
.site-header .subline {
  margin-top: 0.3rem;
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Only ever visible on the local app (see .env-local below) -- the
   published static site strips the "env-local" body class entirely, so
   this stays display:none there regardless. */
.env-badge {
  display: none;
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  vertical-align: middle;
}
.env-local .env-badge { display: inline-block; }
.site-header .tagline { color: var(--ink-soft); margin-top: 0.4rem; }

.header-actions {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  max-width: calc(100% - 3rem);
}

.header-actions .btn-small { font-size: 0.85rem; padding: 0.5rem 0.9rem; }
.header-actions select { padding: 0.5rem 0.6rem; font-size: 0.85rem; }

/* Visually couples the Random button with its own meal-type select, so it
   reads as one self-contained control -- independent of the search bar,
   the tag sidebar, the other meal-type filter, and sort. */
.random-group {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: var(--card);
  padding: 0.55rem 0.6rem 0.55rem 1.1rem;
}
.random-group select {
  border: none;
  background: transparent;
  padding: 0.4rem 0.3rem;
  font-size: 0.85rem;
  color: var(--ink);
}
.random-group .btn { white-space: nowrap; }

@media (max-width: 640px) {
  .header-actions {
    position: static;
    justify-content: center;
    max-width: none;
    margin-bottom: 1rem;
  }
}

#refresh-live-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.site-header.slim {
  text-align: left;
  padding: 1.25rem 1.5rem;
}

.back-link {
  text-decoration: none;
  font-weight: 600;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

.empty-state {
  text-align: center;
  color: var(--ink-soft);
  margin-top: 3rem;
  font-size: 1.05rem;
}

.dashboard { margin-top: 1rem; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-value {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.4rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.dashboard-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
}

.search-input {
  flex: 1 1 240px;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
}

.sort-select {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.9rem;
}

.cal-chip, .made-chip {
  background: #e0f0e2;
  color: var(--accent-dark);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.card {
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  position: relative;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:hover, .card:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(30, 41, 33, 0.14);
  outline: none;
}

.card-image {
  height: 140px;
  background-color: var(--line);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.card-body { padding: 0.9rem 1rem 1.1rem; }
.card-body h3 { font-size: 1.05rem; margin-bottom: 0.4rem; }

.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.tag-chip {
  display: inline-block;
  background: var(--line);
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

/* Book browsing layout: a persistent tag sidebar beside search/sort/grid,
   instead of a full-width panel that pushes the grid down the page when
   open. Stacks on narrow screens since there's no room for two columns. */
.book-layout {
  display: flex;
  align-items: flex-start;
  gap: 1.5rem;
}

.book-main {
  flex: 1;
  min-width: 0;
}

.tag-sidebar {
  flex: 0 0 230px;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.tag-sidebar-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}
.tag-sidebar-title { font-size: 1rem; margin: 0; }
.clear-tags-btn {
  border: none;
  background: transparent;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
}
.clear-tags-btn:hover { text-decoration: underline; }
.clear-tags-btn:disabled {
  color: var(--ink-soft);
  opacity: 0.55;
  cursor: default;
}
.clear-tags-btn:disabled:hover { text-decoration: none; }

@media (max-width: 760px) {
  .book-layout { flex-direction: column; }
  .tag-sidebar { flex: none; width: 100%; position: static; max-height: none; }
}

.tag-group { margin-bottom: 1rem; }
.tag-group:last-child { margin-bottom: 0; }

.tag-group summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  list-style: none;
  user-select: none;
}
.tag-group summary::-webkit-details-marker { display: none; }
.tag-group summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 0.35rem;
  transition: transform 0.15s ease;
}
.tag-group[open] summary::before { transform: rotate(90deg); }

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.tag-pill {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tag-pill:hover { border-color: var(--accent); color: var(--accent-dark); }

.tag-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.card-delete {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(30, 41, 33, 0.55);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.card:hover .card-delete, .card:focus-visible .card-delete { opacity: 1; }

.made-badge {
  position: absolute;
  top: 0;
  right: 0;
  width: 64px;
  height: 64px;
  background: rgba(14, 20, 16, 0.72);
  clip-path: polygon(100% 0, 100% 100%, 0 0);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 0.4rem 0.4rem 0 0;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  pointer-events: none;
}
.card-delete:hover { background: var(--danger); }

.recipe-detail { padding-top: 0.5rem; }

.recipe-top {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* The made-panel button sits beside the hero image specifically -- not the
   whole header block -- so it stays a compact, aligned pair instead of
   competing with the (variable-length) title/tags for a row of its own. */
.recipe-media-row {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}

#hero-image {
  width: 220px;
  height: 160px;
  object-fit: cover;
  border-radius: 14px;
  box-shadow: var(--shadow);
  flex: none;
}

.recipe-heading h1 { font-size: 2rem; margin-bottom: 0.4rem; }
.source-link { font-size: 0.9rem; }

.warning {
  background: #fbeee3;
  border: 1px solid #eecbaa;
  color: #7a4a1f;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.recipe-columns {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 2.5rem;
  align-items: start;
}

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

.ingredients-panel {
  background: var(--card);
  border-radius: 14px;
  padding: 1.25rem 1.4rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 1.5rem;
}

.panel-header {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.panel-header h2 { font-size: 1.2rem; }

.control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.scale-controls {
  display: flex;
  gap: 0.3rem;
}

.scale-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 0.3rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.scale-btn:hover { border-color: var(--accent); color: var(--accent-dark); }

.scale-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#ingredients {
  list-style: none;
  padding: 0;
  margin: 0 0 1.1rem;
}

#ingredients li {
  padding: 0.4rem 0;
  border-bottom: 1px dashed var(--line);
  font-size: 0.97rem;
}

#ingredients li:last-child { border-bottom: none; }

.instructions-panel h2 { font-size: 1.2rem; margin-bottom: 0.9rem; }

#instructions {
  padding-left: 1.3rem;
  margin: 0;
}

#instructions li {
  margin-bottom: 1.1rem;
  font-size: 1.03rem;
  line-height: 1.65;
}

.measure {
  color: var(--accent-dark);
  background: #e0f0e2;
  padding: 0.05rem 0.35rem;
  border-radius: 5px;
  font-weight: 600;
  white-space: nowrap;
}

.made-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  flex: none;
}

.made-panel .btn { white-space: nowrap; }

.btn-small { padding: 0.45rem 0.8rem; font-size: 0.85rem; }

.made-history { text-align: right; }

.made-history summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  list-style: none;
}
.made-history summary::-webkit-details-marker { display: none; }
.made-history summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 0.3rem;
  transition: transform 0.15s ease;
}
.made-history[open] summary::before { transform: rotate(90deg); }
.made-history summary:hover { color: var(--accent-dark); }

.made-note {
  color: var(--ink-soft);
  font-size: 0.85rem;
  margin: 0.5rem 0 0.4rem;
  text-align: left;
}

.made-dates {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.made-dates li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.4rem 0.3rem 0.75rem;
  font-size: 0.85rem;
}

.made-remove {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  border-radius: 50%;
}

.made-remove:hover { background: var(--danger); color: #fff; }

.btn[hidden] { display: none; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-block { width: 100%; }

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

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  margin-top: 2rem;
}
.btn-danger:hover { background: var(--danger); color: #fff; }

.error { color: var(--danger); }

@media (prefers-color-scheme: dark) {
  :root {
    --cream: #141b16;
    --card: #1e2921;
    --ink: #e6f0e5;
    --ink-soft: #a3b6a5;
    --line: #354a37;
    --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    --accent: #5fb377;
    --accent-dark: #85d69a;
  }
  .measure { background: #1f3a26; color: var(--accent-dark); }
  .warning { background: #3a2c1c; border-color: #5c4527; color: #e3b98a; }
  .cal-chip, .made-chip { background: #1f3a26; color: var(--accent-dark); }

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
}

.active-filter-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.92rem;
}

.active-filter-banner[hidden] { display: none; }

.dashboard-page { padding-top: 0.5rem; }

.chart-panel {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.5rem;
}

.chart-panel h2 { font-size: 1.15rem; margin-bottom: 0.25rem; }
.chart-panel .chart-subtitle { color: var(--ink-soft); font-size: 0.85rem; margin: 0 0 1rem; }

.chart-svg-wrap { overflow-x: auto; }
.chart-svg-wrap svg { display: block; }

.chart-mark { cursor: pointer; transition: opacity 0.12s ease; }
.chart-mark:hover, .chart-mark:focus-visible { opacity: 0.78; outline: none; }

.chart-axis-label {
  fill: var(--chart-axis);
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.chart-data-label {
  fill: var(--ink);
  font-size: 11px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  pointer-events: none;
}

.chart-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform: translate(-50%, -120%);
  white-space: nowrap;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.1rem;
  margin-top: 1rem;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.15rem 0.3rem 0.15rem 0.15rem;
  border-radius: 999px;
  transition: background 0.15s ease;
}

.chart-legend-item:hover, .chart-legend-item:focus-visible { background: var(--line); outline: none; }

.chart-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: none;
}

.chart-empty {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* The local app is the editable "admin" copy (add/delete recipes, mark as
   made for real, publish) -- a deliberately different grey/blue look from
   the published green site, so it's obvious at a glance which one you're
   looking at. Same specificity as :root and the dark-mode block above
   (both (0,1,0)) but declared last, so it wins the cascade regardless of
   system theme -- this is a fixed admin skin, not something that should
   follow prefers-color-scheme. The "env-local" class only exists in
   public/ -- scripts/publish.js strips it from the exported HTML, so the
   static site never sees these rules. */
.env-local {
  --cream: #e9ebed;
  --card: #ffffff;
  --ink: #2b2f33;
  --ink-soft: #5c6570;
  --accent: #4a90d9;
  --accent-dark: #2f6cb0;
  --line: #d8dbde;
  --shadow: 0 6px 18px rgba(43, 47, 51, 0.1);
}
