:root {
  --bg: #f3f5ef;
  --card: #ffffff;
  --card-2: #f7f9f4;
  --ink: #0e0f0c;
  --muted: #5d6659;
  --line: #e2e7dc;
  --brand: #9fe870;
  --brand-hover: #8fdc5c;
  --brand-ink: #163300;
  --brand-soft: #e8f8dc;
  --dark: #163300;
  --dark-ink: #ffffff;
  --warn: #9a4a00;
  --warn-soft: #fff1d6;
  --danger: #c4320a;
  --ok: #2f7a12;
  --shadow: 0 1px 2px rgba(14, 15, 12, 0.04), 0 8px 24px rgba(14, 15, 12, 0.06);
  --radius: 22px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1410;
    --card: #181f19;
    --card-2: #1e2620;
    --ink: #f1f5ee;
    --muted: #a1ad9c;
    --line: #2a332b;
    --brand-soft: #22341a;
    --dark: #9fe870;
    --dark-ink: #163300;
    --warn: #ffc46b;
    --warn-soft: #3a2a10;
    --danger: #ff8a65;
    --ok: #9fe870;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
svg { width: 20px; height: 20px; flex: none; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; line-height: 1.15; }
h2 { font-size: 22px; font-weight: 800; }
h3 { font-size: 17px; font-weight: 700; }
p { margin: 0; }
small { font-size: 0.8em; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.app { max-width: 560px; margin: 0 auto; padding: 0 16px; padding-bottom: env(safe-area-inset-bottom); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 18px 0 8px; }
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 22px; letter-spacing: -0.04em; color: var(--ink); text-decoration: none; }
.logo-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); font-size: 20px; }

.page { display: flex; flex-direction: column; gap: 16px; padding: 8px 0 40px; }
.page.has-bar { padding-bottom: 120px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 24px; border: 0; border-radius: 999px;
  font-weight: 700; font-size: 16px; text-decoration: none; white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-dark { background: var(--dark); color: var(--dark-ink); }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--card-2); }
.btn-small { min-height: 40px; padding: 0 16px; font-size: 14px; }
.btn-small svg { width: 18px; height: 18px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 8px 0; color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-align: left; }
.btn-link.danger { color: var(--danger); }
.icon-btn { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); }
.icon-btn:hover { background: var(--card-2); color: var(--ink); }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- cards & fields ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px; }
.card.center { align-items: center; text-align: center; padding: 36px 22px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 14px; font-weight: 600; color: var(--muted); }
input[type="text"], input[type="number"] {
  width: 100%; min-height: 52px; padding: 0 16px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--card); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus { border-color: var(--ink); box-shadow: 0 0 0 3px var(--brand-soft); }
input::placeholder { color: var(--muted); opacity: 0.7; }
.error { color: var(--danger); font-weight: 600; font-size: 15px; }

/* ---------- home ---------- */
.hero { padding: 20px 4px 8px; }
.hero h1 { font-size: clamp(34px, 9vw, 46px); font-weight: 800; letter-spacing: -0.045em; }
.hero .hl { background: linear-gradient(transparent 62%, var(--brand) 62%); padding: 0 2px; }
@media (prefers-color-scheme: dark) { .hero .hl { background: none; color: var(--brand); } }
.hero p { margin-top: 14px; font-size: 18px; color: var(--muted); max-width: 30em; }

.upload {
  display: flex; align-items: center; gap: 16px; padding: 20px;
  border: 2px dashed var(--line); border-radius: 18px; background: var(--card-2);
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.upload:hover { border-color: var(--brand); background: var(--brand-soft); }
.upload-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--brand); color: var(--brand-ink); flex: none; }
.upload-icon svg { width: 28px; height: 28px; }
.upload-text { display: flex; flex-direction: column; }
.upload-text strong { font-size: 17px; }
.upload-text span { color: var(--muted); font-size: 14px; }

