:root {
  --bg: #faf6f0;
  --surface: #ffffff;
  --surface-2: #f3ede4;
  --text: #2b2520;
  --muted: #7b7068;
  --line: #e7ddd0;
  --accent: #e0703a;
  --accent-ink: #ffffff;
  --accent-soft: #fde9dc;
  --meat: #c2493a;
  --meat-bg: #fbe8e3;
  --fish: #2b76ad;
  --fish-bg: #e2eff9;
  --side: #5b8c3a;
  --side-bg: #eaf3e1;
  --fridge: #2c8aa8;
  --fridge-bg: #e0f2f7;
  --freeze: #5d5fc9;
  --freeze-bg: #e8e8fb;
  --warn: #b7791f;
  --warn-bg: #fdf3dc;
  --danger: #c53030;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1714;
    --surface: #25211d;
    --surface-2: #2f2a25;
    --text: #f2ebe3;
    --muted: #a99e93;
    --line: #3b3530;
    --accent: #f08a52;
    --accent-ink: #1a1714;
    --accent-soft: #3d2a1f;
    --meat: #f0897a;
    --meat-bg: #3a2420;
    --fish: #7bb8e6;
    --fish-bg: #1c2d3b;
    --side: #9ccb78;
    --side-bg: #25311d;
    --fridge: #6cc3de;
    --fridge-bg: #1b3038;
    --freeze: #a4a6f5;
    --freeze-bg: #2a2a48;
    --warn: #f0c060;
    --warn-bg: #3a3020;
    --danger: #f08080;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; margin: 18px 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }

/* ---------- レイアウト ---------- */
.app-h {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.app-h h1 { font-size: 1.05rem; letter-spacing: .02em; }
.app-h .logo { font-size: 1.3rem; }
main { max-width: 1180px; margin: 0 auto; padding: 14px 16px 24px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 9px; border: 0; background: none; color: var(--muted);
  font-size: .72rem; cursor: pointer;
}
.tabs button span { font-size: 1.25rem; line-height: 1; }
.tabs button.active { color: var(--accent); font-weight: 700; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* ---------- フォーム ---------- */
.field { display: block; margin: 12px 0; }
.label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input:not([type=checkbox]):not([type=radio]), select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  min-height: 42px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.num { width: 84px; flex: none; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: .88rem; white-space: nowrap; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
.btn.block { width: 100%; margin-top: 12px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--surface); cursor: pointer; font-size: 1.1rem;
}
.icon-btn.small { width: 30px; height: 30px; font-size: .85rem; }
.linkish { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 4px 0; font-weight: 600; }
.linkish.danger { color: var(--danger); }
.note { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-size: .88rem; }
.note.warn { background: var(--warn-bg); color: var(--warn); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; font-size: .82rem; cursor: pointer;
  background: var(--surface); min-height: 30px;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }
.chip.off { color: var(--muted); }
.chip.pref.like { background: var(--side-bg); border-color: var(--side); font-weight: 600; }
.chip.pref.dislike { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }

/* ---------- 週ナビ・生成パネル ---------- */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.weeknav-mid { text-align: center; }
.weeknav-title { font-weight: 800; font-size: 1.1rem; }

.gen summary {
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; font-weight: 700; list-style: none;
}
.gen summary::-webkit-details-marker { display: none; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 8px 4px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.seg-opt small { color: var(--muted); font-size: .72rem; }
.seg-opt input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); }

.summary { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 14px 2px 8px; font-size: .88rem; color: var(--muted); }

/* ---------- カレンダー ---------- */
.week-grid { display: grid; gap: 10px; }
@media (min-width: 900px) {
  .week-grid { grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); }
}
.day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.day-h { display: flex; align-items: center; justify-content: space-between; }
.day-date { display: flex; align-items: baseline; gap: 6px; }
.dow {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--text); color: var(--bg); font-weight: 800;
}
.md { font-weight: 700; color: var(--muted); }
.storage-toggle { border: 0; background: none; padding: 0; cursor: pointer; }
.sbadge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.sbadge.fridge { background: var(--fridge-bg); color: var(--fridge); }
.sbadge.freeze { background: var(--freeze-bg); color: var(--freeze); }

