:root {
  --bg1: #15324a;
  --bg2: #070d14;
  --text: #fff;
  --muted: rgba(255, 255, 255, 0.62);
  --green: #3fd16b;
  --green-d: #23a34b;
  --blue: #36a8ff;
  --blue-d: #1a78d1;
  --red: #ff5a5a;
  --gold: #ffd60a;
  --sheet: #1c2836;
  --font: Fredoka, "Arial Rounded MT Bold", ui-rounded, system-ui, -apple-system, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(120% 80% at 50% 0%, var(--bg1), var(--bg2));
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { font-family: inherit; touch-action: manipulation; cursor: pointer; }
input { font-family: inherit; -webkit-user-select: text; user-select: text; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

/* ---- lobby / waiting ---- */

#lobby, #waiting {
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.panel {
  width: 100%;
  max-width: 360px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.logo svg { width: 108px; height: 108px; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.5)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-6deg); } }

h1 { margin: 0; font-size: 46px; font-weight: 700; letter-spacing: 0.5px; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3); }
h2 { margin: 0; font-size: 28px; }
h3 { margin: 0 0 4px; font-size: 22px; }
.tag { margin: -4px 0 8px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 14px; margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 14px; color: var(--muted); }
.field input, .join-row input {
  width: 100%;
  font-size: 20px;
  padding: 13px 16px;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  outline: none;
}
.field input:focus, .join-row input:focus { border-color: var(--blue); }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 600; }
.join-row .btn { flex: 0 0 96px; }

.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: rgba(255, 255, 255, 0.15); }

#lobby .invite-only { display: none; }
#lobby.invite .invite-only { display: flex; flex-direction: column; gap: 10px; }
#lobby.invite .normal-only { display: none; }
.normal-only { display: flex; flex-direction: column; gap: 12px; }

