/* ============================================================
   SplitCheck — tip & split the bill
   Direction: warm diner-check meets modern fintech. Cream paper,
   tangerine accent, deep espresso ink, mint for "settled".
   Fraunces (display) · Hanken Grotesk (UI) · Space Mono (tallies).
   ============================================================ */

:root {
  --paper:   #fff7ec;
  --paper-2: #fdeede;
  --card:    #ffffff;
  --ink:     #241a12;
  --ink-2:   #6a5c4f;
  --line:    #eaddca;
  --brand:   #f2621f;   /* tangerine */
  --brand-d: #d24d10;
  --brand-t: #fde3d3;   /* tint */
  --mint:    #0fa88b;
  --mint-t:  #d6f2ea;
  --gold:    #f3a712;
  --shadow:  0 1px 2px rgba(60,38,20,.06), 0 12px 30px -14px rgba(60,38,20,.28);
  --shadow-sm: 0 1px 2px rgba(60,38,20,.08), 0 4px 12px -8px rgba(60,38,20,.22);
  --r-lg: 22px;
  --r-md: 15px;
  --r-sm: 11px;
  --maxw: 480px;
  --font-ui: "Hanken Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-disp: "Fraunces", Georgia, serif;
  --font-mono: "Space Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(120% 60% at 100% 0%, var(--paper-2), transparent 60%),
    radial-gradient(90% 50% at 0% 100%, #fdece0, transparent 55%),
    var(--paper);
  background-attachment: fixed;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

.app {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 18px calc(40px + env(safe-area-inset-bottom));
}

/* ---------------- topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 4px 12px;
  margin-bottom: 4px;
  background: linear-gradient(var(--paper) 62%, rgba(255,247,236,0));
  padding-top: calc(14px + env(safe-area-inset-top));
}
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 12px;
  background: var(--brand); box-shadow: var(--shadow-sm);
  --paper: #fff; --ink: #fff;
}
.brand-mark svg path[stroke] { stroke: #fff; }
.brand-mark svg path[fill="var(--paper)"] { fill: rgba(255,255,255,.14); }
.brand-name {
  font-family: var(--font-disp); font-weight: 600; font-size: 1.32rem;
  letter-spacing: -.02em; line-height: 1;
}
.brand-name span { color: var(--brand); }
.brand-name.small { font-size: 1.05rem; }
.ghost-btn {
  font: inherit; font-weight: 600; font-size: .85rem;
  color: var(--ink-2); background: transparent;
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 7px 15px; cursor: pointer;
  transition: background .18s, color .18s, border-color .18s, transform .1s;
}
.ghost-btn:hover { background: #fff; color: var(--ink); border-color: #ddc9ad; }
.ghost-btn:active { transform: scale(.96); }

/* ---------------- hero ---------------- */
.hero { padding: 12px 4px 22px; }
.hero h1 {
  font-family: var(--font-disp); font-weight: 600;
  font-size: clamp(1.9rem, 8.5vw, 2.5rem); line-height: 1.02;
  letter-spacing: -.025em; margin: 0 0 10px;
}
.hero .sub { margin: 0; color: var(--ink-2); font-size: 1.02rem; max-width: 34ch; }

/* ---------------- mode switch ---------------- */
.mode-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--paper-2); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 4px; margin-bottom: 20px;
  position: sticky; top: calc(64px + env(safe-area-inset-top)); z-index: 20;
}
.mode-btn {
  font: inherit; font-weight: 600; font-size: .95rem;
  color: var(--ink-2); background: transparent; border: 0;
  padding: 11px 8px; border-radius: 999px; cursor: pointer;
  transition: color .2s, background .2s, box-shadow .2s;
}
.mode-btn.is-active { color: var(--ink); background: var(--card); box-shadow: var(--shadow-sm); }
.mode-btn:not(.is-active):hover { color: var(--ink); }

/* ---------------- cards ---------------- */
.panel { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-sm);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.field-label {
  display: block; font-weight: 700; font-size: .78rem;
  text-transform: uppercase; letter-spacing: .09em; color: var(--ink-2);
  margin-bottom: 11px;
}
.hint { margin: 11px 2px 0; font-size: .82rem; color: var(--ink-2); }
.count-pill {
  font-size: .78rem; font-weight: 600; color: var(--brand-d);
  background: var(--brand-t); padding: 4px 11px; border-radius: 999px;
}

