/* axisplit — mobile-first. Base rules are the phone layout; min-width queries add room.
   Every color resolves through these tokens, so dark mode is one block. */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --surface-3: #e4e8e4;
  --text: #141b18;
  --text-2: #5b6862;
  --text-3: #87928c;
  --border: #e0e4df;
  --border-strong: #c9d0ca;

  --accent: #0e6b51;
  --accent-hover: #0a5843;
  --on-accent: #ffffff;
  --accent-text: #0c6a50;
  --accent-soft: #e1f1ea;

  --warn: #8a5207;
  --warn-soft: #fdf4e2;
  --warn-line: #efd9ab;
  --danger: #b4261f;
  --on-danger: #ffffff;
  --danger-soft: #fdeceb;
  --success: #17683a;
  --success-soft: #e5f3e9;
  --success-line: #c4e3cc;
  --info: #22599a;
  --info-soft: #e8f0fb;
  --ring: #3f82e4;

  /* Photo overlay colors sit on the receipt image, so they don't change with the theme. */
  --box-open: #f2a93b;
  --box-open-ink: #1f1505;
  --box-done: #19b37c;
  --box-done-ink: #0f7a53;
  --box-hit: #4f8fe8;

  --shadow: 0 1px 2px rgb(20 27 24 / .06), 0 6px 18px -10px rgb(20 27 24 / .16);
  --r: 12px;
  --r-lg: 16px;
  --gutter: max(16px, env(safe-area-inset-left));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1311;
    --surface: #151c19;
    --surface-2: #1b2420;
    --surface-3: #25302b;
    --text: #e6ece9;
    --text-2: #9daca5;
    --text-3: #6f7e77;
    --border: #25302b;
    --border-strong: #36433d;

    --accent: #3cc493;
    --accent-hover: #5bd5a7;
    --on-accent: #04190f;
    --accent-text: #62d7aa;
    --accent-soft: #11302a;

    --warn: #f0b660;
    --warn-soft: #29200f;
    --warn-line: #4c3a19;
    --danger: #f2776d;
    --on-danger: #2b0906;
    --danger-soft: #351715;
    --success: #73d69e;
    --success-soft: #11291b;
    --success-line: #204b31;
    --info: #8cbcf3;
    --info-soft: #14243a;
    --ring: #82b3f6;

    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 22px -12px rgb(0 0 0 / .7);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
