:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #efe8dc;
  --text: #2a2622;
  --muted: #6f665c;
  --line: #e2d9cb;
  --accent: #b4532a;
  --accent-text: #ffffff;
  --accent-soft: #f6e3d6;
  --ok: #3f7d4e;
  --danger: #b23a3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 8px rgba(60, 40, 20, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #262320;
    --surface-2: #322e29;
    --text: #f1ebe2;
    --muted: #b0a596;
    --line: #3d3832;
    --accent: #e0814f;
    --accent-text: #1c1a17;
    --accent-soft: #3d2c22;
    --ok: #7cc28d;
    --danger: #f08080;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
main {
  max-width: 720px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.6rem; line-height: 1.2; margin: .2em 0 .4em; }
h2 { font-size: 1.15rem; margin: 1.6em 0 .5em; }
h3 { font-size: .95rem; margin: 1em 0 .3em; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .88rem; }
.hidden { display: none !important; }

button, .button {
  font: inherit; min-height: 44px; padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.link { border: none; background: none; padding: 8px 6px; color: var(--accent); min-height: 44px; }
button:disabled { opacity: .5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.45; }
label { display: block; font-weight: 600; font-size: .92rem; margin: 14px 0 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > * { flex: 1 1 0; min-width: 0; }
.row > .auto { flex: 0 0 auto; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

/* Header and tabs */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.top .title { font-weight: 700; font-size: 1.25rem; }
.tabs { display: flex; gap: 6px; margin: 4px 0 12px; overflow-x: auto; }
.tabs a {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--text);
  background: var(--surface-2); min-height: 40px; display: inline-flex; align-items: center;
}
.tabs a.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 8px 0 14px; }
.filters select { font-size: .9rem; padding: 8px; }

/* Recipe cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  border: 1px solid var(--line); text-decoration: none; color: inherit; display: flex; flex-direction: column;
}
.card .thumb { aspect-ratio: 4 / 3; background: var(--surface-2); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 2rem; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .body { padding: 10px 12px 12px; }
.card .name { font-weight: 600; line-height: 1.25; }
.card .meta { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.empty { text-align: center; padding: 40px 10px; color: var(--muted); }
.fab { position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(20px + env(safe-area-inset-bottom)); box-shadow: 0 4px 14px rgba(0,0,0,.2); padding: 12px 22px; }

/* Add screen */
.choices { display: grid; gap: 12px; }
.choice {
  display: flex; align-items: center; gap: 14px; text-align: left; justify-content: flex-start;
  padding: 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); min-height: 72px; width: 100%;
}
.choice .icon { font-size: 1.6rem; }
.choice strong { display: block; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 14px; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 30px auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; margin: 12px 0; }
.error { color: var(--danger); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumbs figure { margin: 0; position: relative; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; display: block; }
.thumbs button { position: absolute; top: -8px; right: -8px; min-height: 30px; width: 30px; padding: 0; border-radius: 50%; }

/* Recipe page */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 2px 10px; font-size: .82rem; }
.facts { color: var(--muted); font-size: .92rem; }
.comments { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 14px; margin: 4px 0 16px; }
.comments h2 { margin: 0 0 8px; font-size: 1rem; }
.comment { border-top: 1px solid rgba(0,0,0,.08); padding: 8px 0; }
.comment:first-of-type { border-top: none; }
.comment .text { white-space: pre-wrap; }
.comment .when { font-size: .78rem; color: var(--muted); }
.comments textarea { min-height: 60px; background: var(--surface); }
.photos { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0; }
.photos img { height: 110px; border-radius: 10px; display: block; }
.cook { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px; margin: 14px 0; }
.switch { position: relative; width: 52px; height: 32px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; min-height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; background: #fff; border-radius: 50%; transition: transform .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }
.ingredients { list-style: none; padding: 0; margin: 0; }
.ingredients li label {
  display: flex; align-items: flex-start; gap: 12px; font-weight: 400; font-size: 1rem; margin: 0;
  padding: 10px 4px; border-bottom: 1px solid var(--line); min-height: 48px; cursor: pointer;
}
.ingredients input[type=checkbox] { width: 24px; height: 24px; min-height: 0; flex: 0 0 auto; margin: 0; accent-color: var(--ok); }
.ingredients li.done span { text-decoration: line-through; color: var(--muted); }
.method { padding-left: 1.4em; }
.method li { margin: 0 0 12px; padding-left: 4px; }
.notes { white-space: pre-wrap; background: var(--surface); border-radius: 10px; padding: 12px 14px; border: 1px solid var(--line); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; max-width: calc(100% - 32px);
  box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 10;
}
.login { max-width: 360px; margin: 12vh auto 0; }
