/* ============================================================
   onenine99 — UPI amount splitter
   Compact scale: 15px base, 4px spacing rhythm.
   Violet is spent in three places only — brand mark, the
   primary action, and the split segments. Everything else
   is ink, grey and hairline.
   ============================================================ */

:root {
  --ink:        #1A1C2E;
  --ink-2:      #474A66;
  --muted:      #71748E;
  --faint:      #A0A2B8;
  --paper:      #FFFFFF;
  --surface:    #FAFAFC;
  --surface-2:  #F1F1F6;
  --line:       #E5E5EE;
  --line-soft:  #EFEFF4;
  --accent:     #5B57E8;
  --accent-deep:#4340D4;
  --accent-wash:#F0EFFE;
  --paid:       #0E9F6E;
  --danger:     #CE3450;

  --r-card: 14px;
  --r-tile: 10px;
  --r-ctl:  8px;

  --shadow-lift: 0 1px 2px rgba(26,28,46,.04), 0 8px 24px -14px rgba(26,28,46,.18);

  --gut: clamp(16px, 4vw, 40px);
  --maxw: 1040px;
  --qr-dark: #1A1C2E;
}

html[data-theme="dark"] {
  --ink:        #ECECF4;
  --ink-2:      #B7B9CE;
  --muted:      #8D90AB;
  --faint:      #64678200;   /* overridden below */
  --faint:      #666981;
  --paper:      #191A2B;
  --surface:    #111222;
  --surface-2:  #23253A;
  --line:       #2B2D45;
  --line-soft:  #23253A;
  --accent:     #8582FF;
  --accent-deep:#9D9BFF;
  --accent-wash:#22234000;
  --accent-wash:#242440;
  --paid:       #35C794;
  --danger:     #FF7C90;
  --shadow-lift: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -18px rgba(0,0,0,.9);
  --qr-dark: #14152A;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: 'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; }
p { margin: 0; }
svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.skip { position: absolute; left: -9999px; top: 0; z-index: 99; background: var(--accent); color: #fff; padding: 8px 14px; font-weight: 700; }
.skip:focus { left: 0; }

:where(a, button, input, [tabindex]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 5px; }

/* ---------- top bar ---------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: var(--maxw); margin: 0 auto; padding: 14px var(--gut);
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--accent); }
.brand-mark { width: 21px; height: 21px; flex: none; }
.brand-mark, .brand-mark * { stroke: none; }
.brand-name { color: var(--ink); font-weight: 700; font-size: 15px; letter-spacing: -0.02em; }
.brand-name b { font-weight: 800; color: var(--accent); }

.topbar-actions { display: flex; align-items: center; gap: 2px; }
.ghost-btn {
  font: inherit; font-weight: 600; font-size: 13.5px; color: var(--muted);
  background: none; border: 0; cursor: pointer; padding: 6px 10px; border-radius: var(--r-ctl);
}
.ghost-btn:hover { color: var(--ink); background: var(--surface-2); }
.icon-btn {
  width: 30px; height: 30px; flex: none; padding: 7px;
  color: var(--muted); background: none; border: 0; border-radius: var(--r-ctl); cursor: pointer;
}
.icon-btn:hover { color: var(--ink); background: var(--surface-2); }
.icon-btn .ico-moon { display: none; }
html[data-theme="dark"] .icon-btn .ico-sun { display: none; }
html[data-theme="dark"] .icon-btn .ico-moon { display: block; }

/* ---------- setup ---------- */

.stage {
  max-width: var(--maxw); margin: 0 auto;
  padding: clamp(14px, 3vw, 34px) var(--gut) 56px;
  display: grid; gap: clamp(28px, 4vw, 48px);
  grid-template-columns: 1fr; align-items: start;
}
@media (min-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr) 372px; gap: 52px; }
}

.pitch { max-width: 30rem; }
.pitch h1 { font-size: clamp(25px, 3.1vw, 33px); letter-spacing: -0.035em; margin-bottom: 12px; }
.lede { font-size: 15px; color: var(--muted); line-height: 1.6; max-width: 30rem; }

/* ---------- split preview ---------- */

