:root {
  color-scheme: light;
  --bg: var(--tg-theme-bg-color, #f3f5f7);
  --text: var(--tg-theme-text-color, #17202a);
  --hint: var(--tg-theme-hint-color, #667085);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --line: rgba(23, 32, 42, 0.08);
  --green: #1f9d55;
  --green-press: #187a42;
  --on-green: #ffffff;
  --warn-bg: #fff6d8;
  --warn: #8a6a12;
  --danger-bg: #fdecec;
  --danger: #b43333;
  --ok-bg: #e7f6ee;
  --ok: #146c3a;
  --radius: 16px;
  --keyboard: 0px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #0f141b);
  --text: var(--tg-theme-text-color, #f2f4f7);
  --hint: var(--tg-theme-hint-color, #98a2b3);
  --card: var(--tg-theme-secondary-bg-color, #1b2430);
  --line: rgba(255, 255, 255, 0.1);
  --warn-bg: #3a3218;
  --warn: #f5d98a;
  --danger-bg: #3a2222;
  --danger: #ffb4b4;
  --ok-bg: #163226;
  --ok: #b6ebc8;
}

* { box-sizing: border-box; }

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

button, textarea { font: inherit; color: inherit; }

#app { min-height: 100vh; }

.screen {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(108px + env(safe-area-inset-bottom) + var(--keyboard));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.brand { font-size: 13px; color: var(--hint); }

.linkish, .icon-button {
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 8px 0;
  cursor: pointer;
}

h1 { font-size: 28px; line-height: 1.15; margin: 0 0 8px; }

.lead, .hint { color: var(--hint); line-height: 1.4; }

.card, .banner, textarea, .user {
  background: var(--card);
  border-radius: var(--radius);
}

textarea {
  width: 100%;
  min-height: 280px;
  border: 0;
  resize: vertical;
  padding: 16px;
  line-height: 1.45;
  font-size: 16px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.editor-wrap {
  position: relative;
}

.suggest-box {
  position: fixed;
  z-index: 40;
  max-height: 220px;
  overflow: auto;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), inset 0 0 0 1px var(--line);
}

.suggest-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--card);
}

.suggest-toolbar-label {
  font-size: 12px;
  color: var(--hint);
}

.suggest-close {
  border: 0;
  background: var(--bg);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
}

.suggest-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  cursor: pointer;
}

.suggest-item:last-child { border-bottom: 0; }
.suggest-item:hover,
.suggest-item.active {
  background: color-mix(in srgb, var(--green) 12%, var(--card));
}

.chip.selected {
  box-shadow: inset 0 0 0 2px var(--green);
}

.similar-box {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--warn-bg);
  color: var(--warn);
}

.similar-item {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  background: var(--card);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
}

.row { display: flex; gap: 8px; margin: 12px 0; }

.chip {
  border: 0;
  background: var(--card);
  border-radius: 999px;
  padding: 10px 14px;
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
}

.banner { padding: 14px 16px; margin: 12px 0; line-height: 1.4; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.danger { background: var(--danger-bg); color: var(--danger); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }

.save-status {
  font-size: 12px;
  color: var(--hint);
  min-height: 1.2em;
  margin: 6px 2px 0;
}
.save-status.saving,
.save-status.dirty { color: var(--warn); }
.save-status.saved { color: var(--ok); }
.save-status.error,
.save-status.conflict { color: var(--danger); }

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}

.footer-inner { max-width: 520px; margin: 0 auto; }

.primary, .secondary {
  width: 100%;
  border: 0;
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
}

.primary { background: var(--green); color: var(--on-green); font-weight: 650; }
.primary:active { background: var(--green-press); }
.primary:disabled { opacity: 0.45; cursor: default; }
.secondary { background: transparent; color: var(--hint); }
.stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.center { text-align: center; padding-top: 18vh; }
.mark {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 32px;
  background: var(--card);
}
.mark.lock { background: var(--danger-bg); }
.mark.wait { background: var(--warn-bg); }

.user {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: inset 0 0 0 1px var(--line);
}

.user-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.user-actions button {
  border: 0;
  border-radius: 999px;
  padding: 8px 10px;
  background: var(--bg);
  cursor: pointer;
}

.status { font-size: 12px; color: var(--hint); }
.actions-only { margin-top: 8px; }

.dish-list { display: grid; gap: 8px; margin: 12px 0; }
.dish-row {
  width: 100%;
  text-align: left;
  border: 0;
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
}
.dish-row.muted { color: var(--hint); cursor: default; }
.tag {
  font-size: 12px;
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
}
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }

.form { display: grid; gap: 12px; }
.field-wrap { display: grid; gap: 6px; font-size: 14px; color: var(--hint); }
.field {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text);
  font: inherit;
}

.covers {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 16px;
}
.cover {
  border: 0;
  background: var(--card);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: inset 0 0 0 1px var(--line);
  text-align: left;
  cursor: pointer;
}
.cover.selected { box-shadow: inset 0 0 0 2px var(--green); }

.toggle {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 8px 0 16px;
}

.steps { list-style: none; padding: 0; margin: 24px 0; display: grid; gap: 12px; }
.steps li {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--card);
  color: var(--hint);
}
.steps li.done { color: var(--ok); background: var(--ok-bg); }
.steps li.active { color: var(--text); box-shadow: inset 0 0 0 1px var(--green); }

.mark.ok { background: var(--ok-bg); color: var(--ok); }
.mark.danger { background: var(--danger-bg); color: var(--danger); }