.dishes { display: flex; flex-direction: column; gap: 6px; }
.dish {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  width: 100%; text-align: left; cursor: pointer;
  border: 0; border-left: 4px solid var(--side);
  border-radius: 10px; padding: 8px 10px;
  background: var(--side-bg);
}
.dish.main { padding: 10px; }
.dish.kind-meat { background: var(--meat-bg); border-left-color: var(--meat); }
.dish.kind-fish { background: var(--fish-bg); border-left-color: var(--fish); }
.dish.kind-other.main { background: var(--surface-2); border-left-color: var(--muted); }
.dish-tag { font-size: .7rem; color: var(--muted); font-weight: 700; }
.dish-name { font-weight: 700; line-height: 1.35; }
.dish.main .dish-name { font-size: 1rem; }
.dish.side .dish-name { font-size: .88rem; font-weight: 600; }
.dish-sub { font-size: .75rem; color: var(--muted); }
.dish .warn { font-size: .72rem; color: var(--warn); font-weight: 700; }
.dish.empty-slot { border: 1px dashed var(--line); background: transparent; color: var(--muted); align-items: center; }
.day-f { display: flex; flex-direction: column; gap: 6px; margin-top: auto; }
.day-f .chip { padding: 2px 9px; font-size: .75rem; min-height: 26px; }
.day-f .chip.off { text-decoration: line-through; opacity: .7; }
.servings { font-size: .8rem; font-weight: 700; color: var(--muted); text-align: right; }
.hint { margin: 10px 2px; }

.prep { padding-left: 1.3em; margin: 8px 0; }
.prep li { margin: 10px 0; }
.prep-h { display: flex; justify-content: space-between; gap: 8px; }
.prep p { margin: 2px 0; font-size: .9rem; }
.tips { background: var(--surface-2); border-radius: 10px; padding: 6px 12px; font-size: .88rem; }

