:root {
  --bg: #fbf7f2;
  --card: #ffffff;
  --text: #2f2a26;
  --muted: #8a8079;
  --border: #eadfd4;
  --accent: #e8773a;
  --accent-soft: #fde8da;
  --danger: #c9453b;
  --meat: #e36b5b;
  --fish: #3f8fd2;
  --soy: #b58a2e;
  --egg: #e0b400;
  --veg: #4a9e5c;
  --other: #8a8079;
  --tabbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a18;
    --card: #282523;
    --text: #efe9e4;
    --muted: #a39a92;
    --border: #3a3532;
    --accent-soft: #4a3325;
  }
}

* { 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", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  border-bottom: 1px solid var(--border);
}
.app-header h1 { margin: 0; font-size: 20px; }

main { padding: 12px 16px; max-width: 640px; margin: 0 auto; }

h2 { font-size: 16px; margin: 20px 0 8px; color: var(--muted); }
h3 { font-size: 15px; margin: 0 0 8px; }

.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.theme-card p { margin: 6px 0; font-weight: 600; }
.date-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; color: var(--muted); }

.balance { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.balance-label { font-size: 13px; color: var(--muted); }

.dish-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.dish-head strong { font-size: 16px; }

.chip {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--other);
}
.g-meat { background: var(--meat); }
.g-fish { background: var(--fish); }
.g-soy { background: var(--soy); }
.g-egg { background: var(--egg); }
.g-veg { background: var(--veg); }
.g-other { background: var(--other); }

.badges { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.badge {
  font-size: 12px;
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 1px 7px;
}

.hint { font-size: 13px; color: var(--muted); margin: 4px 0 6px; }
.memo { font-size: 14px; white-space: pre-wrap; margin: 4px 0 8px; }
.reaction { font-size: 20px; }
.empty { color: var(--muted); text-align: center; padding: 16px 0; }
.note { font-size: 13px; color: var(--muted); margin: 6px 0; }

input, select, textarea {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  width: 100%;
}
input[type="checkbox"] { width: auto; }
input[type="date"] { width: auto; }

.kw { margin: 4px 0 8px; font-size: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 15px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 14px;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.small { font-size: 14px; padding: 6px 10px; }
.btn.wide { width: 100%; margin: 12px 0; padding: 12px; }

.site-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.site-btns .btn { padding: 8px 4px; font-size: 14px; font-weight: 600; }
.site-cookpad { color: #d86f16; }
.site-kurashiru { color: #d2394a; }
.site-nadia { color: #3a9a6c; }

.eat { margin-top: 8px; width: 100%; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 120px; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters input[type="search"] { grid-column: 1 / -1; }

.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; }

.stock-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.stock-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 14px;
}
.stock-item.on { background: var(--accent-soft); border-color: var(--accent); }
.stock-item input { margin: 0; }
#stock-new { flex: 1; }

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.history-type { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.history-name { flex: 1; }
.icon-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16px;
  padding: 4px 8px;
  cursor: pointer;
}

dialog {
  border: none;
  border-radius: 16px;
  padding: 16px;
  width: min(92vw, 480px);
  background: var(--card);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
dialog label input, dialog label select, dialog label textarea { margin-top: 2px; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tabbar button {
  height: var(--tabbar-h);
  border: none;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  -webkit-tap-highlight-color: transparent;
}
.tabbar button span { font-size: 22px; line-height: 1; }
.tabbar button.active { color: var(--accent); font-weight: 700; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(40, 36, 33, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  z-index: 30;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
