/* Matagent.
   Two contexts with different needs: browsing at a desk, and cooking at arm's
   length with wet hands. Cook mode therefore uses noticeably larger type and
   bigger targets than the rest of the app rather than the same scale. */

:root {
  --bg: #14110f;
  --surface: #1f1a17;
  --surface-2: #2a2320;
  --line: #3a312c;
  --text: #f2ece6;
  --muted: #a89c92;
  --accent: #e8a33d;
  --accent-soft: #3a2c18;
  --green: #7fb069;
  --red: #d97757;
  --radius: 14px;
  --tap: 44px;
  color-scheme: dark light;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf6f1;
    --surface: #fff;
    --surface-2: #f2ece4;
    --line: #e2d8cc;
    --text: #241d18;
    --muted: #7a6c60;
    --accent: #b26b09;
    --accent-soft: #fbeeda;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: inherit; }

/* ---------- top bar ---------- */

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-top));
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

#nav { display: flex; gap: 2px; flex: none; }

#nav a {
  padding: 8px 13px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 550;
  font-size: 0.92rem;
  white-space: nowrap;
}

#nav a.active { background: var(--accent-soft); color: var(--accent); }
#nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- planner ---------- */

.weekhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.day {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.day.today { background: linear-gradient(90deg, var(--accent-soft), transparent 60%); }

.daylabel {
  flex: none;
  width: 5.4em;
  padding-top: 2px;
}

.daylabel .dow { font-weight: 650; text-transform: capitalize; }
.daylabel .date { color: var(--muted); font-size: 0.82rem; }

.slot { flex: 1; min-width: 0; }
.slot .name { font-weight: 600; }
.slot .why { color: var(--muted); font-size: 0.86rem; margin-top: 2px; }

.slotactions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.slotactions button, .slotactions .btn {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.84rem;
  font-weight: 500;
}

.suggestion {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.suggestion .pick { flex: none; }
.suggestion .score {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 0.8rem;
}

dialog {
  width: min(96vw, 620px);
  max-height: 86vh;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
}

dialog::backdrop { background: rgb(0 0 0 / 0.55); }

/* ---------- after cooking ---------- */

dialog.review .choice { margin-bottom: 14px; }
dialog.review .choice .slotactions { margin-top: 5px; }

dialog.review .choice button {
  min-height: 42px;
  padding: 0 16px;
  font-size: 0.95rem;
}

dialog.review input[type="file"] {
  width: 100%;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
}

#search-form { flex: 1; }

#search {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* below 16px iOS zooms the page on focus */
}

#search:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#topbar.hidden { display: none; }

/* ---------- layout ---------- */

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 18px 16px 64px;
}

h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 { font-size: 1.05rem; margin: 28px 0 10px; }

.muted { color: var(--muted); }
.small { font-size: 0.86rem; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- library ---------- */

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

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.card .thumb {
  aspect-ratio: 4 / 3;
  background: var(--surface-2) center/cover no-repeat;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1.6rem;
}

.card .body { padding: 11px 13px 13px; }
.card .title { font-weight: 600; line-height: 1.3; }

/* ---------- recipe ---------- */

.hero {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 16px;
  background: var(--surface-2);
}

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 4px; }

button, .btn {
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
}

button:hover, .btn:hover { border-color: var(--accent); }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn.primary, button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1b1410;
}

ul.ingredients { list-style: none; margin: 0; padding: 0; }

ul.ingredients li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.amount {
  flex: none;
  min-width: 5.2em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--accent);
}

.prep, .note { color: var(--muted); }

ol.steps { margin: 0; padding-left: 1.3em; }
ol.steps li { padding: 7px 0; }

.section-name {
  margin: 20px 0 6px;
  font-weight: 650;
  color: var(--accent);
  font-size: 0.95rem;
}

.source { margin-top: 26px; }

/* ---------- cook mode ---------- */

body.cooking { --tap: 52px; }

.cook {
  font-size: 1.18rem;
  line-height: 1.6;
}

.cook h1 { font-size: 1.5rem; }

.cookbar {
  position: sticky;
  top: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 0;
  margin-bottom: 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
}

.servings {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.servings button {
  min-width: var(--tap);
  border: 0;
  border-radius: 0;
  background: var(--surface);
  font-size: 1.3rem;
}

.servings output {
  min-width: 4.6em;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.cook ul.ingredients li,
.cook ol.steps li {
  padding: 12px 0;
  cursor: pointer;
}

.cook .done {
  opacity: 0.42;
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.wakelock {
  font-size: 0.8rem;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.wakelock::before {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.wakelock.on::before { background: var(--green); }

.timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 4px;
  padding: 2px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.timer.running { background: var(--accent); color: #1b1410; }
.timer.done { border-color: var(--red); background: var(--red); color: #fff; }

#timers {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

#timers:empty { display: none; }

/* ---------- editor ---------- */

form.editor { display: grid; gap: 14px; margin-top: 16px; }

label { display: grid; gap: 6px; font-weight: 550; font-size: 0.9rem; }

input[type="text"], textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

textarea { min-height: 190px; resize: vertical; font-variant-numeric: tabular-nums; }

/* ---------- feedback ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(90vw, 460px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.3);
}

#toast.error { border-color: var(--red); color: var(--red); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
