:root {
  --bg: #fbf6ec;
  --surface: #fffdf8;
  --ink: #2b1d0e;
  --muted: #6d5a45;
  --line: #e7dcc8;
  --brand: #7a3e12;
  --brand-ink: #fff8ee;
  --accent: #e0a526;
  --eaten: #2f7d4f;
  --danger: #a12a1a;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 10 / 8%), 0 4px 14px rgb(60 40 10 / 6%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b150f;
    --surface: #251d15;
    --ink: #f3e9da;
    --muted: #bba78f;
    --line: #3d3124;
    --brand: #e0a526;
    --brand-ink: #1b150f;
    --eaten: #6cc591;
    --danger: #ff8a7a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

/* Display rules below would otherwise override the hidden attribute. */
[hidden] { display: none !important; }

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

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

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

h1 { font-size: clamp(1.4rem, 3.5vw, 2rem); line-height: 1.2; margin: 0 0 .5rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

button, .button, select, input[type="search"] {
  font: inherit;
  color: inherit;
}

button, .button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: .45rem 1rem;
}

button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, .button:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .6rem max(1rem, env(safe-area-inset-left));
  background: var(--brand);
  color: var(--brand-ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
}

.tabs { display: flex; gap: .25rem; }

.tabs a {
  color: inherit;
  text-decoration: none;
  padding: .3rem .75rem;
  border-radius: 999px;
}

.tabs a[aria-current="page"] { background: rgb(255 255 255 / 18%); }

.install {
  margin-left: auto;
  background: var(--accent);
  color: #2b1d0e;
  border: 0;
  font-weight: 600;
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem max(1rem, env(safe-area-inset-right)) 4rem;
}

/* Intro and progress */
.intro { margin-bottom: 1rem; }
.progress-text { margin: 0 0 .35rem; color: var(--muted); }

progress {
  width: 100%;
  height: .7rem;
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { background: var(--eaten); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--eaten); border-radius: 999px; }

/* Filters */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: .6rem;
  align-items: end;
  margin: 1rem 0 .5rem;
}

.filters label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
.filters .search { grid-column: 1 / -1; }

.filters select, .filters input {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1rem;
}

.diet-note, .result-count { color: var(--muted); font-size: .9rem; margin: .25rem 0; }

/* Cards */
.group-heading {
  font-size: 1.05rem;
  margin: 1.5rem 0 .6rem;
  padding-bottom: .3rem;
  border-bottom: 1px solid var(--line);
}

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

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card.is-eaten { border-color: var(--eaten); }

.card-open {
  display: flex;
  flex-direction: column;
  border: 0;
  border-radius: 0;
  padding: 0;
  text-align: left;
  background: none;
  flex: 1;
}

.thumb {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--line);
}

.placeholder {
  display: grid;
  place-items: center;
  font-size: 3.5rem;
}

.cat-cheese { background: #f6e3a1; }
.cat-cured-meat, .cat-meat { background: #f2c1b0; }
.cat-fish { background: #bfe0ec; }
.cat-dairy-honey { background: #f8dca0; }
.cat-oil { background: #d6e3b0; }
.cat-produce { background: #cfe8c1; }
.cat-bakery { background: #ecd3b0; }
.cat-condiment { background: #e8d0e6; }
.cat-drink { background: #d7dcf2; }

.card-text { display: grid; gap: .15rem; padding: .7rem .8rem .4rem; }
.card-name { font-weight: 650; font-size: 1.05rem; line-height: 1.25; }
.card-meta { font-size: .85rem; color: var(--muted); }

.card-actions, .detail-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .3rem .8rem .7rem;
}

.eaten {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.eaten input { width: 1.4rem; height: 1.4rem; accent-color: var(--eaten); margin: 0; }
.is-eaten .eaten { color: var(--eaten); }

.rating { display: inline-flex; }

.star {
  border: 0;
  background: none;
  padding: .2rem;
  min-width: 36px;
  min-height: 44px;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--line);
}
.star.on { color: var(--accent); }
.star:hover { color: var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 3rem 0; }

/* Detail dialog */
dialog {
  width: min(680px, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 1.5rem);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 35%);
}

dialog::backdrop { background: rgb(30 20 10 / 55%); }

.detail { position: relative; }

.close {
  position: absolute;
  top: .6rem;
  right: .6rem;
  z-index: 1;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  background: rgb(255 255 255 / 85%);
  color: #2b1d0e;
}

.detail-thumb { display: block; width: 100%; height: auto; max-height: 360px; object-fit: cover; aspect-ratio: 4 / 3; }
.detail-body { padding: 1rem 1.25rem 1.25rem; }
.detail-body h2 { margin: 0; font-size: 1.6rem; line-height: 1.2; }
.kicker { margin: 0 0 .25rem; color: var(--muted); font-size: .9rem; }
.local { margin: .1rem 0 0; color: var(--muted); font-style: italic; }
.detail-actions { padding: .5rem 0; justify-content: flex-start; gap: 1rem; }
.eaten-on { color: var(--muted); font-size: .85rem; }
.links { padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.credit { font-size: .8rem; color: var(--muted); }

/* Settings and about */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1rem 1.25rem;
  margin: 0 0 1rem;
  max-width: 720px;
}

.panel legend { font-weight: 700; padding: 0 .3rem; }
.choice { display: block; padding: .35rem 0; cursor: pointer; }
.choice small { display: block; color: var(--muted); margin-left: 1.6rem; }
.choice.sub { margin-left: 1.6rem; }
.buttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.danger { color: var(--danger); border-color: currentcolor; }
.status { min-height: 1.5em; color: var(--muted); margin-bottom: 0; }

.about { max-width: 760px; }
.about li { margin: .3rem 0; }
.credits { font-size: .85rem; columns: 2 280px; }
.generated { color: var(--muted); font-size: .9rem; }

.notfound { text-align: center; padding: 4rem 1rem; }

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .6rem; }
  .card-name { font-size: .95rem; }
  .card-actions { padding: .2rem .5rem .5rem; }
  .star { min-width: 28px; font-size: 1.15rem; }
  .tabs a { padding: .3rem .5rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .card { transition: border-color .2s; }
}
