/* ============ FaceCard — mobile-first styles ============ */
:root {
  --green: #22c55e;
  --green-dark: #16a34a;
  --green-soft: #dcfce7;
  --green-tint: #f0fdf4;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e5e7eb;
  --bg: #f7f8f7;
  --card: #ffffff;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
  --shadow-sm: 0 4px 14px rgba(15, 23, 42, .06);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --hand: 'Caveat', cursive;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  background-image: radial-gradient(circle at 20% 0%, #e9fbef 0, transparent 40%),
                    radial-gradient(circle at 90% 80%, #eef5ff 0, transparent 35%);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
button { font-family: inherit; }
ul, ol { margin: 0; padding: 0; list-style: none; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  background: rgba(247, 248, 247, .85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); }
.brand-icon {
  position: relative; width: 30px; height: 30px; border-radius: 9px;
  background: var(--green); color: #fff; display: grid; place-items: center; font-size: 15px;
}
.brand-icon .brand-face { position: absolute; font-size: 10px; }
.brand-name { font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: #fff; color: var(--ink-2); cursor: pointer;
}

.app { max-width: 430px; margin: 0 auto; padding: 8px 18px 40px; }

/* ---------- Screens (states) ---------- */
.screen { display: none; animation: fadeUp .35s ease both; }
.screen.is-active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Buttons ---------- */
.btn {
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border: none; border-radius: 18px; padding: 16px 20px; font-weight: 700; font-size: 16px;
  cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--green); color: #fff; box-shadow: 0 10px 24px rgba(34, 197, 94, .35); }
.btn-primary:hover { background: var(--green-dark); }
.btn-xl { padding: 18px 22px; font-size: 17px; }
.btn-chev { margin-left: auto; font-size: 13px; opacity: .85; }
.btn-secondary { background: #f1f5f9; color: var(--ink); margin-top: 10px; }
.btn-secondary:hover { background: #e8edf3; }
.btn-light { background: var(--green-soft); color: #14532d; margin-top: 16px; }
.btn-light:hover { background: #c9f7d7; }
.btn-ghost { background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; padding: 12px; margin-top: 4px; }
.btn-ghost:hover { color: var(--ink); }
.btn-sm { width: auto; padding: 12px 16px; font-size: 14px; border-radius: 14px; }

/* ======================================================
   STATE 1 — LANDING
   ====================================================== */
.landing-copy { text-align: center; padding: 10px 0 6px; }
.headline {
  font-size: clamp(38px, 11vw, 46px); line-height: 1.02; font-weight: 900; letter-spacing: -.04em; margin: 0 0 10px;
}
.headline-accent { display: block; }
.subtext { margin: 0; font-size: 17px; color: var(--ink-2); font-weight: 500; }
.underline-doodle { position: relative; white-space: nowrap; }
.underline-doodle::after {
  content: ''; position: absolute; left: -2px; right: -2px; bottom: -6px; height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 10' preserveAspectRatio='none'%3E%3Cpath d='M1 7 Q 25 1, 50 6 T 99 4' stroke='%2322c55e' stroke-width='3.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center / 100% 100%;
}

/* Collage */
.collage { position: relative; height: 300px; margin: 22px 0 18px; }
.collage-card {
  position: absolute; overflow: hidden; background: #fff; padding: 7px; border-radius: 20px; box-shadow: var(--shadow);
}
.collage-card img { width: 100%; height: 100%; object-fit: cover; border-radius: 14px; }
.collage-main { width: 170px; height: 230px; left: 50%; top: 14px; transform: translateX(-50%) rotate(-4deg); z-index: 3; }
.collage-side { width: 112px; height: 140px; padding: 5px; z-index: 2; }
.collage-side img { border-radius: 11px; filter: grayscale(.7); }
.collage-a { left: 4px; bottom: 6px; transform: rotate(-9deg); }
.collage-b { right: 4px; bottom: 10px; transform: rotate(8deg); }
.sticker {
  position: absolute; right: 26px; top: 10px; z-index: 4;
  background: #bbf7d0; color: #14532d; font-family: var(--hand); font-size: 17px; line-height: 1; font-weight: 600;
  text-transform: uppercase; padding: 10px 12px; border-radius: 12px; transform: rotate(10deg);
  box-shadow: var(--shadow-sm); text-align: center;
}
.doodle { font-family: var(--hand); font-size: 18px; line-height: 1.05; color: var(--ink-2); text-transform: uppercase; font-weight: 600; }
.doodle-left { position: absolute; left: 8px; top: 48px; transform: rotate(-8deg); }
.arrow-doodle { position: absolute; left: 70px; top: 14px; color: var(--ink-2); font-size: 16px; transform: rotate(-60deg); }

/* Trust row */
.trust-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 22px; text-align: center; }
.trust-row li { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 4px; }
.trust-row i { width: 36px; height: 36px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); display: grid; place-items: center; color: var(--ink); font-size: 14px; margin-bottom: 4px; }
.trust-row strong { font-size: 13px; font-weight: 700; }
.trust-row span { font-size: 11px; color: var(--muted); line-height: 1.25; }

/* ======================================================
   STATE 2 — SCANNING
   ====================================================== */
.screen-dark {
  background: #111318; border-radius: 28px; overflow: hidden; margin-top: 4px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.viewfinder { position: relative; width: 100%; aspect-ratio: 3 / 4; background: #0b0d12; overflow: hidden; }
.viewfinder video, .viewfinder img { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.viewfinder img#preview-img { transform: none; }
.viewfinder-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: #2a2f3a; font-size: 140px; }

.scan-frame { position: absolute; inset: 14% 16% 20%; pointer-events: none; }
.corner { position: absolute; width: 34px; height: 34px; border: 3px solid var(--green); filter: drop-shadow(0 0 6px rgba(34,197,94,.8)); }
.corner.tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 14px; }
.corner.tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 14px; }
.corner.bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 14px; }
.corner.br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 14px; }
.scan-line {
  position: absolute; left: 6px; right: 6px; height: 3px; top: 0;
  background: linear-gradient(90deg, transparent, var(--green), transparent);
  box-shadow: 0 0 18px 4px rgba(34,197,94,.55);
  animation: scan 2.2s ease-in-out infinite;
}
@keyframes scan { 0% { top: 2%; } 50% { top: 96%; } 100% { top: 2%; } }
.face-dots i { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); opacity: 0; animation: blink 2.2s infinite; }
.face-dots i:nth-child(1) { left: 32%; top: 36%; animation-delay: .2s; }
.face-dots i:nth-child(2) { left: 64%; top: 36%; animation-delay: .5s; }
.face-dots i:nth-child(3) { left: 49%; top: 52%; animation-delay: .8s; }
.face-dots i:nth-child(4) { left: 40%; top: 68%; animation-delay: 1.1s; }
.face-dots i:nth-child(5) { left: 58%; top: 68%; animation-delay: 1.4s; }
@keyframes blink { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }

.analyze-panel { padding: 18px 18px 22px; color: #fff; background: linear-gradient(180deg, #1b1f27, #111318); }
.analyze-head { display: flex; align-items: center; gap: 12px; font-size: 17px; margin-bottom: 14px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--green); animation: spin .9s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.analyze-steps li { display: flex; align-items: center; gap: 10px; font-size: 14px; color: rgba(255,255,255,.4); padding: 6px 0 6px 4px; transition: color .3s; }
.analyze-steps li.active { color: #fff; }
.analyze-steps li.done { color: rgba(255,255,255,.85); }
.check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); display: grid; place-items: center; flex-shrink: 0; font-size: 10px; transition: all .3s; }
.analyze-steps li.active .check { border-color: var(--green); border-top-color: transparent; animation: spin .9s linear infinite; }
.analyze-steps li.done .check { background: var(--green); border-color: var(--green); color: #fff; animation: none; }
.analyze-steps li.done .check::before { content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900; }
.analyze-foot { margin: 14px 0 0; text-align: center; font-size: 13px; color: rgba(255,255,255,.5); }

/* ======================================================
   STATE 3 — RESULT
   ====================================================== */
.score-hero {
  position: relative; text-align: center; padding: 26px 18px 22px; border-radius: var(--radius);
  background: linear-gradient(180deg, #f0fdf4, #ffffff); border: 1px solid #d9f5e2; overflow: hidden;
}
.confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); position: relative; }
.big-score { position: relative; display: flex; align-items: baseline; justify-content: center; gap: 4px; margin: 6px 0 4px; }
.big-score span { font-size: 92px; font-weight: 900; letter-spacing: -.06em; line-height: 1; color: #15803d; }
.big-score small { font-size: 20px; font-weight: 700; color: var(--muted); }
.score-tag { position: relative; margin: 0; font-size: 14px; font-weight: 600; color: var(--ink-2); }

.feature-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.feature-grid li { background: #fff; border-radius: 16px; padding: 12px 6px; text-align: center; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: center; gap: 3px; }
.feature-grid i { font-size: 15px; color: var(--ink); }
.feature-grid span { font-size: 11px; color: var(--muted); font-weight: 500; }
.feature-grid strong { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }

.potential-pill { background: var(--green-soft); color: #14532d; border-radius: 14px; padding: 12px; text-align: center; font-weight: 600; font-size: 15px; }
.potential-pill strong { font-weight: 800; }
.insight { text-align: center; font-size: 14px; color: var(--ink-2); margin: 12px 8px 16px; line-height: 1.45; }

/* Share card */
.share-card {
  display: grid; grid-template-columns: 112px 1fr; gap: 12px; align-items: center;
  background: #fff; border-radius: 22px; padding: 10px; margin-top: 20px; box-shadow: var(--shadow); transform: rotate(-1.5deg);
}
.share-photo { position: relative; width: 112px; aspect-ratio: 4 / 5; border-radius: 16px; overflow: hidden; background: #e2e8f0; }
.share-photo img { width: 100%; height: 100%; object-fit: cover; }
.share-photo img[src=""] { display: none; }
.share-photo-fallback { position: absolute; inset: 0; display: grid; place-items: center; color: #94a3b8; font-size: 48px; z-index: -1; }
.share-body { padding: 4px 6px 4px 0; }
.share-brand { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 800; }
.share-brand i { width: 16px; height: 16px; border-radius: 4px; background: var(--green); color: #fff; display: grid; place-items: center; font-size: 9px; }
.share-line { margin: 6px 0 0; font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.share-score { margin: 0; font-weight: 900; font-size: 30px; letter-spacing: -.04em; line-height: 1.05; }
.share-score span { color: #15803d; }
.share-cta { margin: 6px 0 0; font-size: 14px; font-weight: 600; color: var(--ink-2); line-height: 1.5; }

/* Join form */
.join-form { margin-top: 22px; background: #fff; border-radius: 18px; padding: 14px; box-shadow: var(--shadow-sm); }
.join-label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; font: inherit; font-size: 15px; outline: none; }
.join-row input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.join-form.joined { opacity: .55; pointer-events: none; }

/* ======================================================
   BATTLE / LEADERBOARD
   ====================================================== */
.battle { margin-top: 36px; background: #fff; border-radius: 28px; padding: 22px 16px 18px; box-shadow: var(--shadow); position: relative; }
.battle-head { position: relative; }
.battle-head h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.03em; }
.battle-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; max-width: 230px; }
.doodle-right { position: absolute; right: 0; top: -2px; text-align: center; transform: rotate(6deg); font-size: 16px; }

.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 8px; align-items: end; margin-top: 22px; }
.podium-card { background: #f8fafc; border-radius: 18px; padding: 14px 8px 12px; text-align: center; position: relative; }
.podium-card.first { background: var(--green-tint); border: 1px solid #c6f0d2; padding-top: 22px; box-shadow: 0 10px 30px rgba(34,197,94,.18); }
.podium-card .crown { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); font-size: 22px; filter: drop-shadow(0 2px 4px rgba(250,204,21,.5)); }
.avatar { width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 8px; display: grid; place-items: center; font-size: 28px; background: #fff; box-shadow: var(--shadow-sm); border: 2px solid #fff; }
.podium-card.first .avatar { width: 64px; height: 64px; font-size: 32px; border-color: var(--green); }
.podium-name { font-size: 13px; font-weight: 700; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium-score { font-size: 24px; font-weight: 900; letter-spacing: -.04em; display: block; margin-top: 2px; }
.rank-badge { display: inline-block; margin-top: 6px; font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: #e2e8f0; color: var(--ink-2); }
.rank-badge.gold { background: #fef3c7; color: #92400e; }
.rank-badge.bronze { background: #ffedd5; color: #9a3412; }
.podium-card.me { outline: 2px solid var(--green); }

.board { margin-top: 12px; }
.board li { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-top: 1px solid var(--line); font-size: 14px; }
.board .rank { width: 26px; color: var(--muted); font-weight: 700; font-size: 13px; }
.board .mini-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: #f1f5f9; font-size: 16px; }
.board .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 800; }
.board li.me { background: var(--green-tint); border-radius: 12px; border-top-color: transparent; }
.board-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 10px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 28px; line-height: 1.5; padding: 0 10px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 600; padding: 12px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 50; white-space: nowrap; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Tablet / desktop: keep it a phone-shaped card ---------- */
@media (min-width: 720px) {
  body { padding: 24px 0 48px; }
  .topbar { max-width: 430px; margin: 0 auto; border-radius: 22px 22px 0 0; position: static; }
  .app {
    background: rgba(255,255,255,.55); border: 1px solid #eef0ee; border-radius: 0 0 30px 30px;
    box-shadow: 0 30px 80px rgba(15,23,42,.1); padding-top: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
