:root {
  --navy: #0c2230;
  --navy-2: #123445;
  --navy-3: #1d4657;
  --paper: #f4ebd8;
  --paper-2: #fff8e9;
  --ink: #16272d;
  --muted: #748289;
  --amber: #f4b942;
  --amber-dark: #674600;
  --coral: #e4775c;
  --teal: #5fb3b3;
  --green: #6eaf71;
  --danger: #c85858;
  --line: rgba(22, 39, 45, .15);
  --shadow: 0 20px 60px rgba(2, 12, 18, .28);
  --radius: 18px;
  --body: "Bahnschrift", "Avenir Next", "Trebuchet MS", sans-serif;
  --display: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--navy); }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px),
    var(--navy);
  background-size: 22px 22px;
  color: var(--paper);
  font-family: var(--body);
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.ambient { position: fixed; border-radius: 50%; filter: blur(70px); pointer-events: none; opacity: .22; }
.ambient-one { width: 280px; height: 280px; background: var(--teal); top: -150px; right: -80px; }
.ambient-two { width: 240px; height: 240px; background: var(--coral); bottom: 10%; left: -170px; }
.eyebrow { color: var(--amber); font-size: 10px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 18px;
}
.gate-card {
  width: min(100%, 420px);
  padding: 30px 24px 26px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  position: relative;
}
.ticket { border-radius: var(--radius); }
.ticket::before, .ticket::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--navy);
  top: 46%;
}
.ticket::before { left: -10px; }
.ticket::after { right: -10px; }
.gate-card .eyebrow { color: #9a6800; }
.gate-card h1 {
  font-family: var(--display);
  font-size: clamp(42px, 12vw, 58px);
  line-height: .95;
  margin: 8px 0 12px;
  letter-spacing: -.045em;
}
.gate-card > p { color: #59676c; margin: 0 0 20px; line-height: 1.45; }
.gate-mark {
  float: right;
  transform: rotate(4deg);
  border: 2px solid rgba(196, 81, 51, .55);
  color: #b74e34;
  border-radius: 50%;
  padding: 14px 8px;
  font-weight: 900;
  font-size: 11px;
  letter-spacing: .08em;
}
.gate-mark span { color: #9a6800; }
.gate-form, #simpleDialogForm { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 12px; font-weight: 800; color: #516168; }
label small, .rate-card small { font-weight: 500; color: #7c898d; }
input, select, textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  color: var(--ink);
  background: rgba(255,255,255,.58);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #a36f00; box-shadow: 0 0 0 3px rgba(244,185,66,.25); }
textarea { resize: vertical; }
.primary, .secondary {
  min-height: 48px;
  border-radius: 13px;
  border: 0;
  padding: 12px 16px;
  font-weight: 900;
  cursor: pointer;
}
.primary { background: var(--amber); color: var(--amber-dark); box-shadow: 0 8px 22px rgba(244,185,66,.23); }
.primary:active { transform: translateY(1px); }
.secondary { background: transparent; color: inherit; border: 1px solid currentColor; }
.secondary.compact { min-height: 40px; padding: 8px 13px; }
.secondary.full, .full { width: 100%; }
.gate-error { margin-top: 14px; padding: 11px 13px; border-radius: 10px; color: #8b2929; background: #f9d9d2; font-size: 13px; }
.identity-copy { font-weight: 800; }
.identity-choices { display: grid; gap: 10px; }
.identity-choice { display: flex; align-items: center; gap: 12px; width: 100%; border: 1px solid var(--line); padding: 12px; border-radius: 13px; background: var(--paper-2); color: var(--ink); font-weight: 900; text-align: left; }

.app {
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
  background: rgba(8, 29, 40, .76);
  box-shadow: 0 0 80px rgba(0,0,0,.2);
}
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 18px 12px;
  background: linear-gradient(to bottom, rgba(12,34,48,.98), rgba(12,34,48,.91));
  backdrop-filter: blur(12px);
}
.trip-title { min-height: 44px; display: flex; align-items: center; gap: 6px; background: none; border: 0; padding: 4px 0; color: var(--paper); font-family: var(--display); font-size: 22px; font-weight: 700; text-align: left; }
.sync-pill { display: flex; align-items: center; gap: 7px; min-height: 44px; border: 1px solid rgba(255,255,255,.15); border-radius: 999px; padding: 7px 10px; background: rgba(255,255,255,.06); color: #b9c7cb; font-size: 11px; font-weight: 800; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(110,175,113,.15); }
.sync-pill.pending .sync-dot { background: var(--amber); }
.sync-pill.error .sync-dot { background: var(--danger); }
.sync-pill.syncing .sync-dot { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

#main { min-height: 0; }
.screen { display: none; padding: 8px 16px 110px; animation: reveal .24s ease both; }
.screen.active { display: block; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
.balance-ribbon { min-height: 42px; display: flex; align-items: center; justify-content: center; color: #b8c8cd; font-size: 12px; letter-spacing: .02em; }
.balance-ribbon strong { color: var(--amber); margin-left: 5px; }
.amount-stage { padding: 12px 8px 20px; text-align: center; }
.amount-stage > label { color: #8fa3aa; font-size: 11px; letter-spacing: .25em; }
.amount-line { display: flex; justify-content: center; align-items: baseline; color: var(--paper); }
.amount-line span { font-family: var(--display); font-size: 25px; color: var(--amber); }
.amount-line input {
  width: min(72vw, 330px);
  min-height: 84px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--paper);
  font-family: var(--display);
  font-size: clamp(58px, 16vw, 78px);
  line-height: 1;
  text-align: center;
  box-shadow: none;
}
.amount-line input::placeholder { color: rgba(244,235,216,.18); }
.conversion-preview { min-height: 20px; color: #9fb1b6; font-size: 12px; }
.paper-panel { position: relative; background: var(--paper); color: var(--ink); padding: 20px; box-shadow: var(--shadow); }
.field-label { font-size: 10px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; color: #68777c; }
.line-input { border-width: 0 0 1px; border-radius: 0; background: transparent; padding-inline: 0; font-family: var(--display); font-size: 21px; }
.line-input:focus { box-shadow: none; }
.field-block { margin-top: 20px; }
.field-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.text-button { min-height: 44px; border: 0; background: none; color: #9a6800; font-weight: 900; font-size: 12px; padding: 8px 0; cursor: pointer; }
.member-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.member-chip { min-height: 42px; display: flex; align-items: center; gap: 7px; border: 1px solid rgba(22,39,45,.16); border-radius: 999px; background: rgba(255,255,255,.48); color: var(--ink); padding: 7px 11px 7px 8px; font-weight: 800; cursor: pointer; }
.member-chip .avatar, .avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: #10232b; font-size: 10px; font-weight: 950; }
.member-chip.selected { border-color: var(--chip); background: color-mix(in srgb, var(--chip) 19%, white); box-shadow: inset 0 0 0 1px var(--chip); }
.member-chip.selected::after { content: "✓"; font-size: 11px; }
.split-preview { margin-top: 10px; padding: 10px 12px; border-left: 3px solid var(--teal); background: rgba(95,179,179,.11); color: #43656b; font-size: 12px; }
.more-details { margin-top: 18px; border-top: 1px dashed rgba(22,39,45,.22); padding-top: 10px; }
.more-details summary, .settlement-history summary { cursor: pointer; color: #6d777b; font-size: 12px; font-weight: 900; padding: 7px 0; }
.more-details label { margin-top: 12px; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions, .dialog-actions { display: flex; gap: 10px; margin-top: 18px; }
.form-actions .primary { flex: 1; }
.save-expense { min-height: 54px; font-size: 15px; }

.section-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; padding: 16px 2px 14px; }
.section-head h2, .section-subhead h3, .people-card h3 { font-family: var(--display); margin: 3px 0 0; }
.section-head h2 { font-size: 34px; }
.icon-button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(255,255,255,.17); background: rgba(255,255,255,.07); color: var(--paper); font-size: 20px; }
.filter-row { display: flex; gap: 7px; margin-bottom: 12px; }
.filter { min-height: 44px; border: 1px solid rgba(255,255,255,.15); border-radius: 999px; padding: 7px 12px; background: transparent; color: #9fb1b6; font-size: 12px; font-weight: 900; }
.filter.active { background: var(--amber); border-color: var(--amber); color: var(--amber-dark); }
.expense-list { display: grid; gap: 9px; }
.date-label { margin: 14px 2px 4px; color: #82969d; font-size: 10px; letter-spacing: .15em; text-transform: uppercase; }
.expense-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 11px;
  padding: 13px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 15px;
  background: rgba(255,255,255,.055);
  color: var(--paper);
  text-align: left;
}
.expense-row.voided { opacity: .48; }
.expense-row.pending { border-color: rgba(244,185,66,.5); }
.expense-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--paper); color: var(--ink); font-size: 18px; }
.expense-main strong { display: block; }
.expense-main small { color: #91a3aa; }
.expense-amount { text-align: right; }
.expense-amount strong { display: block; font-family: var(--display); font-size: 17px; }
.expense-amount small { color: var(--amber); }
.empty-state { padding: 32px 20px; border: 1px dashed rgba(255,255,255,.18); border-radius: 15px; color: #8ea2a8; text-align: center; }

.total-spend { text-align: right; color: #92a5ab; font-size: 10px; text-transform: uppercase; }
.total-spend strong { display: block; color: var(--paper); font-family: var(--display); font-size: 17px; text-transform: none; }
.balance-list { display: grid; gap: 10px; }
.balance-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 11px; padding: 14px; background: var(--paper); color: var(--ink); border-radius: 15px; }
.balance-row .detail { color: #718087; font-size: 11px; }
.balance-row .net { text-align: right; font-weight: 950; }
.balance-row .net.positive { color: #2e7d57; }
.balance-row .net.negative { color: #b44e42; }
.section-subhead { margin: 26px 2px 10px; }
.section-subhead h3 { margin: 0; font-size: 20px; }
.section-subhead p { margin: 4px 0; color: #8da0a7; font-size: 11px; }
.settlement-list { display: grid; gap: 8px; }
.settlement-suggestion { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px; border: 1px solid rgba(244,185,66,.35); border-radius: 14px; background: rgba(244,185,66,.08); color: var(--paper); text-align: left; }
.settlement-suggestion strong { color: var(--amber); }
.settlement-history { margin-top: 18px; }
.settlement-history summary { color: #9aabb0; }
.history-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 2px; border-bottom: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.history-row.reversed { opacity: .45; text-decoration: line-through; }

.rate-card { position: relative; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 20px; background: var(--paper); color: var(--ink); }
.rate-card strong { display: block; margin-top: 5px; font-family: var(--display); font-size: 25px; }
.rate-card small { display: block; }
.people-card { margin-top: 14px; padding: 16px; border-radius: 16px; background: rgba(255,255,255,.055); }
.people-card h3 { margin: 0; }
.people-list { display: grid; margin-top: 8px; }
.person-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 11px; padding: 11px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.person-row:last-child { border-bottom: 0; }
.person-row small { color: #8ea2a8; }
.person-action { border: 0; background: none; color: #9fb0b5; padding: 8px; }
.reliability-card { display: flex; gap: 12px; margin: 14px 0; padding: 15px; border-radius: 15px; background: rgba(95,179,179,.11); color: #b7c8cc; }
.reliability-card .shield { flex: 0 0 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--teal); border-radius: 50%; color: var(--teal); }
.reliability-card p { margin: 3px 0 0; font-size: 11px; line-height: 1.4; }
.logout { width: 100%; margin-top: 12px; color: #8fa2a8; }

.bottom-nav {
  position: fixed;
  z-index: 25;
  left: 50%;
  bottom: 0;
  width: min(100%, 520px);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px 8px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255,255,255,.09);
  background: rgba(7,25,35,.96);
  backdrop-filter: blur(16px);
}
.bottom-nav button { min-height: 54px; display: grid; place-items: center; align-content: center; gap: 3px; border: 0; border-radius: 13px; background: transparent; color: #7f969f; font-size: 10px; font-weight: 900; }
.bottom-nav button span { min-height: 19px; font-size: 18px; letter-spacing: -4px; }
.bottom-nav button.active { color: var(--amber); background: rgba(244,185,66,.09); }

.sheet {
  width: min(calc(100% - 20px), 500px);
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 10px 18px max(22px, env(safe-area-inset-bottom));
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.sheet::backdrop { background: rgba(1,10,15,.72); backdrop-filter: blur(3px); }
.sheet-grab { width: 42px; height: 4px; margin: 2px auto 16px; border-radius: 999px; background: rgba(22,39,45,.2); }
.sheet h2 { font-family: var(--display); font-size: 28px; margin: 4px 0 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.detail-tile { padding: 11px; border-radius: 12px; background: rgba(22,39,45,.06); }
.detail-tile small { display: block; color: #748187; }
.share-lines { margin: 14px 0; border-top: 1px dashed var(--line); }
.share-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.danger-button { width: 100%; min-height: 44px; margin-top: 8px; border: 1px solid #c85858; border-radius: 12px; background: transparent; color: #a43c3c; font-weight: 900; }
.toast { position: fixed; z-index: 60; left: 50%; bottom: calc(82px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); transform: translate(-50%, 20px); padding: 11px 14px; border-radius: 999px; background: #071923; color: var(--paper); box-shadow: var(--shadow); font-size: 12px; font-weight: 800; opacity: 0; pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .app { min-height: calc(100dvh - 36px); border-radius: 26px; overflow: hidden; }
  .bottom-nav { bottom: 18px; border-radius: 0 0 26px 26px; }
  .app-header { border-radius: 26px 26px 0 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