.btn {
  border: 0;
  border-radius: 18px;
  padding: 13px 18px;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(#55e07f, var(--green-d));
  box-shadow: 0 5px 0 #17773a, 0 8px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #17773a, 0 3px 8px rgba(0, 0, 0, 0.3); }
.btn.big { font-size: 22px; padding: 16px 20px; }
.btn.blue { background: linear-gradient(#5cbcff, var(--blue-d)); box-shadow: 0 5px 0 #11549a, 0 8px 18px rgba(0, 0, 0, 0.35); }
.btn.ghost { background: rgba(255, 255, 255, 0.1); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); }
.btn.danger { background: linear-gradient(#ff7676, #d93b3b); box-shadow: 0 5px 0 #8f1f1f; }
.btn:disabled { opacity: 0.6; transform: none; }
.link { background: none; border: 0; color: var(--muted); font-size: 15px; text-decoration: underline; padding: 6px; }
.err { color: var(--red); min-height: 1.2em; margin: 0; }

.code-box {
  font-size: 54px;
  font-weight: 700;
  letter-spacing: 12px;
  padding: 10px 0 10px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px dashed rgba(255, 255, 255, 0.25);
  -webkit-user-select: text;
  user-select: text;
}
.link-text { font-size: 13px; color: var(--muted); word-break: break-all; margin: 0; -webkit-user-select: text; user-select: text; }
.waiting-dots::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.shake { animation: shake 0.35s; border-color: var(--red) !important; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }

/* ---- game (GamePigeon look: light gray backdrop, players on the screen edges) ---- */

#game { flex-direction: column; background: linear-gradient(#ececee, #d6d6d9); color: #2b2b2e; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

#hud {
  position: relative;
  z-index: 2;
  padding: max(10px, env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
}
#status {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  min-height: 22px;
  color: #55565c;
}

.player {
  position: absolute;
  z-index: 3;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}
.player.left .plabel { align-self: flex-start; }
.player.right .plabel { align-self: flex-end; }
.player.offline .avatar { filter: grayscale(0.8); opacity: 0.6; }
/* nobody in this seat yet: the avatar becomes an invite button */
.player.empty .avatar {
  background: rgba(255, 255, 255, 0.6);
  color: #8a8b90;
  box-shadow: inset 0 0 0 2px rgba(120, 120, 128, 0.35);
  text-shadow: none;
  pointer-events: auto;
  cursor: pointer;
}
.player.empty .group { visibility: hidden; }
.invite-pill {
  display: block;
  margin: 6px auto 0;
  padding: 8px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(#5cbcff, #1a78d1);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 3px 0 #11549a, 0 4px 10px rgba(0, 0, 0, 0.2);
  pointer-events: auto;
}
.invite-pill[hidden] { display: none; }
.invite-pill:active { transform: translateY(2px); box-shadow: 0 1px 0 #11549a; }
.plabel {
  font-weight: 700;
  font-size: 12px;
  color: #6b6c72;
  max-width: 84px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 2px;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}
.avatar {
  width: var(--av, 52px);
  height: var(--av, 52px);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: calc(var(--av, 52px) * 0.46);
  color: #fff;
  background: linear-gradient(160deg, #ffb26b, #f0606e);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}
.avatar[data-seat='1'] { background: linear-gradient(160deg, #7fd7ff, #5468e8); }
.player.left .avatar { border-radius: 0 10px 10px 0; }
.player.right .avatar { border-radius: 10px 0 0 10px; }
.player.winner .avatar { box-shadow: 0 0 0 3px #ffd426, 0 0 18px 4px rgba(255, 212, 38, 0.8); }
.turn { font-size: 10px; line-height: 1; color: #55565c; visibility: hidden; }
.player.active .turn { visibility: visible; }
.group {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  pointer-events: auto;
  display: grid;
  place-items: center;
}
.group i {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px dashed rgba(90, 90, 96, 0.55);
}
.group.solids i, .group.stripes i, .group.eight i {
  border: 0;
  box-shadow: inset -3px -3px 5px rgba(0, 0, 0, 0.35), inset 2px 2px 4px rgba(255, 255, 255, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
}
.group.solids i { background: radial-gradient(circle at 35% 30%, #a9a9ae, #5d5d63 70%); }
.group.stripes i { background: linear-gradient(#f4f3ef 0 28%, #6d6d73 28% 72%, #f4f3ef 72%); }
.group.eight i { background: radial-gradient(circle at 50% 46%, #fff 0 22%, transparent 24%), radial-gradient(circle at 35% 30%, #555, #0d0d0d 70%); }
.tip {
  position: absolute;
  top: calc(100% - 26px);
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(40, 40, 44, 0.9);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.player.left .tip { left: calc(100% + 4px); }
.player.right .tip { right: calc(100% + 4px); }
.tip[hidden] { display: none; }

.spin-btn {
  position: absolute;
  z-index: 3;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.3));
}
.spin-btn[hidden] { display: none; }
.mini-cue {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #ececec 55%, #b7b7b7);
}
.mini-cue i, .spin-dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e8332f;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
}
.skip-btn {
  position: absolute;
  z-index: 3;
  width: 54px;
  height: 54px;
  margin-left: -27px;
  border: 0;
  border-radius: 50%;
  background: rgba(25, 30, 32, 0.72);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.skip-btn svg { width: 24px; height: 24px; fill: #fff; }
.skip-btn[hidden] { display: none; }

#bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px max(10px, env(safe-area-inset-bottom));
  pointer-events: none;
}
#bar > * { pointer-events: auto; }
.corner-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: #fff;
  color: #8a8b90;
  font-size: 22px;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.corner-btn svg { width: 24px; height: 24px; fill: #9a9ba0; }
.corner-btn.react { font-size: 22px; background: rgba(255, 255, 255, 0.7); }
.corner-btn:active { transform: scale(0.94); }
.react-wrap { position: relative; }
.react-wrap.hidden { visibility: hidden; }
.react-tray {
  position: absolute;
  bottom: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(4, 48px);
  gap: 4px;
  padding: 8px;
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.react-tray[hidden] { display: none; }
.emoji { width: 48px; height: 48px; border: 0; background: none; font-size: 30px; border-radius: 12px; }
.emoji:active { background: rgba(0, 0, 0, 0.06); }

/* end of game: GamePigeon's yellow banner across the table, warm tint for a win */
.banner {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(circle at 50% 45%, rgba(255, 236, 140, 0.18), rgba(214, 186, 60, 0.42));
  animation: fade 0.35s;
  will-change: opacity; /* own layer, so the table canvas can never paint over it */
}
.banner.lost { background: radial-gradient(circle at 50% 45%, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.32)); }
.banner[hidden] { display: none; }
.banner-box {
  width: min(64vw, 300px);
  padding: 12px 22px;
  border-radius: 6px;
  background: #ffd426;
  color: #111;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.banner.lost .banner-box { background: #e9e9ec; color: #222; }
.banner-more {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
.banner.show-more .banner-more { opacity: 1; pointer-events: auto; }
.banner-more p {
  margin: 0;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  text-align: center;
}
.banner-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---- modals ---- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  animation: fade 0.2s;
}
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%;
  max-width: 340px;
  background: var(--sheet);
  border-radius: 26px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

.spin-ball {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 6px auto;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #e8e8e8 50%, #9a9a9a);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
  touch-action: none;
}
.spin-ball .spin-dot { width: 26px; height: 26px; box-shadow: 0 0 0 3px #fff, 0 2px 6px rgba(0, 0, 0, 0.4); }
.cross-h, .cross-v { position: absolute; background: rgba(0, 0, 0, 0.12); }
.cross-h { left: 12%; right: 12%; top: 50%; height: 2px; }
.cross-v { top: 12%; bottom: 12%; left: 50%; width: 2px; }

.help ul { text-align: left; padding-left: 18px; margin: 0; font-size: 15px; line-height: 1.4; display: flex; flex-direction: column; gap: 8px; color: rgba(255, 255, 255, 0.85); }

/* ---- toasts & floaters ---- */

#toasts {
  position: fixed;
  left: 0;
  right: 0;
  top: 38%;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(10, 18, 28, 0.88);
  font-weight: 600;
  font-size: 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
  transition: opacity 0.4s, transform 0.4s;
}
.toast.good { background: linear-gradient(#4ade80, #16a34a); }
.toast.bad { background: linear-gradient(#ff7676, #d93b3b); }
.toast.out { opacity: 0; transform: translateY(-12px); }
@keyframes toastIn { from { transform: scale(0.6); opacity: 0; } }

#floaters { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.floater {
  position: absolute;
  bottom: 80px;
  animation: floatUp 2.4s ease-out forwards;
  opacity: 0;
}
.floater.mine { left: 22%; }
.floater.theirs { right: 22%; }
@keyframes floatUp {
  0% { opacity: 0; transform: translate(0, 0) scale(0.5); }
  12% { opacity: 1; transform: translate(calc(var(--dx) * 0.2), -40px) scale(1.1); }
  100% { opacity: 0; transform: translate(var(--dx), -55vh) scale(1); }
}
.confetti {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  animation: fall 2.8s ease-in forwards;
}
@keyframes fall { to { transform: translateY(105vh) rotate(var(--r)); } }

/* ---- your games (lobby) ---- */

.my-games { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.my-games[hidden] { display: none; }
.my-games h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin: 0; }
.game-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  color: #fff;
  font-size: 16px;
  text-align: left;
}
.game-row:active { transform: translateY(2px); }
.game-row .gr-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-row .gr-state { font-size: 14px; color: var(--muted); white-space: nowrap; }
.game-row.mine { border-color: var(--gold); background: rgba(255, 214, 10, 0.12); }
.game-row.mine .gr-state { color: var(--gold); font-weight: 600; }
.game-row { cursor: pointer; }
.game-row .gr-state { margin-left: auto; }
.gr-x {
  flex: 0 0 28px;
  height: 28px;
  margin: -4px -8px -4px 2px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}
.gr-x:active { background: rgba(255, 255, 255, 0.2); }
