:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --ink: #1c1c1e;
  --ink-2: #8e8e93;
  --line: rgba(60, 60, 67, 0.12);
  --brand: #ff7043;
  --brand-2: #ff9a5a;
  --chef: #ff7043;
  --foodie: #34a0ff;
  --green: #34c759;
  --red: #ff3b30;
  --amber: #ff9f0a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elev: #1c1c1e;
    --ink: #ffffff;
    --ink-2: #98989f;
    --line: rgba(84, 84, 88, 0.4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC",
    "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#app { display: flex; flex-direction: column; height: 100dvh; }

.hidden { display: none !important; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 6px) 12px 8px;
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(20px);
  -webkit-backdrop-filter: saturate(1.6) blur(20px);
  border-bottom: 0.5px solid var(--line);
}
.top-title { font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.icon-btn {
  border: none; background: transparent; color: var(--brand);
  font-size: 24px; line-height: 1; width: 40px; height: 34px;
  border-radius: 10px;
}
.icon-btn:active { background: var(--line); }

/* ---------------- main view ---------------- */
#view {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(var(--tabbar-h) + var(--safe-bot) + 20px);
}
#view.no-tab { padding-bottom: calc(var(--safe-bot) + 24px); }

/* ---------------- tab bar ---------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(var(--safe-bot));
  height: calc(var(--tabbar-h) + var(--safe-bot));
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(20px);
  -webkit-backdrop-filter: saturate(1.6) blur(20px);
  border-top: 0.5px solid var(--line);
}
.tab {
  border: none; background: transparent; color: var(--ink-2);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 10px; font-weight: 600; padding-top: 6px;
}
.tab .ti { font-size: 22px; line-height: 1; }
.tab.active { color: var(--brand); }

/* ---------------- generic ---------------- */
.hero {
  text-align: center; padding: 26px 10px 10px;
}
.hero .logo { font-size: 60px; }
.hero h1 { margin: 8px 0 4px; font-size: 26px; font-weight: 800; }
.hero p { margin: 0; color: var(--ink-2); font-size: 14px; }

.section-title {
  font-size: 13px; color: var(--ink-2); font-weight: 600;
  margin: 18px 4px 8px; text-transform: none; letter-spacing: .3px;
}

.card {
  background: var(--bg-elev); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.card + .card { margin-top: 10px; }

.list { background: var(--bg-elev); border-radius: 16px; overflow: hidden; }
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 0.5px solid var(--line);
}
.list-row:last-child { border-bottom: none; }
.list-row:active { background: var(--line); }
.list-row .lead { font-size: 26px; width: 34px; text-align: center; }
.list-row .body { flex: 1; min-width: 0; }
.list-row .body .t { font-size: 16px; font-weight: 600; }
.list-row .body .s { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.list-row .trail { color: var(--ink-2); font-size: 14px; }

/* inputs */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-2); margin: 0 4px 6px; }
.input, textarea.input, select.input {
  width: 100%; border: none; outline: none;
  background: var(--bg-elev); color: var(--ink);
  border-radius: 12px; padding: 14px 16px; font-size: 16px;
  border: 0.5px solid var(--line);
}
textarea.input { min-height: 72px; resize: none; }

