/* 小厨 v0.1.0 — warm terracotta + cream. No green primary. */
:root {
  --terra: #B44A32;
  --terra-deep: #8F3A28;
  --terra-soft: #C56A54;
  --cream: #F8F1EA;
  --cream-deep: #F3E6D8;
  --surface: #FBF7F3;
  --card: #FFFCF9;
  --ink: #1F1612;
  --muted: #6A574E;
  --line: #E8D9CC;
  --pri: #B44A32;
  --pri-ink: #FFFCF9;
  --acc: #F3E4DC;
  --acc-ink: #8F3A28;
  --amber: #C4843A;
  --danger: #8F3A28;
  --shadow: 0 1px 2px rgba(31, 22, 18, .06), 0 8px 24px -10px rgba(180, 74, 50, .18);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --header-h: 56px;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
html { height: calc(var(--vh, 1vh) * 100); }
body {
  font-family: -apple-system, "MiSans", "HarmonyOS Sans SC", "PingFang SC",
    "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: #EFE4D8;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  position: fixed; inset: 0; width: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { appearance: none; background: none; border: 0; padding: 0; cursor: pointer; }
img { max-width: 100%; display: block; }

#app {
  max-width: 430px;
  margin: 0 auto;
  height: 100%;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 0 1px rgba(180, 74, 50, .08), 0 24px 60px -24px rgba(31, 22, 18, .35);
  overflow: hidden;
}

/* Splash — SpeakUp/SayIt structure, terracotta instead of jade/indigo */
#splash {
  position: absolute; inset: 0; z-index: 80;
  background: var(--terra);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  color: var(--pri-ink);
  transition: opacity .4s ease;
}
#splash img { width: 120px; height: 120px; border-radius: 28px; box-shadow: 0 8px 28px -8px rgba(31, 22, 18, .35); }
#splash .splash-name { font-size: 30px; font-weight: 700; letter-spacing: .04em; }
#splash .splash-ver { font-size: 13px; font-weight: 600; letter-spacing: .08em; opacity: .9; }

/* Header */
.topbar {
  display: flex; align-items: center; gap: 8px;
  min-height: var(--header-h);
  padding: calc(8px + var(--safe-top)) 10px 8px 12px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(1.3) blur(14px);
  -webkit-backdrop-filter: saturate(1.3) blur(14px);
  box-shadow: 0 1px 0 var(--line), 0 6px 18px -12px rgba(31, 22, 18, .25);
  z-index: 5; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: -.02em; min-width: 0; flex: 1; }
.brand img { width: 32px; height: 32px; border-radius: 8px; box-shadow: 0 3px 8px -2px color-mix(in srgb, var(--terra) 45%, transparent); }
.brand .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand .sub { display: block; font-size: 10px; font-weight: 600; color: var(--muted); letter-spacing: .02em; margin-top: -2px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.lang-switch {
  display: inline-flex; background: var(--acc); border-radius: 999px; padding: 3px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--terra) 10%, transparent);
}
.lang-switch button {
  min-width: 44px; min-height: 36px; padding: 0 10px; border-radius: 999px;
  font-size: 13px; font-weight: 700; color: var(--acc-ink);
}
.lang-switch button.on { background: var(--terra); color: var(--pri-ink); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--terra);
}
.icon-btn:active { background: var(--acc); }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.version-chip {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  opacity: 0.75;
  letter-spacing: 0.02em;
  user-select: none;
  pointer-events: none;
  white-space: nowrap;
  padding: 2px 4px;
}

/* Main + nav */
#main {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(16px + var(--nav-h) + var(--safe-bot));
}
#main.no-nav { padding-bottom: calc(16px + var(--safe-bot)); }
#main.cook-main { padding: 0; overflow: hidden; display: flex; flex-direction: column; }

