:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --surface-2: #f5ede1;
  --ink: #2b2118;
  --ink-2: #6b5a4a;
  --line: #e7dccb;
  --accent: #b4471f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e0d3;
  --gold: #c98a1a;
  --sage: #5f7a4e;
  --sage-soft: #e3ebd9;
  --plum: #7a3b55;
  --danger: #a3261b;
  --hero-1: #7c2d12;
  --hero-2: #b4471f;
  --shadow: 0 1px 2px rgb(60 35 10 / 0.06), 0 4px 16px rgb(60 35 10 / 0.06);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1511;
    --surface: #261e18;
    --surface-2: #2f251e;
    --ink: #f3e9dc;
    --ink-2: #bba892;
    --line: #3d3027;
    --accent: #e0703f;
    --accent-ink: #1b1511;
    --accent-soft: #4a2a1b;
    --gold: #e2a83f;
    --sage: #9bb586;
    --sage-soft: #2c3524;
    --plum: #d48aa8;
    --danger: #f07a6c;
    --hero-1: #4a1c0b;
    --hero-2: #7c2d12;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: Fraunces, Georgia, serif; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h2 { font-size: 1.35rem; }

.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* Hero */
.hero {
  background: linear-gradient(135deg, var(--hero-1), var(--hero-2));
  color: #fff7ee;
  padding: 40px 0 72px;
}
.hero h1 { font-size: clamp(2rem, 6vw, 3rem); line-height: 1.1; }
.eyebrow { margin: 0 0 6px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.78rem; opacity: 0.85; }
.ev-meta { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-weight: 500; }
.ev-meta li::before { content: attr(data-icon); margin-right: 6px; }
.ev-meta a { color: inherit; }
.ev-notes { margin: 10px 0 0; max-width: 60ch; opacity: 0.9; white-space: pre-line; }
.ev-notes:empty { display: none; }
.hero .link-btn { color: #fff7ee; opacity: 0.85; margin-top: 12px; padding-left: 0; }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: -44px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-family: Fraunces, Georgia, serif; font-size: 1.9rem; line-height: 1.1; }
.stat span { color: var(--ink-2); font-size: 0.85rem; }
@media (max-width: 600px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Layout */
.columns { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 16px; align-items: start; margin: 20px 0 32px; }
@media (max-width: 820px) { .columns { grid-template-columns: minmax(0, 1fr); } }

.stat.warn b { color: var(--accent); }

/* Cards & forms */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.add-row { display: flex; gap: 8px; margin-bottom: 14px; }
.add-row > input:first-child, .add-row .grow { flex: 1 1 auto; min-width: 0; }
.wrap-row { flex-wrap: wrap; }
.wrap-row .grow { flex-basis: 100%; }

.num { width: 64px; flex: 0 0 64px; text-align: center; }
.row-end { display: flex; justify-content: flex-end; margin: 8px 0 14px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; min-width: 0; }
.field > span { font-size: 0.8rem; font-weight: 600; color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: 0.9rem; margin: 0 0 8px; }

input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
  min-height: 42px;
}
select { width: auto; }
.field select { width: 100%; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 10px; padding: 9px 16px; cursor: pointer; min-height: 42px; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--danger); border-color: transparent; padding-left: 4px; }
.btn:hover { filter: brightness(1.05); }
.link-btn { font: inherit; font-size: 0.9rem; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

/* Guests */
.guests { list-style: none; margin: 0; padding: 0; }
.guest { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.guest:first-child { border-top: 0; }
.guest-name {
  flex: 1; min-width: 0; text-align: left; font: inherit; font-weight: 500; color: inherit;
  background: none; border: 0; padding: 6px 0; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.guest-name:hover { color: var(--accent); }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.stepper span { min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.stepper button { font: inherit; width: 34px; height: 34px; border: 0; background: var(--surface-2); color: var(--ink); cursor: pointer; font-size: 1.1rem; }
.stepper button:disabled { opacity: 0.35; cursor: default; }
.empty { color: var(--ink-2); text-align: center; padding: 18px; border: 1px dashed var(--line); border-radius: 10px; margin: 0; }
.empty[hidden] { display: none; }

/* Dishes board */
.menu { display: flex; flex-direction: column; gap: 14px; }
.course h3 {
  margin: 0 0 4px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2);
  display: flex; gap: 8px; align-items: center;
}
.course h3 span { background: var(--surface-2); border-radius: 999px; padding: 0 7px; font-size: 0.72rem; }
.course ul { list-style: none; margin: 0; padding: 0; }
.dish { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.dish-name {
  flex: 1; min-width: 0; text-align: left; font: inherit; color: inherit; background: none; border: 0;
  padding: 6px 0; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.dish-name:hover { color: var(--accent); }
.dish-who { min-height: 36px; padding: 5px 8px; font-size: 16px; max-width: 50%; flex: 0 1 auto; min-width: 0; background: var(--sage-soft); border-color: transparent; }
.dish.open .dish-who { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.gap-note { margin: 0; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; color: var(--ink-2); font-size: 0.9rem; }

/* Dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 20px;
  width: min(480px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(30 15 5 / 0.45); }
dialog h2 { margin-bottom: 14px; }
dialog .add-row { margin-bottom: 0; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 500; opacity: 0; pointer-events: none; transition: 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot { color: var(--ink-2); font-size: 0.8rem; padding-bottom: 32px; text-align: center; }

[hidden] { display: none !important; }
.wrap-row select { flex: 1 1 0; min-width: 0; }

/* Group-by toggle */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { font: inherit; font-size: 0.85rem; font-weight: 600; border: 0; background: none; color: var(--ink-2); padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.course h3 em { font-style: normal; text-transform: none; letter-spacing: 0; font-weight: 500; }
.dish-type { font-size: 0.8rem; color: var(--ink-2); background: var(--surface-2); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.card-head { flex-wrap: wrap; }

/* iOS Safari: never let content widen the page, and keep form text >= 16px so
   focusing a field doesn't auto-zoom. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overflow-x: hidden; }
body { overflow-x: hidden; }
.card, .course, .guest, .dish { min-width: 0; }
input, select, textarea { font-size: 16px; }
.dish-name, .guest-name { white-space: normal; overflow-wrap: anywhere; line-height: 1.3; }
.field.narrow { flex: 0 0 84px; }
.center { text-align: center; }

/* Page nav */
.topnav { display: flex; gap: 6px; margin-bottom: 22px; }
.topnav a {
  color: #fff7ee; text-decoration: none; font-weight: 600; font-size: 0.9rem;
  padding: 6px 14px; border-radius: 999px; background: rgb(255 255 255 / 0.12);
}
.topnav a[aria-current="page"] { background: #fff7ee; color: var(--hero-1); }

/* Shopping page */
.hero.slim { padding: 24px 0 30px; }
.progress-text { margin: 8px 0 8px; font-weight: 500; opacity: 0.9; }
.progress-text:empty { display: none; }
.progress { height: 6px; border-radius: 999px; background: rgb(255 255 255 / 0.2); overflow: hidden; max-width: 420px; }
.progress span { display: block; height: 100%; width: 0; background: #f6c453; transition: width 0.3s; }
.shop-card { margin: 20px 0 32px; }
.qty { flex: 1 1 0; min-width: 0; }
.shop-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: -2px 0 10px; color: var(--ink-2); font-size: 0.9rem; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); margin: 0; }
.shop-sec { margin-top: 14px; }
.shop-sec h3 {
  margin: 0 0 2px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-2);
  display: flex; gap: 8px; align-items: center;
}
.shop-sec h3 span { background: var(--surface-2); border-radius: 999px; padding: 0 7px; font-size: 0.72rem; }
.shop-sec ul { list-style: none; margin: 0; padding: 0; }
.shop-item { display: flex; align-items: center; gap: 10px; border-top: 1px solid var(--line); min-width: 0; }
.shop-item:first-child { border-top: 0; }
.check {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line);
  background: var(--bg); cursor: pointer; position: relative; padding: 0;
}
.check::after { content: ""; position: absolute; inset: 0; }
.shop-item.done .check { background: var(--sage); border-color: var(--sage); }
.shop-item.done .check::before {
  content: ""; position: absolute; left: 7px; top: 2px; width: 7px; height: 13px;
  border: solid var(--surface); border-width: 0 3px 3px 0; transform: rotate(45deg);
}
.shop-text {
  flex: 1; min-width: 0; text-align: left; font: inherit; color: inherit; background: none; border: 0;
  padding: 11px 0; cursor: pointer; display: flex; flex-direction: column; gap: 1px;
}
.shop-name { overflow-wrap: anywhere; line-height: 1.3; }
.shop-qty { color: var(--ink-2); font-size: 0.9rem; margin-left: 4px; }
.shop-note { color: var(--ink-2); font-size: 0.82rem; line-height: 1.3; }
.shop-item.done .shop-name { text-decoration: line-through; color: var(--ink-2); }
.shop-item.done .shop-note { opacity: 0.6; }

/* Public page extras */
.stats-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 480px; }
@media (max-width: 600px) { .stats-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.public-card { margin: 20px 0 32px; max-width: 640px; }
.public-card .menu { gap: 16px; }
.dish-label { flex: 1; min-width: 0; padding: 6px 0; overflow-wrap: anywhere; line-height: 1.3; }
.who-tag { font-size: 0.85rem; background: var(--sage-soft); border-radius: 999px; padding: 3px 10px; white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.who-tag.open { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.public-card .dish { border-top: 1px solid var(--line); }
.public-card .dish:first-child { border-top: 0; }
