:root {
  color-scheme: light dark;
  --bg: #f7f3ea;
  --surface: #fffdf8;
  --surface-2: #efe9dc;
  --ink: #2a2a26;
  --muted: #6d6a60;
  --line: #e0d9c9;
  --brand: #2f5d50;
  --brand-ink: #ffffff;
  --plenty: #2f7a5b;
  --plenty-soft: #dcefe5;
  --low: #a86a00;
  --low-soft: #fbeccb;
  --out: #b4412f;
  --out-soft: #f8dfd9;
  --shadow: 0 6px 24px rgba(50, 40, 20, .16);
  --nav-h: 68px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1d1a;
    --surface: #272823;
    --surface-2: #33342e;
    --ink: #eeece4;
    --muted: #aaa79b;
    --line: #3c3d36;
    --brand: #7cc2ab;
    --brand-ink: #14241f;
    --plenty: #7fd0ab;
    --plenty-soft: #24402f;
    --low: #eebd5f;
    --low-soft: #453617;
    --out: #f0937f;
    --out-soft: #4a2820;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

/* ログイン */
.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  max-width: 420px;
  margin: 0 auto;
}
.login h1 { margin: 0; font-size: 28px; color: var(--brand); }
.login p { margin: 0; color: var(--muted); }
.error { color: var(--out); font-size: 14px; min-height: 21px; margin: 0; }

/* ヘッダー */
.head {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 8px;
}
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; }
.head h1 { margin: 0; font-size: 20px; }
.offline { font-size: 12px; color: var(--out); background: var(--out-soft); padding: 2px 8px; border-radius: 999px; }
.search { margin-top: 8px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 14px; color: var(--muted); }

.field {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  /* iOSで16px未満だと入力時に画面が拡大される */
  font-size: 16px;
}
.field::placeholder { color: var(--muted); }

.toggle { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.toggle button { min-height: 32px; padding: 0 12px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.toggle button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; }

main { padding: 4px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px); max-width: 640px; margin: 0 auto; }
.group-title { margin: 18px 0 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }

/* 品物の行 */
.row { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; min-height: 60px; }
.row + .row { border-top: 1px solid var(--line); }
.row-main { flex: 1; min-width: 0; text-align: left; min-height: 44px; display: block; }
.row-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.row-meta { display: flex; flex-wrap: wrap; gap: 2px 8px; font-size: 13px; color: var(--muted); }

.seg { display: inline-flex; flex: none; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.seg button { width: 48px; min-height: 44px; font-size: 13px; border-radius: 8px; color: var(--muted); }
.seg button[aria-pressed="true"][data-status="plenty"] { background: var(--plenty-soft); color: var(--plenty); font-weight: 700; }
.seg button[aria-pressed="true"][data-status="low"] { background: var(--low-soft); color: var(--low); font-weight: 700; }
.seg button[aria-pressed="true"][data-status="out"] { background: var(--out-soft); color: var(--out); font-weight: 700; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 0 7px; border-radius: 999px; }
.badge.danger { background: var(--out-soft); color: var(--out); }
.badge.warn { background: var(--low-soft); color: var(--low); }
.badge.calm { background: var(--surface-2); color: var(--muted); }

/* 買い物リスト */
.check {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}
.check span { width: 26px; height: 26px; border: 2px solid var(--brand); border-radius: 8px; display: block; }
.skip { flex: none; width: 64px; min-height: 44px; font-size: 12px; line-height: 1.3; color: var(--muted); white-space: pre-line; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

/* ボタン */
.btn {
  min-height: 46px;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--surface-2);
  font-weight: 600;
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--out); background: transparent; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.link { color: var(--brand); font-weight: 600; min-height: 36px; font-size: 14px; }

/* 下のナビ */
.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: 1fr 1fr 84px 1fr 1fr;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
  color: var(--muted);
}
.nav-btn svg { width: 24px; height: 24px; }
.nav-btn[aria-current="page"] { color: var(--brand); font-weight: 700; }
.nav-count {
  position: absolute;
  top: 6px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--out);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
@media (prefers-color-scheme: dark) { .nav-count { color: #2a120d; } }
.mic {
  align-self: start;
  justify-self: center;
  width: 72px;
  height: 72px;
  margin-top: -22px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  border: 4px solid var(--bg);
}
.mic svg { width: 32px; height: 32px; }

/* 下から出るパネル */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(20, 18, 10, .45); }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
  max-width: 640px;
  margin: 0 auto;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .pulse { animation: none !important; } }
.sheet h2 { margin: 0 0 12px; font-size: 18px; overflow-wrap: anywhere; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
.field-title { font-size: 14px; font-weight: 600; }
.form label small { font-weight: 400; color: var(--muted); }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn { flex: 1; }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; width: auto; font-size: 15px; }

/* 音声 */
.voice-state { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.pulse {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  animation: pulse 1.2s ease-in-out infinite;
}
.pulse svg { width: 24px; height: 24px; }
.pulse.idle { animation: none; background: var(--surface-2); color: var(--muted); }
@keyframes pulse { 50% { transform: scale(1.12); opacity: .75; } }
.voice-text { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.voice-text.placeholder { font-weight: 400; color: var(--muted); }
.voice-input { display: flex; gap: 8px; margin-top: 12px; }
.voice-input .field { flex: 1; min-width: 0; }
.hints { margin: 12px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.hints button { padding: 6px 10px; min-height: 36px; font-size: 13px; background: var(--surface-2); border-radius: 999px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

.answer { display: grid; gap: 10px; padding: 4px 0 12px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.answer:last-of-type { border-bottom: 0; margin-bottom: 0; }
.answer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.answer-name { font-size: 18px; font-weight: 700; overflow-wrap: anywhere; }
.answer-line { font-size: 15px; }
.answer-line b { color: var(--muted); font-weight: 500; font-size: 13px; margin-right: 6px; }
.status-word { font-weight: 700; }
.status-word.plenty { color: var(--plenty); }
.status-word.low { color: var(--low); }
.status-word.out { color: var(--out); }

/* まとめて追加 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; background: var(--surface-2); font-size: 14px; }
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.sticky-bottom { position: sticky; bottom: calc(-20px - env(safe-area-inset-bottom)); background: var(--surface); padding: 12px 0 calc(env(safe-area-inset-bottom) + 4px); }

/* 結果の通知 */
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 26px);
  z-index: 30;
  max-width: 616px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.toast-text { flex: 1; min-width: 0; font-size: 14px; overflow-wrap: anywhere; }
.toast button { flex: none; min-height: 40px; padding: 0 10px; font-weight: 700; font-size: 14px; color: var(--bg); text-decoration: underline; text-underline-offset: 3px; }
