/* Hallmark · macrostructure: receipt/docket app screens · design-system: design.md · designed-as-app
 * theme: custom · vibe: "market receipt, warm paper, tomato sticker" · paper: oklch(96% 0.018 70) · accent: oklch(52% 0.17 30)
 * display: Fraunces roman · body: Instrument Sans · mono: Spline Sans Mono · axes: light / roman-serif / warm
 * studied: no · context: user-approved direction · gates: pass
 */

:root {
  --color-paper:       oklch(96% 0.018 70);
  --color-paper-2:     oklch(93% 0.02 70);
  --color-paper-3:     oklch(90% 0.022 70);
  --color-ink:         oklch(21% 0.012 60);
  --color-ink-2:       oklch(40% 0.012 60);
  --color-muted:       oklch(48% 0.012 60);
  --color-rule:        oklch(80% 0.018 70);
  --color-rule-2:      oklch(86% 0.016 70);
  --color-accent:      oklch(52% 0.17 30);
  --color-accent-deep: oklch(46% 0.15 30);
  --color-accent-ink:  oklch(97% 0.014 70);
  --color-focus:       oklch(50% 0.21 30);

  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Instrument Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Spline Sans Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --space-3xs: 0.25rem; --space-2xs: 0.5rem; --space-xs: 0.75rem;
  --space-sm: 1rem; --space-md: 1.5rem; --space-lg: 2rem;
  --space-xl: 3rem; --space-2xl: 4.5rem;

  --text-xs: 0.6875rem; --text-sm: 0.8125rem; --text-md: 0.9375rem;
  --text-lg: 1.125rem; --text-xl: 1.5rem; --text-2xl: 2rem; --text-3xl: 2.625rem;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-short: 180ms;
  --dur-strike: 220ms;

  --radius-btn: 10px;
  --radius-card: 6px;
  --nav-h: 60px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow-x: clip; }
body {
  background: var(--color-paper);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: var(--text-md);
  line-height: 1.45;
  overscroll-behavior-y: none;
}

#app {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100%;
  padding: max(env(safe-area-inset-top), 14px) var(--space-sm) calc(var(--nav-h) + 84px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--color-ink); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; font-style: normal; line-height: 1.12; }

:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }

.screen { animation: fade var(--dur-short) var(--ease-out); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- shared vocabulary ---------- */
.micro {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--color-muted);
}
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.leader { flex: 1; min-width: 12px; border-bottom: 2px dotted var(--color-rule); margin: 0 8px; transform: translateY(-0.28em); }

.rule-h { border: none; border-top: 1px solid var(--color-rule); }

.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  font-family: var(--font-mono); font-size: 0.625rem; font-weight: 600;
  letter-spacing: 0.02em; color: var(--color-accent-ink);
}
.avatar.lg { width: 42px; height: 42px; font-size: 0.8125rem; }
.avatars { display: flex; }
.avatars .avatar { border: 2px solid var(--color-paper); }
.avatars .avatar:not(:first-child) { margin-left: -7px; }

.stamp {
  display: inline-block;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--color-accent-deep);
  border: 1.5px solid var(--color-accent-deep);
  border-radius: 4px;
  padding: 1px 7px;
}

.sticker {
  display: inline-block;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--color-accent); color: var(--color-accent-ink);
  border-radius: 4px;
  padding: 2px 8px;
}