.join-code { display: flex; gap: 10px; }
.code-input { text-transform: uppercase; letter-spacing: 0.25em; font-weight: 700; font-size: 20px; text-align: center; }
.join-code .btn { flex: none; }

.steps { list-style: none; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.steps li { display: flex; gap: 12px; padding: 16px; border-radius: 18px; background: var(--card); font-size: 14px; color: var(--muted); }
.steps li span { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; background: var(--brand-soft); color: var(--ink); font-weight: 800; font-size: 14px; flex: none; }
.steps strong { display: block; color: var(--ink); font-size: 15px; }

/* ---------- scanning ---------- */
.scan-card { align-items: center; text-align: center; }
.scan-card .stack { width: 100%; }
.scan-preview { position: relative; width: 100%; max-height: 340px; border-radius: 16px; overflow: hidden; background: var(--card-2); min-height: 160px; }
.scan-preview img { display: block; width: 100%; max-height: 340px; object-fit: cover; object-position: top; }
.scan-preview.is-scanning img { filter: saturate(0.6) brightness(0.95); }
.scan-line { position: absolute; left: 0; right: 0; height: 80px; top: -80px; background: linear-gradient(transparent, rgba(159, 232, 112, 0.55), transparent); animation: scan 1.8s ease-in-out infinite; }
@keyframes scan { to { top: 100%; } }

.spinner { width: 36px; height: 36px; border-radius: 999px; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- lobby header ---------- */
.bill-head { background: var(--dark); color: var(--dark-ink); border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.bill-head-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.bill-head h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.035em; word-break: break-word; }
.eyebrow { font-size: 13px; font-weight: 600; opacity: 0.75; margin-bottom: 4px; }
.code-chip { display: flex; flex-direction: column; align-items: center; padding: 8px 14px; border: 0; border-radius: 14px; background: var(--brand); color: var(--brand-ink); flex: none; }
.code-chip span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; }
.code-chip strong { font-size: 18px; letter-spacing: 0.12em; }
@media (prefers-color-scheme: dark) { .code-chip { background: var(--brand-ink); color: var(--brand); } }
.bill-head-stats { display: flex; gap: 28px; }
.bill-head-stats div { display: flex; flex-direction: column; }
.bill-head-stats span { font-size: 13px; opacity: 0.75; font-weight: 600; }
.bill-head-stats strong { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.bill-head-stats .accent { color: var(--brand); }
@media (prefers-color-scheme: dark) { .bill-head-stats .accent { color: var(--brand-ink); } }
.host-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.host-actions .btn-ghost { color: var(--dark-ink); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--dark-ink) 30%, transparent); }
.host-actions .btn-ghost:hover { background: color-mix(in srgb, var(--dark-ink) 10%, transparent); }

/* ---------- banners & tags ---------- */
.banner { display: flex; gap: 10px; align-items: center; padding: 14px 16px; border-radius: 16px; font-size: 15px; }
.banner-info { background: var(--brand-soft); justify-content: space-between; }
.banner-info .btn { flex: none; }
.banner-lock { background: color-mix(in srgb, var(--dark-ink) 12%, transparent); padding: 10px 14px; font-weight: 600; }
.banner-ok { background: var(--brand-soft); font-weight: 600; }
.banner-ok svg { color: var(--ok); }
.banner-warn { background: var(--warn-soft); color: var(--ink); flex-direction: column; align-items: stretch; gap: 6px; }
.banner-warn strong { color: var(--warn); }
.banner-warn ul { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.banner-warn li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--card-2); color: var(--muted); font-size: 12px; font-weight: 700; vertical-align: middle; box-shadow: inset 0 0 0 1px var(--line); }
.tag-warn { background: var(--warn-soft); color: var(--warn); box-shadow: none; }
.tag-accent { background: var(--brand); color: var(--brand-ink); box-shadow: none; }

