:root {
  --bg: #f6f2ec;
  --card: #ffffff;
  --ink: #2c2438;
  --muted: #8b8296;
  --accent: #7c5cbf;
  --accent-soft: #ede7fa;
  --good: #3e9d63;
  --warn: #e0a03c;
  --bad: #d05b5b;
  --line: #e8e1d8;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(44, 36, 56, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- PIN ---------- */
.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.pin-card {
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 36px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.pin-emoji { font-size: 56px; }
.pin-card h1 { font-size: 24px; }
.pin-card p { color: var(--muted); }
#pin-input {
  font-size: 28px;
  text-align: center;
  letter-spacing: 12px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  width: 100%;
  outline: none;
}
#pin-input:focus { border-color: var(--accent); }
.pin-error { color: var(--bad); font-weight: 600; }

/* ---------- layout ---------- */
#main {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.header-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 8px;
}
main#view {
  flex: 1;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 88px);
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

/* ---------- who picker ---------- */
.who-picker {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  scrollbar-width: none;
}
.who-picker::-webkit-scrollbar { display: none; }
.who-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--card);
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.who-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  border: none;
  background: none;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.tab span { font-size: 22px; }
.tab.active { color: var(--accent); }

/* ---------- shared bits ---------- */
button { font-family: inherit; cursor: pointer; }
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 700;
  background: var(--card);
  border: 2px solid var(--line);
  color: var(--ink);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:active { transform: scale(0.97); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 {
  font-size: 17px;
  margin-bottom: 12px;
}
.section-note { color: var(--muted); font-size: 13px; margin-top: 6px; }

input[type="text"], input[type="date"], select, textarea {
  font-family: inherit;
  font-size: 16px;
  padding: 11px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  width: 100%;
  outline: none;
  appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.row { display: flex; gap: 8px; }
.row > * { min-width: 0; }
.grow { flex: 1; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 12px;
  font-size: 15px;
}
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------- meal chips ---------- */
.chip-wrap { display: flex; flex-wrap: wrap; gap: 8px; }
.meal-chip {
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 14px;
  font-weight: 600;
}
.meal-chip.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- dinner cards ---------- */
.dinner-card .dinner-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.dinner-name { font-size: 17px; font-weight: 800; }
.dinner-date { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.dinner-notes { color: var(--muted); font-size: 14px; margin-top: 4px; }
.rating-rows { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.rating-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.rating-row .rname { width: 76px; font-weight: 600; color: var(--muted); flex-shrink: 0; }
.rating-row.me .rname { color: var(--accent); }
.stars { display: flex; gap: 2px; }
.star {
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  padding: 2px;
  filter: grayscale(1) opacity(0.35);
}
.star.lit { filter: none; }
.star:not(.tappable) { pointer-events: none; }
.avg-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 13px;
  border-radius: 999px;
  padding: 3px 9px;
}

/* ---------- shopping ---------- */
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  border: none;
  width: 100%;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  text-align: left;
}
.list-row .count { color: var(--muted); font-weight: 600; font-size: 14px; }

.store-filter { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; scrollbar-width: none; }
.store-filter::-webkit-scrollbar { display: none; }
.store-filter .meal-chip { flex: 0 0 auto; }

.store-group-label {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 14px 4px 6px;
}
.item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.item-check {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--card);
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.item-row.checked .item-check { background: var(--good); border-color: var(--good); }
.item-name { flex: 1; font-size: 16px; font-weight: 600; }
.item-row.checked .item-name { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.item-qty { color: var(--muted); font-size: 13px; }
.item-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 18px;
  padding: 4px;
}
.checked-note { font-size: 12px; color: var(--muted); }

.back-link {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  padding: 0 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---------- prefs ---------- */
.pref-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.pref-row:last-child { border-bottom: none; }
.pref-meal { flex: 1; font-size: 15px; font-weight: 600; }
.verdict-btns { display: flex; gap: 6px; }
.verdict {
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  font-size: 18px;
  width: 42px;
  height: 40px;
  filter: grayscale(1) opacity(0.5);
}
.verdict.active { filter: none; }
.verdict.active[data-v="love"] { border-color: var(--good); background: #e9f6ee; }
.verdict.active[data-v="ok"]   { border-color: var(--warn); background: #fbf3e2; }
.verdict.active[data-v="no"]   { border-color: var(--bad);  background: #fbe9e9; }
.pref-summary { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- plan-from-meals ---------- */
.plan-meal {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
.plan-meal.picked { border-color: var(--accent); background: var(--accent-soft); }
.plan-check {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--card);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
}
.plan-meal.picked .plan-check { background: var(--accent); border-color: var(--accent); }

/* ---------- summary ---------- */
.sum-row {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.sum-row:last-child { border-bottom: none; }
.sum-head {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.sum-rank { font-size: 20px; width: 30px; text-align: center; flex-shrink: 0; }
.sum-name { font-size: 15px; font-weight: 700; }
.sum-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; }
.vote-pill {
  font-size: 13px;
  border-radius: 999px;
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.vote-pill.v-love { background: #e9f6ee; border-color: var(--good); }
.vote-pill.v-ok   { background: #fbf3e2; border-color: var(--warn); }
.vote-pill.v-no   { background: #fbe9e9; border-color: var(--bad); }
.sum-detail { padding: 10px 0 4px 40px; display: flex; flex-direction: column; gap: 8px; }
.sum-detail textarea { resize: vertical; }
.sum-rated-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-weight: 600;
}
.sum-rated-row:last-child { border-bottom: none; }

.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 92px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 50;
  animation: toastfade 2s forwards;
}
@keyframes toastfade {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  10%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; }
}
