* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 20% 10%, #6d5ef0 0%, #4b3acb 45%, #2c1f8f 100%);
  color: #fff;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 18px;
  background: rgba(30, 27, 75, 0.72);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

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

.logo {
  width: 34px;
  height: 34px;
  display: block;
}

.title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.me {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
}

.me-name {
  font-weight: 600;
}

.me-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.me-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

.me-avatar.pulse {
  animation: avatar-pulse 0.6s ease;
}

@keyframes avatar-pulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

.me-hearts {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  overflow: visible;
}

/* ---------- Arena ---------- */

.arena {
  position: relative;
  flex: 1;
  overflow: hidden;
}

/* ---------- Bubbles ---------- */

.bubble {
  position: absolute;
  /* Physics writes translate(x, y) with x,y as absolute arena coords, and
     translate(-50%, -50%) centers the bubble on that point. Anchoring at
     left/top 0 (not 50%) keeps the coordinate spaces consistent. */
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  will-change: transform;
  animation: fade-in 0.3s ease;
  user-select: none;
  -webkit-user-select: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.bubble-inner {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22), inset 0 0 0 3px rgba(255, 255, 255, 0.55);
  overflow: hidden;
  animation: pop 0.35s ease;
  transition: transform 0.2s ease;
}

@keyframes pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.bubble:hover .bubble-inner {
  transform: scale(1.08);
}

.bubble:hover .name {
  background: #fff;
}

.avatar {
  width: 88%;
  height: 88%;
}

.avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

.name {
  margin-top: 6px;
  padding: 2px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
  color: #333;
  font-size: 12px;
  font-weight: 600;
  max-width: 110px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  transition: background 0.2s ease;
}

/* ---------- Flying hearts ---------- */

.heart-fly {
  position: absolute;
  width: 22px;
  height: 22px;
  background: url("/assets/heart.svg") no-repeat center / contain;
  pointer-events: none;
  z-index: 20;
  animation: float-up 1.1s ease-out forwards;
}

@keyframes float-up {
  0% {
    opacity: 0;
    transform: translateY(0) scale(0.4) rotate(-12deg);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-130px) scale(1.35) rotate(14deg);
  }
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  color: #d6336c;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 20px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 30;
  animation: toast-in 0.3s ease;
  white-space: nowrap;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- Name prompt ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(900px 600px at 50% 30%, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.35));
  backdrop-filter: blur(4px);
}

.name-card {
  width: min(360px, 90vw);
  background: #fff;
  color: #1f2937;
  border-radius: 20px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: pop 0.35s ease;
}

.name-card .brand {
  justify-content: center;
}

.name-card h1 {
  margin: 0;
  font-size: 22px;
}

.name-card .hint {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
  text-align: center;
}

.name-card input {
  padding: 12px 14px;
  font-size: 16px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  outline: none;
}

.name-card input:focus {
  border-color: #7c5cff;
}

.name-card button {
  padding: 12px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #ff5f8f, #7c5cff);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.name-card button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error {
  margin: 0;
  color: #dc2626;
  font-size: 13px;
  text-align: center;
  min-height: 16px;
}

/* ---------- Top bar actions ---------- */

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s ease;
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ---------- Battle panel ---------- */

.battle-panel {
  position: fixed;
  top: 76px;
  right: 14px;
  z-index: 15;
  width: 210px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: rgba(30, 27, 75, 0.85);
  backdrop-filter: blur(8px);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.battle-panel h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.countdown {
  font-size: 40px;
  font-weight: 800;
  text-align: center;
  line-height: 1;
  margin-bottom: 6px;
  color: #ffd166;
}

.battle-hint {
  margin: 8px 0 4px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
}

.timeout-label {
  display: block;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 4px;
}

.battle-panel select {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: none;
  margin-bottom: 10px;
  font-size: 14px;
}

.start-btn {
  width: 100%;
  padding: 10px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #ff5f8f, #7c5cff);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.participants {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}

.participants li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 13px;
}

.participants li.me,
.ranking li.me {
  background: rgba(124, 92, 255, 0.35);
}

.p-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.p-net {
  font-weight: 700;
  margin-left: 8px;
}

.p-net.pos,
.r-net.pos {
  color: #6ee7a0;
}

.p-net.neg,
.r-net.neg {
  color: #ff8f8f;
}

/* ---------- Bubble actions ---------- */

.bubble-actions {
  position: relative;
  z-index: 5; /* keep the buttons above neighbouring bubbles so they stay clickable */
  display: flex;
  gap: 6px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}

.bubble:hover .bubble-actions,
.bubble-actions:focus-within {
  opacity: 1;
  pointer-events: auto;
}

.action-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s ease;
}

.action-btn.heart {
  background: #ffe3ec;
}

.action-btn.baffe {
  background: #ffe9d6;
}

.action-btn:active {
  transform: scale(0.88);
}

/* ---------- Baffe effects ---------- */

.baffe-fly {
  position: absolute;
  width: 26px;
  height: 26px;
  font-size: 22px;
  line-height: 1;
  pointer-events: none;
  z-index: 20;
  animation: float-up 1.1s ease-out forwards;
}

.baffe-fly::after {
  content: "💢";
}

@keyframes slap-wobble {
  0% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-10deg) scale(1.12); }
  40% { transform: rotate(8deg) scale(1.04); }
  60% { transform: rotate(-7deg) scale(1.08); }
  100% { transform: rotate(0) scale(1); }
}

.bubble-inner.slapped {
  animation: slap-wobble 0.5s ease;
}

.me-avatar.slapped {
  animation: avatar-slap 0.5s ease;
}