/* ---------------- money input ---------------- */
.money-input {
  display: flex; align-items: center; gap: 6px;
  border: 2px solid var(--line); border-radius: var(--r-md);
  padding: 4px 16px; background: var(--paper);
  transition: border-color .18s, background .18s;
}
.money-input:focus-within { border-color: var(--brand); background: #fff; }
.money-input .cur {
  font-family: var(--font-disp); font-size: 1.7rem; font-weight: 500;
  color: var(--ink-2); line-height: 1;
}
.money-field {
  flex: 1; min-width: 0; font-family: var(--font-disp);
  font-size: 2.1rem; font-weight: 600; letter-spacing: -.02em;
  color: var(--ink); background: transparent; border: 0;
  padding: 8px 0; width: 100%;
  font-variant-numeric: tabular-nums;
}
.money-field:focus { outline: none; }
.money-field::placeholder { color: #cdbda4; }
.money-input.small { padding: 2px 12px; }
.money-input.small .cur { font-size: 1.1rem; }
.money-input.small .money-field { font-size: 1.25rem; padding: 9px 0; }

/* ---------------- chips ---------------- */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-row.tight { gap: 6px; }
.chip {
  flex: 1 1 auto; min-width: 56px;
  font: inherit; font-weight: 700; font-size: .98rem;
  color: var(--ink); background: var(--paper);
  border: 2px solid var(--line); border-radius: var(--r-sm);
  padding: 11px 6px; cursor: pointer;
  transition: all .16s ease; text-align: center;
}
.chip-row.tight .chip { padding: 9px 4px; font-size: .9rem; min-width: 40px; }
.chip:hover { border-color: #e0b79c; }
.chip:active { transform: scale(.95); }
.chip.is-active {
  background: var(--brand); color: #fff; border-color: var(--brand);
  box-shadow: 0 6px 16px -8px var(--brand);
}
.chip-custom { flex: 0 0 auto; }
.custom-tip {
  display: flex; align-items: center; gap: 4px; margin-top: 10px;
  border: 2px solid var(--brand); border-radius: var(--r-sm);
  padding: 4px 14px; background: #fff; max-width: 160px;
}
.custom-tip-field {
  font: inherit; font-weight: 700; font-size: 1.15rem; color: var(--ink);
  border: 0; background: transparent; width: 100%; padding: 8px 0;
}
.custom-tip-field:focus { outline: none; }
.custom-tip .pct { font-weight: 700; color: var(--ink-2); }

/* ---------------- stepper ---------------- */
.stepper {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--paper); border: 2px solid var(--line);
  border-radius: var(--r-md); padding: 8px;
}
.step-btn {
  width: 52px; height: 52px; border-radius: 12px;
  font-size: 1.7rem; font-weight: 600; line-height: 1;
  color: var(--brand-d); background: #fff; border: 1.5px solid var(--line);
  cursor: pointer; display: grid; place-items: center;
  transition: transform .1s, background .16s, box-shadow .16s;
}
.step-btn:hover { background: var(--brand-t); }
.step-btn:active { transform: scale(.92); }
.step-btn:disabled { opacity: .38; cursor: not-allowed; }
.step-value { text-align: center; font-family: var(--font-disp); }
.step-value span { display: block; font-size: 2rem; font-weight: 600; line-height: 1; }
.step-value small {
  font-family: var(--font-ui); font-size: .74rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em; color: var(--ink-2);
}

/* ---------------- toggle ---------------- */
.toggle-row {
  display: flex; align-items: center; gap: 11px; margin-top: 16px;
  cursor: pointer; user-select: none;
}
.toggle-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  flex: 0 0 auto; width: 46px; height: 27px; border-radius: 999px;
  background: var(--line); position: relative; transition: background .2s;
}
.toggle-thumb {
  position: absolute; top: 3px; left: 3px; width: 21px; height: 21px;
  border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm);
  transition: transform .2s;
}
.toggle-row input:checked + .toggle-track { background: var(--mint); }
.toggle-row input:checked + .toggle-track .toggle-thumb { transform: translateX(19px); }
.toggle-row input:focus-visible + .toggle-track { outline: 3px solid var(--brand); outline-offset: 2px; }
.toggle-label { font-size: .92rem; color: var(--ink); font-weight: 500; }

/* ---------------- receipt ---------------- */
.receipt { position: relative; margin-top: 4px; filter: drop-shadow(var(--shadow)); }
.receipt-perf {
  height: 12px;
  background:
    radial-gradient(circle at 8px 0, transparent 0 7px, var(--card) 7px) repeat-x;
  background-size: 16px 12px;
}
.receipt-perf.top { background-position: 0 -6px; }
.receipt-perf.bottom { background-position: 0 6px; transform: scaleY(-1); }
.receipt-body {
  background: var(--card); padding: 6px 22px 20px;
}
.r-line {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 0; font-size: 1rem; color: var(--ink-2);
  border-bottom: 1px dashed var(--line);
}
.r-line span:first-child { font-weight: 500; }
.r-line.total { color: var(--ink); font-weight: 700; border-bottom: 0; }
.r-line.total .mono { font-weight: 700; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; color: var(--ink); }
.r-dash { border-top: 2px dashed var(--line); margin: 6px 0 4px; }
.per-person {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 16px 0 6px; text-align: center;
}
.pp-label {
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .12em; color: var(--brand-d);
}
.pp-amount {
  font-family: var(--font-disp); font-size: 3.2rem; font-weight: 600;
  letter-spacing: -.03em; color: var(--ink); line-height: 1;
}
.r-note {
  margin: 12px 0 0; text-align: center; font-size: .82rem; color: var(--ink-2);
  min-height: 0;
}