/* manipulation: rapid taps on the photo must not trigger Safari's double-tap zoom; pinch zoom still works. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text);
  font: 400 16px/1.45 var(--font); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent-text); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; margin-bottom: .25rem; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -.01em; margin-bottom: .5rem; }
p { margin-bottom: .75rem; }
small { font-size: .8rem; }
code { font-family: var(--mono); font-size: .86em; background: var(--surface-3); padding: .1em .35em; border-radius: 5px; }
.muted { color: var(--text-2); font-size: .88rem; }
.amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.icon { width: 1.15em; height: 1.15em; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; opacity: 0; }

/* ---------- Controls ---------- */
button, .btn {
  --btn-bg: var(--accent); --btn-hover: var(--accent-hover); --btn-fg: var(--on-accent); --btn-border: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .55rem 1rem; border: 1px solid var(--btn-border); border-radius: 11px;
  background: var(--btn-bg); color: var(--btn-fg); font: inherit; font-size: .94rem; font-weight: 600;
  text-decoration: none; cursor: pointer; touch-action: manipulation; transition: background-color .15s, border-color .15s, transform .08s;
}
button:not(:disabled):active, .btn:active { transform: scale(.98); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary, .btn.secondary { --btn-bg: var(--surface); --btn-hover: var(--surface-2); --btn-fg: var(--text); --btn-border: var(--border-strong); }
button.danger { --btn-bg: var(--danger); --btn-hover: var(--danger); --btn-fg: var(--on-danger); }
button.text-button { --btn-bg: transparent; --btn-hover: var(--surface-2); --btn-fg: var(--accent-text); padding-inline: .6rem; }
button.small, .btn.small { min-height: 36px; padding: .35rem .8rem; font-size: .86rem; border-radius: 10px; }
button.large, .btn.large { min-height: 52px; padding: .7rem 1.2rem; font-size: 1rem; border-radius: 13px; width: 100%; }
button.icon-button { --btn-bg: transparent; --btn-hover: var(--surface-2); --btn-fg: var(--text-3); width: 44px; padding: 0; }
@media (hover: hover) {
  button:not(:disabled):hover, .btn:hover { background: var(--btn-hover); }
}

/* 16px inputs: smaller text makes iOS Safari zoom the page on focus. */
input { width: 100%; min-width: 0; min-height: 46px; padding: .6rem .8rem; border: 1px solid var(--border-strong); border-radius: 11px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; -webkit-appearance: none; appearance: none; }
input::placeholder { color: var(--text-3); }
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
label { display: block; font-size: .85rem; font-weight: 600; }
label input { margin-top: .35rem; font-weight: 400; }
.input-group { display: flex; gap: .5rem; margin-top: .35rem; }
.input-group > input { flex: 1; margin-top: 0; }
.input-group > button { flex: none; }
.stack { display: flex; flex-direction: column; gap: .9rem; }

/* Busy forms keep a visible spinner instead of looking disabled. */
[aria-busy=true] button:disabled { opacity: .85; cursor: progress; }
[aria-busy=true] button::before, [aria-busy=true] .upload-button::before { content: ""; width: 1em; height: 1em; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
[aria-busy=true] .upload-button { pointer-events: none; opacity: .85; }
[aria-busy=true] .upload-button .icon { display: none; }

/* ---------- Layout ---------- */
.site-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; max-width: 1180px; margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) var(--gutter) 10px; }
.brand { display: inline-flex; align-items: center; gap: .5rem; color: var(--text); font-weight: 700; font-size: 1.05rem; letter-spacing: -.03em; text-decoration: none; }
.brand-mark { width: 26px; height: 26px; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { stroke: var(--on-accent); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.brand-mark circle { fill: var(--on-accent); }
main { width: 100%; max-width: 760px; margin: 0 auto; padding: .5rem var(--gutter) calc(5rem + env(safe-area-inset-bottom)); }
main.wide { max-width: 1180px; }
main.narrow { max-width: 440px; padding-top: 1.5rem; }

.back-link { display: inline-flex; align-items: center; gap: .35rem; margin-bottom: .5rem; color: var(--text-2); font-size: .9rem; font-weight: 550; text-decoration: none; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .75rem; }
.page-head > div { min-width: 0; }
.page-head p { margin: 0; }
.head-actions { display: flex; flex-direction: column; align-items: flex-end; gap: .45rem; flex: none; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; margin: 1.75rem 0 .6rem; }
.section-head h2 { margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 1.1rem; margin-bottom: 1rem; }
.panel > :last-child { margin-bottom: 0; }

/* ---------- People ---------- */
.avatar { display: inline-grid; place-items: center; flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%;
  background: var(--c, var(--accent)); color: #fff; font-size: .76rem; font-weight: 700; line-height: 1; text-transform: uppercase;
  text-shadow: 0 1px 1px rgb(0 0 0 / .25); }
.dot { display: inline-block; width: .65em; height: .65em; border-radius: 50%; background: var(--c); margin-right: .4em; flex-shrink: 0; }
.person { display: flex; align-items: center; gap: .6rem; min-width: 0; flex: 1 1 auto; font-weight: 550; }

/* ---------- Notices & status ---------- */
.notice { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .6rem 1rem; padding: .8rem .9rem;
  margin-bottom: 1rem; border: 1px solid; border-radius: var(--r); font-size: .9rem; color: var(--text); }
.notice-body { display: flex; align-items: flex-start; gap: .6rem; flex: 1; min-width: min(14rem, 100%); }
.notice-body > .icon { width: 20px; height: 20px; }
.notice p:last-child { margin-bottom: 0; }
.notice.warning { background: var(--warn-soft); border-color: var(--warn-line); }
.notice.warning strong, .notice.warning .notice-body > .icon { color: var(--warn); }
.notice.success { background: var(--success-soft); border-color: var(--success-line); }
.notice.success strong, .notice.success .notice-body > .icon { color: var(--success); }
.notice.compact { padding: .6rem .8rem; font-size: .86rem; }
.detect-notice form { margin-top: .75rem; }

.badge { display: inline-flex; align-items: center; gap: .35rem; flex: none; padding: .2rem .6rem .2rem .5rem; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2); font-size: .74rem; font-weight: 650; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.settled { color: var(--success); background: var(--success-soft); }
.badge.pending_confirm { color: var(--success); background: var(--success-soft); }
.badge.awaiting_tokens, .badge.splitting { color: var(--info); background: var(--info-soft); }

/* ---------- Home ---------- */
.upload-form { margin-bottom: .5rem; }
.upload-button { position: relative; cursor: pointer; }
.upload-button:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
.upload-form .busy-help { margin: .5rem 0 0; }

.receipt-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: .5rem; margin: 0; padding: 0; list-style: none; }
.receipt-card { display: flex; align-items: center; gap: .25rem; padding-right: .15rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.receipt-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: .75rem; padding: .6rem; color: inherit; text-decoration: none; }
.receipt-link img { flex: none; width: 44px; height: 56px; object-fit: cover; border-radius: 7px; background: var(--surface-3); }
.receipt-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .2rem; }
.receipt-title { font-weight: 600; font-size: .95rem; }
.receipt-sub { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .5rem; color: var(--text-2); font-size: .8rem; }