/* ---------- tabs & segmented ---------- */
.tabs, .segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 4px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); }
.segmented { background: var(--card-2); box-shadow: inset 0 0 0 1px var(--line); }
.tabs button, .segmented button { min-height: 44px; border: 0; border-radius: 999px; background: transparent; font-weight: 700; color: var(--muted); }
.tabs button[aria-selected="true"], .segmented button[aria-checked="true"] { background: var(--dark); color: var(--dark-ink); }

/* ---------- items ---------- */
.hint { color: var(--muted); font-size: 14px; padding: 0 4px; }
.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; transition: box-shadow 0.15s; }
.item.is-mine { box-shadow: inset 0 0 0 2px var(--brand), var(--shadow); }
.item-main { display: flex; align-items: flex-start; gap: 14px; width: 100%; padding: 16px; border: 0; background: transparent; text-align: left; }
.item-main:disabled { opacity: 1; }
.check { display: grid; place-items: center; width: 28px; height: 28px; margin-top: 1px; border-radius: 999px; box-shadow: inset 0 0 0 2px var(--line); color: transparent; flex: none; transition: background 0.15s; }
.check svg { width: 16px; height: 16px; }
.is-mine .check { background: var(--brand); color: var(--brand-ink); box-shadow: none; }
.item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.item-name { font-weight: 700; font-size: 16px; word-break: break-word; }
.item-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.item-meta:empty { display: none; }
.item-price { font-weight: 800; font-size: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.claimers { display: flex; flex-wrap: wrap; gap: 6px; }
.claimer { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 2px; border-radius: 999px; background: var(--card-2); font-size: 13px; font-weight: 600; box-shadow: inset 0 0 0 1px var(--line); }
.stepper-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px 14px 58px; font-size: 14px; color: var(--muted); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--card-2); border-radius: 999px; padding: 4px; box-shadow: inset 0 0 0 1px var(--line); }
.stepper button { width: 36px; height: 36px; border: 0; border-radius: 999px; background: var(--card); font-size: 20px; font-weight: 700; box-shadow: var(--shadow); }
.stepper button:disabled { opacity: 0.35; }
.stepper output { min-width: 56px; text-align: center; font-weight: 800; color: var(--ink); }
.stepper output small { color: var(--muted); font-weight: 600; }

