:root {
  color-scheme: light dark;
  --paper: #f6f1e7;
  --card: #fffdf8;
  --ink: #2b2620;
  --muted: #736a5d;
  --line: #e2d9c8;
  --accent: #b5482a;
  --accent-ink: #ffffff;
  --accent-soft: #f6e2d8;
  --green: #4d6b3c;
  --green-soft: #e4ecd9;
  --amber: #8a5d10;
  --amber-soft: #f6e8c6;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  --sans: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  --radius: 12px;
  --tabs-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1e1b17;
    --card: #2a2620;
    --ink: #efe8db;
    --muted: #a99f8f;
    --line: #40392f;
    --accent: #e0805f;
    --accent-ink: #1e1b17;
    --accent-soft: #46291e;
    --green: #a7c48f;
    --green-soft: #2f3a26;
    --amber: #e3bb6c;
    --amber-soft: #3f3218;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.6 var(--sans);
  overflow-wrap: anywhere;
}
.view {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabs-h) + 88px + env(safe-area-inset-bottom));
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.35; margin: 0; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; min-height: 40px; }
.head-left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.section { margin-top: 26px; }
.section > h2 { margin-bottom: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card.tap { display: block; width: 100%; text-align: left; cursor: pointer; text-decoration: none; color: inherit; }
.card.tap:hover { border-color: var(--muted); }
.card.tap.recipe-card, .card.tap.row { display: flex; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; white-space: nowrap;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--accent); }
.btn.wide { width: 100%; }
.btn.compact { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.add-row .btn { flex: none; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--line); color: var(--ink); }
.icon-btn.on { color: var(--accent); }
.ico { width: 20px; height: 20px; display: block; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1 1 0; max-width: 136px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px;
}
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabs .ico { width: 22px; height: 22px; }

.fab {
  position: fixed; z-index: 4; right: max(16px, calc(50vw - 324px));
  bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
  box-shadow: 0 3px 10px rgb(0 0 0 / .22);
}
.fab .ico { width: 26px; height: 26px; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 16px 6px; margin: 0 -16px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 36px; padding: 4px 13px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer; font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.tag { display: inline-block; padding: 0 8px; border-radius: 6px; font-size: 12px; line-height: 20px; background: var(--line); color: var(--muted); white-space: nowrap; }
.tag.want { background: var(--accent-soft); color: var(--accent); }
.tag.favorite { background: var(--amber-soft); color: var(--amber); }
.tag.cooked { background: var(--green-soft); color: var(--green); }
.tag.warn { background: var(--amber-soft); color: var(--amber); }

/* 週の表示 */
.day { display: grid; grid-template-columns: 52px 1fr; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.day:first-child { border-top: 0; }
.day-date { font-family: var(--serif); line-height: 1.25; }
.day-date b { display: block; font-size: 20px; font-weight: 600; }
.day-date.today { color: var(--accent); }
.day-empty { color: var(--muted); font-size: 14px; align-self: center; }
.slot { display: flex; flex-direction: column; gap: 2px; }
.slot + .slot { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.slot-body { flex: 1 1 auto; min-width: 0; }
.slot-title { font-weight: 600; color: inherit; text-decoration: none; display: block; }
.slot-title:hover { color: var(--accent); }
.slot.done .slot-title { color: var(--muted); text-decoration: line-through; }
.slot-why { font-size: 12.5px; color: var(--muted); }
.slot-actions { display: flex; flex: none; margin: 0 0 -6px -10px; }
.cook-day { border-left: 3px solid var(--accent); }
.eat-line { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.eat-line:first-child { border-top: 0; }
.eat-line .when { flex: none; width: 76px; font-family: var(--serif); }
.eat-line .when.today { color: var(--accent); font-weight: 600; }

/* レシピ */
.recipe-card { display: flex; gap: 12px; align-items: center; }
.thumb { width: 64px; height: 64px; flex: none; border-radius: 8px; object-fit: cover; background: var(--line); display: grid; place-items: center; color: var(--muted); }
.recipe-title { font-weight: 600; }
.photos { display: flex; gap: 8px; overflow-x: auto; }
.photos img { height: 180px; border-radius: 8px; cursor: zoom-in; }
.photo-edit { position: relative; flex: none; }
.photo-edit img { height: 96px; display: block; border-radius: 8px; }
.photo-edit button { position: absolute; top: 2px; right: 2px; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: rgb(0 0 0 / .6); color: #fff; cursor: pointer; display: grid; place-items: center; }
.ing-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px dotted var(--line); }
.ing-row:first-child { border-top: 0; }
.ing-group { font-size: 12px; color: var(--muted); margin-right: 6px; }
.ing-have { color: var(--green); font-size: 12px; margin-left: 6px; }
.segment { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segment button { min-height: 44px; padding: 4px 2px; border: 0; background: var(--card); font-size: 13px; color: var(--muted); cursor: pointer; border-left: 1px solid var(--line); }
.segment button:first-child { border-left: 0; }
.segment button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 600; }

/* フォーム */
label.field { display: block; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field-help { display: block; font-size: 12.5px; color: var(--muted); margin-top: 4px; }
input[type=text], input[type=url], input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  font-size: 16px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ing-edit { display: grid; grid-template-columns: 1fr 100px 36px; gap: 6px; align-items: center; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.days button { min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; color: var(--muted); padding: 0; }
.days button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* 買い物・在庫 */
.check-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); min-height: 48px; }
.check-row:first-child, label.check-row:only-of-type { border-top: 0; }
.check-row input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--accent); margin: 0; }
.check-row.checked .item-name { text-decoration: line-through; color: var(--muted); }
.item-name { font-weight: 500; }
.item-from { font-size: 12.5px; color: var(--muted); }
.group-title { font-size: 13px; font-weight: 600; color: var(--muted); margin: 18px 0 6px; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1 1 auto; min-width: 0; }
.status-btn { flex: none; min-height: 36px; min-width: 66px; padding: 2px 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); cursor: pointer; font-size: 13px; }
.status-btn.ok { color: var(--green); background: var(--green-soft); border-color: transparent; }
.status-btn.low { color: var(--amber); background: var(--amber-soft); border-color: transparent; }
.status-btn.out { color: var(--muted); }
.exp-soon { color: var(--accent); font-weight: 600; }

/* はじめて */
.welcome { padding-top: 12px; }
.welcome h1 { font-size: 28px; margin-bottom: 8px; }
.style-pick { display: grid; gap: 10px; margin: 18px 0; }
.style-card { text-align: left; padding: 14px 16px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--card); cursor: pointer; }
.style-card[aria-pressed="true"] { border-color: var(--accent); }
.style-card b { display: block; font-family: var(--serif); font-size: 18px; font-weight: 600; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .btn { margin-top: 12px; }
.note { font-size: 13px; color: var(--muted); padding: 10px 12px; border-radius: 10px; background: var(--line); background: color-mix(in srgb, var(--line) 45%, transparent); }

dialog {
  width: min(560px, calc(100vw - 24px)); max-height: 86dvh;
  border: 1px solid var(--line); border-radius: 16px; padding: 18px;
  background: var(--paper); color: var(--ink); overflow-y: auto;
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.picker-item { display: block; width: 100%; text-align: left; padding: 10px 4px; background: none; border: 0; border-top: 1px solid var(--line); cursor: pointer; }
.toast {
  position: fixed; z-index: 20; left: 50%; transform: translate(-50%, 16px);
  bottom: calc(var(--tabs-h) + 20px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px); width: max-content;
  padding: 9px 16px; border-radius: 10px;
  background: var(--ink); color: var(--paper); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media print { .tabs, .fab, .toast { display: none; } }