.share-list { margin: 0; padding: 0; list-style: none; }
.share-list li { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-bottom: 1px solid var(--border); font-size: .94rem; }
.share-list li:last-child { border-bottom: 0; }
.share-list .amount { margin-left: auto; text-align: right; }

dialog { width: min(420px, calc(100% - 2rem)); padding: 1.4rem; border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 60px -16px rgb(0 0 0 / .4); }
dialog::backdrop { background: rgb(6 12 10 / .5); }
dialog h2 { font-size: 1.2rem; }
dialog p { font-size: .93rem; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }
.dialog-actions form { margin: 0; }
/* Upload focus area: the photo with a draggable four-cornered area; outside it is dimmed. */
/* Item dialog: Delete sits apart from Save, on the far side, so a slip doesn't delete. */
.item-form { display: grid; gap: .8rem; margin: 0; }
.item-form h2 { margin: 0; }
.item-form label { display: grid; gap: .3rem; font-size: .88rem; font-weight: 600; }
.item-form .dialog-actions { margin-top: .25rem; }
.item-form .danger-text { --btn-fg: var(--danger); margin-right: auto; padding-inline: .4rem; }
.focus-dialog { width: min(560px, calc(100% - 1rem)); max-height: calc(100vh - 1rem); max-height: calc(100dvh - 1rem); padding: 1rem; }
.focus-dialog .dialog-actions { margin-top: .75rem; }
/* A fixed window onto the photo: two fingers zoom and pan it, one finger draws. */
.focus-viewport { position: relative; height: 48vh; height: 48dvh; margin-top: .5rem; overflow: hidden; border-radius: 10px;
  background: var(--surface-3); touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.focus-surface { position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff; }
.focus-surface.animate { transition: transform .3s ease; }
.focus-surface img { position: absolute; left: 50%; top: 50%; max-width: none; max-height: none; -webkit-touch-callout: none; }
/* Level lines while straightening, to line the receipt's text up against. */
.focus-viewport.leveling::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 27px, rgb(0 122 255 / .55) 27px 28px); }
.zoom-controls { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; }
.zoom-controls button { --btn-bg: rgb(15 23 20 / .72); --btn-hover: rgb(15 23 20 / .86); --btn-fg: #fff; width: 40px; min-height: 40px; padding: 0; border-radius: 10px; }
.turn-tools { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; }
.turn-tools button { flex: none; }
.straighten { display: flex; flex: 1; align-items: center; gap: .5rem; min-width: 0; font-size: .86rem; font-weight: 600; }
.straighten input { flex: 1; min-width: 0; min-height: 36px; padding: 0; border: 0; background: none; box-shadow: none;
  -webkit-appearance: auto; appearance: auto; accent-color: var(--accent); }
.straighten output { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; color: var(--text-2); }
.focus-shade { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.focus-shade .shade { fill: rgb(0 0 0 / .5); }
.focus-shade .edge { fill: none; stroke: #fff; stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
/* Small dots, so they hide little of a small receipt; the invisible ring makes them a 44px touch target. */
.focus-handle { position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border: 2px solid var(--accent); border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .6); cursor: grab; scale: calc(1 / var(--z, 1)); }  /* same size at any zoom */
.focus-handle::before { content: ""; position: absolute; inset: -16px; border-radius: 50%; }
.focus-tools { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .5rem; font-size: .86rem; }
.focus-tools button { flex: none; }

/* ---------- Receipt board ---------- */
/* The person picker sticks to the top so the current selection stays visible over a long photo. */
.token-toolbar { position: sticky; top: 0; z-index: 30; margin: 0 calc(-1 * var(--gutter)) .75rem; padding: max(8px, env(safe-area-inset-top)) var(--gutter) 8px;
  background: var(--bg); border-bottom: 1px solid var(--border); }
/* One swipeable row however big the group is. */
.tokenbar { display: flex; gap: .4rem; margin: 0 calc(-1 * var(--gutter)); padding: 2px var(--gutter) 4px; overflow-x: auto;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tokenbar::-webkit-scrollbar { display: none; }
.tokenbar .token { --btn-bg: var(--surface); --btn-hover: var(--surface-2); --btn-fg: var(--text); --btn-border: var(--border-strong);
  flex: none; gap: .45rem; padding: .25rem .85rem .25rem .25rem; border-radius: 999px; font-size: .9rem; white-space: nowrap; }
.tokenbar .token .avatar { width: 34px; height: 34px; font-size: .82rem; }
.tokenbar .token.selected { --btn-bg: color-mix(in srgb, var(--c) 16%, var(--surface)); --btn-hover: var(--btn-bg); --btn-border: var(--c);
  box-shadow: 0 0 0 2px var(--c); }
/* Adding people: a chip at the end of the bar opens a name field under it, kept open for the next name. */
.tokenbar .add-token { --btn-bg: transparent; --btn-hover: var(--surface-2); --btn-fg: var(--accent-text); --btn-border: var(--border-strong);
  flex: none; gap: .4rem; min-height: 42px; padding: .25rem .9rem; border-style: dashed; border-radius: 999px; font-size: .9rem; white-space: nowrap; }
.token-toolbar:has(#add-person:not([hidden])) .add-token { display: none; }  /* the open field is the way to add */
.add-person { display: flex; align-items: center; gap: .4rem; margin-top: .4rem; }
.add-person input { flex: 1; min-width: 0; margin: 0; }
.add-person button { flex: none; }
.check { opacity: 0; font-size: .85em; }
.selected .check { opacity: 1; }
.toolbar-status { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-top: .3rem; font-size: .84rem; }
#selection-hint { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.connection { display: inline-flex; align-items: center; gap: .4rem; color: var(--text-3); font-size: .76rem; white-space: nowrap; }
.connection::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.connection[data-state=live]::before { background: #22c55e; }
.connection[data-state=offline]::before { background: var(--warn); }

.receipt-workspace { display: grid; gap: 1rem; align-items: start; }
/* No padding here: boxes are positioned in % of .photo and must match the image's rendered rect. Cropped,
   the box shows the receipt: .photo is the whole photo, scaled up and shifted so the receipt fills it. */
.imgwrap { position: relative; overflow: hidden; border-radius: var(--r); background: #0b0f0e; cursor: pointer; }
.imgwrap .photo { position: relative; }
.imgwrap.cropped .photo { position: absolute; }
.imgwrap img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.box { position: absolute; display: flex; align-items: center; border: 2px dashed var(--box-open); border-radius: 6px;
  background: rgb(242 169 59 / .08); pointer-events: none; transition: background-color .2s, border-color .2s, box-shadow .2s; }
.box.assigned { border: 2px solid var(--box-done); background: rgb(25 179 124 / .07); }
.box.hit { border: 2px solid var(--box-hit); background: rgb(79 143 232 / .2); box-shadow: 0 0 0 4px rgb(79 143 232 / .32); }
.box-number { position: absolute; left: -22px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 18px; height: 18px;
  border-radius: 5px; background: var(--box-open); color: var(--box-open-ink); font: 700 .62rem/1 var(--font); box-shadow: 0 1px 3px rgb(0 0 0 / .3); }
.box.assigned .box-number { background: var(--box-done-ink); color: #fff; }
.box .lbl { position: absolute; bottom: calc(100% + 6px); left: 0; max-width: 100%; padding: .2rem .5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  border-radius: 6px; background: #0f1714; color: #fff; font-size: .72rem; box-shadow: 0 4px 12px rgb(0 0 0 / .3); opacity: 0; transition: opacity .15s; }
.box.hit .lbl { opacity: 1; }
/* Pips sit along the box where they were tapped (receipt.js sets left); the default is the right end. */
.box .tokens { position: absolute; inset: 0; }
button.pip { --btn-bg: var(--c); --btn-hover: var(--c); --btn-fg: #fff; position: absolute; top: 50%; left: calc(100% - 12px); margin: -12px 0 0 -12px;
  width: 24px; height: 24px; min-height: 24px; padding: 0; border: 2px solid #fff;
  border-radius: 50%; font-size: .62rem; font-weight: 700; line-height: 1; text-transform: uppercase; text-shadow: 0 1px 1px rgb(0 0 0 / .3);
  box-shadow: 0 1px 4px rgb(0 0 0 / .4); pointer-events: auto; }
.pip b { position: absolute; z-index: 1; top: -8px; right: -8px; min-width: 16px; height: 16px; padding: 0 3px; border-radius: 99px; background: #fff; color: #111;
  font-size: .6rem; font-weight: 800; line-height: 16px; text-shadow: none; box-shadow: 0 1px 3px rgb(0 0 0 / .4); }
.pip.flash { animation: flash .45s ease; }
.drop-marker { position: absolute; z-index: 5; width: 16px; height: 16px; border-radius: 50%; background: var(--c); pointer-events: none; animation: fall .5s ease forwards; }
.manual-entry { margin: .75rem 0 0; padding: 0; }
.manual-entry summary { display: flex; align-items: center; gap: .55rem; padding: .85rem 1rem; cursor: pointer; font-size: .92rem; font-weight: 600; list-style: none; }
.manual-entry summary::-webkit-details-marker { display: none; }
.manual-entry > p, .manual-entry > form { margin-inline: 1rem; }
/* The name gets the width; a price is a few characters. */
.manual-form { display: grid; grid-template-columns: 8rem minmax(0, 1fr); align-items: end; gap: .6rem; padding-bottom: 1rem; }
.manual-name { grid-column: 1 / -1; }
.manual-price input { text-align: right; font-variant-numeric: tabular-nums; }
/* Drawing a box: drags draw instead of scrolling, and taps don't place tokens. */
.imgwrap.drawing { touch-action: none; cursor: crosshair; }
.box.draft { z-index: 4; border: 2px solid var(--box-hit); background: rgb(79 143 232 / .22); box-shadow: 0 0 0 3px rgb(79 143 232 / .35); cursor: move; }
.box.editing { visibility: hidden; }  /* its draft stands in while it's adjusted */
/* Small dots on the draft's corners, with an invisible ring that makes them a 44px touch target. */
.corner-handle { position: absolute; width: 16px; height: 16px; margin: -9px 0 0 -9px; border: 2px solid var(--box-hit); border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .6); pointer-events: auto; cursor: nwse-resize; }
.corner-handle::before { content: ""; position: absolute; inset: -16px; border-radius: 50%; }
.corner-handle[data-corner="0"] { left: 0; top: 0; }
.corner-handle[data-corner="1"] { left: 100%; top: 0; cursor: nesw-resize; }
.corner-handle[data-corner="2"] { left: 100%; top: 100%; }
.corner-handle[data-corner="3"] { left: 0; top: 100%; cursor: nesw-resize; }
/* While a box is edited: what to do, Cancel and Save, kept on screen under a long photo. */
.box-editor-bar { position: sticky; bottom: env(safe-area-inset-bottom); z-index: 20; display: flex; align-items: center; gap: .5rem;
  margin-top: .5rem; padding: .45rem .45rem .45rem .9rem; border-radius: 14px; background: rgb(15 23 20 / .94); color: #eef4f1;
  font-size: .88rem; box-shadow: 0 12px 32px -12px rgb(0 0 0 / .5); }
.box-editor-bar > span { flex: 1; min-width: 0; }
.box-editor-bar button { flex: none; min-height: 40px; }
.box-editor-bar .text-button { --btn-fg: #8ff0c4; --btn-hover: rgb(255 255 255 / .12); }
.total-check { margin: -.25rem 0 .75rem; color: var(--success); font-size: .86rem; font-weight: 600; }
.notice.total-check { margin-top: 0; color: var(--text); font-weight: 400; }
#quickadd { position: absolute; z-index: 6; width: min(85%, 300px); padding: .65rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); cursor: auto; }
#quickadd .qa-row { display: flex; gap: .3rem; margin-top: .4rem; }
#quickadd .qa-row input { flex: 1; }
#quickadd button { padding: .4rem .6rem; }

/* Items and shares */
.review-panel { margin: 0; }
.review-head { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; margin-bottom: .4rem; }
.review-head h2 { margin: 0; }
.review-head .muted { font-size: .84rem; }
.review-head:not(:first-child) { margin-top: 1.5rem; }
progress { display: block; width: 100%; height: 6px; margin: 0 0 .75rem; border: 0; border-radius: 99px; overflow: hidden; background: var(--surface-3); -webkit-appearance: none; appearance: none; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }
progress::-webkit-progress-bar { background: var(--surface-3); }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
.item-review { margin: 0; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.item-review > li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: .6rem; padding: .55rem .6rem .6rem; border-top: 1px solid var(--border); }
.item-review > li:first-child { border-top: 0; }
.item-review > li.unassigned { background: color-mix(in srgb, var(--warn-soft) 70%, var(--surface)); }
.item-review > li.muted { display: block; padding: 1rem; }
/* Same colors as the numbered photo boxes, so list rows map onto the image. */
.item-jump { --btn-bg: var(--box-done-ink); --btn-hover: var(--btn-bg); --btn-fg: #fff; grid-row: span 2; align-self: start;
  width: 28px; height: 28px; min-height: 28px; margin-top: 8px; padding: 0; border-radius: 8px; font-size: .76rem; font-weight: 700; }
li.unassigned .item-jump { --btn-bg: var(--box-open); --btn-fg: var(--box-open-ink); }
/* The whole row adds the selected person, like tapping the item on the photo. */
.item-add { --btn-bg: transparent; --btn-hover: var(--surface-2); --btn-fg: var(--text); justify-content: flex-start; gap: .6rem; width: 100%;
  min-height: 44px; padding: .35rem .4rem; text-align: left; font-weight: 600; }
.item-add > strong { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.item-add::after { content: "+"; display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
  border: 1.5px solid var(--sel-c, var(--border-strong)); color: var(--sel-c, var(--text-3)); font-size: 1.1rem; font-weight: 500; line-height: 1; }
.item-add { grid-column: 2 / -1; }
/* A labelled button, not a hidden gesture: every item says it can be changed. */
.item-edit { --btn-fg: var(--text-2); align-self: end; gap: .3rem; min-height: 36px; padding-inline: .5rem; font-weight: 550; }
.holders { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; padding-left: .4rem; }
.holder { --btn-bg: color-mix(in srgb, var(--c) 14%, var(--surface)); --btn-hover: color-mix(in srgb, var(--c) 22%, var(--surface)); --btn-fg: var(--text);
  --btn-border: color-mix(in srgb, var(--c) 45%, var(--surface)); gap: .35rem; min-height: 34px; padding: .15rem .65rem .15rem .2rem; border-radius: 999px; font-size: .84rem; font-weight: 550; }
.holder .avatar { width: 24px; height: 24px; font-size: .66rem; }
.holder .count { color: var(--text-2); font-weight: 750; font-variant-numeric: tabular-nums; }
.holder::after { content: "−"; margin-left: .15rem; color: var(--text-3); font-weight: 600; }
.unassigned-label { color: var(--warn); font-weight: 600; font-size: .82rem; }
/* Ticking people off: a checklist, one tap per person, with what to read out to them. */
.tick-help { margin: -.25rem 0 .5rem; font-size: .84rem; }
.share-list.ticks { padding: 0 .75rem; }
.ticks li { gap: .6rem; }
.ticks .person { align-items: flex-start; }
.ticks .person > div { min-width: 0; }
.ticks .had, .ticks .lapsed { display: block; color: var(--text-2); font-size: .8rem; font-weight: 400; overflow-wrap: anywhere; }
.ticks .lapsed { color: var(--warn); font-weight: 600; }
button.tick { --btn-bg: var(--surface); --btn-hover: var(--surface-2); --btn-fg: transparent; --btn-border: var(--border-strong);
  flex: none; width: 44px; min-height: 44px; padding: 0; border-radius: 12px; }
button.tick[aria-pressed=true] { --btn-bg: var(--success); --btn-hover: var(--success); --btn-fg: #fff; --btn-border: var(--success); }
button.tick:hover .icon { color: var(--text-3); }
button.tick[aria-pressed=true]:hover .icon { color: #fff; }
.ticks .remove-person { flex: none; margin-right: -.6rem; }
#ticked { margin: .6rem 0 0; }

.feedback-toast { position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 80; display: flex; align-items: center; gap: .75rem;
  width: max-content; max-width: calc(100% - 2rem); padding: .45rem .45rem .45rem .95rem; transform: translateX(-50%);
  border-radius: 14px; background: rgb(15 23 20 / .94); color: #eef4f1; font-size: .88rem; box-shadow: 0 16px 40px -12px rgb(0 0 0 / .5); }
.feedback-toast > span { padding-block: .4rem; }
.feedback-toast button { --btn-bg: rgb(255 255 255 / .12); --btn-hover: rgb(255 255 255 / .2); --btn-fg: #8ff0c4;
  min-height: 36px; padding: .3rem .85rem; border-radius: 9px; font-size: .86rem; }

@keyframes flash { from { transform: scale(.5); } to { transform: scale(1); } }
@keyframes fall { from { opacity: 1; transform: scale(1.6); } to { opacity: 0; transform: scale(.6); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Larger screens ---------- */
@media (min-width: 720px) {
  h1 { font-size: 1.75rem; }
  main { padding-top: 1rem; }
  main.narrow { padding-top: 3rem; }
  .panel { padding: 1.4rem; }
  .manual-form { grid-template-columns: minmax(0, 1fr) 8rem auto; }
  .manual-name { grid-column: auto; }
  .upload-form .btn.large { width: auto; }
  .token-toolbar { margin-inline: 0; padding-inline: 0; }
  .tokenbar { flex-wrap: wrap; margin-inline: 0; padding-inline: 0; overflow: visible; }
}
@media (min-width: 960px) {
  .receipt-workspace { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* The receipt's currency: a quiet control under its heading. */
.currency-form { margin: .35rem 0 0; }
.currency-form label { display: inline-flex; align-items: center; gap: .45rem; color: var(--text-2); font-size: .84rem; font-weight: 500; }
.currency-form select { min-height: 36px; padding: .2rem .5rem; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; }
