:root {
  --bg: #fbf2f5;
  --surface: #ffffff;
  --surface-soft: #fff8fa;
  --pink: #d98796;
  --pink-dark: #c0687a;
  --pink-light: #f5d5dd;
  --navy: #2b3e5d;
  --navy-dark: #1f2e47;
  --text: #272228;
  --text-muted: #766871;
  --border: #edd5dc;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 4px 14px rgba(43, 62, 93, 0.06);
  --shadow-md: 0 12px 32px rgba(43, 62, 93, 0.12);
  --shadow-card: 0 18px 40px rgba(139, 64, 86, 0.22);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 12% 8%, rgba(217, 135, 150, 0.2), transparent 42%),
    radial-gradient(circle at 90% 15%, rgba(43, 62, 93, 0.08), transparent 36%),
    var(--bg);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 14px 16px 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 10px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.brand-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--navy);
}

.brand-sub {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pink-dark);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--navy);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-pill:active {
  transform: scale(0.96);
}

.icon-pill--subtle {
  background: var(--surface-soft);
}

.badge-count {
  background: var(--pink);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Views */
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.auth-tabs[hidden] {
  display: none;
}

.auth-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.auth-tab--active {
  background: linear-gradient(135deg, var(--pink), var(--pink-dark));
  color: #fff;
  box-shadow: 0 4px 12px rgba(192, 104, 122, 0.25);
}

.form-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  color: var(--pink-dark);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-divider::before,
.form-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-switch-hint {
  margin: 4px 0 0;
  text-align: center;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.member-status-pill--inactive {
  background: #fde2e4;
  color: #9e2a2b;
}

.view {
  display: none;
  flex-direction: column;
  gap: 16px;
  animation: fadeIn 0.25s ease;
}

.view--active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-intro {
  text-align: center;
  padding: 4px 6px 0;
}

.hero-intro h1 {
  margin: 0 0 6px;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.55rem;
  color: var(--navy);
}

.hero-intro p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* Live Preview */
.preview-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.preview-card-frame {
  width: 100%;
  max-width: 390px;
  aspect-ratio: 910 / 572;
  border-radius: 18px;
  overflow: hidden;
  filter: drop-shadow(0 12px 24px rgba(139, 64, 86, 0.18));
}

.preview-card-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.preview-caption {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--pink-dark);
}

/* Form */
.card-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

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

.form-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--navy);
}

.form-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.96rem;
  color: var(--text);
  background: var(--surface-soft);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--pink-dark);
  background: #fff;
}

.form-input--sm {
  padding: 9px 12px;
  font-size: 0.88rem;
}

.field-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Photo Picker */
.photo-picker {
  display: flex;
  align-items: center;
  gap: 14px;
}

.photo-thumb {
  width: 78px;
  height: 78px;
  flex-shrink: 0;
  border-radius: 14px;
  border: 2px dashed var(--pink);
  background: var(--surface-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.photo-placeholder {
  font-size: 1.8rem;
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Birthdate & Zodiac Pill */
.birthdate-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.zodiac-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #fce8ee, #f5d5dd);
  border: 1px solid #e7b5c3;
  color: var(--navy);
  font-weight: 700;
  font-size: 0.86rem;
  white-space: nowrap;
}

.zodiac-symbol {
  font-size: 1.05rem;
}

/* Signature Pad */
.sig-tools {
  display: flex;
  gap: 12px;
}

.text-btn {
  border: none;
  background: none;
  padding: 2px 4px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--navy);
  cursor: pointer;
}

.text-btn--danger {
  color: var(--pink-dark);
}

.signature-box {
  position: relative;
  border: 1.5px dashed var(--pink);
  border-radius: var(--radius-md);
  background: #fffdfd;
  overflow: hidden;
  touch-action: none;
  height: 128px;
}

.signature-box canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.signature-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-size: 0.84rem;
  color: #b49aa3;
}

