:root {
  --bg: #0b0712;
  --bg-grad-1: rgba(224, 32, 122, 0.55);
  --bg-grad-2: rgba(96, 58, 235, 0.5);
  --bg-grad-3: rgba(46, 92, 235, 0.28);
  --card: rgba(255, 255, 255, 0.055);
  --card-hover: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.13);
  --ink: #ffffff;
  --ink-soft: rgba(255, 255, 255, 0.62);
  --ink-faint: rgba(255, 255, 255, 0.38);
  --accent: #ff2f7e;
  --accent-2: #7c3aed;
  --accent-grad: linear-gradient(135deg, #ff2f7e, #a12bef 60%, #7c3aed);
  --accent-ink: #ffffff;
  --green: #38d99a;
  --red: #ff5f7e;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.45);

  --cat-food: #ff9f5a;
  --cat-lodging: #b98bff;
  --cat-transit: #5ec2ff;
  --cat-activities: #38d99a;
  --cat-coffeeshop: #7fe07f;
  --cat-other: #a89fc9;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 900px 650px at 12% 8%, var(--bg-grad-1), transparent 60%),
    radial-gradient(ellipse 1000px 750px at 90% 0%, var(--bg-grad-2), transparent 58%),
    radial-gradient(ellipse 1000px 800px at 50% 105%, var(--bg-grad-3), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 0 96px;
}

.loading, .empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(to bottom, rgba(11, 7, 18, 0.92) 70%, transparent);
  backdrop-filter: blur(10px);
  padding: 20px 18px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.topbar h1 {
  font-size: 21px;
  margin: 0 0 8px;
  letter-spacing: -0.01em;
  font-weight: 800;
}

.topbar .share-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--ink);
  flex: none;
}

.people-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.person-chip {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12.5px;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chip-method {
  color: var(--ink-faint);
  font-size: 11px;
}

.person-chip.add {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--ink-soft);
  font-weight: 600;
}

.person-chip.unset {
  border: 1px dashed var(--accent);
}

.person-chip.unset .chip-method {
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Landing (create/join) ---------- */
.landing {
  padding: 56px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.landing .brand {
  text-align: center;
}

.landing .brand h1 {
  font-size: 40px;
  margin: 0 0 8px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.landing .brand p {
  color: var(--ink-soft);
  margin: 0;
  font-size: 14.5px;
}

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  backdrop-filter: blur(16px);
}

.panel h2 {
  font-size: 13px;
  margin: 0 0 2px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}

.people-draft {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.person-draft-row {
  display: grid;
  grid-template-columns: 1fr 30px;
  gap: 8px;
  align-items: center;
}

.row-remove {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 15px;
  padding: 6px;
}

.row-remove-spacer {
  display: block;
  width: 30px;
}

.hint-text {
  font-size: 12px;
  color: var(--ink-faint);
  line-height: 1.5;
}

input, select, textarea {
  font: inherit;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  width: 100%;
  accent-color: var(--accent);
}

input::placeholder, textarea::placeholder {
  color: var(--ink-faint);
}

select {
  color: var(--ink);
}
select option {
  background: #1a1424;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  font: inherit;
  cursor: pointer;
}

.btn {
  background: var(--accent-grad);
  color: var(--accent-ink);
  border: none;
  border-radius: 12px;
  padding: 13px 16px;
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 6px 20px rgba(255, 47, 126, 0.28);
}

.btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

.btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: none;
}

.btn.danger {
  background: var(--red);
  color: #fff;
}

.btn.block { width: 100%; }

/* ---------- Balance summary ---------- */
.balance-card {
  margin: 4px 18px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  backdrop-filter: blur(16px);
}

.balance-card .headline {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.usd-summary {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 14px;
}

.usd-line + .usd-line {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.usd-amt {
  font-size: 30px;
  font-weight: 800;
  color: var(--red);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.usd-who {
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 3px;
}

.usd-note {
  font-size: 11.5px;
  color: var(--ink-faint);
}

.exact-label {
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-bottom: 4px;
}

.balance-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 15px;
}

.balance-line .amt.owe { color: var(--red); }
.balance-line .amt.even { color: var(--ink-soft); }
.balance-line .amt.settled { color: var(--green); }

.settle-btn {
  margin-top: 12px;
  font-size: 13.5px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
}

/* ---------- Filters ---------- */
.filters {
  display: flex;
  gap: 6px;
  padding: 0 18px 12px;
  overflow-x: auto;
}

.chip {
  flex: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--ink-soft);
}

.chip.active {
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
}

/* ---------- Expense list ---------- */
.section-label {
  padding: 0 18px 8px;
  font-size: 11.5px;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 18px;
}

.expense {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  backdrop-filter: blur(10px);
}

.cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}
.cat-food { background: var(--cat-food); }
.cat-lodging { background: var(--cat-lodging); }
.cat-transit { background: var(--cat-transit); }
.cat-activities { background: var(--cat-activities); }
.cat-coffeeshop { background: var(--cat-coffeeshop); }
.cat-other { background: var(--cat-other); }

.expense .info { flex: 1; min-width: 0; }
.expense .desc {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expense .meta {
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-top: 2px;
}
.expense .amount {
  font-weight: 700;
  font-size: 15px;
  flex: none;
  text-align: right;
}
.expense .amount .cur {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-faint);
  display: block;
}
.expense .thumb {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex: none;
}
.expense .del {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 18px;
  padding: 4px 2px;
  flex: none;
}

.settlement {
  background: rgba(56, 217, 154, 0.08);
  border: 1px dashed rgba(56, 217, 154, 0.4);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--green);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent-grad);
  color: #fff;
  border: none;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(255, 47, 126, 0.45);
}

/* ---------- Modal / sheet ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 2, 8, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}

.sheet {
  background: #150f1e;
  background-image:
    radial-gradient(ellipse 500px 300px at 100% 0%, rgba(124, 58, 237, 0.25), transparent 60%),
    radial-gradient(ellipse 500px 300px at 0% 0%, rgba(255, 47, 126, 0.18), transparent 60%);
  border: 1px solid var(--border);
  border-bottom: none;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
}

.sheet h2 {
  margin: 4px 0 18px;
  font-size: 19px;
  font-weight: 800;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.amount-row {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 8px;
}

.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 11px;
  overflow: hidden;
}
.seg button {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: none;
  padding: 11px 4px;
  font-size: 13px;
  color: var(--ink-soft);
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button.active {
  background: var(--accent-grad);
  color: #fff;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.cat-grid button {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 11px;
  padding: 11px 6px;
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: var(--ink-soft);
}
.cat-grid button.active {
  border-color: transparent;
  background: var(--accent-grad);
  color: #fff;
  font-weight: 600;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.split-grid .who {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.split-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.photo-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.photo-row img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
}
.photo-row label.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.error-text {
  color: var(--red);
  font-size: 13px;
  margin: -4px 0 10px;
}

.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e1630;
  border: 1px solid var(--border);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
  box-shadow: var(--shadow);
}