.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-bot));
  background: var(--card);
  box-shadow: 0 -1px 0 var(--line), 0 -8px 24px -14px rgba(31, 22, 18, .28);
}
.tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 52px; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tabbar button svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--terra); }
.tabbar button.on svg { background: color-mix(in srgb, var(--terra) 13%, transparent); border-radius: 10px; padding: 2px; box-sizing: content-box; }

/* display:flex on these bars would otherwise override the hidden attribute
   and leave the tab bar painted over the cook-step buttons. */
.topbar[hidden],
.tabbar[hidden],
#app.cook-mode .tabbar,
#app.cook-mode .topbar {
  display: none !important;
}


/* Library */
.search {
  width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 16px; background: var(--card); margin-bottom: 12px;
}
.search:focus { outline: 2px solid color-mix(in srgb, var(--terra) 45%, transparent); border-color: var(--terra); }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 6px; -webkit-overflow-scrolling: touch; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); min-height: 36px;
}
.chip.on { background: var(--terra); color: var(--pri-ink); border-color: transparent; }

.grid { display: flex; flex-direction: column; gap: 14px; }
.card-recipe {
  display: block; width: 100%; text-align: left; background: var(--card);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}
.card-recipe .hero {
  width: 100%; aspect-ratio: 16/10; object-fit: cover; background: var(--cream-deep);
}
.card-recipe .body { padding: 10px 12px 12px; }
.card-recipe h3 { margin: 0 0 4px; font-size: 17px; font-weight: 700; }
.card-recipe .meta { display: flex; gap: 10px; color: var(--muted); font-size: 12px; font-weight: 600; }
.card-recipe .tags { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 600; color: var(--acc-ink); background: var(--acc); padding: 2px 8px; border-radius: 999px; }

/* Recipe detail */
.hero-lg { width: 100%; aspect-ratio: 16/10; object-fit: cover; border-radius: var(--radius); background: var(--cream-deep); box-shadow: var(--shadow); }
.page-title { font-size: 24px; font-weight: 800; margin: 12px 0 4px; letter-spacing: -.02em; }
.lead { color: var(--muted); margin: 0 0 12px; line-height: 1.45; font-size: 15px; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pill { background: var(--acc); color: var(--acc-ink); font-weight: 700; font-size: 12px; padding: 6px 10px; border-radius: 999px; }

.section-h { font-size: 15px; font-weight: 800; margin: 18px 0 8px; }
.ing-list, .step-list { list-style: none; margin: 0; padding: 0; }
.ing-list li, .shop-item {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px;
}
.ing-list .qty { color: var(--muted); font-weight: 600; white-space: nowrap; }
.step-list li { display: flex; gap: 10px; padding: 10px 0; }
.step-num {
  flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--terra); color: var(--pri-ink);
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800;
}
.step-body { flex: 1; min-width: 0; }
.step-body p { margin: 0; line-height: 1.5; }
.step-thumb { width: 100%; aspect-ratio: 16/10; object-fit: cover; border-radius: 12px; margin-top: 8px; background: var(--cream-deep); }

.actions { display: flex; flex-direction: column; gap: 8px; margin: 16px 0 8px; }
.btn {
  min-height: 48px; border-radius: 16px; padding: 10px 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 1px 2px rgba(31, 22, 18, .06);
}
.btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn-pri {
  background: linear-gradient(180deg, color-mix(in srgb, var(--terra) 82%, #fff) 0%, var(--terra) 55%, color-mix(in srgb, var(--terra) 88%, #000) 100%);
  color: var(--pri-ink);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28), 0 6px 16px -6px color-mix(in srgb, var(--terra) 70%, transparent);
}
.btn-sec { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: var(--terra); box-shadow: none; }
.btn[disabled] { opacity: .5; }
.row-btns { display: flex; gap: 8px; }
.row-btns .btn { flex: 1; }

.read-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--acc); border-radius: 16px; padding: 8px;
  color: var(--acc-ink);
}
.read-bar .status { flex: 1; font-size: 13px; font-weight: 600; }

