:root {
  --bg: #08080f;
  --surface: #15152a;
  --surface-2: #1d1d38;
  --line: #34345e;
  --line-soft: #26264c;
  --text: #f4f5ff;
  --muted: #a3a7d6;
  --violet: #7c5cff;
  --violet-deep: #6a45e6;
  --fuchsia: #d65cff;
  --cyan: #2ee6cf;
  --red: #ff5277;
  --amber: #ffd15c;
  --ring: #b6a6ff;

  --radius: 20px;
  --grad-brand: linear-gradient(135deg, #7c5cff, #d65cff);
  --grad-crew: linear-gradient(160deg, #173947, #112d44);
  --grad-imp: linear-gradient(160deg, #45142e, #2c0d22);

  /* spacing scale */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 22px; --s6: 32px; --s7: 48px;

  /* motion */
  --ease-out-quint: cubic-bezier(.22, 1, .36, 1);
  --ease-out-expo: cubic-bezier(.16, 1, .3, 1);
  --dur-fast: .16s;
  --dur-mid: .26s;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: contain;
  overflow-x: hidden;
  position: relative;
}

/* ---------- focus ---------- */
:focus-visible { outline: 2.5px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
:focus:not(:focus-visible) { outline: none; }

/* ---------- ambient background ---------- */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-blobs::before, .bg-blobs::after {
  content: ""; position: absolute; width: 80vw; height: 80vw; max-width: 520px; max-height: 520px;
  border-radius: 50%; filter: blur(70px); opacity: .5;
}
.bg-blobs::before { background: var(--violet); top: -18%; left: -22%; animation: float1 16s ease-in-out infinite; }
.bg-blobs::after { background: var(--fuchsia); bottom: -20%; right: -25%; opacity: .38; animation: float2 19s ease-in-out infinite; }
@keyframes float1 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(8%, 12%) scale(1.12); } }
@keyframes float2 { 0%,100% { transform: translate(0,0) scale(1); } 50% { transform: translate(-10%, -8%) scale(1.08); } }

#app {
  position: relative;
  display: flex; flex-direction: column;
  min-height: 100dvh;
  max-width: 460px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), var(--s5)) var(--s5) calc(env(safe-area-inset-bottom) + var(--s6));
}

/* ---------- screens ---------- */
.screen { display: none; }
.screen.active { display: flex; flex: 1; flex-direction: column; animation: screenIn .4s var(--ease-out-quint) both; }
.screen:focus { outline: none; }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ---------- top bar (install + language) ---------- */
.topbar { display: flex; align-items: center; gap: var(--s2); padding-top: var(--s2); }
.install-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-size: 13px; font-weight: 700; letter-spacing: .3px; cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast);
}
.install-chip[hidden] { display: none; }
.install-chip:active { transform: scale(.96); }
@media (hover: hover) { .install-chip:hover { border-color: var(--violet); background: var(--surface-2); } }
.lang-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); margin-left: auto; }
.lang-switch button {
  min-height: 40px; padding: 0 16px; border: none; border-radius: 999px;
  background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .5px;
  cursor: pointer; transition: background var(--dur-fast), color var(--dur-fast);
}
.lang-switch button.active { background: var(--violet-deep); color: #fff; }
@media (hover: hover) { .lang-switch button:not(.active):hover { color: var(--text); } }

/* ---------- header ---------- */
.app-head { text-align: center; padding: var(--s2) 0 var(--s6); }
.logo {
  width: 76px; height: 76px; margin: 0 auto var(--s4); border-radius: 22px;
  display: grid; place-items: center; font-size: 40px;
  background: var(--grad-brand);
  box-shadow: 0 12px 30px rgba(124,92,255,.45), inset 0 1px 0 rgba(255,255,255,.25);
  animation: bob 4s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-6px) rotate(3deg); } }
.app-head h1 { font-size: 40px; font-weight: 800; letter-spacing: 4px; }
.tagline { color: var(--muted); font-size: 14px; margin-top: var(--s2); letter-spacing: .3px; }