.splitviz { margin-top: clamp(24px, 4vw, 36px); padding-top: 18px; border-top: 1px solid var(--line); }
.splitviz-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 10px; min-height: 22px;
}
.splitviz-line { font-size: 16px; font-weight: 700; letter-spacing: -0.02em; color: var(--faint); transition: color .2s ease; }
.splitviz[data-state="live"] .splitviz-line { color: var(--ink); }
.splitviz-count { font-size: 12px; font-weight: 700; color: var(--faint); white-space: nowrap; }

.splitbar {
  display: flex; gap: 3px; height: 34px; align-items: stretch;
  padding: 4px; border-radius: 9px; background: var(--surface-2);
  border: 1px solid var(--line-soft);
}
.splitviz[data-state="empty"] .splitbar::after {
  content: ""; flex: 1; border-radius: 5px;
  background: repeating-linear-gradient(115deg, var(--line) 0 6px, transparent 6px 13px);
}
.seg { border-radius: 5px; min-width: 1px; background: var(--accent); animation: segIn .3s cubic-bezier(.2,.8,.3,1) backwards; }
.seg.seg-rem { opacity: .38; }
@keyframes segIn { from { transform: scaleY(.3); opacity: 0; } }

.splitviz-foot { margin-top: 9px; min-height: 18px; font-size: 12.5px; color: var(--muted); }
.splitviz-foot b { color: var(--ink-2); font-weight: 700; }
.splitviz-foot.over { color: var(--danger); font-weight: 600; }

/* ---------- form ---------- */

.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-lift); }
.form { padding: 22px; }
.form-head { margin-bottom: 18px; }
.form-head h2 { font-size: 17px; margin-bottom: 3px; }
.form-head p { color: var(--muted); font-size: 13px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 5px; color: var(--ink-2); }
.optional { font-weight: 500; color: var(--faint); }

.field input {
  width: 100%; font: inherit; font-size: 14.5px; font-weight: 500;
  padding: 9px 11px; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.field input::placeholder { color: var(--faint); font-weight: 400; }
.field input:hover { border-color: #CFD0DE; }
html[data-theme="dark"] .field input:hover { border-color: #3A3D59; }
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.field.invalid input { border-color: var(--danger); }

.money { position: relative; display: flex; align-items: center; }
.money input { padding-left: 28px; padding-right: 44px; font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.money-sym { position: absolute; left: 11px; font-size: 15px; font-weight: 600; color: var(--muted); pointer-events: none; }
.money-cur { position: absolute; right: 11px; font-size: 11px; font-weight: 700; color: var(--faint); pointer-events: none; }

.hint { margin-top: 6px; font-size: 12px; color: var(--faint); }
.err  { margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--danger); }
.rule { border: 0; border-top: 1px solid var(--line-soft); margin: 18px 0; }

.btn-primary {
  width: 100%; margin-top: 4px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 700; font-size: 14.5px;
  color: #fff; background: var(--accent); border: 0; border-radius: var(--r-ctl);
  padding: 11px 16px; cursor: pointer; transition: background .12s ease;
}
html[data-theme="dark"] .btn-primary { color: #12132A; }
.btn-primary svg { width: 17px; height: 17px; flex: none; stroke-width: 2.2; }
.btn-primary:hover { background: var(--accent-deep); }

.assure {
  margin-top: 12px; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 11.5px; color: var(--faint);
}
.assure svg { width: 13px; height: 13px; flex: none; }

/* ---------- results ---------- */

.results { max-width: var(--maxw); margin: 0 auto; padding: 8px var(--gut) 56px; }

.ledger {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); padding: 12px 0 12px; margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  display: grid; gap: 12px;
}
@media (min-width: 820px) {
  .ledger { grid-template-columns: minmax(0,1fr) 270px; align-items: end; column-gap: 32px; }
  .ledger-tools { grid-column: 1 / -1; }
}

.back {
  display: inline-flex; align-items: center; gap: 5px;
  font: inherit; font-weight: 600; font-size: 12.5px; color: var(--muted);
  background: none; border: 0; padding: 0; margin-bottom: 6px; cursor: pointer;
}
.back svg { width: 14px; height: 14px; }
.back:hover { color: var(--accent); }

.ledger-main h2 { font-size: 21px; letter-spacing: -0.03em; }
.ledger-sub { margin-top: 2px; color: var(--muted); font-size: 12.5px; }

.meter { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line-soft); }
.meter-fill { height: 100%; width: 0%; border-radius: 99px; background: var(--paid); transition: width .4s cubic-bezier(.2,.8,.3,1); }
.meter-legend { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.collected { color: var(--paid); }
.remaining { color: var(--faint); }

.ledger-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 12.5px;
  color: var(--ink-2); background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  padding: 6px 10px; cursor: pointer; transition: border-color .12s ease, color .12s ease;
}
.tool svg { width: 14px; height: 14px; flex: none; }
.tool:hover { color: var(--ink); border-color: var(--faint); }
.tool.danger:hover { color: var(--danger); border-color: var(--danger); }
.tool[data-done="1"] { color: var(--paid); border-color: var(--paid); }

/* ---------- QR grid ---------- */

.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
}

.qr {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-tile);
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
  transition: opacity .2s ease, border-color .15s ease;
}
.qr[data-paid="1"] { opacity: .45; border-color: var(--paid); }
.qr[data-paid="1"]:hover { opacity: 1; }