/* ---------------- people (items mode) ---------------- */
.people-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.people-list:empty { display: none; }
.person-tag {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--paper); border: 1.5px solid var(--line);
  border-radius: 999px; padding: 6px 8px 6px 13px; font-weight: 600; font-size: .92rem;
}
.person-tag .dot { width: 10px; height: 10px; border-radius: 50%; }
.person-tag .rm {
  width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: #f0e4d3; color: var(--ink-2); font-size: 1rem; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
  transition: background .16s, color .16s;
}
.person-tag .rm:hover { background: var(--brand); color: #fff; }
.add-person, .add-item { display: flex; gap: 8px; }
.add-item { flex-wrap: wrap; }
.text-field {
  flex: 1; min-width: 0; font: inherit; font-size: 1rem; font-weight: 500;
  color: var(--ink); background: var(--paper);
  border: 2px solid var(--line); border-radius: var(--r-md);
  padding: 12px 14px;
}
.text-field:focus { outline: none; border-color: var(--brand); background: #fff; }
.text-field::placeholder { color: #b9a88f; }
.add-item .text-field { flex: 1 1 100%; }
.add-item .money-input { flex: 1 1 auto; }
.add-btn {
  flex: 0 0 auto; font: inherit; font-weight: 700; font-size: .95rem;
  color: #fff; background: var(--ink); border: 0; border-radius: var(--r-md);
  padding: 0 20px; cursor: pointer; transition: background .16s, transform .1s;
}
.add-btn:hover { background: var(--brand); }
.add-btn:active { transform: scale(.96); }

/* ---------------- items list ---------------- */
.empty-note { margin: 4px 2px; color: var(--ink-2); font-size: .9rem; }
.items-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.items-list:has(.item-row) .empty-note { display: none; }
.item-row {
  background: var(--paper); border: 1.5px solid var(--line);
  border-radius: var(--r-md); padding: 12px 13px;
}
.item-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.item-name { font-weight: 600; font-size: 1rem; }
.item-price { font-family: var(--font-mono); font-weight: 700; }
.item-rm {
  margin-left: 8px; border: 0; background: transparent; color: var(--ink-2);
  cursor: pointer; font-size: 1.1rem; padding: 0 2px; line-height: 1;
}
.item-rm:hover { color: var(--brand); }
.item-assign { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.assign-chip {
  font: inherit; font-size: .8rem; font-weight: 600;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink-2);
  border-radius: 999px; padding: 5px 12px; cursor: pointer;
  transition: all .14s; display: inline-flex; align-items: center; gap: 6px;
}
.assign-chip .adot { width: 8px; height: 8px; border-radius: 50%; opacity: .35; }
.assign-chip.on { color: var(--ink); border-color: transparent; }
.assign-chip.on .adot { opacity: 1; }
.assign-chip:active { transform: scale(.95); }
.item-share {
  margin-top: 9px; font-size: .8rem; color: var(--ink-2);
}
.item-warn { color: var(--brand-d); font-weight: 600; }

/* ---------------- items results ---------------- */
.results-items { display: flex; flex-direction: column; gap: 12px; }
.result-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm); overflow: hidden;
}
.result-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; gap: 10px;
}
.result-who { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.08rem; }
.result-who .dot { width: 13px; height: 13px; border-radius: 50%; }
.result-owes { font-family: var(--font-disp); font-size: 1.7rem; font-weight: 600; letter-spacing: -.02em; }
.result-break {
  border-top: 1px dashed var(--line); padding: 12px 18px;
  font-size: .86rem; color: var(--ink-2);
  display: none;
}
.result-card.open .result-break { display: block; }
.rb-line { display: flex; justify-content: space-between; padding: 3px 0; }
.rb-line .mono { font-size: .84rem; color: var(--ink-2); }
.result-toggle {
  width: 100%; text-align: left; background: transparent; border: 0;
  font: inherit; padding: 0; cursor: pointer;
}
.grand-check {
  background: var(--mint-t); border: 1px solid #a9e0d2;
  border-radius: var(--r-md); padding: 14px 18px;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; color: #0a6a58;
}
.grand-check .mono { color: #0a6a58; }
.grand-check.warn { background: #fdeede; border-color: #f0cba9; color: var(--brand-d); }
.grand-check.warn .mono { color: var(--brand-d); }
.results-empty {
  text-align: center; color: var(--ink-2); font-size: .92rem;
  padding: 26px 20px; background: var(--card);
  border: 1px dashed var(--line); border-radius: var(--r-lg);
}

/* ---------------- footer ---------------- */
.foot {
  margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--line);
  color: var(--ink-2);
}
.foot-mark { margin-bottom: 8px; }
.foot p { margin: 0 0 8px; font-size: .9rem; }
.foot .tiny { font-size: .78rem; opacity: .85; }

/* ---------------- utility ---------------- */
[hidden] { display: none !important; }

@media (min-width: 620px) {
  .app { padding-top: 6px; }
  .hero h1 { font-size: 2.9rem; }
  .two-col { display: grid; grid-template-columns: 1fr 1.3fr; gap: 18px; align-items: start; }
}

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