/* ---------- blocks ---------- */
.block {
  background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,0));
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: var(--s4); margin-bottom: var(--s3);
}
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s4); }
.block-head h2 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 1.6px; color: var(--muted); }
.hint-text { font-size: 12px; color: var(--muted); }
.counter {
  min-width: 26px; height: 26px; padding: 0 var(--s2); border-radius: 999px;
  background: var(--violet-deep); color: #fff; font-size: 13px; font-weight: 700;
  display: grid; place-items: center;
}

/* ---------- player inputs ---------- */
.player-row { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); animation: rowIn var(--dur-mid) var(--ease-out-quint) both; }
@keyframes rowIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.pnum {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; line-height: 1; font-variant-numeric: tabular-nums;
  font-size: 13px; font-weight: 700; transform: translateY(-1px);
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.player-row input {
  flex: 1; min-width: 0; min-height: 48px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 13px; padding: var(--s3) var(--s4); font-size: 16px;
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.player-row input:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(124,92,255,.3); }
.player-row input::placeholder { color: #8388bc; }
.remove-btn {
  flex: 0 0 44px; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
  border-radius: 12px; font-size: 20px; line-height: 1; cursor: pointer;
  transition: color var(--dur-fast), background var(--dur-fast), transform var(--dur-fast);
}
.remove-btn:active { background: var(--surface-2); color: var(--red); transform: scale(.92); }
.remove-btn:disabled { opacity: .28; cursor: not-allowed; }
.add-btn {
  width: 100%; min-height: 48px; margin-top: var(--s1);
  background: transparent; border: 1.5px dashed var(--line); color: var(--muted);
  border-radius: 13px; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: border-color var(--dur-fast), color var(--dur-fast);
}
.add-btn:active { border-color: var(--violet); color: var(--violet); }

/* ---------- buttons ---------- */
.primary-btn {
  position: relative; width: 100%; min-height: 56px; margin-top: auto;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  background: var(--grad-brand); color: #fff; border: none; border-radius: var(--radius);
  font-size: 18px; font-weight: 700; cursor: pointer;
  box-shadow: 0 10px 26px rgba(124,92,255,.4);
  transition: transform var(--dur-fast) var(--ease-out-quint), box-shadow var(--dur-fast), filter var(--dur-fast);
}
.primary-btn .arrow { transition: transform var(--dur-mid) var(--ease-out-quint); }
.primary-btn:active { transform: translateY(2px) scale(.99); box-shadow: 0 4px 14px rgba(124,92,255,.35); }
.primary-btn:active .arrow { transform: translateX(4px); }
.ghost-btn {
  width: 100%; min-height: 50px; margin-top: var(--s3);
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: var(--radius); font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
}
.ghost-btn:active { background: var(--surface); transform: scale(.99); }

/* secondary buttons stop stealing the auto margin from the primary */
#result .primary-btn, #revealImposter .primary-btn { margin-top: auto; }
#result .ghost-btn, #revealImposter .ghost-btn { margin-top: var(--s3); }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  position: relative; user-select: none; cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
  min-height: 44px; padding: 0 var(--s4); border-radius: 14px;
  background: var(--surface); border: 1.5px solid var(--line); color: var(--text);
  font-size: 15px; font-weight: 600;
  transition: transform var(--dur-fast) var(--ease-out-quint), background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.chip .emoji { font-size: 16px; transition: transform var(--dur-fast) var(--ease-out-quint); }
.chip:not(.on) { color: var(--muted); }
.chip:active { transform: scale(.95); }
.chip.on { background: rgba(124,92,255,.18); border-color: var(--violet); color: var(--text); }
.chip.on .emoji { transform: scale(1.12); }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.chip:has(input:focus-visible) { outline: 2.5px solid var(--ring); outline-offset: 2px; }

/* ---------- stepper ---------- */
.stepper { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); }
.stepper button {
  flex: 0 0 56px; width: 56px; height: 56px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; line-height: 1; padding: 0;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-size: 26px; cursor: pointer; transition: transform var(--dur-fast) var(--ease-out-quint), background var(--dur-fast);
}
.stepper button:active:not(:disabled) { background: var(--surface-2); transform: scale(.92); }
.stepper button:disabled { opacity: .32; cursor: not-allowed; }
.imp-display { text-align: center; line-height: 1; }
.imp-display span { font-size: 38px; font-weight: 800; }
.imp-display small { display: block; font-size: 12px; color: var(--muted); margin-top: var(--s1); }

/* ---------- toggles ---------- */
.toggles { padding: var(--s1) var(--s4); }
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s4) 0; border-bottom: 1px solid var(--line-soft); cursor: pointer;
}
.switch-row:last-child { border-bottom: none; }
.switch-label strong { display: block; font-size: 16px; font-weight: 600; }
.switch-label small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; line-height: 1.35; }
.switch { position: relative; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.track { display: block; width: 52px; height: 31px; border-radius: 999px; background: var(--line); transition: background var(--dur-mid) ease; position: relative; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 25px; height: 25px; border-radius: 50%; background: #fff; transition: transform var(--dur-mid) var(--ease-out-quint); box-shadow: 0 2px 5px rgba(0,0,0,.35); }
.switch input:checked + .track { background: var(--grad-brand); }
.switch input:checked + .track::after { transform: translateX(21px); }
.switch input:focus-visible + .track { outline: 2.5px solid var(--ring); outline-offset: 3px; }

/* ---------- error ---------- */
.error { color: var(--red); font-size: 14px; min-height: 20px; text-align: center; margin: var(--s1) 0 var(--s2); font-weight: 600; }
.error:not(:empty) { animation: shake .35s ease; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* ---------- overline / shared text ---------- */
.overline { font-size: 12px; font-weight: 700; letter-spacing: 2.5px; text-transform: uppercase; color: var(--muted); }
.overline.center { text-align: center; margin-bottom: var(--s5); }

/* ---------- reveal cards screen ---------- */
.dots { display: flex; justify-content: center; gap: 7px; padding: var(--s2) 0 var(--s5); flex-wrap: wrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: all var(--dur-mid) var(--ease-out-quint); }
.dot.done { background: var(--violet); }
.dot.now { background: var(--fuchsia); transform: scale(1.5); box-shadow: 0 0 10px var(--fuchsia); }

.pass-name {
  text-align: center; font-size: clamp(24px, 7vw, 32px); font-weight: 800; margin: var(--s1) 0 var(--s5);
  text-wrap: balance; overflow-wrap: anywhere;
}

/* ---------- flip card ---------- */
.card {
  position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 54vh;
  margin: 0 auto; cursor: pointer;
  user-select: none; -webkit-user-select: none; touch-action: none;
  perspective: 1500px; -webkit-perspective: 1500px;
  border-radius: 26px;
}
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
  transition: transform .5s var(--ease-out-expo);
}
.card.revealed .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s4); text-align: center; padding: 26px; border-radius: 26px;
  border: 1px solid var(--line);
  box-shadow: 0 22px 50px rgba(0,0,0,.5);
}
.card-back {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.035) 0 12px, transparent 12px 24px),
    linear-gradient(160deg, var(--surface-2), var(--surface));
  color: var(--muted);
}
.card-back::before { content: ""; position: absolute; inset: 12px; border: 1.5px dashed var(--line); border-radius: 18px; }
.card-icon { font-size: 50px; animation: tapPulse 1.6s ease-in-out infinite; }
@keyframes tapPulse { 0%,100% { transform: translateY(0); opacity: .9; } 50% { transform: translateY(-7px); opacity: 1; } }
.card-back-text { font-size: 18px; font-weight: 600; letter-spacing: .5px; }
.card-front {
  transform: rotateY(180deg);
  background: var(--grad-crew); border-color: rgba(46,230,207,.42);
}
.card.imposter .card-front { background: var(--grad-imp); border-color: rgba(255,82,119,.5); }

