:root {
  --ground: #F6F5F1;
  --surface: #ffffff;
  --ink: #1B1F1D;
  --muted: #5B625E;
  --line: #E2E0D8;
  --line-soft: #EFEDE6;
  --accent: #2E6B4F;
  --accent-soft: #DCEBE2;
  --accent-ink: #1F4D38;
  --star: #E0A21B;
  --danger: #A32D2D;
  --chip: #EFEDE6;
  --seg: #E9E7DF;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }

.display { font-family: 'Bricolage Grotesque', 'DM Sans', sans-serif; letter-spacing: -0.02em; }

/* ---------- shell ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }
#view { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 0 16px 120px; }

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; align-items: flex-end;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
}
#tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500; min-height: 44px; justify-content: flex-end;
}
#tabbar a.active { color: var(--accent); font-weight: 700; }
#tabbar a svg { width: 24px; height: 24px; }
#tabbar a.add { color: var(--ink); font-weight: 700; }
#tabbar a.add .plus {
  width: 44px; height: 44px; border-radius: 999px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
}

@media (min-width: 900px) {
  #tabbar { top: 0; bottom: 0; right: auto; width: 96px; flex-direction: column; justify-content: flex-start; align-items: stretch; gap: 10px; border-top: 0; border-right: 1px solid var(--line); padding: 24px 8px; }
  #tabbar a { flex: none; justify-content: center; }
  #view { margin-left: calc(96px + max(24px, (100vw - 96px - 960px) / 2)); max-width: 960px; padding-bottom: 60px; }
}

/* ---------- common ---------- */
.page-head { display: flex; align-items: baseline; justify-content: space-between; padding: 24px 0 12px; gap: 12px; }
.page-head h1 { font-size: 28px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: 14px; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.outline { border-color: var(--accent); color: var(--accent); }
.btn.danger { color: var(--danger); border-color: #E7BDBD; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; padding: 0; text-decoration: none; color: var(--ink);
}
.icon-btn svg { width: 20px; height: 20px; }

.chip {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.chip.tag { min-height: 28px; padding: 0 10px; background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); font-size: 12px; font-weight: 500; }
.chip.opt { min-height: 32px; padding: 0 12px; font-size: 13px; background: var(--chip); border-color: transparent; }
.chip.opt.on { background: var(--accent); color: #fff; }
.chip.dashed { background: transparent; border: 1px dashed var(--muted); }
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip-row .chip { flex: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.card.pad { padding: 14px; }
.list { margin: 0; padding: 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.list > li { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); display: flex; justify-content: space-between; gap: 12px; }
.list > li:last-child { border-bottom: 0; }

.eyebrow { margin: 20px 0 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }

.seg { display: flex; padding: 4px; background: var(--seg); border-radius: 12px; }
.seg button, .seg a {
  flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; color: #4A524E; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; text-decoration: none; padding: 0 12px;
}
.seg .on { background: var(--surface); color: var(--ink); font-weight: 700; }
.seg.sm { padding: 3px; border-radius: 10px; display: inline-flex; }
.seg.sm button { min-height: 38px; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 13px; font-weight: 700; }
.input, .textarea, .select {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; outline: none;
}
.input:focus, .textarea:focus, .select:focus, .btn:focus-visible, .chip:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }

.search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; }
.search svg { width: 18px; height: 18px; color: var(--muted); flex: none; }

/* ---------- library ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.rcard { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; text-decoration: none; color: inherit; }
.rthumb { position: relative; height: 104px; background-size: cover; background-position: center; }
.rthumb .src { position: absolute; top: 8px; left: 8px; background: #fff; border-radius: 999px; padding: 2px 8px; font-size: 11px; font-weight: 700; }
.rthumb .fav { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; }
.rbody { padding: 10px 10px 12px; }
.rtitle { font-size: 14px; font-weight: 700; line-height: 1.25; min-height: 35px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rmeta { margin-top: 6px; font-size: 12px; color: var(--muted); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); font-size: 20px; margin-bottom: 8px; }

/* ---------- recipe detail ---------- */
.hero { position: relative; height: 180px; margin: 0 -16px; background-size: cover; background-position: center; }
.hero .back { position: absolute; top: 16px; left: 16px; }
.hero .fav-btn { position: absolute; top: 16px; right: 16px; }
.hero .srcpill { position: absolute; bottom: 12px; left: 16px; background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; text-decoration: none; }
.stars button { border: 0; background: transparent; padding: 4px; font-size: 22px; line-height: 1; color: #CFCBBE; min-width: 32px; min-height: 36px; }
.stars button.on { color: #B7791F; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: #fff; font-size: 22px; }
.stepper .val { min-width: 64px; text-align: center; }
.stepper .val b { display: block; font-size: 22px; line-height: 1; }
.stepper .val span { font-size: 12px; color: var(--muted); }
.ing-amt { font-weight: 700; white-space: nowrap; }
.steps { margin: 0; padding-left: 22px; line-height: 1.55; }
.steps li { margin-bottom: 8px; padding-left: 4px; }

/* ---------- plan ---------- */
.day { display: flex; gap: 10px; align-items: stretch; margin-bottom: 8px; }
.daylabel { flex: none; width: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.daylabel .d { font-size: 12px; color: var(--muted); font-weight: 500; }
.daylabel .n { font-size: 18px; font-weight: 700; }
.daylabel.today .n { color: var(--accent); }
.entries { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.entry { display: flex; align-items: center; gap: 10px; padding: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-height: 56px; }
.entry .thumb { flex: none; width: 40px; height: 40px; border-radius: 8px; background-size: cover; background-position: center; }
.entry .t { font-size: 14px; font-weight: 700; line-height: 1.2; text-decoration: none; color: inherit; }
.entry .sv { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-top: 2px; }
.entry .sv button { width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: #fff; line-height: 1; }
.add-entry { display: flex; align-items: center; gap: 8px; padding: 0 14px; min-height: 48px; background: transparent; border: 1px dashed #9AA09C; border-radius: 12px; color: #4A524E; font-size: 14px; }
.add-entry.compact { min-height: 40px; }

.gro-item { display: flex; align-items: center; gap: 12px; min-height: 48px; border-bottom: 1px solid var(--line-soft); }
.gro-item input { flex: none; width: 22px; height: 22px; accent-color: var(--accent); }
.gro-item .nm { flex: 1; min-width: 0; font-size: 15px; }
.gro-item.done .nm, .gro-item.done .q { text-decoration: line-through; color: #6B726E; }
.gro-item .q { font-size: 14px; font-weight: 700; }
.aisle { margin: 14px 0 0; padding-top: 6px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }

/* ---------- sheets, toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20, 24, 22, 0.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--ground); width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.sheet h2 { font-size: 20px; margin-bottom: 12px; }
.sheet .opt-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pick { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; margin-bottom: 6px; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 12px; min-height: 56px; }
.pick .thumb { flex: none; width: 40px; height: 40px; border-radius: 8px; background-size: cover; background-position: center; }

#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; max-width: 90vw;
}

.toggle { position: relative; width: 48px; height: 28px; border: 0; border-radius: 999px; background: #B9BDB9; padding: 0; flex: none; }
.toggle[aria-checked="true"] { background: var(--accent); }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 999px; background: #fff; transition: transform 0.12s; }
.toggle[aria-checked="true"]::after { transform: translateX(20px); }

.notice { padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; font-weight: 500; }
.notice.warn { background: #FBEFD5; color: #6B4A0B; }

.clip-preview { margin: 0; padding: 10px; background: var(--ground); border-radius: 10px; font: 13px/1.45 'DM Sans', system-ui, sans-serif; color: var(--muted); white-space: pre-wrap; word-break: break-word; max-height: 110px; overflow: hidden; }

/* ---------- cook mode ---------- */
.cook { position: fixed; inset: 0; z-index: 50; background: var(--ground); overflow: auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.cook > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.cook-head { display: flex; align-items: center; gap: 12px; padding-bottom: 12px; position: sticky; top: -16px; padding-top: 16px; margin-top: -16px; background: var(--ground); z-index: 1; }
.cook-ing { margin: 4px auto 14px; }
.cook-ing summary { cursor: pointer; font-weight: 700; min-height: 44px; display: flex; align-items: center; }
.cook-steps { display: flex; flex-direction: column; gap: 10px; }
.cstep {
  display: flex; gap: 14px; align-items: flex-start; width: 100%; text-align: left; min-height: 64px;
  padding: 14px; font-size: 20px; line-height: 1.4; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.cstep .num { flex: none; width: 32px; height: 32px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin-top: 1px; }
.cstep.done { background: transparent; color: #6B726E; text-decoration: line-through; }
.cstep.done .num { background: #6B726E; text-decoration: none; }

/* ---------- print ---------- */
.print-only { display: none; }
@media print {
  body { background: #fff; }
  #tabbar, .no-print, #toast, .overlay, .cook { display: none !important; }
  .print-only { display: block; }
  #view { max-width: none; margin: 0; padding: 0; }
  .hero { height: 0; margin: 0; }
  .card, .list { border-color: #ccc; }
  a { text-decoration: none; }
  .steps li { break-inside: avoid; }
}