.signature-placeholder.is-hidden {
  opacity: 0;
}

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 12px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.14s ease, filter 0.14s ease, background 0.14s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn--primary {
  background: linear-gradient(135deg, var(--pink), var(--pink-dark));
  color: #fff;
  box-shadow: 0 6px 16px rgba(192, 104, 122, 0.28);
}

.btn--navy {
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  color: #fff;
  box-shadow: 0 6px 16px rgba(43, 62, 93, 0.24);
}

.btn--outline {
  background: var(--surface);
  color: var(--navy);
  border: 1.5px solid var(--border);
}

.btn--sm {
  padding: 9px 13px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

.btn--lg {
  padding: 14px 18px;
  font-size: 1rem;
}

.btn--full {
  width: 100%;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fff0f2;
  border: 1px solid #f4b7c2;
  color: #a62639;
  font-size: 0.84rem;
  font-weight: 600;
}

/* VIEW 2: Card & 3D Flip */
.card-stage-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.member-status-pill {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--pink-light);
  color: var(--navy);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.card-stage-header h2 {
  margin: 4px 0 0;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.45rem;
  color: var(--navy);
}

.tap-hint {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.flip-scene {
  width: 100%;
  aspect-ratio: 910 / 572;
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
}

.flip-card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}

.flip-card.is-flipped {
  transform: rotateY(180deg);
}

.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 22px;
  overflow: hidden;
}

.flip-face--front {
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 16px 30px rgba(139, 64, 86, 0.24));
}

.flip-face--front img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.flip-corner-hint {
  position: absolute;
  right: 12px;
  bottom: 10px;
  background: rgba(43, 62, 93, 0.82);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

.flip-corner-hint--inline {
  position: static;
  background: rgba(255, 255, 255, 0.18);
}

.flip-face--back {
  transform: rotateY(180deg);
  box-shadow: var(--shadow-card);
  background: linear-gradient(145deg, #2b3e5d 0%, #3b4f73 55%, #5b3b54 100%);
  color: #fff;
  border: 3px solid #f2c4d0;
}

.qr-card-back {
  height: 100%;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.qr-back-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.qr-back-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  padding: 3px;
}

.qr-back-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
}

.qr-back-sub {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  color: #f5d5dd;
  font-weight: 600;
}

.qr-back-body {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

.qr-code-box {
  background: #fff;
  padding: 8px;
  border-radius: 14px;
  width: clamp(104px, 31vw, 152px);
  height: clamp(104px, 31vw, 152px);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.qr-code-box svg {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-member-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.qr-member-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(0.95rem, 3.8vw, 1.25rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #ffdce5;
}

.qr-member-name {
  font-family: 'Caveat', cursive;
  font-size: clamp(1.35rem, 5vw, 1.8rem);
  line-height: 1.05;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qr-member-details {
  font-size: 0.74rem;
  color: rgba(255, 255, 255, 0.82);
}

.qr-back-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.78);
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  padding-top: 8px;
}

.card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.sync-toast {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

/* VIEW 3: Directory */
.directory-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.directory-header h2 {
  margin: 0;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.35rem;
  color: var(--navy);
}

.directory-sub {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.directory-toolbar {
  display: flex;
  gap: 8px;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease;
}

.member-row:hover {
  border-color: var(--pink);
}

.member-row:active {
  transform: scale(0.985);
}

.member-row-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.member-row-nick {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.96rem;
}

.member-row-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.member-row-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--pink-dark);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 36px 18px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Camera Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(25, 20, 28, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-sheet {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--navy);
}

.icon-close {
  border: none;
  background: var(--surface-soft);
  color: var(--navy);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 0.95rem;
  cursor: pointer;
}

.camera-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #111;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.camera-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-guide {
  position: absolute;
  inset: 14px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  pointer-events: none;
}

.camera-controls {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

@media (max-width: 380px) {
  .birthdate-row {
    grid-template-columns: 1fr;
  }
}
