:root {
  --ground: #f4f2ec;
  --paper: #ffffff;
  --ink: #111114;
  --muted: #55555e;
  --line: #e4e1d8;
  --accent: #ffd60a;
  --good-bg: #ddf3e8;
  --good-fg: #04563e;
  --warn-bg: #ffe9c7;
  --warn-fg: #5c2e00;
  --sans: 'Bricolage Grotesque', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --radius: 16px;
  --shadow: 3px 3px 0 var(--ink);
}

/* Fast repeated taps (3 beers = 3 taps) shouldn't double-tap zoom. Pinch zoom still works. */
* { box-sizing: border-box; touch-action: manipulation; }

html, body {
  margin: 0;
  height: 100%;
  background: #e7e4dc;
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 3px solid #3d5afe; outline-offset: 2px; }
h1:focus { outline: none; }

.app {
  position: relative;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  background: var(--ground);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@media (min-width: 520px) {
  .app { border-left: 2px solid var(--ink); border-right: 2px solid var(--ink); }
}

/* Header */
.top {
  flex: none;
  height: 64px;
  padding: env(safe-area-inset-top) 16px 0;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 23px; font-weight: 800; letter-spacing: -0.03em; }
button.brand { justify-self: center; min-height: 44px; padding: 0 6px; border: none; border-radius: 10px; background: none; }
.step { text-align: right; font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--muted); }

/* Screens */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 20px 24px; display: flex; flex-direction: column; gap: 18px; }
/* Children keep their natural height so the list scrolls instead of being squashed and clipped. */
.scroll > * { flex-shrink: 0; }
.scroll { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.foot {
  flex: none;
  padding: 14px 20px calc(18px + env(safe-area-inset-bottom));
  border-top: 2px solid var(--ink);
  background: var(--paper);
  display: flex;
  gap: 10px;
  align-items: center;
}
.title { display: flex; flex-direction: column; gap: 6px; }
h1 { margin: 0; font-size: 34px; line-height: 1.05; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
.lead { margin: 0; font-size: 16px; line-height: 1.4; color: var(--muted); }
.note { margin: 0; font-size: 15px; line-height: 1.4; color: var(--muted); }
.mono { font-family: var(--mono); }

/* Buttons */
.btn {
  height: 56px;
  padding: 0 20px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  font-size: 17px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
.btn-primary { flex: 1; background: var(--accent); font-size: 18px; box-shadow: var(--shadow); }
.btn-primary:active:not(:disabled) { box-shadow: none; transform: translate(3px, 3px); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-sm { height: 44px; padding: 0 16px; font-size: 15px; border-radius: 999px; }
.icon-btn {
  width: 44px; height: 44px; padding: 0; flex: none;
  border: 2px solid var(--ink); border-radius: 12px; background: var(--paper);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn.plain { border: none; background: var(--ground); }
.icon-btn.square { width: 56px; height: 56px; border-radius: var(--radius); }

/* Card */
.card { background: var(--paper); border: 2px solid var(--ink); border-radius: 20px; box-shadow: 4px 4px 0 var(--ink); }

/* Scan */
.viewfinder {
  flex: 1; min-height: 300px; position: relative; overflow: hidden;
  border: 2px solid var(--ink); border-radius: 24px; background: #1e1e24;
  display: flex; align-items: center; justify-content: center;
}
/* The photo scrolls inside the frame, so long receipts stay readable. */
.preview-scroll { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 0 0 72px; }
.preview-scroll img.preview { display: block; width: 100%; height: auto; }
.corner, .pill, .scanline { z-index: 1; pointer-events: none; }
.corner { position: absolute; width: 34px; height: 34px; border: 0 solid var(--accent); }
.corner.tl { top: 18px; left: 18px; border-top-width: 4px; border-left-width: 4px; border-top-left-radius: 10px; }
.corner.tr { top: 18px; right: 18px; border-top-width: 4px; border-right-width: 4px; border-top-right-radius: 10px; }
.corner.bl { bottom: 18px; left: 18px; border-bottom-width: 4px; border-left-width: 4px; border-bottom-left-radius: 10px; }
.corner.br { bottom: 18px; right: 18px; border-bottom-width: 4px; border-right-width: 4px; border-bottom-right-radius: 10px; }
.paper {
  width: 210px; background: #fff; padding: 18px 16px 20px; transform: rotate(-2.5deg);
  font-family: var(--mono); font-size: 11px; line-height: 1.3;
  display: flex; flex-direction: column; gap: 6px; box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}
.paper .row { display: flex; gap: 8px; }
.paper .row span:nth-child(2) { flex: 1; }
.paper .rule { border-top: 1px dashed var(--ink); margin: 4px 0; }
.paper .center { text-align: center; }
.pill {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); white-space: nowrap;
  padding: 10px 16px; border-radius: 999px; background: rgba(17, 17, 20, 0.82); color: #fff; font-size: 15px; font-weight: 600;
}
.pill.busy { background: var(--accent); color: var(--ink); border: 2px solid var(--ink); font-weight: 700; }
/* Scanning: a bright line sweeps up and down the photo while the AI reads it. */
.scan-shade { position: absolute; inset: 0; z-index: 1; pointer-events: none; background: rgba(17, 17, 20, 0.25); }
.scanline {
  position: absolute; left: 14px; right: 14px; top: 0; height: 5px; border-radius: 3px;
  background: var(--accent); box-shadow: 0 0 18px 6px rgba(255, 214, 10, 0.85), 0 0 48px 16px rgba(255, 214, 10, 0.35);
  animation: sweep 2.4s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
@keyframes sweep { from { top: 4%; } to { top: calc(96% - 5px); } }
.dots span { display: inline-block; animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  /* No sweeping for people who turn motion off: a gentle glow pulse instead. */
  .scanline { top: 50%; animation: glow 1.6s ease-in-out infinite alternate; }
  @keyframes glow { from { opacity: 0.35; } to { opacity: 1; } }
}
.shutter-row { flex: none; padding: 8px 20px calc(22px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; }
.shutter {
  width: 80px; height: 80px; border: 3px solid var(--ink); border-radius: 50%; background: var(--accent); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.shutter span { width: 56px; height: 56px; border: 2px solid var(--ink); border-radius: 50%; }
.file-label { position: relative; }
.file-label input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-label:focus-within { outline: 3px solid #3d5afe; outline-offset: 3px; }
.links { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.link-btn { border: none; background: none; padding: 10px 4px; min-height: 44px; font-size: 15px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.error { padding: 12px 14px; border: 2px solid var(--ink); border-radius: var(--radius); background: var(--warn-bg); color: var(--warn-fg); font-size: 15px; font-weight: 600; line-height: 1.35; }

/* Review */
.edit-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 72px 44px; gap: 6px; align-items: center; padding: 10px 10px 10px 12px; border-bottom: 1px solid var(--line); }
.field {
  height: 44px; width: 100%; min-width: 0; padding: 0 8px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px;
}
.field:focus { border-color: var(--ink); outline: none; }
.field.num { font-family: var(--mono); text-align: right; padding: 0 8px; }
.field.qty { text-align: center; padding: 0 4px; }
.col-head { display: grid; grid-template-columns: 44px minmax(0, 1fr) 72px 44px; gap: 6px; padding: 12px 10px 0 12px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.col-head span:nth-child(3) { text-align: right; }
.add-row { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.charges { padding: 12px 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.charge { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 10px; align-items: center; font-size: 15px; }
.charge label { color: var(--muted); }
.totals { padding: 14px 16px; border-top: 1px dashed var(--ink); display: flex; flex-direction: column; gap: 6px; font-family: var(--mono); font-size: 14px; }
.totals .row { display: flex; justify-content: space-between; }
.totals .row.big { font-size: 16px; font-weight: 700; }
.select { height: 44px; padding: 0 10px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-size: 16px; }

/* People */
.add-form { display: flex; flex-direction: column; gap: 8px; }
.add-form label { font-size: 15px; font-weight: 700; }
.add-form .row { display: flex; gap: 10px; }
.add-form input { flex: 1; min-width: 0; height: 52px; padding: 0 14px; border: 2px solid var(--ink); border-radius: 14px; background: #fff; font-size: 17px; }
.person-row { display: flex; align-items: center; gap: 12px; height: 62px; padding: 0 8px 0 12px; border: 2px solid var(--ink); border-radius: var(--radius); background: #fff; }
.avatar { flex: none; width: 38px; height: 38px; border-radius: 50%; color: #fff; font-size: 17px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.person-name { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { margin: 0; padding: 18px; border: 2px dashed #b9b5aa; border-radius: var(--radius); font-size: 15px; color: var(--muted); text-align: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.count { flex: none; font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--muted); }

/* Assign */
.segments { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 6px; }
.segment { height: 40px; padding: 0; border: none; background: transparent; display: flex; align-items: center; }
.segment span { display: block; width: 100%; height: 12px; border-radius: 6px; background: #d3d0c7; }
.segment.partial span { background: #e8a33d; }
.segment.done span { background: var(--ink); }
.segment.current span { background: var(--accent); border: 2px solid var(--ink); }
.item-card { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 12px; }
.meta { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: 13px; color: var(--muted); }
.item-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.item-head h1 { font-size: 30px; overflow-wrap: anywhere; }
.item-head .price { flex: none; font-family: var(--mono); font-size: 22px; font-weight: 700; }
.status { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: var(--warn-bg); color: #6b3600; font-size: 14px; font-weight: 700; }
.status.done { background: var(--good-bg); color: var(--good-fg); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.cell { position: relative; min-width: 0; }
.tap {
  width: 100%; height: 68px; padding: 0 12px; border: 2px solid var(--ink); border-radius: var(--radius); background: #fff;
  box-shadow: var(--shadow); text-align: left; display: flex; align-items: center; gap: 8px;
}
.tap.on { color: #fff; box-shadow: none; }
.tap.has-minus { padding-right: 58px; }
.tap .dot { flex: none; width: 12px; height: 12px; border-radius: 50%; }
.tap .txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tap .nm { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tap .sub { font-family: var(--mono); font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.tap.on .sub { color: #fff; }
.minus { position: absolute; top: 12px; right: 8px; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Summary */
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 2px solid var(--ink); border-radius: var(--radius); background: #fff; font-size: 15px; line-height: 1.35; }
.banner .tick { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--good-bg); color: var(--good-fg); display: flex; align-items: center; justify-content: center; }
.banner .amt { flex: none; font-family: var(--mono); font-weight: 700; }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); font-weight: 600; padding: 10px 10px 10px 14px; }
.tip-head { display: flex; justify-content: space-between; align-items: baseline; }
.tip-head strong { font-size: 17px; }
/* Presets share the row equally; Custom takes the width its label needs. */
.tips { display: flex; gap: 6px; }
.tips > * { flex: 1 1 0; min-width: 0; }
.tips > :last-child { flex: none; padding: 0 8px; }
.tips button { height: 44px; padding: 0; border: 2px solid var(--ink); border-radius: 12px; background: #fff; font-size: 15px; font-weight: 700; }
.tips button[aria-pressed='true'] { background: var(--ink); color: #fff; }
/* The custom tip box sits in the row like a selected button. */
.tip-custom { height: 44px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--ink); border-radius: 12px; background: var(--ink); color: #fff; font-size: 16px; font-weight: 700; cursor: text; }
.tip-custom:focus-within { outline: 3px solid #3d5afe; outline-offset: 2px; }
/* 16px so iPhones don't zoom in when it's focused. */
.tip-custom input { width: 4ch; min-width: 0; padding: 0; border: none; background: none; font-size: 16px; font-weight: 700; text-align: right; }
.tip-custom input:focus-visible { outline: none; }
.tip-custom input::placeholder { color: rgba(255, 255, 255, 0.5); }
.person-card { border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.person-card > button { width: 100%; height: 68px; padding: 0 14px; border: none; background: transparent; text-align: left; display: flex; align-items: center; gap: 12px; }
.person-card .total { flex: none; font-family: var(--mono); font-size: 20px; font-weight: 700; }
.person-card .chev { flex: none; transition: transform 0.15s; }
.person-card[data-open='true'] .chev { transform: rotate(180deg); }
.breakdown { padding: 0 16px 16px 64px; display: flex; flex-direction: column; gap: 6px; font-family: var(--mono); font-size: 13px; }
.breakdown .row { display: flex; justify-content: space-between; gap: 12px; }
.breakdown .row span:last-child { flex: none; }
.breakdown .muted { color: var(--muted); }
.breakdown .rule { border-top: 1px dashed #b9b5aa; margin: 4px 0; }
.check { display: flex; align-items: center; justify-content: center; gap: 8px; font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--good-fg); }
/* Keep "£x + £y tip" together if a big bill wraps the line. */
.check b { font-weight: inherit; white-space: nowrap; }

.toast {
  position: absolute; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 5;
  padding: 10px 16px; border: 2px solid var(--ink); border-radius: 999px; background: var(--ink); color: #fff; font-weight: 700; white-space: nowrap;
}
