:root {
  --bg: #f7f3ee;
  --surface: #ffffff;
  --text: #2a2622;
  --muted: #7a7168;
  --line: #e8e1d8;
  --accent: #c2512b;
  --accent-soft: #f6e3da;
  --done: #b8afa5;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 4px 16px rgb(60 40 20 / 6%);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #262320;
    --text: #efe9e2;
    --muted: #a39a90;
    --line: #3a3530;
    --accent: #e8794f;
    --accent-soft: #3d2a21;
    --done: #6b635b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
button, input, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text);
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: #c0392b; }
.btn.icon { width: 44px; padding: 0; font-size: 20px; }
.btn.ghost { border-color: transparent; background: transparent; }

.fab {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: calc(20px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 20px rgb(0 0 0 / 20%); cursor: pointer;
  display: grid; place-items: center; text-decoration: none;
}

/* ---- List ---- */
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.top h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; flex: 1; }
.count { color: var(--muted); font-size: 14px; }

.search {
  width: 100%; height: 48px; padding: 0 16px 0 44px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='9' cy='9' r='6'/%3E%3Cpath d='m14 14 4 4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 16px center;
  outline: none;
}
.search:focus { border-color: var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 12px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 14px; color: var(--text);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-top: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); text-decoration: none; color: inherit;
  display: flex; flex-direction: column;
}
.card .thumb { aspect-ratio: 4 / 3; object-fit: cover; width: 100%; background: var(--accent-soft); }
.card .ph {
  aspect-ratio: 5 / 2; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 26px; font-weight: 700; opacity: .8;
}
.card .body { padding: 10px 12px 12px; }
.card h3 { margin: 0; font-size: 15px; line-height: 1.3; font-weight: 600; }
.card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* ---- Recipe ---- */
.bar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.bar .spacer { flex: 1; }
.hero { border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; max-height: 360px; }
.hero img { width: 100%; height: 100%; max-height: 360px; object-fit: cover; }
.recipe h1 { font-size: 30px; line-height: 1.15; margin: 0 0 10px; letter-spacing: -0.02em; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tag { font-size: 13px; padding: 2px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.facts { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 20px; color: var(--muted); font-size: 15px; }
.facts a { word-break: break-all; }

.scaler {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px;
  color: var(--text);
}
.scaler button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--accent); }
.scaler button:hover { background: var(--accent-soft); }
.scaler span { min-width: 92px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }

.cols { display: grid; gap: 28px; }
@media (min-width: 760px) { .cols { grid-template-columns: minmax(260px, 1fr) 2fr; } }
.cols h2 { font-size: 20px; margin: 0 0 8px; }
.cols h4 { margin: 16px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.ing { list-style: none; margin: 0; padding: 0; }
.ing li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.ing .amt { min-width: 76px; font-weight: 600; font-variant-numeric: tabular-nums; }

.steps { margin: 0; padding-left: 24px; }
.steps li { margin-bottom: 12px; padding-left: 4px; }
.notes { margin-top: 28px; padding: 14px 16px; background: var(--surface); border-radius: var(--radius); white-space: pre-wrap; color: var(--muted); }
.notes strong { color: var(--text); display: block; margin-bottom: 4px; }

/* ---- Cook mode ---- */
.cook { font-size: 20px; }
.cook h1 { font-size: 26px; margin: 0; flex: 1; line-height: 1.2; }
.cook .cols { gap: 36px; }
.cook .ing li { cursor: pointer; padding: 12px 4px; align-items: center; user-select: none; }
.cook .ing li::before {
  content: ""; flex: none; width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--line);
}
.cook .ing li.done { color: var(--done); text-decoration: line-through; }
.cook .ing li.done::before { background: var(--accent); border-color: var(--accent); }
.cook .steps { list-style: none; padding: 0; counter-reset: s; }
.cook .steps li {
  counter-increment: s; position: relative; cursor: pointer; user-select: none;
  padding: 14px 16px 14px 56px; margin-bottom: 10px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid transparent;
}
.cook .steps li::before {
  content: counter(s); position: absolute; left: 14px; top: 14px;
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 16px; font-weight: 700;
}
.cook .steps li.current { border-color: var(--accent); }
.cook .steps li.done { color: var(--done); }
.cook .steps li.done::before { content: "✓"; background: var(--line); color: var(--muted); }
.wake { font-size: 13px; color: var(--muted); }

/* ---- Editor ---- */
.form { display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.form .hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.form input[type=text], .form input[type=number], .form input[type=url], .form textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-weight: 400; outline: none;
}
.form input:focus, .form textarea:focus { border-color: var(--accent); }
.form textarea { resize: vertical; line-height: 1.6; }
.row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.row3 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr 1.4fr; }
@media (max-width: 520px) { .row3 { grid-template-columns: 1fr 1fr; } .row3 > :last-child { grid-column: span 2; } }
.photo-edit { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.photo-edit img { width: 120px; height: 90px; object-fit: cover; border-radius: 10px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; padding-top: 6px; }
.actions .spacer { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .2s; font-size: 15px;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media print {
  .bar, .fab, .scaler button { display: none !important; }
  body { background: #fff; }
}
