:root {
  --bg: #f4f4fb;
  --card: #ffffff;
  --text: #1c1c28;
  --muted: #6b6b80;
  --line: #e4e4ef;
  --accent: #5b5bd6;
  --accent-2: #7fa7e0;
  --accent-text: #ffffff;
  --owe: #c2410c;
  --owed: #15803d;
  --danger: #b91c1c;
  --chip: #ececf8;
  --shadow: 0 8px 24px rgba(40, 40, 90, 0.12);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111118;
    --card: #1b1b26;
    --text: #ececf4;
    --muted: #9d9db4;
    --line: #2c2c3c;
    --accent: #8b8bf0;
    --accent-2: #5f86c4;
    --accent-text: #0f0f18;
    --owe: #fb923c;
    --owed: #4ade80;
    --danger: #f87171;
    --chip: #262636;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom));
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 0;
  background: none;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.boot {
  display: grid;
  place-items: center;
  min-height: 80vh;
  font-size: 28px;
  font-weight: 700;
  color: var(--muted);
}

/* ---------- buttons and fields */

.btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
  background: var(--chip);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: none; color: var(--danger); }
.btn.link { background: none; color: var(--accent); width: auto; padding: 8px; }
.btn:disabled { opacity: 0.5; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  min-height: 44px;
}
.field textarea { min-height: 72px; resize: vertical; }

.seg { display: flex; gap: 6px; background: var(--chip); padding: 4px; border-radius: 12px; }
.seg button { flex: 1; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 12px;
  min-height: 36px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 14px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 8px 0; }

/* ---------- login */

.login { padding-top: 12vh; }
.login h1 { font-size: 40px; margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login .or { text-align: center; color: var(--muted); margin: 20px 0; font-size: 14px; }

/* ---------- home */

.topbar { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; }
.topbar h1 { font-size: 22px; margin: 0; }

.hero {
  border-radius: 20px;
  padding: 22px 20px;
  color: #fff;
  background: linear-gradient(135deg, #5b5bd6, #7fa7e0);
  box-shadow: var(--shadow);
}
.hero .label { opacity: .85; font-size: 14px; }
.hero .amount { font-size: 36px; font-weight: 700; margin: 2px 0 14px; letter-spacing: -0.5px; }
.hero .btn { background: rgba(255,255,255,.22); color: #fff; width: auto; display: inline-block; }

.month { margin: 22px 4px 6px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row .icon {
  flex: none;
  width: 38px; height: 38px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--chip);
  font-size: 18px;
}
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); }
.row .side { text-align: right; font-size: 13px; }
.row .side b { display: block; font-size: 15px; }
.owe { color: var(--owe); }
.owed { color: var(--owed); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.fab {
  position: fixed;
  right: max(20px, calc(50vw - 260px));
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 62px; height: 62px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 34px;
  line-height: 1;
  box-shadow: var(--shadow);
}

/* ---------- sheet */

.backdrop { position: fixed; inset: 0; background: rgba(10,10,20,.45); z-index: 10; }
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  z-index: 11;
  box-shadow: var(--shadow);
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet header { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { font-size: 18px; margin: 0; }

.amount-input {
  display: flex; align-items: center; justify-content: center;
  font-size: 44px; font-weight: 700; margin: 8px 0;
}
.amount-input span { color: var(--muted); }
.amount-input input {
  width: 7ch;
  border: 0;
  background: none;
  font-size: 44px;
  font-weight: 700;
  text-align: left;
  outline: none;
}
.quick { justify-content: center; margin-bottom: 8px; }

.split-row { display: flex; gap: 10px; }
.split-row .field { flex: 1; margin: 6px 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 32px; }
.split-label { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }

.history { font-size: 13px; color: var(--muted); margin-top: 16px; }
.history li { margin: 4px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 12px;
  z-index: 20;
  max-width: 90vw;
}
