:root {
  --bg: #14121f;
  --surface: #1f1c30;
  --surface-2: #2a2640;
  --text: #f4f1ff;
  --muted: #a39fbf;
  --accent: #ff5a7a;
  --accent-2: #ffc23d;
  --accent-text: #1a1020;
  --ok: #3ddc97;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
h1, h2, .btn, strong { font-family: Fredoka, Inter, system-ui, sans-serif; }
h1 { margin: 0; font-size: 28px; letter-spacing: 0.3px; }
h2 { margin: 0 0 4px; font-size: 19px; }
p { margin: 0; }
.muted { color: var(--muted); }
.tiny { font-size: 12.5px; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; justify-content: center; }

#app { height: 100%; max-width: 560px; margin: 0 auto; position: relative; }
.screen { min-height: 100%; padding: calc(16px + var(--safe-top)) 16px calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 16px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 14px; padding: 6px 2px 4px; }
.logo { width: 52px; height: 52px; position: relative; flex: none; }
.logo span { position: absolute; width: 26px; height: 26px; border-radius: 50%; }
.logo span:nth-child(1) { background: #ff5a5f; left: 0; top: 4px; }
.logo span:nth-child(2) { background: #ffc23d; right: 0; top: 4px; mix-blend-mode: screen; }
.logo span:nth-child(3) { background: #3ab7ff; left: 13px; bottom: 0; mix-blend-mode: screen; }

.card { background: var(--surface); border-radius: var(--radius); padding: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
input {
  width: 100%; font: 600 18px Fredoka, Inter, sans-serif; color: var(--text);
  background: var(--surface-2); border: 2px solid transparent; border-radius: 12px; padding: 11px 14px; outline: none;
  -webkit-user-select: text; user-select: text;
}
input:focus { border-color: var(--accent); }
.join .row { gap: 10px; }
.join input { text-transform: uppercase; letter-spacing: 4px; }
.guest p { margin-top: 8px; }

/* Game cards */
.games { display: flex; flex-direction: column; gap: 12px; }
.game-card {
  display: flex; gap: 14px; align-items: center; text-align: left; width: 100%;
  background: var(--surface); color: var(--text); border: 0; border-radius: var(--radius);
  padding: 12px; cursor: pointer; transition: transform .12s ease, background .12s ease;
}
.game-card:active { transform: scale(0.98); }
.game-card:hover { background: var(--surface-2); }
.game-card p { color: var(--muted); font-size: 13.5px; line-height: 1.4; }
.thumb { width: 84px; height: 84px; border-radius: 14px; flex: none; background: var(--surface-2); }

/* Buttons */
.btn {
  border: 0; border-radius: 14px; padding: 12px 18px; font-size: 16px; font-weight: 600; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #ff8a4c); color: #fff; white-space: nowrap;
  transition: transform .1s ease, opacity .1s ease; touch-action: manipulation;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.big { padding: 16px; font-size: 19px; width: 100%; }

/* Lobby */
.lobby-top { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; padding-top: 6px; }
#lobby-game { font-size: 15px; font-family: Fredoka, sans-serif; color: var(--accent-2); letter-spacing: 1px; text-transform: uppercase; }
.code-box { display: flex; flex-direction: column; background: var(--surface); padding: 12px 26px; border-radius: var(--radius); }
.code-box strong { font-size: 40px; letter-spacing: 8px; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.players li { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 14px; padding: 10px 12px; }
.players .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font: 600 14px Fredoka, sans-serif; color: #1a1020; flex: none; }
.players .name { flex: 1; font-weight: 600; }
.players .tag { font-size: 11px; background: var(--surface-2); color: var(--muted); padding: 3px 8px; border-radius: 99px; }
.players .x { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.players li.off { opacity: .5; }
.lobby-actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

/* Play */
.screen.play { padding: calc(6px + var(--safe-top)) 0 calc(6px + var(--safe-bottom)); gap: 6px; height: 100%; min-height: 0; overflow: hidden; }
.hud { padding: 0 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 38px; font-size: 14px; }
.hud .pill { background: var(--surface); padding: 6px 10px; border-radius: 99px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.hud .pill b { font-family: Fredoka, sans-serif; }
.hud .grow { flex: 1; }
.hud .sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.stage { flex: 1; min-height: 0; position: relative; }
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.controls { padding: 0 12px; display: flex; gap: 10px; align-items: center; justify-content: center; min-height: 58px; flex-wrap: wrap; }
.controls .btn { min-width: 90px; }
.controls .swatches { display: flex; gap: 7px; }
.controls .swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.controls .swatch.on { border-color: #fff; transform: scale(1.1); }
.controls .meter { width: 70px; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.controls .meter i { display: block; height: 100%; background: var(--accent-2); }
.dice-btn {
  width: 74px; height: 74px; border-radius: 18px; border: 0; background: #fff; cursor: pointer; padding: 0;
  box-shadow: 0 6px 0 #c9c4e0; transition: transform .1s ease; touch-action: manipulation;
}
.dice-btn:disabled { opacity: .5; box-shadow: 0 3px 0 #c9c4e0; transform: translateY(3px); }
.dice-btn.rolling { animation: shake .45s ease; }
@keyframes shake { 0%,100% { transform: rotate(0) } 25% { transform: rotate(-14deg) } 50% { transform: rotate(12deg) } 75% { transform: rotate(-6deg) } }

.emotes { position: absolute; right: 8px; top: calc(52px + var(--safe-top)); display: flex; flex-direction: column; gap: 4px; z-index: 4; }
.emotes button[data-e] { display: none; }
.emotes.open button[data-e] { display: block; }
.emotes .emote-toggle { opacity: .75; }
.emotes button { background: var(--surface); border: 0; border-radius: 10px; font-size: 16px; width: 34px; height: 34px; cursor: pointer; }
.emote-float { position: absolute; font-size: 34px; pointer-events: none; animation: floatUp 1.8s ease-out forwards; z-index: 5; }
@keyframes floatUp { from { transform: translateY(0) scale(.6); opacity: 1 } to { transform: translateY(-120px) scale(1.2); opacity: 0 } }

.banner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
  background: rgba(20, 18, 31, .88); padding: 14px 22px; border-radius: 16px; text-align: center;
  font: 600 22px Fredoka, sans-serif; pointer-events: none; animation: pop .3s ease; max-width: 90%;
}
.banner small { display: block; font: 500 13px Inter, sans-serif; color: var(--muted); margin-top: 4px; }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.7); opacity: 0 } }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(8, 6, 16, .7); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card { background: var(--surface); border-radius: 22px; padding: 22px; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.results { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.results li { display: flex; align-items: center; gap: 10px; background: var(--surface-2); padding: 10px 12px; border-radius: 12px; }
.results .medal { font-size: 22px; width: 28px; text-align: center; }
.results .n { flex: 1; font-weight: 600; }
.results li.me { outline: 2px solid var(--accent-2); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: #fff; color: #1a1020; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 30;
  box-shadow: 0 8px 30px rgba(0,0,0,.35); max-width: 90%; text-align: center;
}
.conn { position: fixed; top: calc(8px + var(--safe-top)); left: 50%; transform: translateX(-50%); background: var(--accent-2); color: #1a1020; padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 600; z-index: 30; }

@media (min-width: 700px) {
  #app { max-width: 900px; }
  .screen:not(.play) { max-width: 560px; margin: 0 auto; }
}

/* Wallet */
.wallet { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wallet > div { display: flex; flex-direction: column; }
.wallet strong { font-size: 24px; }
.results .coins { font: 600 13px Fredoka, sans-serif; color: var(--accent-2); margin-left: 6px; }