.qr-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.qr-idx { font-size: 11px; font-weight: 600; color: var(--faint); }
.qr-idx b { color: var(--ink-2); font-weight: 700; }
.qr-dl { width: 22px; height: 22px; padding: 4px; flex: none; color: var(--faint); background: none; border: 0; border-radius: 5px; cursor: pointer; }
.qr-dl:hover { color: var(--accent); background: var(--accent-wash); }

.qr-canvas-wrap { position: relative; border-radius: 6px; overflow: hidden; background: #fff; aspect-ratio: 1; }
.qr canvas { display: block; width: 100%; height: 100%; }
.qr-stamp { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(255,255,255,.86); }
.qr-stamp span {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--paid); color: #fff; font-size: 11px; font-weight: 800;
  padding: 4px 9px; border-radius: 99px;
}
.qr-stamp svg { width: 12px; height: 12px; stroke-width: 2.8; }
.qr[data-paid="1"] .qr-stamp { display: flex; }

.qr-amt { font-size: 17px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.qr[data-paid="1"] .qr-amt { text-decoration: line-through; text-decoration-thickness: 1.5px; color: var(--muted); }

.qr-apps { display: none; gap: 4px; }
body[data-touch="1"] .qr-apps { display: grid; grid-template-columns: repeat(3, 1fr); }
.qr-app {
  display: flex; align-items: center; justify-content: center;
  font: inherit; font-size: 10.5px; font-weight: 700; text-decoration: none;
  color: var(--muted); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 2px;
}
.qr-app:active { background: var(--accent-wash); border-color: var(--accent); color: var(--accent); }

.qr-pay {
  display: none; align-items: center; justify-content: center;
  font: inherit; font-size: 12.5px; font-weight: 700; text-decoration: none;
  color: #fff; background: var(--accent); border-radius: 6px; padding: 8px;
}
html[data-theme="dark"] .qr-pay { color: #12132A; }
body[data-touch="1"] .qr-pay { display: flex; }

.qr-mark {
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; font-weight: 600; color: var(--faint);
  cursor: pointer; user-select: none;
  border-top: 1px solid var(--line-soft); margin-top: 1px; padding-top: 8px;
}
.qr-mark input { position: absolute; opacity: 0; width: 0; height: 0; }
.qr-box {
  width: 15px; height: 15px; flex: none;
  border: 1.5px solid var(--line); border-radius: 4px;
  display: grid; place-items: center; color: transparent; background: var(--paper);
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.qr-box svg { width: 10px; height: 10px; stroke-width: 3.2; }
.qr-mark input:focus-visible + .qr-box { outline: 2px solid var(--accent); outline-offset: 2px; }
.qr-mark:hover .qr-box { border-color: var(--paid); }
.qr[data-paid="1"] .qr-box { background: var(--paid); border-color: var(--paid); color: #fff; }
.qr[data-paid="1"] .qr-mark { color: var(--paid); }

.disclaimer {
  margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 12px; line-height: 1.6; color: var(--faint); max-width: 64ch;
}

/* ---------- footer ---------- */

.foot {
  max-width: var(--maxw); margin: 0 auto;
  padding: 18px var(--gut) 28px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--faint);
}

/* ---------- how-it-works ---------- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(26,28,46,.38); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: var(--gut);
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: relative; background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow-lift);
  padding: 24px; max-width: 440px; width: 100%; max-height: 84vh; overflow-y: auto;
  animation: pop .18s cubic-bezier(.2,.8,.3,1);
}
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.sheet h3 { font-size: 17px; margin-bottom: 14px; }
.sheet-close {
  position: absolute; top: 14px; right: 14px; width: 26px; height: 26px; padding: 7px;
  color: var(--muted); background: var(--surface-2); border: 0; border-radius: 6px; cursor: pointer;
}
.sheet-close:hover { color: var(--ink); }
.how { margin: 0; padding-left: 1.2em; display: grid; gap: 9px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.how::marker { font-weight: 700; }
.how b { color: var(--ink); font-weight: 700; }
.how-note { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--faint); line-height: 1.55; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 22px; z-index: 80; transform: translate(-50%, 16px);
  background: var(--ink); color: var(--surface);
  font-size: 12.5px; font-weight: 600; padding: 8px 14px; border-radius: 99px;
  box-shadow: 0 8px 24px -8px rgba(26,28,46,.45);
  opacity: 0; pointer-events: none; transition: opacity .16s ease, transform .16s ease;
}
html[data-theme="dark"] .toast { background: var(--surface-2); color: var(--ink); }
.toast[data-show="1"] { opacity: 1; transform: translate(-50%, 0); }

/* ---------- print ---------- */

.print-head { display: none; }

@media print {
  .topbar, .foot, .ledger-tools, .back, .disclaimer, .qr-apps, .qr-pay, .qr-dl, .toast, .sheet-backdrop { display: none !important; }
  body { background: #fff; font-size: 11px; }
  .results { padding: 0; max-width: none; }
  .ledger { position: static; border: 0; padding: 0; margin: 0 0 10px; }
  .print-head { display: block; font-weight: 800; font-size: 13px; margin-bottom: 8px; }
  .grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .qr { break-inside: avoid; border: 1px solid #ccc; padding: 8px; opacity: 1 !important; }
  .qr-mark { display: none; }
  @page { margin: 10mm; }
}

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

/* ============================================================
   Mobile — most people meet this on a phone.
   ============================================================ */

@supports (padding: max(0px)) {
  .topbar, .stage, .results, .foot {
    padding-left: max(var(--gut), env(safe-area-inset-left));
    padding-right: max(var(--gut), env(safe-area-inset-right));
  }
}

/* iOS zooms the page when a focused input is under 16px. */
@media (pointer: coarse) {
  .field input { font-size: 16px; padding: 11px 12px; }
  .money input { font-size: 18px; padding-left: 30px; padding-right: 46px; }
  .btn-primary { padding: 14px 16px; font-size: 15.5px; }
  .ghost-btn, .icon-btn, .tool, .back { min-height: 36px; }
  .qr-mark { padding-top: 10px; padding-bottom: 2px; font-size: 12.5px; }
  .qr-box { width: 18px; height: 18px; }
  .qr-dl { width: 28px; height: 28px; padding: 6px; }
}

@media (max-width: 680px) {
  .pitch h1 { font-size: 23px; }
  .lede { font-size: 14px; }

  /* The form is the job on a phone — lead with it, keep the pitch as context below. */
  .stage { gap: 24px; padding-bottom: 40px; display: flex; flex-direction: column; }
  .form { order: -1; }

  .splitviz { margin-top: 20px; }
  .splitbar { height: 30px; }

  .ledger { padding: 10px 0; gap: 10px; margin-bottom: 14px; }
  .ledger-main h2 { font-size: 18px; }
  .ledger-sub { font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Tools scroll sideways rather than wrapping into a tall block above the codes. */
  .ledger-tools {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 calc(var(--gut) * -1); padding: 0 var(--gut) 2px;
  }
  .ledger-tools::-webkit-scrollbar { display: none; }
  .tool { flex: none; }

  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .qr { padding: 8px; gap: 7px; }
  .qr-amt { font-size: 16px; }

  .sheet { padding: 20px; max-height: 88vh; }
  .toast { left: var(--gut); right: var(--gut); bottom: 16px; transform: translateY(16px); text-align: center; }
  .toast[data-show="1"] { transform: translateY(0); }
}

@media (max-width: 400px) {
  .brand-name { font-size: 14px; }
  .ghost-btn { font-size: 12.5px; padding: 6px 8px; }
  .qr-idx { font-size: 10.5px; }
}

/* Two columns hold all the way down; one wide QR per row wastes the screen. */
@media (max-width: 300px) {
  .grid { grid-template-columns: 1fr; }
}
