:root {
  color-scheme: dark;
  --bg: #000;
  --surface: #1c1c1e;
  --sheet: #1c1c1e;
  --field: #2c2c2e;
  --field-active: #5a5a60;
  --line: #38383a;
  --text: #fff;
  --muted: #98989f;
  --accent: #ffd60a;
  --on-accent: #1a1500;
  --positive: #32d583;
  --negative: #ff5a4f;
  --radius-lg: 24px;
  --radius-md: 16px;
  --tap: 48px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.3;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body.sheet-open { overflow: hidden; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p { margin: 0; }
.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }

/* Layout */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 104px);
}
.topbar { display: flex; justify-content: space-between; align-items: center; min-height: var(--tap); }
.topbar-title { font-weight: 700; }
.spacer { width: var(--tap); }

.round-button {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  font-size: 20px;
  font-weight: 700;
}
.pill-button {
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
}

.hero { text-align: center; padding: 4px 0 20px; }
.hero-emoji { font-size: 56px; line-height: 1.15; }
.hero h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.hero-sub { color: var(--muted); margin-top: 2px; }

/* Segmented controls */
.segments {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface);
  border-radius: 999px;
}
.segments.on-sheet { background: var(--field); }
.segment {
  flex: 1;
  min-height: 42px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
}
.segment[aria-pressed="true"], .segment[aria-selected="true"] { background: var(--field-active); }

/* Expenses */
.totals { display: flex; flex-wrap: wrap; gap: 4px 16px; justify-content: space-around; text-align: center; padding: 20px 0 8px; }
.totals-label { color: var(--muted); font-size: 15px; }
.totals .amount { font-size: 22px; margin-top: 2px; }

.section-title { font-size: 20px; font-weight: 800; margin: 20px 0 10px; }

.row-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  text-align: left;
}
.row-emoji { font-size: 30px; width: 36px; text-align: center; flex: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 15px; }
.group-row .row-title { white-space: normal; }
.row-sub strong { font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 56px 24px; }
.empty-emoji { font-size: 44px; margin-bottom: 10px; }

.floating-action {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  min-height: 54px;
  padding: 0 28px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 800;
  box-shadow: 0 8px 24px rgb(0 0 0 / 60%);
  white-space: nowrap;
}

/* Balances */
.summary-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  margin-top: 20px;
  padding: 18px 16px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  text-align: left;
}
.summary-emoji { font-size: 44px; line-height: 1; flex: none; }
.summary-main { flex: 1; min-width: 0; }
.summary-title { font-size: 20px; font-weight: 800; }
.summary-sub { color: var(--muted); }
.chevron { color: var(--muted); font-size: 24px; flex: none; }
.link-card {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-top: 8px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  color: var(--accent);
  font-weight: 700;
}
.avatar {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--field-active);
  font-weight: 800;
  font-size: 19px;
}
.avatar.me { background: var(--accent); color: var(--on-accent); }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.paid-amount { color: var(--accent); }

/* Detail */
.group { background: var(--surface); border-radius: var(--radius-lg); overflow: hidden; }
.group-row { display: flex; align-items: center; gap: 14px; padding: 12px 16px; min-height: 68px; }
.group-row + .group-row { border-top: 1px solid var(--line); }
.danger-button {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-top: 28px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  color: var(--negative);
  font-weight: 700;
}

/* Sheets */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgb(0 0 0 / 60%);
  animation: fade-in 180ms ease-out;
}
.sheet {
  position: absolute;
  inset: calc(env(safe-area-inset-top) + 12px) 0 0;
  max-width: 560px;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--sheet);
  border-radius: 28px 28px 0 0;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 24px);
  animation: slide-up 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet .round-button { background: var(--field); }
.sheet-menu { top: auto; }
.sheet-center { text-align: center; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop { animation: none; }
}