/* Cooking */
.cook-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--cream); }
.cook-head {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) 10px 8px;
  flex-shrink: 0;
}
.cook-head .title { flex: 1; font-weight: 800; font-size: 15px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer-pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 10px; border-radius: 999px;
  background: var(--acc); color: var(--acc-ink); font-weight: 800; font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.timer-pill.running { background: var(--terra); color: var(--pri-ink); }
.timer-pill.warn { background: var(--amber); color: #fff; }
.timer-pill.zero { background: var(--terra-deep); color: var(--pri-ink); }

.cook-body { flex: 1; overflow: auto; padding: 0 16px 12px; min-height: 0; }
.step-progress { color: var(--muted); font-weight: 700; font-size: 13px; margin: 0 0 8px; }
.cook-photo, .cook-photo-fallback {
  width: 100%; aspect-ratio: 16/10; object-fit: cover;
  border-radius: var(--radius); background: var(--cream-deep); margin-bottom: 12px;
}
.cook-photo-fallback {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-weight: 600; font-size: 14px; text-align: center; padding: 16px;
}
.cook-text { font-size: 22px; font-weight: 650; line-height: 1.4; margin: 0 0 12px; }
.step-ings { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.step-ings .label { width: 100%; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }

.voice-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.switch {
  width: 52px; height: 32px; border-radius: 999px; background: var(--line); position: relative; flex-shrink: 0;
}
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(31,22,18,.25); transition: transform .18s ease;
}
.switch.on { background: var(--terra); }
.switch.on .knob { transform: translateX(20px); }
.voice-note { font-size: 12px; color: var(--muted); margin: 0 0 8px; line-height: 1.4; }

.cook-footer {
  flex-shrink: 0; display: flex; gap: 10px;
  padding: 10px 16px calc(16px + var(--safe-bot));
  background: var(--cream);
  position: relative;
  z-index: 7;
}
.cook-footer .btn { flex: 1; min-height: 64px; font-size: 18px; border-radius: 18px; }
.cook-footer .btn-sec { flex: 0.85; }

/* Timer page */
.timer-face {
  text-align: center; padding: 18px 8px 10px;
  font-size: 64px; font-weight: 800; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.custom-row { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.custom-row input {
  width: 72px; min-height: 44px; text-align: center; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); font-weight: 700; font-size: 18px;
}

/* Fridge / shop / kcal */
.ing-grid { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.ing-toggle {
  padding: 8px 12px; min-height: 40px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; font-size: 14px;
}
.ing-toggle.on { background: var(--terra); color: var(--pri-ink); border-color: transparent; }
.match { font-size: 12px; font-weight: 700; color: var(--acc-ink); }

.shop-item label { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.shop-item input { width: 22px; height: 22px; accent-color: var(--terra); }
.shop-item.checked span { text-decoration: line-through; color: var(--muted); }
.kcal-total { font-size: 40px; font-weight: 800; letter-spacing: -.03em; margin: 4px 0 2px; }
.kcal-unit { color: var(--muted); font-size: 14px; font-weight: 700; }
.log-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 8px; }

.empty { text-align: center; color: var(--muted); padding: 36px 20px; line-height: 1.5; font-weight: 600; }

.settings-card {
  background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
  margin-bottom: 12px; border: 1px solid color-mix(in srgb, var(--line) 80%, transparent);
}
.settings-card h3 { margin: 0 0 8px; font-size: 16px; }
.settings-card p { margin: 0 0 8px; color: var(--muted); line-height: 1.5; font-size: 14px; }
.mono { font-variant-numeric: tabular-nums; }

#toast {
  position: absolute; left: 50%; bottom: calc(var(--nav-h) + 16px + var(--safe-bot));
  transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 40; white-space: nowrap; max-width: 90%;
  overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#app.cook-mode #toast { bottom: calc(88px + var(--safe-bot)); }

.back-row { margin: -4px 0 8px; }
