:root {
  --bg: #0b0d10;
  --surface: #14181d;
  --surface-2: #1a1f26;
  --border: #222a33;
  --text: #f2f4f7;
  --muted: #8a95a3;
  --accent: #4ade80;
  --accent-hover: #22c55e;
  --error: #f87171;
  --radius: 14px;
  --radius-sm: 8px;
  --tap: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---- Topbar ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

#user-email {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- App shell ---- */

#app {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.center-screen {
  min-height: 40vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ---- Typography ---- */

h1, h2, h3 { letter-spacing: -0.02em; }
h1 { font-size: 2rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.4rem; margin: 0.5rem 0 1rem; }
h3 { font-size: 1rem; margin: 0 0 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

.muted { color: var(--muted); }
.msg { margin: 0.75rem 0 0; font-size: 0.95rem; min-height: 1.4em; }
.msg.error { color: var(--error); }
.msg.ok { color: var(--accent); }

/* ---- Forms ---- */

form { display: flex; flex-direction: column; gap: 0.75rem; }
label { font-size: 0.85rem; color: var(--muted); }

input[type="text"],
input[type="email"] {
  width: 100%;
  min-height: var(--tap);
  padding: 0.75rem 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  -webkit-appearance: none;
  appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.2);
}

button {
  min-height: var(--tap);
  padding: 0 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--accent);
  color: #0b0d10;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-text {
  background: transparent;
  color: var(--muted);
  min-height: auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.btn-text:hover { color: var(--text); }

.stack {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ---- Views ---- */

.view { animation: fadeIn 0.15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.view-login .brand { text-align: center; margin: 2rem 0 1.5rem; }
.view-login .brand h1 { margin-bottom: 0.25rem; }

.view-choice { text-align: center; margin-top: 1.5rem; }
.view-choice h2 { font-size: 1.25rem; font-weight: 500; }
.view-choice .stack { margin-top: 1.5rem; }

.view-form h2, .view-household h2, .view-invite h2, .view-join h2 {
  margin-top: 0;
}

/* ---- Cards ---- */

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

.members-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.member-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.member-row:last-child { border-bottom: none; }

.member-name { font-weight: 500; }
.member-role {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---- Invite view ---- */

.invite-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.qr {
  width: 240px;
  height: 240px;
  max-width: 100%;
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.invite-code {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.35em;
  padding-left: 0.35em;
  font-family: "SF Mono", "Menlo", monospace;
}

.invite-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: 100%;
}

/* ---- Join view ---- */

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  border: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  background: transparent;
  color: var(--muted);
  min-height: 40px;
  font-size: 0.9rem;
  border-radius: calc(var(--radius-sm) - 2px);
}
.tab-btn.active { background: var(--surface-2); color: var(--text); }

.scan {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#scan-video {
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1;
  object-fit: cover;
  background: #000;
  border-radius: var(--radius-sm);
  margin: 0 auto;
  display: block;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.35em;
  font-size: 1.4rem;
  font-family: "SF Mono", "Menlo", monospace;
  text-align: center;
  padding-left: 0.5em;
}

.code-form { max-width: 320px; margin: 0 auto; }
