:root {
  --brand: #ff6b4a;
  --brand-2: #ff9f68;
  --brand-ink: #fff;
  --bg: #faf7f4;
  --surface: #ffffff;
  --surface-2: #f3eee9;
  --ink: #1d1b2e;
  --muted: #6f6b7d;
  --line: #ebe4dd;
  --mine: #ff6b4a;
  --mine-ink: #fff;
  --theirs: #ffffff;
  --ok: #12a07a;
  --danger: #e03131;
  --shadow: 0 6px 24px rgba(40, 20, 10, .08);
  --r: 18px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14121c; --surface: #1e1b2b; --surface-2: #29253a; --ink: #f4f1fa; --muted: #a29eb5;
    --line: #322e44; --theirs: #29253a; --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }

#app {
  max-width: 480px; margin: 0 auto; height: 100dvh; display: flex; flex-direction: column;
  background: var(--bg); position: relative; overflow: hidden;
}
@media (min-width: 700px) {
  body { background: linear-gradient(135deg, #ffe3d6, #e9defc); }
  @media (prefers-color-scheme: dark) { body { background: #0c0a12; } }
  #app { height: min(880px, 96dvh); margin-top: 2dvh; border-radius: 28px; box-shadow: 0 20px 70px rgba(30, 10, 40, .25); }
}

/* ---------- shared ---------- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; overflow-y: auto; padding: 0 16px 96px; -webkit-overflow-scrolling: touch; }
.pad-top { padding-top: max(18px, env(safe-area-inset-top)); }
.topbar { padding: max(18px, env(safe-area-inset-top)) 16px 8px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.title { font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.title button { display: inline-flex; align-items: center; gap: 6px; font: inherit; }
.title .chev { font-size: 16px; color: var(--brand); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 18px; flex: none; }
.btn { padding: 12px 18px; border-radius: 14px; font-weight: 700; background: var(--surface-2); }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--brand-ink); box-shadow: 0 6px 16px rgba(255, 107, 74, .35); }
.btn.small { padding: 8px 14px; border-radius: 12px; font-size: 14px; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--brand); padding: 8px 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-h { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; padding: 13px 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.search { margin: 4px 0 12px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 16px 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1.5px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 17px; flex: none; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.lg { width: 84px; height: 84px; font-size: 32px; }
.tile { width: 46px; height: 46px; border-radius: 15px; display: grid; place-items: center; font-size: 24px; background: var(--surface-2); flex: none; }
.tile.lg { width: 56px; height: 56px; border-radius: 18px; font-size: 30px; }

.card { background: var(--surface); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); margin-bottom: 12px; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); flex: none; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

.fab {
  position: absolute; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 5;
  padding: 14px 20px; border-radius: 999px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 10px 24px rgba(255, 107, 74, .45);
}

/* ---------- tab bar ---------- */
.tabbar {
  display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); flex: none;
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; font-weight: 700; color: var(--muted); position: relative; }
.tab .ic { font-size: 22px; filter: grayscale(1); opacity: .7; }
.tab.on { color: var(--brand); }
.tab.on .ic { filter: none; opacity: 1; }
.tab .badge-dot { position: absolute; top: 3px; left: calc(50% + 8px); width: 10px; height: 10px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }

/* ---------- auth ---------- */
.auth { flex: 1; overflow-y: auto; padding: max(28px, env(safe-area-inset-top)) 22px 28px; display: flex; flex-direction: column; }
.hero {
  text-align: center; padding: 26px 8px 18px;
}
.logo { width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 24px; display: grid; place-items: center; font-size: 40px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 12px 28px rgba(255, 107, 74, .4); transform: rotate(-6deg); }
.hero h1 { font-size: 40px; font-weight: 900; letter-spacing: -.03em; }
.hero p { color: var(--muted); margin-top: 6px; font-size: 17px; }
.usecases { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0 6px; }
.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; margin: 18px 0 4px; }
.seg button { flex: 1; padding: 10px; border-radius: 11px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(0, 0, 0, .08); }
.err { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 20px; }
.banner { background: #fff4d6; color: #6b4e00; padding: 10px 14px; border-radius: 14px; font-size: 13px; margin-top: 16px; }
@media (prefers-color-scheme: dark) { .banner { background: #3a3117; color: #f3d98a; } }

/* ---------- community card ---------- */
.community { display: flex; gap: 12px; align-items: center; }
.community .meta { font-size: 13px; color: var(--muted); }
.community .desc { font-size: 14px; color: var(--muted); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- chat ---------- */
.chat-head { display: flex; align-items: center; gap: 10px; padding: max(12px, env(safe-area-inset-top)) 12px 10px; background: var(--surface); border-bottom: 1px solid var(--line); flex: none; }
.chat-head .who { flex: 1; min-width: 0; text-align: left; }
.chat-head .name { font-weight: 800; }
.back { width: 36px; height: 36px; font-size: 24px; color: var(--brand); border-radius: 50%; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 3px; -webkit-overflow-scrolling: touch; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 12px 0 6px; font-weight: 600; }
.msg { max-width: 82%; display: flex; flex-direction: column; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .sender { font-size: 12px; font-weight: 700; color: var(--muted); margin: 8px 8px 2px; }
.bubble { padding: 9px 13px; border-radius: 18px; background: var(--theirs); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); word-break: break-word; white-space: pre-wrap; }
.mine .bubble { background: var(--mine); color: var(--mine-ink); border-bottom-right-radius: 6px; }
.theirs .bubble { border-bottom-left-radius: 6px; }
.time { font-size: 11px; color: var(--muted); margin: 2px 8px 0; }
.plan { background: var(--surface); border: 2px solid var(--brand); border-radius: 20px; padding: 12px 14px; min-width: 250px; box-shadow: var(--shadow); margin: 6px 0; }
.plan .tag { font-size: 11px; font-weight: 800; color: var(--brand); letter-spacing: .08em; text-transform: uppercase; }
.plan .what { font-size: 18px; font-weight: 800; margin: 4px 0 2px; }
.plan .when { color: var(--muted); font-size: 14px; }
.rsvp { display: flex; gap: 6px; margin-top: 10px; }
.rsvp button { flex: 1; padding: 9px 4px; border-radius: 12px; background: var(--surface-2); font-size: 13px; font-weight: 700; }
.rsvp button.on.in { background: var(--ok); color: #fff; }
.rsvp button.on.maybe { background: #f59f00; color: #fff; }
.rsvp button.on.out { background: var(--muted); color: #fff; }
.plan .who { font-size: 13px; color: var(--muted); margin-top: 8px; }
.join-bar { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); text-align: center; }
.quick { display: flex; gap: 8px; overflow-x: auto; padding: 6px 12px 4px; scrollbar-width: none; flex: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--surface); border: 1.5px dashed var(--brand); color: var(--brand); font-size: 13px; font-weight: 700; white-space: nowrap; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); background: var(--bg); flex: none; }
.composer textarea { resize: none; max-height: 120px; min-height: 44px; border-radius: 22px; padding: 11px 16px; }
.send { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-size: 20px; flex: none; display: grid; place-items: center; }
.send:disabled { opacity: .4; }
.plan-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--surface); border: 1.5px solid var(--line); font-size: 20px; flex: none; }

/* ---------- modal ---------- */
.overlay { position: absolute; inset: 0; background: rgba(15, 8, 25, .5); display: flex; align-items: flex-end; z-index: 20; animation: fade .18s; }
.sheet { width: 100%; max-height: 90%; overflow-y: auto; background: var(--bg); border-radius: 26px 26px 0 0; padding: 10px 18px calc(22px + env(safe-area-inset-bottom)); animation: up .22s; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 22px; margin-bottom: 4px; }
.pick { display: flex; align-items: center; gap: 12px; padding: 10px 6px; width: 100%; text-align: left; border-radius: 12px; }
.pick .check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; color: #fff; font-size: 14px; margin-left: auto; }
.pick.on .check { background: var(--brand); border-color: var(--brand); }
.cat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-grid button { padding: 10px 4px; border-radius: 14px; background: var(--surface); border: 1.5px solid var(--line); font-size: 12px; font-weight: 700; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.cat-grid button span { font-size: 22px; }
.cat-grid button.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, var(--surface)); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.spinner { text-align: center; padding: 40px; color: var(--muted); }