.card-role { font-size: 14px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--cyan); }
.card.imposter .card-role { color: var(--red); }
.card-word { font-size: clamp(28px, 9vw, 42px); font-weight: 800; line-height: 1.08; overflow-wrap: anywhere; text-wrap: balance; }
.card-hint { font-size: 15px; color: var(--muted); max-width: 84%; }
.card-hint:empty { display: none; }

.hold-note { text-align: center; color: var(--muted); font-size: 13px; margin: var(--s5) 0 var(--s4); }

/* ---------- result (who starts) ---------- */
.center-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--s5) 0; }
.big-emoji { font-size: 70px; animation: pop .5s var(--ease-out-expo) both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.starts-name {
  font-size: clamp(30px, 9vw, 42px); font-weight: 800; margin-top: var(--s4); color: var(--fuchsia);
  text-wrap: balance; overflow-wrap: anywhere; animation: rise .5s .08s var(--ease-out-quint) both;
}
.starts-sub { font-size: 18px; color: var(--text); margin-top: var(--s1); }
.note { color: var(--muted); font-size: 14px; line-height: 1.6; margin-top: var(--s5); max-width: 320px; text-wrap: pretty; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- reveal imposter ---------- */
#revealImposter.active { padding-top: var(--s6); }
.reveal-card { aspect-ratio: 3 / 4; max-height: 52vh; }
.reveal-card .card-front { background: var(--grad-imp); border-color: rgba(255,82,119,.55); gap: var(--s3); }
.reveal-card.win .card-front { background: linear-gradient(160deg, #143a2c, #0e2a22); border-color: rgba(46,230,207,.55); }
.reveal-card.troll .card-front { background: linear-gradient(160deg, #3a2a14, #2a1f0d); border-color: rgba(255,209,92,.55); }

.rv-emoji { font-size: 48px; }
.rv-label { font-size: 13px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
.rv-names { font-size: clamp(26px, 8vw, 34px); font-weight: 800; line-height: 1.15; color: var(--red); overflow-wrap: anywhere; text-wrap: balance; }
.reveal-card.win .rv-names, .reveal-card.troll .rv-names { color: var(--amber); }
.rv-divider { width: 50px; height: 1px; background: var(--line); margin: var(--s1) 0; }
.rv-word-label { font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.rv-word { font-size: 26px; font-weight: 800; color: var(--cyan); overflow-wrap: anywhere; }
.rv-hint-label { font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.rv-hint { font-size: 18px; font-weight: 700; color: var(--amber); overflow-wrap: anywhere; }

/* ---------- modals (install / update) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: var(--s5);
  background: rgba(4, 4, 10, .7); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--dur-mid) var(--ease-out-quint), visibility var(--dur-mid);
}
.modal-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }
body.modal-open { overflow: hidden; }
.modal {
  width: 100%; max-width: 360px; text-align: center;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line); border-radius: 24px; padding: 28px 24px;
  box-shadow: 0 30px 60px rgba(0,0,0,.6);
  transform: translateY(16px) scale(.96); transition: transform var(--dur-mid) var(--ease-out-expo);
}
.modal-overlay.open .modal { transform: none; }
.modal-emoji { font-size: 48px; display: block; margin-bottom: var(--s3); }
.modal h2 { font-size: 22px; font-weight: 800; margin-bottom: var(--s2); }
.modal p { color: var(--muted); font-size: 14px; line-height: 1.5; margin-bottom: var(--s5); }
.modal .ios-steps {
  color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: var(--s3); line-height: 1.6;
}
.modal .primary-btn { margin-top: 0; }
.modal .ghost-btn { margin-top: var(--s3); }

/* ---------- hover (pointer devices only) ---------- */
@media (hover: hover) {
  .primary-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 32px rgba(124,92,255,.5); filter: brightness(1.06); }
  .primary-btn:hover .arrow { transform: translateX(3px); }
  .ghost-btn:hover { background: var(--surface); color: var(--text); border-color: var(--line); }
  .add-btn:hover { border-color: var(--violet); color: var(--violet); }
  .player-row input:hover { border-color: #45457a; }
  .remove-btn:hover { color: var(--red); border-color: var(--red); }
  .chip:not(.on):hover { border-color: #45457a; color: var(--text); }
  .stepper button:hover:not(:disabled) { background: var(--surface-2); border-color: #45457a; }
  .card:hover .card-back { filter: brightness(1.08); }
}

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .bg-blobs::before, .bg-blobs::after, .logo, .card-icon,
  .player-row, .big-emoji, .starts-name, .screen.active { animation: none !important; }
  .card-inner { transition: transform .15s linear; }
  *, *::before, *::after { transition-duration: .12s !important; }
}