@keyframes avatar-slap {
  0% { transform: rotate(0) scale(1); }
  20% { transform: rotate(-10deg) scale(1.18); }
  40% { transform: rotate(8deg); }
  60% { transform: rotate(-7deg) scale(1.06); }
  100% { transform: rotate(0) scale(1); }
}

/* ---------- Who-did-it label (spectators) ---------- */

.react-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(30, 27, 75, 0.88);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  pointer-events: none;
  z-index: 25;
  white-space: nowrap;
  animation: react-label-fade 1.5s ease-out forwards;
}

@keyframes react-label-fade {
  0% { opacity: 0; transform: translate(-50%, -20%); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -120%); }
}

/* ---------- Summary + leaderboard ---------- */

.summary-card {
  width: min(540px, 94vw);
  background: #fff;
  color: #1f2937;
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: pop 0.35s ease;
}

.summary-card h2 {
  margin: 0;
  font-size: 20px;
}

.ranking {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ranking li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 14px;
}

.rank-medal {
  width: 22px;
  text-align: center;
  font-weight: 700;
}

.r-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.r-hearts {
  font-size: 12px;
  color: #6b7280;
}

.r-net {
  font-weight: 800;
  min-width: 34px;
  text-align: right;
}

.ranking li.empty {
  color: #6b7280;
  font-style: italic;
}

/* ---------- Arena card (fullscreen first screen) ---------- */

.arena-card {
  width: min(380px, 90vw);
  background: #fff;
  color: #1f2937;
  border-radius: 20px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: pop 0.35s ease;
  text-align: center;
}

.arena-card .brand {
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.arena-card .brand .logo {
  width: 84px;
  height: 84px;
}

.arena-card h1 {
  margin: 0;
  font-size: 22px;
}

.arena-card .hint {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
}

.arena-card input {
  flex: 1;
  padding: 12px 14px;
  font-size: 16px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  outline: none;
}

.arena-card input:focus {
  border-color: #7c5cff;
}

.arena-card .ghost-btn {
  color: #7c5cff;
  background: rgba(124, 92, 255, 0.12);
}

.divider {
  color: #9ca3af;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row .start-btn.join {
  width: auto;
  padding: 12px 18px;
  flex-shrink: 0;
}

/* ---------- Lobby ---------- */

.name-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.name-row input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
}

.code-btn {
  font-variant-numeric: tabular-nums;
}

/* ---------- Fullscreen leaderboard (end of round) ---------- */

.lb-overlay {
  background: radial-gradient(900px 600px at 50% 30%, rgba(20, 10, 60, 0.9), rgba(5, 2, 20, 0.96));
}

/* ---------- Fullscreen lobby (waiting for players) ---------- */

.lobby-overlay {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(900px 600px at 50% 30%, rgba(20, 10, 60, 0.92), rgba(5, 2, 20, 0.97));
  backdrop-filter: blur(6px);
}

.lobby-card {
  width: min(420px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  background: #fff;
  color: #1f2937;
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  animation: pop 0.35s ease;
}

.lobby-card .brand {
  flex-direction: column;
  justify-content: center;
  gap: 12px;
}

.lobby-card .brand .logo {
  width: 84px;
  height: 84px;
}

.lobby-card h2 {
  margin: 0;
  font-size: 20px;
}

.lobby-card .code-btn {
  color: #7c5cff;
  cursor: pointer;
}

.lobby-card .ghost-btn {
  color: #7c5cff;
  background: rgba(124, 92, 255, 0.12);
}

.lobby-card .name-row input {
  border: 2px solid #e5e7eb;
  background: #fff;
  color: #1f2937;
}

.lobby-card select {
  padding: 10px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 15px;
  background: #fff;
}

.lobby-players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lobby-players li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #f4f4f8;
}

.lobby-players li.me {
  background: rgba(124, 92, 255, 0.14);
  outline: 2px solid rgba(124, 92, 255, 0.35);
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.25);
}

.player-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

.player-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crown {
  font-size: 18px;
  flex-shrink: 0;
}

.readonly-duration {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  color: #7c5cff;
}

/* ---------- F1 podium + results table ---------- */

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  margin: 14px 0 6px;
}

.podium-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 96px;
}

.podium-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.65);
  display: block;
}

.podium-avatar svg {
  width: 100%;
  height: 100%;
  display: block;
}

.podium-info {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.podium-name {
  font-weight: 700;
  font-size: 14px;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-net {
  font-weight: 800;
}

.podium-block {
  width: 96px;
  border-radius: 10px 10px 0 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding-top: 8px;
  color: #fff;
  font-weight: 800;
}

.podium-block.rank-1 {
  height: 120px;
  background: linear-gradient(180deg, #ffd700, #f0a500);
}

.podium-block.rank-2 {
  height: 90px;
  background: linear-gradient(180deg, #c0c0c0, #9aa0a6);
}

.podium-block.rank-3 {
  height: 70px;
  background: linear-gradient(180deg, #cd7f32, #b06a24);
}

.podium-rank {
  font-size: 22px;
}

.medal-emoji {
  font-size: 16px;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0 10px;
}

.lb-table td {
  padding: 7px 10px;
  border-top: 1px solid #ececf2;
  font-size: 14px;
}

.lb-table tr.me {
  background: rgba(124, 92, 255, 0.14);
}

.t-rank {
  width: 34px;
  text-align: center;
  font-weight: 800;
  color: #6b7280;
}

.t-name {
  font-weight: 600;
}

.t-net {
  text-align: right;
  font-weight: 800;
}

.t-net.pos,
.podium-net.pos {
  color: #16a34a;
}

.t-net.neg,
.podium-net.neg {
  color: #dc2626;
}