.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 999px; font-weight: 800; font-size: 15px; flex: none; color: #10210a; }
.avatar.xs { width: 22px; height: 22px; font-size: 10px; }
.hue-0 { background: #9fe870; } .hue-1 { background: #ffc091; } .hue-2 { background: #a0e1e1; } .hue-3 { background: #ffd56b; }
.hue-4 { background: #c9b6ff; } .hue-5 { background: #ffb3c7; } .hue-6 { background: #b8d7ff; } .hue-7 { background: #d7e8a0; }

.mini-items { list-style: none; margin: 0; padding: 0; }
.mini-items li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.mini-items li:last-child { border-bottom: 0; }

/* ---------- join ---------- */
.rejoin { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; border-top: 1px solid var(--line); }
.rejoin p { padding-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px 4px 6px; border: 0; border-radius: 999px; background: var(--card-2); font-weight: 600; font-size: 14px; box-shadow: inset 0 0 0 1px var(--line); }
.chip:hover { background: var(--brand-soft); }
.tip-chips .chip { padding: 4px 14px; }

/* ---------- totals ---------- */
.progress-label { display: flex; justify-content: space-between; font-size: 14px; font-weight: 600; color: var(--muted); gap: 12px; }
.progress { height: 10px; border-radius: 999px; background: var(--card-2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.progress span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width 0.3s; }
.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.person { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.person.is-me { box-shadow: inset 0 0 0 2px var(--brand), var(--shadow); }
.person-main { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border: 0; background: transparent; text-align: left; }
.person-name { flex: 1; min-width: 0; font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.person-name small { width: 100%; color: var(--muted); font-weight: 500; font-size: 13px; }
.person-total { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.chev { color: var(--muted); transition: transform 0.2s; display: grid; }
.is-open .chev { transform: rotate(90deg); }
.breakdown { padding: 0 16px 14px 68px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.breakdown > div { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.breakdown small { color: var(--muted); }
.breakdown .sub { color: var(--muted); }

/* ---------- editor ---------- */
.editor h3 { margin-top: 8px; }
.editor-head { display: flex; flex-direction: column; gap: 6px; }
.edit-head, .edit-row { display: grid; grid-template-columns: 1fr 64px 112px 36px; gap: 6px; align-items: center; }
.qty-input span { display: none; }
.edit-head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 0 4px; margin-bottom: -6px; }
.edit-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.edit-items .empty { padding: 12px 4px; }
.edit-row input { min-height: 46px; padding: 0 10px; border-radius: 12px; }
.edit-row .e-qty { text-align: center; padding: 0 4px; }
.edit-row .icon-btn { width: 36px; height: 36px; }
/* phones: item name on its own line, quantity and price underneath */
@media (max-width: 520px) {
  .edit-head { display: none; }
  .edit-items { gap: 0; }
  .edit-row { grid-template-columns: 1fr 1fr 36px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .edit-row .e-name { grid-column: 1 / -1; }
  .qty-input { position: relative; }
  .qty-input span { display: block; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; font-size: 14px; pointer-events: none; }
  .edit-row .e-qty { text-align: right; padding: 0 10px 0 40px; }
}
.money-input { position: relative; }
.money-input span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }
.money-input input { padding-left: 24px; text-align: right; font-variant-numeric: tabular-nums; }
.field-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field-row .money-input { width: 140px; flex: none; }
.field-row .label small { font-weight: 500; }
.tip-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.draft-summary { background: var(--card-2); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; font-variant-numeric: tabular-nums; }
.draft-summary > div { display: flex; justify-content: space-between; gap: 12px; }
.draft-summary .strong { font-weight: 800; font-size: 18px; }
.draft-summary .ok { color: var(--ok); font-weight: 600; display: inline-flex; gap: 6px; align-items: center; }
.draft-summary .warn { color: var(--warn); font-weight: 600; }
.editor-actions { display: flex; gap: 10px; justify-content: flex-end; }
.editor-actions .btn { flex: 1; }

/* ---------- bottom bar ---------- */
.bottom-bar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(560px, 100%); padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.bottom-bar div { display: flex; flex-direction: column; }
.bottom-bar span { font-size: 13px; color: var(--muted); font-weight: 600; }
.bottom-bar strong { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }

.footnote { text-align: center; color: var(--muted); font-size: 13px; padding-top: 8px; }

/* ---------- share sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(8, 12, 6, 0.5); animation: fade 0.2s; z-index: 20; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 21;
  width: min(520px, 100%); max-height: 92vh; overflow: auto;
  background: var(--card); border-radius: 28px 28px 0 0; padding: 26px 20px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px; animation: rise 0.25s ease-out;
}
@media (min-width: 600px) { .sheet { bottom: 50%; transform: translate(-50%, 50%); border-radius: 28px; animation: fade 0.2s; } }
.sheet-close { position: absolute; top: 14px; right: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translate(-50%, 40px); opacity: 0; } }
.big-code { display: flex; justify-content: center; gap: 6px; }
.big-code span { display: grid; place-items: center; width: 46px; height: 58px; border-radius: 12px; background: var(--brand-soft); font-size: 28px; font-weight: 800; }
.qr { width: 180px; margin: 0 auto; padding: 10px; background: #fff; border-radius: 16px; }
.qr svg { width: 100%; height: auto; display: block; }
.link-box { padding: 14px 16px; border-radius: 14px; background: var(--card-2); font-size: 14px; font-weight: 600; word-break: break-all; text-align: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%); z-index: 30;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 15px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  animation: fade 0.2s;
}
.toast.good { background: var(--dark); color: var(--dark-ink); }
.toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 380px) {
  .steps { grid-template-columns: 1fr; }
  .big-code span { width: 40px; height: 52px; font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
