/* ==========================================================================
   こんだて自動作成 — モバイルファーストのスタイル
   ========================================================================== */
:root {
  --bg: #fffaf5;
  --surface: #ffffff;
  --surface-2: #fff3e8;
  --border: #f0e2d4;
  --text: #2b2220;
  --text-muted: #8a7a72;
  --brand: #f97316;
  --brand-dark: #e15a05;
  --brand-soft: #ffedd5;
  --protein: #ef5da8;
  --fat: #f5a524;
  --carb: #3fa7d6;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(43, 34, 32, .06), 0 8px 24px rgba(43, 34, 32, .06);
  --tabbar-h: 60px;
  --cta-h: 68px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17120f;
    --surface: #221b17;
    --surface-2: #2c231d;
    --border: #3a2e26;
    --text: #f6ece5;
    --text-muted: #b0a096;
    --brand-soft: #43291a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
               "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

button { font: inherit; color: inherit; cursor: pointer; }

h1, h2, h3 { margin: 0; line-height: 1.35; }

/* --- App bar ------------------------------------------------------------ */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: linear-gradient(135deg, var(--brand), #fb923c);
  color: #fff;
  box-shadow: 0 2px 12px rgba(249, 115, 22, .25);
}
.appbar h1 { font-size: 18px; font-weight: 800; letter-spacing: .02em; }
.appbar h1 span { font-weight: 500; opacity: .85; font-size: 14px; margin-left: 4px; }

.servings {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px;
  background: rgba(255, 255, 255, .22);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  min-height: 36px;
}
.servings svg { width: 16px; height: 16px; fill: currentColor; }

/* --- Layout ------------------------------------------------------------- */
#main {
  padding: 16px 16px calc(var(--tabbar-h) + var(--cta-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 720px;
  margin: 0 auto;
}
.view { display: block; }
.view[hidden] { display: none; }

.section-head { margin-bottom: 12px; }
h2 { font-size: 16px; font-weight: 700; }
.hint { margin: 4px 0 0; color: var(--text-muted); font-size: 12.5px; }
.empty {
  margin: 16px 0;
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* --- 食材ピッカー -------------------------------------------------------- */
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 14px;
  box-shadow: var(--shadow);
}
.search svg { width: 18px; height: 18px; fill: var(--text-muted); flex: none; }
.search input {
  flex: 1;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 16px; /* iOS のズーム防止 */
  padding: 12px 0;
  min-width: 0;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 4px;
  margin: 0 -16px;
  padding-inline: 16px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  min-height: 34px;
}
.chip[aria-selected="true"] {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.ing {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px;
  min-height: 56px;
}
.ing strong { font-size: 13.5px; font-weight: 700; }
.ing small { color: var(--text-muted); font-size: 11px; }
.ing.is-selected { border-color: var(--brand); background: var(--brand-soft); }

/* --- 選択済みリスト ------------------------------------------------------ */
.selected { margin-top: 24px; }
.badge {
  display: inline-block;
  min-width: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.selected-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.item-name { font-weight: 700; font-size: 14px; }
.item-unit { color: var(--text-muted); font-size: 11.5px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 19px;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
}
.stepper button:active { transform: scale(.94); }
.amount {
  width: 68px;
  text-align: right;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}
.unit-label { font-size: 12px; color: var(--text-muted); width: 26px; }
.remove {
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 12px;
  padding: 6px;
  min-height: 34px;
}
.quick { display: flex; gap: 6px; flex-wrap: wrap; grid-column: 1 / -1; }
.quick button {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  min-height: 30px;
}

/* --- CTA / タブバー ------------------------------------------------------ */
.cta-bar[hidden] { display: none; }
.cta-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  z-index: 15;
  padding: 10px 16px;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  display: flex;
  justify-content: center;
}
.cta {
  width: 100%;
  max-width: 688px;
  border: 0;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  padding: 15px 16px;
  box-shadow: 0 6px 18px rgba(249, 115, 22, .35);
  min-height: 48px;
}
.cta:disabled { background: var(--border); color: var(--text-muted); box-shadow: none; }
.cta:active:not(:disabled) { background: var(--brand-dark); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 16;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--tabbar-h);
  font-size: 11px;
  font-weight: 700;
}
.tab svg { width: 22px; height: 22px; fill: currentColor; }
.tab.is-active { color: var(--brand); }

/* --- 提案カード ---------------------------------------------------------- */
.notice {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.card h3 { font-size: 17px; font-weight: 800; }
.card-desc { margin: 6px 0 0; font-size: 13px; color: var(--text-muted); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.meta span {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.rate {
  flex: none;
  text-align: center;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-radius: 12px;
  padding: 6px 10px;
  font-weight: 800;
  font-size: 18px;
  line-height: 1.1;
}
.rate small { display: block; font-size: 10px; font-weight: 700; opacity: .8; }

/* カロリー & PFC */
.nutri {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  align-items: center;
  margin-top: 14px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 14px;
}
.donut { position: relative; width: 96px; height: 96px; }
.donut svg { transform: rotate(-90deg); width: 96px; height: 96px; }
.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}
.donut-center b { font-size: 19px; font-weight: 800; line-height: 1; }
.donut-center small { font-size: 10px; color: var(--text-muted); }

.pfc-rows { display: grid; gap: 8px; }
.pfc-row { display: grid; grid-template-columns: 74px 1fr auto; gap: 8px; align-items: center; font-size: 11.5px; }
.pfc-row i { font-style: normal; display: inline-flex; align-items: center; gap: 5px; font-weight: 700; white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.bar { height: 8px; border-radius: 999px; background: rgba(140, 120, 110, .18); overflow: hidden; position: relative; }
.bar > span { display: block; height: 100%; border-radius: 999px; }
.bar > em {
  position: absolute;
  top: -3px;
  bottom: -3px;
  border-left: 1px dashed var(--text-muted);
  border-right: 1px dashed var(--text-muted);
  opacity: .55;
}
.pfc-val { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.pfc-comment { margin: 10px 0 0; font-size: 12px; color: var(--warn); }
.pfc-comment.is-ok { color: var(--ok); }

.nutrients { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 6px; margin-top: 12px; }
.nutrients div {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}
.nutrients b { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.nutrients small { font-size: 10px; color: var(--text-muted); }

.ing-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pill {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.pill.enough { background: rgba(22, 163, 74, .12); color: var(--ok); }
.pill.short { background: rgba(217, 119, 6, .14); color: var(--warn); }
.pill.missing { background: rgba(220, 38, 38, .1); color: var(--danger); }
.pill.staple { background: var(--surface-2); color: var(--text-muted); }
.pill.optional { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }
.list-label { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-top: 12px; }

details { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
summary { font-size: 13px; font-weight: 700; cursor: pointer; list-style: none; color: var(--brand-dark); }
summary::-webkit-details-marker { display: none; }
summary::after { content: " ▾"; }
details[open] summary::after { content: " ▴"; }
ol.steps { margin: 10px 0 0; padding-left: 20px; font-size: 13px; display: grid; gap: 6px; }

.cooked {
  width: 100%;
  margin-top: 14px;
  border: 1px solid var(--brand);
  background: transparent;
  color: var(--brand-dark);
  border-radius: 12px;
  padding: 12px;
  font-weight: 800;
  min-height: 46px;
}
.cooked:active { background: var(--brand-soft); }
.cooked[disabled] { opacity: .55; border-color: var(--border); color: var(--text-muted); }

/* --- 履歴 --------------------------------------------------------------- */
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.history-item b { font-size: 14px; }
.history-item small { display: block; color: var(--text-muted); font-size: 12px; }
.history-item .blocked { color: var(--warn); font-weight: 700; }

/* --- Loading / toast ----------------------------------------------------- */
.skeleton {
  height: 128px;
  border-radius: 20px;
  margin-bottom: 14px;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--cta-h) + env(safe-area-inset-bottom) + 12px);
  transform: translate(-50%, 16px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 40;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .appbar h1 { font-size: 20px; }
}
