:root {
  --bg: #0b1220;
  --panel: #131c2e;
  --panel-2: #1b2740;
  --ink: #eaf0ff;
  --muted: #8ea3c8;
  --bsky: #1185fe;
  --bsky-d: #0a6fd6;
  --good: #36d399;
  --mid: #fbbf24;
  --bad: #f87272;
  --row: #1a2540;
  --row-hi: #243456;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 50% -10%, #16233f 0%, var(--bg) 60%);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100%;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
}

/* screens */
.screen { display: none; width: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- start ---------- */
.hero { margin: auto 0; text-align: center; padding: 24px 0; }
.hero h1 {
  font-size: clamp(40px, 13vw, 64px);
  line-height: .95; margin: 0 0 14px;
  font-weight: 900; letter-spacing: -.02em;
  background: linear-gradient(135deg, #7cc4ff, var(--bsky) 60%, #b388ff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--muted); font-size: 17px; margin: 0 0 28px; }
.start-form { display: flex; flex-direction: column; gap: 12px; }
.input-wrap {
  display: flex; align-items: center; background: var(--panel);
  border: 1px solid #2a3a5c; border-radius: 14px; padding: 0 14px;
  transition: border-color .15s;
}
.input-wrap:focus-within { border-color: var(--bsky); }
.input-wrap .at { color: var(--muted); font-size: 18px; }
#handle-input {
  flex: 1; background: none; border: 0; color: var(--ink);
  font-size: 18px; padding: 16px 8px; outline: none; min-width: 0;
}
/* typeahead dropdown */
.ta-field { position: relative; }
.typeahead {
  list-style: none; margin: 6px 0 0; padding: 6px; position: absolute;
  left: 0; right: 0; top: 100%; z-index: 20;
  background: var(--panel-2); border: 1px solid #2a3a5c; border-radius: 14px;
  box-shadow: var(--shadow); max-height: 320px; overflow-y: auto;
}
.typeahead[hidden] { display: none; }
.ta-item {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px;
  border-radius: 10px; cursor: pointer; text-align: left;
}
.ta-item.active, .ta-item:hover { background: var(--row); }
.ta-av { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; background: var(--panel); }
.ta-blank { display: grid; place-items: center; font-weight: 800; color: #cfe1ff; background: linear-gradient(135deg, #2a3a5c, #1b2740); }
.ta-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.ta-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ta-handle { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.fineprint { color: var(--muted); font-size: 12.5px; margin-top: 20px; }
.error { color: var(--bad); font-size: 14px; min-height: 0; margin: 0;
  max-height: 0; overflow: hidden; transition: max-height .2s; }
.error.show { max-height: 80px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 14px;
  padding: 16px 18px; cursor: pointer; color: #fff; transition: transform .08s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--bsky), var(--bsky-d)); box-shadow: 0 6px 18px rgba(17,133,254,.35); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: var(--panel-2); color: var(--ink); }
.btn.bsky { background: var(--bsky); width: 100%; font-size: 17px; }
.btn.sticky { position: sticky; bottom: 8px; margin-top: 14px; width: 100%; }
.btn.full { width: 100%; margin-top: 12px; }
.row-btns { display: flex; gap: 10px; margin-top: 12px; }
.row-btns .btn { flex: 1; }

/* ---------- panel ---------- */
.panel {
  background: var(--panel); border: 1px solid #21304e;
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 16px; margin: auto 0; width: 100%;
}
h2 { margin: 0 0 6px; font-size: 22px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 14px; }

/* ---------- loading ---------- */
.loader { margin: auto; text-align: center; color: var(--muted); }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 16px;
  border: 4px solid #2a3a5c; border-top-color: var(--bsky);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- preview ---------- */
.preview-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.preview-chip {
  display: flex; align-items: center; gap: 8px; background: var(--row);
  border-radius: 999px; padding: 5px 12px 5px 5px; font-size: 14px; max-width: 100%;
}
.preview-chip .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.preview-chip .engaged { font-size: 11px; font-weight: 800; color: var(--bsky); background: rgba(17,133,254,.14); border-radius: 999px; padding: 2px 7px; flex: none; }

/* ---------- avatars ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; background: var(--panel-2); }
.preview-chip .avatar { width: 28px; height: 28px; }
.avatar-blank {
  display: grid; place-items: center; font-weight: 800; color: #cfe1ff;
  background: linear-gradient(135deg, #2a3a5c, #1b2740);
}

/* ---------- round head ---------- */
.round-head { display: flex; align-items: center; justify-content: space-between; }
.round-num { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.round-emoji { font-size: 26px; }
.prompt { font-size: 21px; line-height: 1.25; margin: 6px 0 4px; }
.round-sub { color: var(--muted); font-size: 13.5px; line-height: 1.35; margin: 0 0 12px; }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11.5px; font-weight: 700; letter-spacing: .05em; margin-bottom: 8px; }

/* ---------- friend list (sortable) ---------- */
.friend-list { display: flex; flex-direction: column; gap: 8px; touch-action: none; }
.friend-row {
  display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 12px;
  background: var(--row); border: 1px solid #26365a;
  border-radius: 12px; user-select: none; touch-action: none;
  transition: transform .16s cubic-bezier(.2,.8,.2,1), box-shadow .15s, background .15s;
}
.friend-row.dragging {
  transition: none; background: var(--panel-2);
  box-shadow: 0 12px 28px rgba(0,0,0,.5); border-color: var(--bsky);
  z-index: 5; position: relative; cursor: grabbing;
}
.rank {
  width: 26px; height: 26px; flex: none; display: grid; place-items: center;
  background: var(--panel-2); border-radius: 8px; font-weight: 800; font-size: 14px; color: var(--muted);
}
.who { min-width: 0; flex: 1; }
.dname { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.handle { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grip { color: #4a5d85; font-size: 22px; letter-spacing: -2px; cursor: grab; }

/* ---------- reveal ---------- */
.reveal-head { text-align: center; margin-bottom: 14px; }
.reveal-score { font-size: 56px; font-weight: 900; line-height: 1; margin: 4px 0; }
.reveal-prompt { font-size: 16px; margin: 4px 0 2px; }
.reveal-score.good, .final-score.good, .bd-pts.good { color: var(--good); }
.reveal-score.mid, .final-score.mid, .bd-pts.mid { color: var(--mid); }
.reveal-score.bad, .final-score.bad, .bd-pts.bad { color: var(--bad); }
.reveal-list { display: flex; flex-direction: column; gap: 6px; }
.reveal-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  background: var(--row); border-radius: 12px;
  animation: pop .35s both;
}
.reveal-row:nth-child(2) { animation-delay: .04s; }
.reveal-row:nth-child(3) { animation-delay: .08s; }
.reveal-row:nth-child(4) { animation-delay: .12s; }
.reveal-row:nth-child(5) { animation-delay: .16s; }
.reveal-row:nth-child(6) { animation-delay: .20s; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.true-rank { background: var(--bsky); color: #fff; }
.statval { color: var(--bsky); font-size: 13px; font-weight: 700; }
.delta { flex: none; font-weight: 800; font-size: 14px; width: 34px; text-align: right; }
.delta.ok { color: var(--good); }
.delta.off { color: var(--muted); }

/* ---------- results ---------- */
.results-h { text-align: center; }
.final-score { text-align: center; font-size: 76px; font-weight: 900; line-height: 1; }
.final-label { text-align: center; font-size: 26px; font-weight: 800; margin: 4px 0 2px; }
.results .sub, #final-blurb { text-align: center; }
.breakdown { margin: 18px 0; display: flex; flex-direction: column; gap: 6px; }
.bd-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--row); border-radius: 10px; }
.bd-emoji { font-size: 18px; }
.bd-name { flex: 1; font-size: 13.5px; color: var(--muted); }
.bd-pts { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------- compact layout for phones ---------- */
@media (max-width: 560px) {
  .panel { padding: 14px 12px; }
  .prompt { font-size: 18px; margin: 4px 0 3px; }
  .round-sub { font-size: 12px; margin-bottom: 9px; }
  .axis { margin-bottom: 6px; }

  /* sortable rows: shorter, tighter — fit ~10 without scrolling */
  .friend-list { gap: 6px; }
  .friend-row { height: 46px; gap: 9px; padding: 0 10px; border-radius: 10px; }
  .friend-row .avatar { width: 30px; height: 30px; }
  .friend-row .rank { width: 22px; height: 22px; font-size: 12px; border-radius: 6px; }
  .friend-row .dname { font-size: 14px; }
  .friend-row .handle { font-size: 11.5px; }
  .friend-row .grip { font-size: 18px; }

  /* reveal rows share the density problem */
  .reveal-row { gap: 9px; padding: 6px 10px; }
  .reveal-row .avatar { width: 30px; height: 30px; }
  .reveal-row .rank { width: 22px; height: 22px; font-size: 12px; }

  .btn.sticky { padding: 13px 16px; }
}