/* role picker */
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: none; background: transparent; color: var(--ink);
  padding: 9px 0; border-radius: 9px; font-size: 14px; font-weight: 600;
}
.seg button.on { background: var(--bg-elev); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* buttons */
.btn {
  width: 100%; border: none; border-radius: 14px; padding: 15px;
  font-size: 16px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.btn:active { filter: brightness(.94); }
.btn.secondary { background: var(--bg-elev); color: var(--brand); border: 0.5px solid var(--line); }
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: var(--red); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn-row .btn { margin: 0; }

/* dish grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.dish {
  background: var(--bg-elev); border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 6px; position: relative;
  border: 0.5px solid var(--line);
}
.dish:active { transform: scale(.98); }
.dish .em { font-size: 40px; }
.dish .nm { font-size: 15px; font-weight: 700; }
.dish .de { font-size: 11.5px; color: var(--ink-2); }
.dish .meta { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.pill {
  font-size: 10px; padding: 2px 7px; border-radius: 20px;
  background: var(--line); color: var(--ink-2); font-weight: 600;
}
.pill.ai { background: rgba(52,160,255,.15); color: var(--foodie); }
.dish .plus {
  position: absolute; top: 10px; right: 10px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand); color: #fff; border: none;
  font-size: 17px; line-height: 26px; text-align: center;
}
.dish .plus.added { background: var(--green); }

/* member chips */
.member {
  display: flex; align-items: center; gap: 10px; padding: 10px 4px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; color: #fff; flex: none;
}
.avatar.chef { background: var(--chef); }
.avatar.foodie { background: var(--foodie); }
.member .minfo { flex: 1; }
.member .minfo .mn { font-weight: 600; font-size: 15px; }
.member .minfo .mp { font-size: 12px; color: var(--ink-2); }
.role-tag { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.role-tag.chef { background: rgba(255,112,67,.15); color: var(--chef); }
.role-tag.foodie { background: rgba(52,160,255,.15); color: var(--foodie); }

/* order card */
.order {
  background: var(--bg-elev); border-radius: 16px; padding: 14px 16px;
  border: 0.5px solid var(--line);
}
.order + .order { margin-top: 10px; }
.order .oh { display: flex; align-items: center; gap: 10px; }
.order .oh .oe { font-size: 32px; }
.order .oh .ot { flex: 1; }
.order .oh .ot .on { font-size: 16px; font-weight: 700; }
.order .oh .ot .os { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.status {
  font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 20px;
}
.status.pending { background: rgba(255,159,10,.16); color: var(--amber); }
.status.cooking { background: rgba(255,112,67,.16); color: var(--brand); }
.status.done { background: rgba(52,199,89,.16); color: var(--green); }
.status.cancelled { background: var(--line); color: var(--ink-2); }
.order .note { font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.order .oactions { display: flex; gap: 8px; margin-top: 12px; }
.order .oactions .btn { padding: 11px; font-size: 14px; }

/* empty state */
.empty { text-align: center; padding: 60px 20px; color: var(--ink-2); }
.empty .e-em { font-size: 54px; }
.empty p { margin: 12px 0 0; font-size: 14px; }

/* ---------------- sheet ---------------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 92dvh; background: var(--bg);
  border-radius: 20px 20px 0 0; overflow: hidden;
  display: flex; flex-direction: column;
  animation: sheetUp .28s cubic-bezier(.2,.8,.2,1);
  padding-bottom: var(--safe-bot);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-grip {
  width: 38px; height: 5px; border-radius: 3px; background: var(--line);
  margin: 8px auto 4px; flex: none;
}
#sheetBody { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 6px 18px 20px; }

/* recipe */
.recipe-hero { text-align: center; padding: 6px 0 14px; }
.recipe-hero .em { font-size: 56px; }
.recipe-hero h2 { margin: 6px 0 4px; font-size: 22px; }
.recipe-meta { display: flex; justify-content: center; gap: 14px; color: var(--ink-2); font-size: 13px; }
.recipe-meta b { color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.chip {
  background: var(--bg-elev); border: 0.5px solid var(--line);
  border-radius: 12px; padding: 8px 10px; font-size: 13px;
  display: flex; align-items: center; gap: 6px;
}
.chip .ca { color: var(--ink-2); font-size: 12px; }

.step {
  display: flex; gap: 12px; padding: 14px 0; border-bottom: 0.5px solid var(--line);
}
.step:last-child { border-bottom: none; }
.step .sn {
  width: 46px; height: 46px; flex: none; border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  display: grid; place-items: center; font-size: 24px; position: relative;
}
.step .sn .idx {
  position: absolute; top: -6px; left: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink); color: var(--bg-elev);
  font-size: 11px; font-weight: 800; display: grid; place-items: center;
}
.step .sc { flex: 1; }
.step .sc .st { font-weight: 700; font-size: 15px; }
.step .sc .sd { font-size: 14px; margin-top: 3px; line-height: 1.5; }
.step .sc .sp {
  font-size: 12.5px; color: var(--brand); margin-top: 6px;
  background: rgba(255,112,67,.09); border-radius: 8px; padding: 6px 9px;
}
.warn {
  background: rgba(255,59,48,.1); color: var(--red);
  border-radius: 12px; padding: 10px 12px; font-size: 12.5px; margin-top: 4px;
}
.warn div { margin: 2px 0; }

.loading { text-align: center; padding: 40px 0; color: var(--ink-2); }
.spinner {
  width: 30px; height: 30px; margin: 0 auto 14px;
  border: 3px solid var(--line); border-top-color: var(--brand);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bot) + 20px);
  transform: translateX(-50%);
  background: rgba(0,0,0,.85); color: #fff; padding: 11px 18px;
  border-radius: 22px; font-size: 14px; z-index: 100; max-width: 82%;
  text-align: center; backdrop-filter: blur(8px);
}

.mini { font-size: 12px; color: var(--ink-2); text-align: center; margin-top: 14px; line-height: 1.6; }
.add-inline { display: flex; gap: 8px; margin-top: 10px; }
.add-inline .input { flex: 1; }
.add-inline .btn { width: auto; padding: 12px 16px; white-space: nowrap; }