/* torn receipt bottom edge */
.torn { position: relative; }
.torn::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: -7px; height: 8px;
  background: var(--color-paper-2);
  clip-path: polygon(0 0, 100% 0, 100% 20%, 97% 100%, 94% 20%, 91% 100%, 88% 20%, 85% 100%, 82% 20%, 79% 100%, 76% 20%, 73% 100%, 70% 20%, 67% 100%, 64% 20%, 61% 100%, 58% 20%, 55% 100%, 52% 20%, 49% 100%, 46% 20%, 43% 100%, 40% 20%, 37% 100%, 34% 20%, 31% 100%, 28% 20%, 25% 100%, 22% 20%, 19% 100%, 16% 20%, 13% 100%, 10% 20%, 7% 100%, 4% 20%, 1% 100%, 0 20%);
}

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: var(--space-xs); margin-bottom: var(--space-md); min-height: 40px; }
.top .back {
  width: 38px; height: 38px; flex: none;
  border: 1px solid var(--color-rule); border-radius: var(--radius-btn);
  display: grid; place-items: center;
  font-size: 1.125rem; line-height: 1; color: var(--color-ink-2);
  background: var(--color-paper);
  transition: background-color var(--dur-short) var(--ease-out);
}
.top .back:hover { background: var(--color-paper-2); }
.top .back:active { background: var(--color-paper-3); }
.top .title { flex: 1; min-width: 0; }
.top .title h1 { font-size: var(--text-xl); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .title .sub { margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.wordmark { font-family: var(--font-display); font-weight: 650; font-size: 1.375rem; letter-spacing: -0.01em; }
.wordmark .dot { color: var(--color-accent); }

.live { display: inline-flex; align-items: center; gap: 6px; }
.live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--color-accent); animation: live-pulse 2.4s infinite; }
@keyframes live-pulse { 50% { opacity: 0.35; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-block;
  padding: 12px 18px;
  border-radius: var(--radius-btn);
  border: 1.5px solid var(--color-ink);
  background: var(--color-paper);
  font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  text-align: center; white-space: nowrap;
  transition: background-color var(--dur-short) var(--ease-out), transform 100ms var(--ease-out);
}
.btn:hover { background: var(--color-paper-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-accent-ink); }
.btn.primary:hover { background: var(--color-accent-deep); border-color: var(--color-accent-deep); }
.btn.danger { border-color: var(--color-accent-deep); color: var(--color-accent-deep); }
.btn.small { padding: 8px 12px; font-size: var(--text-xs); }
.btn-row { display: flex; gap: var(--space-xs); margin-top: var(--space-sm); }
.btn-row .btn { flex: 1; }

.link-btn {
  font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--color-accent-deep);
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px;
  white-space: nowrap;
}

/* ---------- section labels ---------- */
.section-label {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-xs);
  margin: var(--space-lg) 0 var(--space-2xs);
  padding-bottom: var(--space-3xs);
  border-bottom: 1px solid var(--color-rule);
}

/* ---------- home ---------- */
.hello { margin: var(--space-xs) 0 var(--space-md); }
.hello .hi { color: var(--color-ink-2); font-size: var(--text-md); }
.hello h1 { font-size: var(--text-2xl); margin-top: 2px; }

.ticket {
  display: flex; align-items: center; gap: var(--space-xs);
  border: 1px solid var(--color-rule); border-radius: var(--radius-card);
  background: var(--color-paper);
  padding: 14px var(--space-sm);
  margin-bottom: var(--space-2xs);
  width: 100%; text-align: left;
  transition: background-color var(--dur-short) var(--ease-out);
}
.ticket:hover { background: var(--color-paper-2); }
.ticket:active { background: var(--color-paper-3); }
.ticket .meta { flex: 1; min-width: 0; }
.ticket .name { font-family: var(--font-display); font-weight: 600; font-size: var(--text-lg); }
.ticket .sub { margin-top: 3px; }
.ticket .amt { font-weight: 600; font-size: var(--text-md); }
.ticket .chev { color: var(--color-muted); flex: none; font-size: 1.05rem; }

/* ---------- invite stub ---------- */
.stub {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-xs);
  border: 1.5px dashed var(--color-ink-2); border-radius: var(--radius-card);
  padding: 12px var(--space-sm);
  margin-bottom: var(--space-sm);
  width: 100%; text-align: left;
  background: var(--color-paper);
  transition: background-color var(--dur-short) var(--ease-out);
}
.stub:hover { background: var(--color-paper-2); }
.stub .code {
  font-family: var(--font-mono); font-weight: 600; font-size: 1.375rem;
  letter-spacing: 0.28em; font-variant-numeric: tabular-nums;
}
.stub .hint { margin-top: 2px; }

/* ---------- receipt totals block ---------- */
.receipt {
  background: var(--color-paper-2);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  padding: var(--space-xs) var(--space-sm) var(--space-2xs);
  margin-bottom: var(--space-sm);
}
.receipt .row {
  display: flex; align-items: baseline;
  font-family: var(--font-mono); font-size: var(--text-sm);
  padding: 3px 0;
}
.receipt .row .lbl { text-transform: uppercase; letter-spacing: 0.09em; font-size: var(--text-xs); color: var(--color-muted); }
.receipt .row .val { font-variant-numeric: tabular-nums; font-weight: 500; }
.receipt .row.grand .val { font-weight: 600; font-size: var(--text-md); }
.receipt .row.grand .lbl { color: var(--color-ink); }
.receipt .payers { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: var(--space-2xs) 0 var(--space-3xs); border-top: 1px solid var(--color-rule); margin-top: var(--space-2xs); }
.receipt .payer { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--color-ink-2); }
.receipt .payer .num { font-weight: 600; color: var(--color-ink); }

/* ---------- list rows ---------- */
.aisle { margin-top: var(--space-md); }
.aisle-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding-bottom: var(--space-3xs); margin-bottom: 2px;
  border-bottom: 1px solid var(--color-rule);
}

