:root {
  --black: #000000;
  --bg: #000000;
  --thread: #f4ecdd;
  --thread-dim: #a79fb3;
  --purple: #5a14c4;
  --purple-deep: #2a0a5e;
  --stitch: #5d4a80;
  --danger: #c4425a;
  --surface: rgba(244, 236, 221, 0.04);
  --surface-border: rgba(167, 159, 179, 0.28);
  color-scheme: dark;
  /* In an installed iOS PWA the page draws under the status bar/notch
     (viewport-fit=cover + a translucent status bar), so normal content
     needs this clearance or it renders underneath it. */
  padding-top: env(safe-area-inset-top, 0px);
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --thread: #17131c;
  --thread-dim: #6b6572;
  --stitch: #cfc7d6;
  --surface: rgba(0, 0, 0, 0.03);
  --surface-border: rgba(0, 0, 0, 0.14);
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #ffffff;
    --thread: #17131c;
    --thread-dim: #6b6572;
    --stitch: #cfc7d6;
    --surface: rgba(0, 0, 0, 0.03);
    --surface-border: rgba(0, 0, 0, 0.14);
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); }

/* Stops the elastic rubber-band bounce at the top/bottom of the page. In an
   installed iOS PWA (no address bar to blame it on) that bounce is what
   drags the fixed tabbar out of place, briefly showing bare background
   underneath it. */
html, body { overscroll-behavior-y: none; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--thread);
  font-family: "Zilla Slab", Rockwell, "Roboto Slab", Georgia, serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: clamp(24px, 6vw, 56px) clamp(16px, 4vw, 32px) 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px clamp(16px, 4vw, 32px) 0;
}

.brand {
  font-weight: 700;
  font-size: 20px;
  color: var(--thread);
  text-decoration: none;
  letter-spacing: .02em;
}

.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.topbar-right a { color: var(--thread-dim); text-decoration: none; }
.topbar-right a:hover { color: var(--thread); }
.username-pill {
  border: 1px solid var(--surface-border);
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--thread-dim);
}

h1 { font-size: clamp(26px, 5vw, 34px); margin: 8px 0 4px; }
h2 { font-size: 20px; margin: 0 0 4px; }
p.lede { color: var(--thread-dim); margin: 0 0 32px; line-height: 1.5; }

.card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--thread-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

input[type="email"],
input[type="text"],
input[type="tel"],
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--thread);
  font-family: inherit;
  font-size: 16px;
  margin-bottom: 16px;
}
input:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--surface-border);
  background: transparent;
  color: var(--thread);
  border-radius: 8px;
  padding: 12px 20px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--thread-dim); }
.btn-primary {
  background: linear-gradient(180deg, var(--purple), var(--purple-deep));
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn[hidden] { display: none; }

.error-text { color: var(--danger); font-size: 14px; margin: -8px 0 16px; }
.help-text { color: var(--thread-dim); font-size: 13px; margin-top: -8px; }

.chip {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--surface-border);
  color: var(--thread-dim);
}
.chip-secret { border-color: var(--purple); color: var(--thread); }
.chip-closed { border-color: var(--danger); color: var(--danger); }

.poll-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.poll-question { font-size: 18px; font-weight: 700; margin: 0; }

.option-row {
  position: relative;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  overflow: hidden;
  background: var(--surface);
}
.option-row.selected { border-color: var(--purple); }
.option-row .bar-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(90, 20, 196, .35), rgba(90, 20, 196, .12));
  z-index: 0;
  transition: width .4s ease;
}
.option-row .option-content {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.option-row input[type="radio"] { accent-color: var(--purple); margin-right: 10px; }

.hidden-results {
  color: var(--thread-dim);
  font-size: 13px;
  font-style: italic;
  margin-top: 8px;
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--surface-border); }
th { color: var(--thread-dim); font-weight: 500; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; }

.empty-state { color: var(--thread-dim); text-align: center; padding: 48px 16px; }

.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.code-input {
  letter-spacing: .5em;
  text-align: center;
  font-size: 24px;
}

/* Bottom tab bar (PWA app shell) */
body.has-tabbar .wrap { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  background: rgba(8, 5, 13, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--surface-border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  /* Keeps this on its own compositing layer so iOS Safari doesn't leave a
     gap under it while the address bar animates away during a scroll. */
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  text-decoration: none;
  color: var(--thread-dim);
  font-size: 11px;
  padding: 6px 0;
  border-radius: 10px;
}
.tabbar a .tab-icon { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--thread); }
.tabbar a.active .tab-icon { filter: drop-shadow(0 0 6px rgba(90, 20, 196, .6)); }

/* Balances */
.balance-positive { color: #7fd8a0; }
.balance-negative { color: var(--danger); }
.balance-settled { color: var(--thread-dim); }

/* Checkbox lists (member pickers) */
.checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  text-transform: none;
  color: var(--thread);
  font-size: 15px;
  margin: 0;
}
.checkbox-list input[type="checkbox"] { accent-color: var(--purple); width: auto; }

.member-name { font-weight: 500; }
.member-sub { color: var(--thread-dim); font-size: 12px; }

.back-link { color: var(--thread-dim); text-decoration: none; font-size: 14px; display: inline-block; margin-bottom: 12px; }
.back-link:hover { color: var(--thread); }

.top-actions {
  position: fixed;
  /* position:fixed is relative to the viewport, not any padded ancestor, so
     the safe-area clearance has to be added here directly or this sits
     under the iOS status bar and becomes untappable. */
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
}
.theme-toggle-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--surface-border);
  background: rgba(128, 128, 128, .12);
  color: var(--thread);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
}
.avatar-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 1px solid var(--surface-border);
}
