/* PatunganYuk — visual language: playful creative (violet/cyan gradient, tactile cards) */

:root {
  /* surfaces */
  --canvas: #f7f9fc;
  --surface: #fdfdfe;
  --surface-sub: #f1f5f9;
  --line: #e2e8f0;

  /* text */
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #64748b;

  /* brand */
  --brand: #7c3aed;
  --brand-dark: #6d28d9;
  --accent: #06b6d4;
  --gold: #f59e0b;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-bg: #fef2f2;

  /* shape */
  --r-card: 20px;
  --r-ctl: 12px;
  --r-pill: 999px;

  /* spacing unit = 4px */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;

  --shadow-card: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 24px -14px rgba(15, 23, 42, .14);
  --shadow-pop: 0 10px 25px -5px rgba(124, 58, 237, .18), 0 8px 10px -6px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--canvas);
  background-image: radial-gradient(900px 420px at 12% -8%, rgba(124, 58, 237, .10), transparent 62%),
                    radial-gradient(760px 380px at 96% 4%, rgba(6, 182, 212, .10), transparent 60%);
  background-repeat: no-repeat;
}

h1, h2, h3 { line-height: 1.22; margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
ul, ol, dl { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
input { font: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.wrap { width: 100%; max-width: 1120px; margin-inline: auto; padding-inline: var(--s5); }

/* ---------- header ---------- */
.site-header {
  background-color: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: var(--s3); min-height: 44px; text-decoration: none; color: var(--ink); }
.brand-mark {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 14px;
  background-color: var(--brand);
  background-image: linear-gradient(135deg, var(--brand), var(--accent));
  color: #f8fafc; box-shadow: var(--shadow-pop);
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-text { font-weight: 600; font-size: 1.0625rem; letter-spacing: -.01em; }
.brand-text strong { color: var(--brand); font-weight: 800; }
.header-note { font-size: .8125rem; color: var(--ink-3); font-weight: 500; }

/* ---------- hero ---------- */
.hero { padding-block: var(--s10) var(--s8); max-width: 46rem; }
.hero h1 { font-size: 2.125rem; font-weight: 800; letter-spacing: -.025em; }
.hero h1 .grad { color: var(--brand-dark); }
.hero-sub { margin-top: var(--s3); color: var(--ink-2); font-size: 1.0625rem; max-width: 40rem; }
.hero-actions { margin-top: var(--s6); display: flex; flex-wrap: wrap; gap: var(--s3); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s5);
  border: 1px solid transparent; border-radius: var(--r-ctl);
  font-weight: 700; font-size: .9375rem; cursor: pointer;
  transition: transform .12s ease, box-shadow .18s ease, background-color .18s ease, border-color .18s ease;
}
.btn-primary {
  background-color: var(--brand);
  background-image: linear-gradient(120deg, var(--brand), var(--accent));
  color: #f8fafc;
  box-shadow: 0 8px 18px -8px rgba(124, 58, 237, .55);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 22px -8px rgba(124, 58, 237, .62); }
.btn-ghost { background-color: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: #cbd5e1; background-color: var(--surface-sub); }
.btn-sm { min-height: 44px; padding: 0 var(--s4); }
.btn-block { width: 100%; }
.btn:focus-visible, input:focus-visible, .link-btn:focus-visible, .chip-x:focus-visible {
  outline: 3px solid rgba(124, 58, 237, .45); outline-offset: 2px;
}
.link-btn {
  background: none; border: 0; padding: 0 var(--s1); min-height: 44px; cursor: pointer;
  color: var(--brand-dark); font-size: .8125rem; font-weight: 700; text-decoration: underline;
}

/* ---------- layout ---------- */
.grid { display: grid; grid-template-columns: 1fr; gap: var(--s5); padding-bottom: var(--s10); }

.card {
  background-color: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--s5);
  box-shadow: var(--shadow-card);
  scroll-margin-top: 84px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.card-head h2 { font-size: 1.0625rem; font-weight: 800; letter-spacing: -.01em; }
.counter {
  font-size: .75rem; font-weight: 700; color: var(--brand-dark);
  background-color: #f5f3ff; border: 1px solid #ddd6fe;
  padding: 4px 8px; border-radius: var(--r-pill); white-space: nowrap;
}
.card-result { border-color: #ddd6fe; box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 18px 34px -22px rgba(124,58,237,.42); }

/* ---------- forms ---------- */
.row-form { display: flex; gap: var(--s2); }
.row-form input { flex: 1 1 auto; min-width: 0; }
.stack-form { display: grid; gap: var(--s4); }
.field { display: grid; gap: var(--s2); border: 0; padding: 0; margin: 0; min-width: 0; }
.field > label, .field > legend { font-size: .8125rem; font-weight: 700; color: var(--ink-2); padding: 0; }

input[type="text"], input[type="number"], select {
  width: 100%; min-height: 44px; padding: 0 var(--s4);
  background-color: var(--surface-sub);
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  color: var(--ink);
}
input::placeholder { color: var(--ink-3); }
input:hover, select:hover { border-color: #cbd5e1; }
input:focus, select:focus { background-color: var(--surface); border-color: var(--brand); }
select { appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; background-size: 18px; }

.hint { font-size: .8125rem; color: var(--ink-3); }
.hint strong { color: var(--ink-2); }

.form-error {
  font-size: .8125rem; font-weight: 600; color: var(--danger);
  background-color: var(--danger-bg); border: 1px solid #fecaca;
  padding: var(--s2) var(--s3); border-radius: var(--r-ctl);
}

/* ---------- member chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s3); }
.chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  background-color: #f5f3ff; border: 1px solid #ddd6fe;
  padding: 4px 6px 4px 12px; border-radius: var(--r-pill);
  font-size: .875rem; font-weight: 600; color: #4c1d95;
}
.chip-x {
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: var(--r-pill); background-color: #ede9fe;
  color: #6d28d9; font-size: 1.0625rem; line-height: 1; cursor: pointer;
}
.chip-x:hover { background-color: #ddd6fe; }

/* ---------- member picker ---------- */
.picker { display: flex; flex-wrap: wrap; gap: var(--s2); }
.pick {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s4);
  background-color: var(--surface-sub); border: 1px solid var(--line);
  border-radius: var(--r-pill); cursor: pointer;
  font-size: .875rem; font-weight: 600; color: var(--ink-2);
}
.pick:hover { border-color: #cbd5e1; }
.pick input { position: absolute; opacity: 0; pointer-events: none; }
.pick .dot { width: 9px; height: 9px; border-radius: var(--r-pill); background-color: #cbd5e1; }
.pick:has(input:checked) { background-color: #ecfeff; border-color: #67e8f9; color: #155e75; }
.pick:has(input:checked) .dot { background-color: var(--accent); }
.pick:has(input:focus-visible) { outline: 3px solid rgba(124, 58, 237, .45); outline-offset: 2px; }
.picker-tools { display: flex; gap: var(--s4); margin-top: var(--s2); }

/* ---------- item list ---------- */
.items { display: grid; gap: var(--s2); margin-top: var(--s4); }
.item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3);
  background-color: var(--surface-sub); border: 1px solid var(--line);
  border-radius: var(--r-ctl); padding: var(--s3) var(--s4);
}
.item-main { min-width: 0; }
.item-name { font-weight: 700; font-size: .9375rem; }
.item-meta { font-size: .8125rem; color: var(--ink-3); }
.item-price { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item-del {
  border: 0; background: none; cursor: pointer; color: var(--ink-3);
  font-size: .8125rem; font-weight: 700; text-decoration: underline; padding: 2px;
}
.item-del:hover { color: var(--danger); }
.item-actions { display: grid; gap: 2px; justify-items: end; }

/* ---------- result ---------- */
.summary { display: grid; gap: var(--s1); margin-bottom: var(--s5); }
.summary > div { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4); font-size: .9375rem; }
.summary dt { color: var(--ink-2); }
.summary dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-total { border-top: 1px dashed var(--line); padding-top: var(--s2); margin-top: var(--s1); }
.summary-total dt { font-weight: 800; color: var(--ink); }
.summary-total dd { font-size: 1.25rem; color: var(--brand-dark); }

.sub-head { font-size: .8125rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin-bottom: var(--s3); }

.per-person { display: grid; gap: var(--s2); margin-bottom: var(--s5); }
.person {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  padding: var(--s3) var(--s3); border-radius: var(--r-ctl);
}
.person:nth-child(odd) { background-color: var(--surface-sub); }
.person-name { font-weight: 600; display: block; }
.person-detail { display: block; font-size: .75rem; color: var(--ink-3); font-weight: 500; }
.person-right { display: grid; justify-items: end; gap: 2px; }
.person-total { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.person-tag {
  font-size: .6875rem; font-weight: 700; padding: 0 8px; border-radius: var(--r-pill);
  white-space: nowrap; border: 1px solid transparent;
}
.tag-credit { color: #065f46; background-color: #d1fae5; border-color: #a7f3d0; }
.tag-debt { color: #9a3412; background-color: #ffedd5; border-color: #fed7aa; }
.tag-hold { color: #475569; background-color: #e2e8f0; border-color: #cbd5e1; }

.payer-field { margin-top: var(--s5); padding-top: var(--s5); border-top: 1px dashed var(--line); }

.settle { display: grid; gap: var(--s2); margin-bottom: var(--s5); }
.settle-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2);
  background-color: var(--ok-bg); border: 1px solid #a7f3d0;
  padding: var(--s3) var(--s4); border-radius: var(--r-ctl);
  font-size: .9375rem;
}
.settle-from { font-weight: 700; }
.settle-arrow { color: var(--ok); font-weight: 800; }
.settle-to { font-weight: 700; }
.settle-amount { margin-left: auto; font-weight: 800; color: var(--ok); font-variant-numeric: tabular-nums; }

.result-cols { display: grid; gap: var(--s5); }
.result-actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s4); }

.empty { font-size: .875rem; color: var(--ink-3); margin-top: var(--s3); }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); background-color: var(--surface); padding-block: var(--s6); margin-top: var(--s8); }
.site-footer p { font-size: .8125rem; color: var(--ink-2); max-width: 30rem; }
.site-footer .muted { color: var(--ink-3); margin-top: var(--s1); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%);
  background-color: var(--ink); color: #f8fafc;
  padding: 12px 20px; border-radius: var(--r-pill);
  font-size: .875rem; font-weight: 600; box-shadow: var(--shadow-pop); z-index: 40;
  max-width: calc(100% - 40px);
}

/* ---------- breakpoints ---------- */
@media (min-width: 640px) {
  .hero h1 { font-size: 2.75rem; }
  .wrap { padding-inline: var(--s6); }
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "members items"
      "extra   items"
      "result  result";
  }
  .card--members { grid-area: members; }
  .card--items { grid-area: items; }
  .card--extra { grid-area: extra; }
  .card--result { grid-area: result; }
}

@media (min-width: 1024px) {
  .hero { padding-block: 56px var(--s10); }
  .hero h1 { font-size: 3rem; }
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "members items extra"
      "result  result result";
    gap: var(--s6);
  }
  .card { padding: var(--s6); }
  .card--members, .card--items, .card--extra { align-self: stretch; }
  .result-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s8); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn-primary:hover { transform: none; }
}