/* ---------- 買い物 ---------- */
.progress-card { position: sticky; top: 58px; z-index: 5; padding: 12px 16px; }
.progress-h { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress div { height: 100%; background: var(--accent); transition: width .3s; }
.shop-group { margin: 16px 0; }
.shop-group h3 { margin: 0 0 6px; font-size: .85rem; color: var(--muted); }
.items { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.items:empty { display: none; }
.item { display: flex; align-items: center; border-bottom: 1px solid var(--line); padding-right: 8px; }
.item:last-child { border-bottom: 0; }
.item > label, .item > .item-main { display: flex; align-items: center; gap: 12px; flex: 1; padding: 10px 12px; cursor: pointer; min-height: 52px; }
.item input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.item-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.item-name { font-weight: 600; }
.item-sub { font-size: .76rem; color: var(--warn); }
.item-sub:empty, .item-src:empty { display: none; }
.item-src { font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-qty { font-weight: 700; white-space: nowrap; flex: none; }
.item > label { min-width: 0; }
.item.done .item-name, .item.done .item-qty { text-decoration: line-through; color: var(--muted); }
.covered .items { margin-top: 6px; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }

/* ---------- 在庫 ---------- */
.pform { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.pform select { width: auto; flex: none; }
.plist, .mlist, .rlist, .picklist { list-style: none; padding: 0; margin: 8px 0 0; }
.prow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.prow:last-child { border-bottom: 0; }
.prow-name { flex: 1; min-width: 0; font-weight: 600; }
.prow select { width: auto; flex: none; }

/* ---------- レシピ帳 ---------- */
.filters { margin: 12px 0 8px; }
.search { margin-bottom: 8px; }
.rrow { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin: 6px 0; padding: 4px 6px 4px 0; }
.rrow-main { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 8px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.rrow-name { font-weight: 700; }
.rrow-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .78rem; }
.rrow-flags { display: flex; gap: 2px; }
.flag { width: 34px; height: 34px; border-radius: 50%; border: 0; background: none; cursor: pointer; opacity: .28; font-size: 1rem; }
.flag.on { opacity: 1; background: var(--accent-soft); }
.flag.on.danger { background: var(--warn-bg); }
.pbadge { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--side-bg); color: var(--side); }
.pbadge.kind-meat { background: var(--meat-bg); color: var(--meat); }
.pbadge.kind-fish { background: var(--fish-bg); color: var(--fish); }

/* ---------- 設定 ---------- */
.mrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mrow .mname { flex: 1 1 120px; }
.mrow select { width: auto; }
.mini { display: inline-flex; align-items: center; gap: 4px; font-size: .82rem; color: var(--muted); }
.mini .num { width: 70px; }
.pref-group { margin: 12px 0; }

/* ---------- モーダル ---------- */
.modal-bg {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 14, 8, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@media (min-width: 700px) {
  .modal-bg { align-items: center; }
  .sheet { border-radius: 18px; max-height: 86vh; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-h { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.sheet-h h2 { font-size: 1.25rem; margin: 2px 0 6px; }
.eyebrow { font-size: .78rem; color: var(--muted); font-weight: 700; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.flag-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: .82rem; color: var(--muted); }
.flag-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 700; }
.flag-btn.on.danger { background: var(--warn-bg); border-color: var(--warn); }
.sec-h { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
.sec-h h3 { margin: 0; }
.stepper { display: flex; align-items: center; gap: 10px; }
.ing { list-style: none; padding: 0; margin: 8px 0; }
.ing li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 2px; border-bottom: 1px dotted var(--line); }
.ing li span:last-child { font-weight: 700; white-space: nowrap; }
.steps { padding-left: 1.4em; }
.steps li { margin: 6px 0; }
.box { border-radius: 12px; padding: 4px 14px 10px; margin: 12px 0; }
.box h3 { margin-top: 10px; }
.storage-box { background: var(--fridge-bg); }
.kids-box { background: var(--accent-soft); }
.tip-box { background: var(--surface-2); }
.slot-actions { border-top: 1px solid var(--line); margin-top: 18px; padding-top: 4px; }
.picklist li { margin: 4px 0; }
.pick-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; font-weight: 600; }
.pick-row:hover { border-color: var(--accent); }

/* ---------- 空状態・トースト・ローディング ---------- */
.empty { text-align: center; padding: 32px 16px; }
.empty-icon { font-size: 2.6rem; }
.empty h2 { margin: 8px 0; }
.empty .btn { margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 520px); width: max-content;
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: .88rem;
  transition: all .2s; white-space: pre-line;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

.busy {
  position: fixed; inset: 0; z-index: 80;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(3px);
  padding: 24px; text-align: center; font-weight: 600;
}
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 380px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
}

.chips.taste { margin-top: 6px; }
.tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.like { background: var(--side-bg); color: var(--side); font-weight: 700; }
.tag.dislike { background: var(--warn-bg); color: var(--warn); }

.ing-name small, .ing-qty small, .item-qty small { display: block; font-size: .74rem; font-weight: 400; color: var(--muted); }
.ing-qty, .item-qty { text-align: right; }
.ing li { align-items: flex-start; }
.detail-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 14px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); }

.daypick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 6px; }
.daychip { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0; padding: 6px 0; border-radius: 12px; min-height: 48px; }
.daychip small { font-size: .68rem; color: var(--muted); }
.daychip.weekend.off b { color: var(--muted); }
.daychip .dot { position: absolute; top: 4px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }

#accountBadge { margin-left: auto; }
.home-link { color: var(--accent); font-weight: 700; text-decoration: none; font-size: .9rem; padding: 4px 8px 4px 0; white-space: nowrap; }
.sync-badge span { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-badge { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: .75rem; color: var(--muted); cursor: pointer; }
.sync-badge.error { color: var(--warn); border-color: var(--warn); }
.choice { border: 1px solid var(--line); border-radius: 12px; padding: 4px 14px 12px; margin: 10px 0; }
.choice h3 { margin-top: 10px; }
.plain { list-style: none; padding: 0; margin: 4px 0; }
.plain li { padding: 3px 0; }
.invite { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.invite .code { font-family: ui-monospace, Menlo, monospace; font-size: 1.5rem; font-weight: 800; letter-spacing: .18em; padding: 4px 12px; border-radius: 10px; background: var(--accent-soft); }
.flag-btn.copy { color: var(--text); border-color: var(--accent); }
a.btn { text-decoration: none; }
