:root {
  --bg: #1d1b3a;
  --bg2: #29265a;
  --card: #34307a;
  --card2: #423d94;
  --line: rgba(255, 255, 255, 0.12);
  --text: #ffffff;
  --muted: #b9b5e6;
  --accent: #ffd23f;
  --accent-ink: #2a2200;
  --pink: #ff5a7a;
  --blue: #3fa7ff;
  --green: #3ddc84;
  --purple: #b57bff;
  --red: #ff4d5e;
  --radius: 18px;
  --shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
  --font: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Varela Round', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
}
body {
  background:
    radial-gradient(circle at 15% 10%, rgba(181, 123, 255, 0.25), transparent 40%),
    radial-gradient(circle at 90% 85%, rgba(63, 167, 255, 0.2), transparent 45%),
    var(--bg);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
body.offline::after {
  content: 'Reconnecting…';
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: #fff;
  padding: 6px 14px;
  border-radius: 99px;
  font-weight: 800;
  font-size: 14px;
  z-index: 100;
}
#app {
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
}
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
}
h2 {
  font-size: 18px;
  margin: 0 0 10px;
}
h2 small {
  color: var(--muted);
  font-weight: 600;
}
small {
  font-size: 0.75em;
}
.muted {
  color: var(--muted);
}
.error {
  color: var(--pink);
  font-weight: 700;
}
.center-text {
  text-align: center;
}
.row {
  display: flex;
  align-items: center;
}
.gap {
  gap: 8px;
}

/* ---------- screens ---------- */
.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  overflow-y: auto;
}
.screen.center {
  align-items: center;
  justify-content: center;
  text-align: center;
}
.grow {
  flex: 1;
}
.bottom {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.waiting {
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  animation: pulse 1.6s ease-in-out infinite;
}
.big-emoji {
  font-size: 72px;
}

/* ---------- buttons ---------- */
button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}
.btn {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  font-size: 17px;
  padding: 14px 20px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}
.btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.btn.big {
  font-size: 21px;
  padding: 18px 22px;
  width: 100%;
}
.btn.small {
  font-size: 14px;
  padding: 8px 12px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.btn.ghost {
  background: var(--card);
  color: var(--text);
}
.icon-btn {
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--card);
}