.item {
  display: flex; align-items: flex-start; gap: var(--space-2xs);
  padding: 12px 0 11px;
  border-bottom: 1px solid var(--color-rule-2);
}
.item .tap-zone { display: flex; align-items: flex-start; gap: var(--space-xs); flex: 1; min-width: 0; text-align: left; }
.item .tick {
  width: 22px; height: 22px; margin-top: 1px; flex: none;
  border: 1.5px solid var(--color-ink-2); border-radius: 4px;
  display: grid; place-items: center;
  font-size: 0.8125rem; line-height: 1; color: transparent;
  transition: background-color var(--dur-short) var(--ease-out), border-color var(--dur-short) var(--ease-out), color var(--dur-short) var(--ease-out);
}
.item.bought .tick { background: var(--color-ink); border-color: var(--color-ink); color: var(--color-paper); }
.item .body { flex: 1; min-width: 0; }
.item .line1 { display: flex; align-items: baseline; min-width: 0; }
.item .name { font-weight: 500; min-width: 0; overflow-wrap: anywhere; position: relative; }
.item.bought .name { color: var(--color-muted); }
.item.bought .name::after {
  content: ''; position: absolute; left: -2px; right: -2px; top: 54%;
  border-top: 1.5px solid var(--color-ink-2);
  transform-origin: left center;
  animation: strike var(--dur-strike) var(--ease-out);
}
@keyframes strike { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.item .price { flex: none; font-weight: 500; font-size: var(--text-md); }
.item.bought .price { color: var(--color-muted); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.item .sub { margin-top: 3px; display: flex; align-items: center; gap: var(--space-2xs); flex-wrap: wrap; }
.item .sub .plain { font-size: var(--text-xs); color: var(--color-muted); }
.item .save-tap { padding: 0; margin-top: 5px; display: block; }
.item .more {
  flex: none; color: var(--color-muted);
  font-size: 1.125rem; line-height: 1;
  padding: 4px 2px 4px 8px; margin-top: 2px;
}

.empty { text-align: center; color: var(--color-muted); padding: var(--space-2xl) var(--space-md); }
.empty .glyph { font-family: var(--font-mono); font-size: var(--text-sm); letter-spacing: 0.2em; display: block; margin-bottom: var(--space-xs); color: var(--color-rule); }

/* ---------- add bar + tab bar ---------- */
.addbar {
  position: fixed; z-index: 40;
  right: max(calc(50% - 244px), var(--space-sm));
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
}
.addbar .btn { box-shadow: 0 2px 0 var(--color-accent-deep); }
.addbar .btn:active { transform: translateY(2px); box-shadow: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--color-paper);
  border-top: 1px solid var(--color-rule);
  display: flex; justify-content: center;
}
.tabbar .inner { display: flex; width: 100%; max-width: 520px; }
.tab {
  flex: 1; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: var(--text-xs); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--color-muted);
}
.tab.active { color: var(--color-ink); }
.tab.active .tab-label { border-bottom: 2px solid var(--color-accent); padding-bottom: 2px; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: oklch(25% 0.02 60 / 0.42);
  opacity: 0; transition: opacity var(--dur-short) var(--ease-out);
}
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 520px; margin: 0 auto;
  background: var(--color-paper);
  border-top: 2px solid var(--color-ink);
  padding: var(--space-sm) var(--space-sm) calc(var(--space-sm) + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 240ms var(--ease-out);
  max-height: 86dvh; display: flex; flex-direction: column;
}
.sheet.open { transform: none; }
.sheet h2 { font-size: var(--text-xl); margin-bottom: var(--space-sm); }
.sheet .scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.sheet .btn { display: block; width: 100%; }
.sheet .btn + .btn { margin-top: var(--space-2xs); }
.sheet .btn.small { width: auto; display: inline-block; }

.field { margin-bottom: var(--space-xs); }
.field label { display: block; margin-bottom: var(--space-3xs); }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--color-paper);
  border: 1px solid var(--color-rule);
  border-bottom: 1.5px solid var(--color-ink-2);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  padding: 12px 12px;
  font-size: var(--text-md);
  outline: none;
  transition: border-color var(--dur-short) var(--ease-out), background-color var(--dur-short) var(--ease-out);
}
.field input:focus, .field select:focus, .field textarea:focus { border-bottom-color: var(--color-accent); background: var(--color-paper-2); }
.field-row { display: flex; gap: var(--space-xs); }
.field-row .field { flex: 1; }

