:root {
  --bg: #fbf7f0;
  --surface: #ffffff;
  --text: #2b2622;
  --muted: #7c7268;
  --accent: #b5651d;
  --accent-dark: #8c4d16;
  --border: #eaded0;
  --shadow: 0 1px 3px rgba(80, 60, 40, 0.08), 0 6px 20px rgba(80, 60, 40, 0.06);
  --on-accent: #ffffff;
  --accent-soft: rgba(181, 101, 29, 0.12);
  --radius: 12px;
  --maxw: 720px;
}

[data-theme="dark"] {
  --bg: #1a1410;
  --surface: #261c16;
  --text: #f3ebe3;
  --muted: #b5a394;
  --accent: #d4893a;
  --accent-dark: #e8b06a;
  --border: #3d2f24;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.28);
  --on-accent: #fffaf5;
  --accent-soft: rgba(212, 137, 58, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

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

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

/* ---- Header ---- */

.site-header {
  position: relative;
  text-align: center;
  margin-bottom: 1.75rem;
}

.site-header h1 {
  margin: 0;
  font-size: 2.25rem;
  letter-spacing: -0.02em;
  padding-inline: 7.25rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-dark);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0.32rem 0.7rem;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}

.theme-toggle-icon {
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.site-header .theme-toggle {
  position: absolute;
  top: 0.2rem;
  right: 0;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

/* ---- Search ---- */

.search {
  margin-bottom: 1.5rem;
}

#search {
  width: 100%;
  padding: 0.8rem 1rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.recipe-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.recipe-item a {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.recipe-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.recipe-item a:hover,
.recipe-item a:focus-visible {
  transform: translateY(-1px);
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ---- List filter menus ---- */

.list-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.list-filter {
  flex: 1 1 9rem;
  min-width: 0;
}

.list-filter select {
  display: block;
  width: 100%;
  max-width: 100%;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent-dark);
  background-color: var(--surface);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%238c4d16' d='M1 1.5 L6 6.5 L11 1.5' stroke='none'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  background-size: 0.65rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0.4rem 2rem 0.4rem 0.85rem;
  cursor: pointer;
  line-height: 1.3;
  text-transform: capitalize;
  appearance: none;
  -webkit-appearance: none;
}

.list-filter select:hover,
.list-filter select:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.list-filter select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[data-theme="dark"] .list-filter select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%23e8b06a' d='M1 1.5 L6 6.5 L11 1.5' stroke='none'/></svg>");
}

/* ---- Tag filter chips (pick-for-me) ---- */

.tag-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tag-filter + .family-filter {
  margin-top: -0.85rem;
}

.tag-filter:empty {
  display: none;
}

.chip {
  font: inherit;
  font-size: 0.9rem;
  text-transform: capitalize;
  padding: 0.35rem 0.85rem;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

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

.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* ---- Tag labels ---- */

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tag {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

.recipe-attribution {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
}

.recipe-nutrition {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
}

.recipe-item .recipe-nutrition {
  margin: -0.15rem 0 0;
}

.recipe-item-meta {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
}

.recipe-item .recipe-attribution {
  margin-left: auto;
  text-align: right;
  white-space: nowrap;
}

.cookbook-attribution {
  margin: 0 0 0.35rem;
}

.cookbook-nutrition {
  margin: 0 0 0.5rem;
}

.nutrition-breakdown {
  margin: 0 0 1.25rem;
}

.nutrition-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.nutrition-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.95rem;
  cursor: pointer;
  list-style: none;
  color: var(--accent-dark);
  transition: background 0.12s ease;
}

.nutrition-panel summary::-webkit-details-marker,
.nutrition-panel summary::marker {
  display: none;
  content: "";
}

.nutrition-panel summary:hover {
  background: var(--accent-soft);
}

.nutrition-panel summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nutrition-panel[open] summary {
  border-bottom: 1px solid var(--border);
}

.nutrition-panel-copy {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.nutrition-panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
}

.nutrition-panel-hint {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.nutrition-panel-chevron {
  flex-shrink: 0;
  width: 0.42rem;
  height: 0.42rem;
  margin-right: 0.15rem;
  border-right: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: rotate(45deg);
  transition: transform 0.16s ease;
}

.nutrition-panel[open] .nutrition-panel-chevron {
  transform: rotate(-135deg);
}

.nutrition-panel-body {
  padding: 0.9rem 1rem 1rem;
}

.nutrition-panel-lead {
  margin: 0 0 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.nutrition-bars {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.nutrition-bar-row {
  display: grid;
  grid-template-columns: minmax(6.5rem, 0.9fr) minmax(4rem, 1.4fr) auto;
  gap: 0.5rem;
  align-items: center;
}

.nutrition-bar-label {
  font-size: 0.78rem;
  color: var(--text);
  line-height: 1.25;
}

.nutrition-bar-track {
  height: 0.55rem;
  background: var(--accent-soft);
  border-radius: 999px;
  overflow: hidden;
}

.nutrition-bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.nutrition-bar-val {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  text-align: right;
}

.nutrition-table-wrap {
  overflow-x: auto;
}

.nutrition-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.nutrition-table th,
.nutrition-table td {
  padding: 0.35rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.nutrition-table th:nth-child(n + 3),
.nutrition-table td:nth-child(n + 3) {
  text-align: right;
  white-space: nowrap;
}

.nutrition-table tfoot th,
.nutrition-table tfoot td {
  border-bottom: none;
  padding-top: 0.5rem;
}

.nutrition-notes {
  margin: 0.85rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.cookbook-nutrition-breakdown {
  margin-bottom: 1rem;
}

.recipe-tags {
  margin-bottom: 0;
}

.recipe-share-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.recipe-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-shrink: 0;
}

.share-btn {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-dark);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0.32rem 0.75rem;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}

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

.share-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.recipe-share-row[hidden],
.share-btn[hidden] {
  display: none;
}

.recipe-print-title {
  display: none;
}

/* ---- List actions (cookbook entry) ---- */

.list-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.list-count {
  margin: 0 0 0.5rem;
  padding-inline: 1.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  line-height: 1.3;
}

.cookbook-link {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent-dark);
  text-decoration: none;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color 0.12s ease, color 0.12s ease;
}

.cookbook-link:hover {
  border-color: var(--accent);
}

.cookbook-link.is-disabled {
  opacity: 0.45;
  pointer-events: none;
  cursor: default;
}

/* ---- Cookbook mode ---- */

.cookbook-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.cookbook-bar .back-link {
  justify-self: start;
}

.cookbook-bar .theme-toggle {
  justify-self: end;
}

.back-link {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
}

.back-link:hover {
  text-decoration: underline;
}

.cookbook-counter {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
}

.cookbook-page {
  min-height: 40vh;
}

.cookbook-controls {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.5rem;
}

.flip-btn {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.65rem 1.4rem;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.flip-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.flip-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ---- Pick for me ---- */

.pick-actions {
  display: flex;
  justify-content: center;
  margin: 1.5rem 0;
}

.pick-button {
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 0.8rem 2rem;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease, opacity 0.12s ease;
}

.pick-button:hover:not(:disabled) {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.pick-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.pick-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.75rem;
  text-align: center;
}

.pick-title {
  margin: 0 0 0.75rem;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.pick-result .tag-list {
  justify-content: center;
  margin-bottom: 1.25rem;
}

.pick-result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.pick-view {
  font-weight: 600;
  text-decoration: none;
  color: var(--on-accent);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.6rem 1.4rem;
  transition: background 0.12s ease;
}

.pick-view:hover {
  background: var(--accent-dark);
}

.pick-again {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1.4rem;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease;
}

.pick-again:hover {
  border-color: var(--accent);
  color: var(--accent-dark);
}

/* ---- Messages ---- */

.message {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

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

/* ---- Recipe view ---- */

.back {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 1.25rem;
}

.back a {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 600;
}

.back a:hover {
  text-decoration: underline;
}

.recipe {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.recipe-photo {
  display: block;
  width: 100%;
  height: auto;
}

.recipe-photo[hidden] {
  display: none;
}

.recipe-body {
  padding: 1.5rem 1.75rem;
}

.markdown-body h1 {
  margin-top: 0;
  font-size: 1.9rem;
  letter-spacing: -0.02em;
}

.markdown-body h2 {
  margin-top: 1.75rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.3rem;
}

.markdown-body h3 {
  margin-top: 1.25rem;
  font-size: 1.1rem;
  color: var(--accent-dark);
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.4rem;
}

.markdown-body li {
  margin: 0.3rem 0;
}

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

.markdown-body code {
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  font-size: 0.9em;
}

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

@media (max-width: 480px) {
  .container {
    padding: 1.5rem 1rem 3rem;
  }

  .site-header {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .site-header .theme-toggle {
    position: static;
    align-self: flex-end;
    order: -1;
    margin-bottom: 0.65rem;
  }

  .site-header h1 {
    font-size: 1.9rem;
    padding-inline: 0;
  }

  .recipe-body {
    padding: 1.25rem 1.1rem;
  }
}

/* ---- Print (recipe viewer) ---- */

@media print {
  :root,
  html[data-theme="dark"] {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #2b2622;
    --muted: #5c534a;
    --accent: #b5651d;
    --accent-dark: #8c4d16;
    --border: #d8cfc3;
    --shadow: none;
    --on-accent: #ffffff;
    --accent-soft: rgba(181, 101, 29, 0.12);
    color-scheme: light;
  }

  body {
    background: #ffffff;
    color: var(--text);
  }

  .container {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .back,
  .theme-toggle,
  .recipe-actions,
  .share-btn,
  .print-btn,
  .recipe-photo,
  #recipe-nutrition-breakdown,
  #recipe-message {
    display: none !important;
  }

  .recipe-print-stack {
    display: flex;
    flex-direction: column;
  }

  .recipe-print-title {
    display: block;
    order: 1;
    margin: 0 0 0.5rem;
    font-size: 1.9rem;
    letter-spacing: -0.02em;
    font-weight: 700;
    color: var(--text);
  }

  .recipe-print-title:empty {
    display: none;
  }

  .recipe-attribution {
    order: 2;
    margin-bottom: 0.35rem;
  }

  .recipe-share-row {
    order: 3;
    margin-bottom: 0.35rem;
    display: block;
  }

  .recipe-share-row:has(.recipe-tags[hidden]) {
    display: none;
  }

  .recipe-tags {
    margin-bottom: 0;
  }

  .recipe-nutrition {
    order: 4;
    margin-bottom: 0.75rem;
  }

  .recipe {
    order: 5;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
  }

  .recipe-body {
    padding: 0;
  }

  .recipe-body > h1:first-of-type {
    display: none;
  }

  .markdown-body h2 {
    border-bottom-color: var(--border);
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}