/* ---------- join ---------- */
.join .logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.join .logo span {
  font-size: 72px;
  animation: wobble 2.4s ease-in-out infinite;
}
.join h1 {
  font-size: 46px;
  font-weight: 900;
  text-align: left;
  letter-spacing: -1px;
  background: linear-gradient(90deg, var(--accent), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.join-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 340px;
}
input {
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  padding: 16px;
  border-radius: 16px;
  border: 3px solid var(--card2);
  background: var(--bg2);
  color: var(--text);
  text-align: center;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
input:focus {
  border-color: var(--accent);
}

/* ---------- lobby ---------- */
.topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand {
  font-weight: 900;
  font-size: 22px;
}
.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.player {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding-block: 8px;
  padding-inline: 8px 14px;
  animation: pop-in 0.3s ease-out both;
}
.player.me {
  outline: 3px solid var(--accent);
}
.player.away {
  opacity: 0.5;
}
.player.empty {
  background: transparent;
  border: 2px dashed var(--line);
  animation: none;
}
.player.empty .avatar {
  background: transparent;
  border: 2px dashed var(--line);
  color: var(--muted);
}
.pname {
  flex: 1;
  font-weight: 800;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pname small {
  color: var(--muted);
  font-weight: 600;
}
.mini-btn {
  flex: none;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 9px;
  border-radius: 10px;
  background: var(--bg2);
  color: var(--accent);
  border: 2px solid var(--card2);
}
.mini-btn:active {
  transform: scale(0.95);
}
.pscore {
  font-weight: 900;
  font-size: 18px;
}
.pscore small {
  color: var(--muted);
}
.avatar {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--c, var(--card2));
  font-size: 26px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2);
}
.avatar.sm {
  width: 32px;
  height: 32px;
  font-size: 18px;
}
.avatar.lg {
  width: 64px;
  height: 64px;
  font-size: 38px;
}
.avatar-btn {
  padding: 0;
  border-radius: 50%;
}
.avatar-btn:not(:disabled):active {
  transform: scale(0.9);
}
.games {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.game-card {
  display: flex;
  gap: 14px;
  align-items: center;
  text-align: left;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  border: 3px solid transparent;
  box-shadow: var(--shadow);
}
.game-card:disabled {
  cursor: default;
}
.game-card.selected {
  border-color: var(--accent);
  background: var(--card2);
}
.gemoji {
  font-size: 38px;
}
.gtext {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.gtext b {
  font-size: 18px;
}
.gtext small {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.3;
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 30, 0.75);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
  animation: fade-in 0.2s;
}
.modal-card {
  background: var(--bg2);
  border-radius: 24px;
  padding: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 340px;
  animation: pop-in 0.25s ease-out;
}
.qr {
  background: #fff;
  border-radius: 16px;
  padding: 10px;
}
.qr svg {
  display: block;
  width: 100%;
  height: auto;
}
.url {
  font-weight: 800;
  font-size: 18px;
  word-break: break-all;
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- results ---------- */
.results h1 {
  font-size: 30px;
  font-weight: 900;
}
.podium {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}
.podium li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 14px;
  animation: slide-up 0.4s ease-out both;
  animation-delay: calc(var(--i) * 0.12s);
}
.podium li:first-child {
  background: linear-gradient(90deg, rgba(255, 210, 63, 0.35), var(--card));
  padding: 16px 14px;
}
.podium li.me {
  outline: 3px solid var(--accent);
}
.medal {
  font-size: 30px;
  width: 36px;
  text-align: center;
  font-weight: 900;
}
.gain {
  font-weight: 900;
  font-size: 22px;
  color: var(--green);
}
.gain.neg {
  color: var(--pink);
}
.total {
  color: var(--muted);
  font-weight: 700;
  min-width: 64px;
  text-align: end;
}

/* ---------- in-game ---------- */
.screen.game {
  padding: 0;
  gap: 0;
  overflow: hidden;
}
.scorebar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: rgba(0, 0, 0, 0.2);
}
.chips {
  display: flex;
  gap: 6px;
  flex: 1;
  overflow-x: auto;
}
.chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-block: 3px;
  padding-inline: 3px 10px;
  border-radius: 99px;
  background: var(--card);
  border: 2px solid var(--c);
  font-weight: 900;
  font-size: 15px;
  flex: none;
}
.chip.me {
  background: var(--c);
  color: #1d1b3a;
}
.chip.away {
  opacity: 0.4;
}
.chip-av {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: 17px;
}
.game-root {
  flex: 1;
  position: relative;
  overflow: hidden;
  touch-action: none;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- misc ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 30px);
  background: #fff;
  color: var(--bg);
  font-weight: 800;
  padding: 12px 18px;
  border-radius: 14px;
  opacity: 0;
  transition: 0.25s;
  pointer-events: none;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.confetti {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 150;
}
.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 5px solid var(--card2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes pulse {
  50% {
    opacity: 0.5;
  }
}
@keyframes wobble {
  0%,
  100% {
    transform: rotate(-8deg);
  }
  50% {
    transform: rotate(8deg) scale(1.05);
  }
}
@keyframes pop-in {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}
@keyframes slide-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes shake {
  20%,
  60% {
    transform: translateX(-8px);
  }
  40%,
  80% {
    transform: translateX(8px);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ---------- languages */
.lang-select {
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--card2);
  border-radius: 12px;
  padding: 6px 8px;
  max-width: 110px;
}
.join-lang {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  inset-inline-end: 16px;
}
.join {
  position: relative;
}
.credit {
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
  opacity: 0.8;
}
.credit a {
  color: inherit;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.help .credit {
  text-align: center;
  margin: 14px 0 0;
}
/* Persian: Vazirmatn-like system fonts read better a little larger */
:root[lang='fa'] body {
  font-family: Vazirmatn, Tahoma, var(--font);
}

/* ---------- lobby extras */
.lobby-actions {
  justify-content: flex-end;
  margin-top: -6px;
}
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.players.compact {
  gap: 5px;
}
.players.compact .player {
  padding-block: 4px;
}
.players.compact .avatar {
  width: 34px;
  height: 34px;
  font-size: 20px;
}
.players.compact .pname {
  font-size: 15px;
}
.players.compact .pscore {
  font-size: 16px;
}
.podium.compact {
  gap: 6px;
}
.podium.compact li {
  padding: 6px 12px;
}
.podium.compact li:first-child {
  padding: 10px 12px;
}
.podium.compact .medal {
  font-size: 22px;
}
.podium.compact .avatar {
  width: 34px;
  height: 34px;
  font-size: 20px;
}
.podium.compact .gain {
  font-size: 18px;
}
/* 7–10 players: the score chips wrap onto two rows instead of scrolling */
.chips.many {
  flex-wrap: wrap;
  overflow: visible;
  gap: 4px;
}
.chips.many .chip {
  font-size: 13px;
  padding-inline: 2px 7px;
}
.chips.many .chip-av {
  width: 20px;
  height: 20px;
  font-size: 14px;
}

/* ---------- help */
.modal.help {
  place-items: stretch center;
}
.help-card {
  max-width: 420px;
  text-align: start;
  max-height: calc(100dvh - 32px);
  padding: 16px;
}
.help-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.help-tabs {
  display: flex;
  gap: 6px;
}
.help-tabs button {
  flex: 1;
  font-size: 22px;
  padding: 8px 0;
  border-radius: 12px;
  background: var(--card);
  border: 2px solid transparent;
}
.help-tabs button.on {
  border-color: var(--accent);
  background: var(--card2);
}
.help-page {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.help-page h3 {
  margin: 4px 0 10px;
  font-size: 20px;
}
.help-shot {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}
.help-shot img {
  display: block;
  width: 52%;
  max-width: 210px;
  border-radius: 16px;
  border: 3px solid var(--card2);
  box-shadow: var(--shadow);
}
.help-lines {
  margin: 0;
  padding-inline-start: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  line-height: 1.4;
}
.help-lines .pos {
  color: var(--green);
  font-weight: 900;
}
.help-lines .neg {
  color: var(--pink);
  font-weight: 900;
}

/* right-to-left pages: keep "+3" / "−1" badges reading left-to-right */
:root[dir='rtl'] .pos,
:root[dir='rtl'] .neg,
:root[dir='rtl'] .gain,
:root[dir='rtl'] .pts,
:root[dir='rtl'] .chip-score {
  direction: ltr;
  unicode-bidi: isolate;
}
:root[dir='rtl'] .rx-verdict.pos,
:root[dir='rtl'] .rx-verdict.neg {
  direction: rtl;
}

/* ---------- effects (client/js/ui.js burst / floatText) */
.fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
.fx-p {
  position: absolute;
  border-radius: 50%;
  line-height: 1;
}
.fx-float {
  position: fixed;
  z-index: 61;
  pointer-events: none;
  font-weight: 900;
  font-size: 22px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  direction: ltr;
  unicode-bidi: isolate;
}
.fx-float.pos {
  color: var(--green);
}
.fx-float.neg {
  color: var(--pink);
}
/* score chips bump when points change */
.chip.bump {
  animation: chip-bump 0.45s cubic-bezier(0.3, 1.8, 0.6, 1);
}
.chip.bump-neg {
  animation: chip-bump 0.45s cubic-bezier(0.3, 1.8, 0.6, 1);
  border-color: var(--pink);
}
@keyframes chip-bump {
  40% {
    transform: scale(1.25);
  }
}