/* Forms */
.field-label { display: block; font-size: 17px; font-weight: 800; margin: 22px 0 8px; }
.input, .select {
  display: block;
  width: 100%;
  min-height: 54px;
  padding: 0 18px;
  background: var(--field);
  border: 0;
  border-radius: 999px;
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder { color: var(--muted); }
.select-wrap { position: relative; }
.select-wrap .select { padding-right: 36px; }
.select-wrap::after {
  content: "⌄";
  position: absolute;
  top: 50%;
  right: 18px;
  transform: translateY(-65%);
  color: var(--muted);
  font-weight: 700;
  pointer-events: none;
}
input[type="date"] { line-height: 54px; }
.amount-input { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.two-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.two-columns input[type="date"] { min-width: 0; padding: 0 12px; }
.two-columns .field-label { margin-top: 22px; }
.split-header { display: flex; justify-content: space-between; align-items: center; margin: 22px 0 8px; gap: 12px; }
.split-header .field-label { margin: 0; }
.split-header .segments { flex: none; width: 190px; }
.split-header .segment { min-height: 44px; font-size: 14px; }
.split-row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; min-height: 60px; }
.split-row + .split-row { border-top: 1px solid var(--line); }
.split-row .row-main { font-weight: 500; }
.group.on-sheet { background: var(--field); }
.check {
  width: 28px;
  height: 28px;
  flex: none;
  margin: 0;
  border-radius: 50%;
  border: 2px solid var(--muted);
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.check:checked { background: var(--accent); border-color: var(--accent); }
.check:checked::after { content: "✓"; color: var(--on-accent); font-weight: 800; font-size: 16px; }
.split-input {
  width: 108px;
  min-height: 42px;
  padding: 0 12px;
  background: var(--field-active);
  border: 0;
  border-radius: 12px;
  text-align: right;
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.split-input::placeholder { color: var(--text); opacity: 0.6; }
.split-note { color: var(--muted); font-size: 15px; margin-top: 8px; padding: 0 4px; }
.split-note.negative { color: var(--negative); }

.primary-button {
  display: block;
  width: 100%;
  min-height: 54px;
  margin-top: 28px;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: 999px;
  font-weight: 800;
}
.secondary-button {
  display: block;
  width: 100%;
  min-height: 54px;
  margin-top: 10px;
  background: var(--field);
  border-radius: 999px;
  font-weight: 700;
}
.form-error { color: var(--negative); margin-top: 14px; text-align: center; }

/* Settle sheet */
.settle-amount {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 14px;
  border-radius: 14px;
  background: var(--positive);
  color: #00210f;
  font-size: 30px;
  font-weight: 800;
}
.settle-amount.owing { background: var(--negative); color: #2b0300; }
.settle-card { margin-top: 28px; padding: 20px; background: var(--field); border-radius: var(--radius-lg); }
.settle-line { font-size: 19px; font-weight: 800; }
.settle-line span { color: var(--muted); font-weight: 500; font-size: 16px; }
.settle-card .amount { display: block; font-size: 26px; margin: 8px 0 14px; }
.settle-card .primary-button { margin-top: 0; }

/* Entry screens */
.center-screen {
  min-height: 100dvh;
  max-width: 420px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 20px calc(env(safe-area-inset-bottom) + 24px);
  text-align: center;
}
.center-screen h1 { font-size: 30px; font-weight: 800; }
.center-screen .input { margin-top: 24px; text-align: center; }
.center-screen .hero-sub { margin-top: 6px; }
.person-button {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 68px;
  margin-top: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  font-weight: 700;
  text-align: left;
}
.person-list { margin-top: 20px; }
.loading { min-height: 100dvh; display: grid; place-items: center; font-size: 44px; text-align: center; }
/* Only appears if the app script never starts: app.js replaces this markup as soon as it runs. */
.boot-reload {
  display: block;
  margin-top: 16px;
  color: var(--accent);
  font-size: 17px;
  font-weight: 700;
  visibility: hidden;
  animation: boot-show 0s 8s forwards;
}
@keyframes boot-show { to { visibility: visible; } }

.pull {
  position: fixed;
  z-index: 5;
  top: calc(env(safe-area-inset-top) + 4px);
  left: 50%;
  width: 44px;
  height: 44px;
  margin-left: -22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--field);
  font-size: 24px;
  opacity: 0.6;
  pointer-events: none;
}
.pull[hidden] { display: none; }
.pull.armed { opacity: 1; }
.pull.refreshing { opacity: 1; animation: pull-spin 900ms linear infinite; }
@keyframes pull-spin { to { rotate: 360deg; } }
@media (prefers-reduced-motion: reduce) {
  .pull.refreshing { animation: none; }
}

.settings-note { color: var(--muted); font-size: 15px; text-align: center; margin-top: 12px; }

.toast {
  position: fixed;
  z-index: 20;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 88px);
  max-width: 420px;
  margin: 0 auto;
  padding: 12px 16px;
  background: var(--field);
  border-radius: var(--radius-md);
  text-align: center;
  box-shadow: 0 8px 24px rgb(0 0 0 / 60%);
}
.toast[hidden] { display: none; }
