:root {
  --bg: #f6f1ea;
  --card: #fffdfa;
  --ink: #3b2a1e;
  --sub: #8a715e;
  --line: #e7dccf;
  --accent: #6b4a33;
  --accent-ink: #fff;
  --chip: #f1e8dd;
  --chip-on: #6b4a33;
  --tip: #fff4e0;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1714; --card: #2a221d; --ink: #f1e6da; --sub: #b49f8d; --line: #3d322b;
    --accent: #d39a6a; --accent-ink: #1d1714; --chip: #3a2f28; --chip-on: #d39a6a; --tip: #3b2f22;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
main { max-width: 560px; margin: 0 auto; padding: 0 16px 24px; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 1.2rem; margin-bottom: 8px; }
small { color: var(--sub); font-weight: normal; }
[hidden] { display: none !important; }

.appbar { padding: 14px 16px 6px; max-width: 560px; margin: 0 auto; }
.appbar h1 { font-size: 1.15rem; letter-spacing: .02em; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; min-width: 0;
}
fieldset.card legend { font-weight: 700; font-size: 1.05rem; padding: 0 4px; float: left; width: 100%; margin-bottom: 8px; }
fieldset.card legend + * { clear: both; }
details.card summary { font-weight: 700; cursor: pointer; }
.field-label { display: block; font-size: .85rem; color: var(--sub); margin: 14px 0 6px; font-weight: 600; }
.hint { color: var(--sub); font-size: .85rem; margin: 6px 0; }
.tip { background: var(--tip); border-radius: 12px; padding: 10px 12px; font-size: .92rem; }

.input {
  width: 100%; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 44px;
}
.input:focus-visible, .btn:focus-visible, .chip:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: .92rem; color: var(--ink); background: var(--chip);
  border: 1px solid transparent; border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--accent-ink); font-weight: 700; }
.chips-lg { display: grid; grid-template-columns: 1fr 1fr; }
.chips-lg .chip { border-radius: 14px; padding: 12px; text-align: left; font-size: .98rem; }
.chip .x { margin-left: 6px; opacity: .6; }
.stamps .chip { font-size: 1rem; }

.ai-card { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.ai-card p { margin: 4px 0; }
.scan-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.scan-btns .btn { font-size: .88rem; padding: 10px 6px; white-space: nowrap; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > div { flex: 1 1 140px; }
.seg { display: inline-flex; background: var(--chip); border-radius: 12px; padding: 3px; }
.seg-wide { display: flex; margin: 8px 0 12px; }
.seg button {
  font: inherit; border: 0; background: none; color: var(--ink); padding: 8px 16px; border-radius: 10px; cursor: pointer; flex: 1; min-height: 40px;
}
.seg button[aria-pressed="true"] { background: var(--card); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.stepper { display: inline-flex; align-items: center; gap: 4px; background: var(--chip); border-radius: 12px; padding: 3px; }
.stepper button { font: inherit; font-size: 1.2rem; width: 40px; height: 40px; border: 0; border-radius: 10px; background: var(--card); color: var(--ink); cursor: pointer; }
.stepper output { min-width: 40px; text-align: center; font-weight: 700; font-size: 1.1rem; }

.btn {
  font: inherit; font-weight: 700; border-radius: 14px; padding: 10px 16px; min-height: 44px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.btn small { display: block; font-size: .72rem; font-weight: normal; color: inherit; opacity: .8; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-ghost { background: var(--chip); border-color: transparent; }
.btn-text { background: none; border: 0; color: var(--sub); }
.btn-block { display: block; width: 100%; margin-top: 12px; }
.btn-lg { font-size: 1.08rem; padding: 14px 18px; }
.btn:disabled { opacity: .5; cursor: default; }

/* レシピ結果 */
.banner { background: var(--tip); border-radius: 12px; padding: 10px 12px; margin-top: 12px; font-size: .92rem; }
.recipe-head h2 { font-size: 1.25rem; }
.recipe-head p { margin: 4px 0 0; color: var(--sub); font-size: .9rem; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--chip); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.45rem; line-height: 1.2; }
.stat span { font-size: .8rem; color: var(--sub); }
.stat em { display: block; font-style: normal; font-size: .78rem; color: var(--sub); }
.steps { list-style: none; padding: 0; margin: 0; }
.steps li { display: grid; grid-template-columns: 56px 1fr; gap: 8px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps time { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.steps .add { color: var(--sub); font-size: .85rem; }
.prep { margin: 0; padding-left: 1.2em; }
.reasons { margin: 6px 0 0; padding-left: 1.2em; font-size: .9rem; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .btn-primary { grid-column: 1 / -1; }

/* タイマー */
.timer { text-align: center; padding-top: 16px; }
.timer-step-no { color: var(--sub); margin: 0; font-weight: 700; }
.timer-clock { font-size: clamp(4rem, 22vw, 7rem); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.timer-now { font-size: 1.3rem; font-weight: 700; min-height: 2em; }
.timer-weight { font-size: 2.6rem; font-weight: 800; color: var(--accent); min-height: 1.3em; }
.timer-next { color: var(--sub); min-height: 1.6em; }
.progress { height: 10px; background: var(--chip); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }
.timer-ctrl { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 8px; margin-top: 16px; }

/* 履歴 */
.view-title { margin: 16px 0 4px; }
.hist { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.hist-main { background: none; border: 0; padding: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.hist-main b { display: block; }
.hist-main span { font-size: .85rem; color: var(--sub); }
.hist-memo { grid-column: 1 / -1; font-size: .9rem; margin: 0; }
.hist-ctrl { display: flex; gap: 4px; }
.icon-btn { font: inherit; width: 40px; height: 40px; border-radius: 10px; border: 0; background: var(--chip); color: var(--ink); cursor: pointer; }
.empty { text-align: center; color: var(--sub); padding: 40px 0; }

/* 共有 */
.share-preview { width: 100%; border-radius: 12px; margin-top: 12px; border: 1px solid var(--line); }
.share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.share-actions .btn-primary { grid-column: 1 / -1; }

.tabbar {
  position: fixed; inset: auto 0 0 0; display: flex; justify-content: center; gap: 8px;
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding: 6px 16px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 0 1 160px; font: inherit; border: 0; background: none; color: var(--sub); border-radius: 12px; padding: 6px; cursor: pointer; font-size: 1.2rem;
}
.tabbar button span { display: block; font-size: .75rem; font-weight: 700; }
.tabbar button[aria-current="page"] { color: var(--accent); background: var(--chip); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: calc(100% - 32px);
}