.seg {
  display: flex; gap: var(--space-md);
  border-bottom: 1px solid var(--color-rule);
  margin-bottom: var(--space-sm);
}
.seg button {
  font-family: var(--font-mono); font-size: var(--text-sm); font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--color-muted);
  padding: 6px 0 8px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.seg button.active { color: var(--color-ink); border-bottom-color: var(--color-accent); }

.search-result {
  display: flex; align-items: baseline; width: 100%; text-align: left;
  padding: 11px 2px;
  border-bottom: 1px solid var(--color-rule-2);
  transition: background-color var(--dur-short) var(--ease-out);
}
.search-result:hover { background: var(--color-paper-2); }
.search-result:active { background: var(--color-paper-3); }
.search-result .body { min-width: 0; }
.search-result .name { font-weight: 500; overflow-wrap: anywhere; }
.search-result .sub { margin-top: 2px; display: block; }
.search-result .price { font-weight: 600; }

.store-tag {
  font-family: var(--font-mono); font-size: 0.625rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em;
  border: 1px solid var(--color-rule); border-radius: 3px;
  color: var(--color-muted);
  padding: 0 4px; margin-left: 6px;
  white-space: nowrap;
}

.alt-row {
  display: flex; align-items: center; gap: var(--space-xs);
  padding: 12px 2px;
  border-bottom: 1px solid var(--color-rule-2);
}
.alt-row .body { flex: 1; min-width: 0; }
.alt-row .save-line { margin-top: 3px; }

/* ---------- comments ---------- */
.comments { display: flex; flex-direction: column; gap: var(--space-sm); padding: var(--space-3xs) 0 var(--space-sm); }
.comment { display: flex; gap: var(--space-2xs); align-items: flex-start; }
.comment .note { min-width: 0; border-left: 2px solid var(--color-rule); padding-left: var(--space-2xs); }
.comment.mine .note { border-left-color: var(--color-accent); }
.comment .meta { display: block; margin-bottom: 2px; }
.comment .text { overflow-wrap: anywhere; }
.comment-input { display: flex; gap: var(--space-2xs); margin-top: var(--space-3xs); }
.comment-input input {
  flex: 1; min-width: 0;
  background: var(--color-paper);
  border: 1px solid var(--color-rule);
  border-bottom: 1.5px solid var(--color-ink-2);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  padding: 10px 12px; outline: none;
  transition: border-color var(--dur-short) var(--ease-out);
}
.comment-input input:focus { border-bottom-color: var(--color-accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom));
  z-index: 70;
  background: var(--color-ink); color: var(--color-paper);
  font-family: var(--font-mono); font-size: var(--text-sm);
  border-radius: 4px;
  padding: 9px 16px;
  white-space: nowrap; max-width: calc(100vw - 32px); overflow: hidden; text-overflow: ellipsis;
  animation: toast-in var(--dur-short) var(--ease-out);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(6px); } }

/* ---------- onboarding (styled as a printed receipt) ---------- */
.onboard { display: flex; flex-direction: column; justify-content: center; min-height: 82dvh; text-align: center; }
.onboard .receipt-head { font-family: var(--font-mono); font-size: var(--text-sm); letter-spacing: 0.18em; color: var(--color-muted); text-transform: uppercase; }
.onboard h1 { font-size: var(--text-3xl); margin: var(--space-2xs) 0; overflow-wrap: anywhere; }
.onboard .tagline { color: var(--color-ink-2); margin-bottom: var(--space-lg); }
.onboard .rule-line { font-family: var(--font-mono); color: var(--color-rule); letter-spacing: 0.1em; margin: var(--space-xs) 0; user-select: none; }
.onboard .field input { text-align: center; font-size: var(--text-lg); }
.onboard .btn { margin-top: var(--space-xs); }

.swatches { display: flex; justify-content: center; gap: var(--space-2xs); flex-wrap: wrap; margin: var(--space-sm) 0 var(--space-2xs); }
.swatches button {
  width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid transparent;
  outline-offset: 3px;
  transition: transform 100ms var(--ease-out);
}
.swatches button.sel { border-color: var(--color-paper); box-shadow: 0 0 0 2px var(--color-ink); }
.swatches button:active { transform: scale(0.92); }

/* ---------- profile ---------- */
.profile-card { display: flex; align-items: center; gap: var(--space-xs); padding: var(--space-sm) 0 var(--space-md); border-bottom: 1px solid var(--color-rule); margin-bottom: var(--space-md); }

/* ---------- responsive ---------- */
@media (max-width: 355px) {
  .hello h1 { font-size: var(--text-xl); }
  .onboard h1 { font-size: var(--text-2xl); }
  .stub .code { font-size: 1.125rem; letter-spacing: 0.2em; }
}

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