:root {
  --ground: #F6F1E7;
  --surface: #FFFDF8;
  --sunken: #EFE8DB;
  --line: #E2D9C8;
  --line-strong: #CFC6B6;
  --ink: #1C1A17;
  --muted: #5E574D;
  --accent: #B23A0B;
  --accent-press: #8A2D08;
  --on-accent: #FFFDF8;
  --bar: #1C1A17;
  --on-bar: #F6F1E7;
  --on-bar-muted: #CFC6B6;
  --bar-cta: #E9793F;
  --locked-bg: #DCEBDC;
  --locked-fg: #1F5428;
  --locked-solid: #2F6B3A;
  --editing-bg: #F7E1C6;
  --editing-fg: #7A3208;
  --new-bg: #E8E1D4;
  --new-fg: #4A443C;
  --danger: #A12A0A;
  --scrim: rgba(28, 26, 23, 0.5);

  --display: 'Bricolage Grotesque', 'Arial Narrow', Georgia, serif;
  --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --gutter: 16px;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #171512;
    --surface: #221F1B;
    --sunken: #2B2722;
    --line: #36312A;
    --line-strong: #4A443C;
    --ink: #F3EDE2;
    --muted: #B5AB9B;
    --accent: #F08A4B;
    --accent-press: #F5A370;
    --on-accent: #1C1A17;
    --bar: #F3EDE2;
    --on-bar: #1C1A17;
    --on-bar-muted: #5E574D;
    --bar-cta: #B23A0B;
    --locked-bg: #1F3321;
    --locked-fg: #A8D5AC;
    --locked-solid: #3E8A4A;
    --editing-bg: #3D2A18;
    --editing-fg: #F3C08F;
    --new-bg: #2F2B25;
    --new-fg: #CFC6B6;
    --danger: #FF8A6B;
    --scrim: rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding-inline: var(--gutter);
  padding-top: calc(var(--safe-top) + 12px);
  padding-bottom: calc(var(--safe-bottom) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.app.has-bar { padding-bottom: calc(var(--safe-bottom) + 110px); }
.loading { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- header */
.topnav { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.eyebrow {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent);
}
.eyebrow::before { content: ''; width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.title { margin: 0; font-family: var(--display); font-weight: 800; letter-spacing: -0.02em; line-height: 1; font-size: clamp(34px, 10vw, 46px); }
.lede { margin: 0; color: var(--muted); font-size: 15px; max-width: 42ch; }
.head { display: flex; flex-direction: column; gap: 10px; }

/* ---------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1.5px solid transparent;
  font-weight: 700; font-size: 15px; text-decoration: none; white-space: nowrap;
  transition: transform 80ms ease, background-color 120ms ease;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-press); }
.btn-dark { background: var(--ink); color: var(--ground); }
.btn-outline { background: transparent; border-color: var(--ink); color: var(--ink); }
.btn-quiet { background: transparent; color: var(--muted); padding: 0 8px; min-height: 44px; font-weight: 600; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }
.btn-lg { min-height: 54px; font-size: 16px; }
.btn:disabled { background: var(--new-bg); color: var(--muted); border-color: transparent; }
.btn-sm { min-height: 40px; padding: 0 12px; font-size: 14px; border-radius: 12px; }
.pill-btn {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--ink);
  background: transparent; color: var(--ink); font-size: 14px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.pill-btn[aria-pressed="true"] { background: var(--ink); color: var(--ground); }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; color: var(--muted); font-weight: 600; font-size: 15px; text-decoration: none; background: none; border: 0; padding: 0; }
.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 22px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); display: inline-flex; align-items: center; justify-content: center;
}
svg { flex-shrink: 0; }

/* ---------- status pills + avatars */
.status { padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-locked { background: var(--locked-bg); color: var(--locked-fg); }
.status-editing { background: var(--editing-bg); color: var(--editing-fg); }
.status-new, .status-empty { background: var(--new-bg); color: var(--new-fg); }
.avatar {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 20px; color: #FFFDF8;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 800; font-size: 18px;
}

/* ---------- people list (home) */
.list { display: flex; flex-direction: column; gap: 8px; }
.person-row {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 68px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-align: left;
}
.person-row:active { background: var(--sunken); }
.person-meta { display: flex; flex-direction: column; gap: 2px; flex-grow: 1; min-width: 0; }
.person-name { font-size: 17px; font-weight: 600; }
.person-detail { font-size: 13px; color: var(--muted); }
.home-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.home-actions .btn-dark { flex: 1 1 200px; }
.empty {
  padding: 28px 20px; text-align: center; color: var(--muted); font-size: 15px;
  background: var(--surface); border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
}
.footer-link { align-self: center; }

/* ---------- keypad + dots */
.dots { display: flex; justify-content: center; gap: 18px; padding: 6px 0; }
.dot { width: 18px; height: 18px; border-radius: 9px; border: 2px solid var(--ink); background: transparent; transition: background-color 90ms ease; }
.dot.filled { background: var(--ink); }
.dots.error .dot { border-color: var(--danger); }
.dots.shake { animation: shake 320ms ease; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.key {
  height: 60px; border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
  font-family: var(--mono); font-size: 24px; font-weight: 500; color: var(--ink);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.key:active { background: var(--sunken); }
.key-del { background: transparent; border-color: transparent; display: flex; align-items: center; justify-content: center; }
.form-error { min-height: 20px; margin: 0; text-align: center; font-size: 14px; font-weight: 600; color: var(--danger); }
.hint { margin: 0; font-size: 14px; color: var(--muted); }

.steps { display: flex; gap: 8px; }
.step {
  flex: 1; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--new-bg); color: var(--new-fg); font-size: 14px; font-weight: 600;
}
.step.active { background: var(--ink); color: var(--ground); }
.step.complete { background: var(--locked-bg); color: var(--locked-fg); }
.step-num { width: 22px; height: 22px; border-radius: 11px; border: 1.5px solid currentColor; display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; }
.setpin { display: flex; flex-direction: column; gap: 18px; flex-grow: 1; }
.setpin-entry { display: flex; flex-direction: column; gap: 14px; margin-top: auto; }
.setpin-prompt { text-align: center; font-weight: 600; }

/* ---------- order screen */
.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  margin-inline: calc(var(--gutter) * -1); padding: 2px var(--gutter) 4px;
  position: sticky; top: 0; z-index: 5; background: var(--ground);
  padding-top: calc(var(--safe-top) + 8px); margin-top: calc(var(--safe-top) * -1 - 8px);
}
.chips::-webkit-scrollbar { display: none; }
.lock-banner {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px;
  background: var(--locked-bg); color: var(--locked-fg); font-size: 14px; font-weight: 600;
}
.menu-item {
  display: flex; align-items: center; gap: 12px; padding: 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.menu-item-meta { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.menu-item-name { font-size: 16px; font-weight: 600; line-height: 1.25; }
.menu-item-price { font-size: 13px; color: var(--muted); }
.menu-item-sub { font-size: 13px; color: var(--muted); }
.in-order { align-self: flex-start; padding: 2px 8px; border-radius: 999px; background: var(--editing-bg); color: var(--editing-fg); font-size: 12px; font-weight: 700; }
.add-group { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; flex-shrink: 0; max-width: 55%; }
.add-btn {
  min-width: 52px; min-height: 44px; padding: 0 12px; border-radius: 12px; border: none;
  background: var(--accent); color: var(--on-accent); font-size: 14px; font-weight: 700; touch-action: manipulation;
}
.add-btn:active { background: var(--accent-press); }
.cat-title { margin: 8px 0 0; font-family: var(--display); font-weight: 800; font-size: 22px; }

/* ---------- bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--bar); color: var(--on-bar);
  padding: 12px var(--gutter) calc(12px + var(--safe-bottom));
}
.bar-inner { max-width: 528px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.bar.locked { background: var(--locked-solid); color: #FFFDF8; }
.bar-meta { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.bar-label { font-size: 13px; color: var(--on-bar-muted); }
.bar.locked .bar-label { color: #E6F2E6; }
.bar-total { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 24px; font-weight: 700; }
.bar .btn-cta { background: var(--bar-cta); color: var(--bar); }
.bar.locked .btn-cta { background: #FFFDF8; color: #1F5428; }
.bar.locked .btn-ghost { border-color: #FFFDF8; color: #FFFDF8; background: transparent; }
@media (prefers-color-scheme: dark) {
  .bar .btn-cta { color: #FFFDF8; }
}

/* ---------- sheets */
.scrim {
  position: fixed; inset: 0; z-index: 50; background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 140ms ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: calc(100dvh - var(--safe-top) - 24px);
  background: var(--ground); border-radius: 24px 24px 0 0;
  display: flex; flex-direction: column; overflow: hidden;
  animation: rise 200ms cubic-bezier(.2, .8, .2, 1);
}
.sheet-head { padding: 20px 20px 12px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.sheet-title { margin: 0; font-family: var(--display); font-size: 26px; font-weight: 800; line-height: 1.1; }
.sheet-body { padding: 0 20px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 12px; }
.sheet-foot { padding: 12px 20px calc(16px + var(--safe-bottom)); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.sheet-pad { padding: 20px 20px calc(24px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.scrim.still, .scrim.still .sheet { animation: none; }
@keyframes rise { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.side-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.side-chip {
  min-height: 52px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 6px; touch-action: manipulation;
}
.side-chip.on { background: var(--ink); color: var(--ground); border-color: var(--ink); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.line {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.line-meta { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.line-title { font-size: 15px; font-weight: 600; line-height: 1.25; }
.line-sides { font-size: 13px; color: var(--muted); }
.line-price { font-size: 13px; font-weight: 700; }
.stepper { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.stepper button {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--ground); font-size: 20px; line-height: 1; touch-action: manipulation;
}
.stepper .num { min-width: 24px; text-align: center; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.input, .textarea {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-size: 16px;
}
.textarea { resize: vertical; min-height: 72px; }
.input:disabled, .textarea:disabled { opacity: 0.7; }
.totals { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px dashed var(--line-strong); font-size: 14px; }
.totals .row-between span:first-child { color: var(--muted); }
.totals .grand { font-size: 19px; font-weight: 700; }
.totals .grand span:first-child { color: var(--ink); }
.fine { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- everyone */
.quick { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.quick-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.card {
  display: flex; flex-direction: column; gap: 10px; padding: 12px 14px 14px;
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
}
.card.selected { border-color: var(--accent); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-label { flex-grow: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.check { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex-shrink: 0; }
.card-lines { display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 1px dashed var(--line); }
.card-line { display: flex; gap: 10px; font-size: 14px; }
.card-line .qty { min-width: 26px; font-weight: 700; }
.card-line .what { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.card-line .sides { font-size: 12px; color: var(--muted); }
.note { padding: 8px 10px; border-radius: 10px; background: var(--sunken); font-size: 13px; color: var(--ink); overflow-wrap: anywhere; }
.card-total { display: flex; justify-content: space-between; align-items: baseline; }
.card-total span:first-child { font-size: 13px; color: var(--muted); }
.card-total .num { font-size: 17px; font-weight: 700; }
.card-empty { padding-top: 10px; border-top: 1px dashed var(--line); font-size: 14px; color: var(--muted); }

.combined { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.combined-row { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.combined-row:last-child { border-bottom: 0; }
.combined-row .qty { font-size: 16px; font-weight: 700; min-width: 32px; }
.combined-row .what { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.combined-row .who { font-size: 12px; font-weight: 600; color: var(--editing-fg); }
.section-label { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 4px 0 0; }
.warn { padding: 10px 12px; border-radius: 12px; background: var(--editing-bg); color: var(--editing-fg); font-size: 13px; font-weight: 600; }

/* ---------- organizer */
.panel { display: flex; flex-direction: column; gap: 12px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h2 { margin: 0; font-family: var(--display); font-size: 20px; font-weight: 800; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form .input { flex: 1 1 160px; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 10px; }
.pin-card { display: flex; flex-direction: column; gap: 12px; padding: 18px; border-radius: var(--radius); background: var(--bar); color: var(--on-bar); }
.pin-card .section-label { color: var(--on-bar-muted); margin: 0; }
.pin-digits { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.pin-digits span { height: 64px; border-radius: 12px; background: rgba(127, 127, 127, 0.18); display: flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 34px; font-weight: 700; color: var(--bar-cta); }
.pin-card .btn-outline { border-color: var(--on-bar); color: var(--on-bar); }
.admin-person { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.admin-person:last-child { border-bottom: 0; }
.admin-person .person-meta { flex: 1 1 140px; }
.admin-person-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 100;
  top: calc(var(--safe-top) + 12px); max-width: calc(100% - 32px);
  padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--ground);
  font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.toast.error { background: var(--danger); color: #FFFDF8; }
.conn { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.conn::before { content: ''; width: 7px; height: 7px; border-radius: 4px; background: var(--locked-solid); }
.conn.off::before { background: var(--line-strong); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
