:root {
  --bg: #171a26;
  --bg2: #1f2333;
  --card: #262b3e;
  --line: #343a52;
  --text: #f3f4f8;
  --muted: #a3a9c2;
  --yellow: #ffd166;
  --red: #ef476f;
  --green: #06d6a0;
  --blue: #4cc9f0;
  --font: 'Fredoka', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow-x: hidden;
}
button, input { font-family: inherit; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  border: 0;
  border-radius: 14px;
  padding: 10px 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--line);
  box-shadow: 0 4px 0 #11131c;
  cursor: pointer;
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #11131c; }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.primary { background: var(--yellow); color: #1b1f2e; box-shadow: 0 4px 0 #b8892a; }
.btn.big { padding: 14px 24px; font-size: 19px; }
.btn.huge { padding: 18px 40px; font-size: 24px; border-radius: 18px; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
}
.lbl { font-size: 13px; color: var(--muted); font-weight: 500; margin: 12px 0 6px; display: block; text-transform: uppercase; letter-spacing: .06em; }
.lbl:first-child { margin-top: 0; }
input {
  width: 100%;
  padding: 12px 14px;
  font-size: 18px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--bg2);
  color: var(--text);
  outline: none;
}
input:focus { border-color: var(--yellow); }
.hint { color: var(--muted); text-align: center; margin: 10px 0; }

/* ---------- home ---------- */
.screen { min-height: 100vh; }
#home {
  display: flex;
  justify-content: center;
  padding: 32px 16px;
  background:
    radial-gradient(circle at 20% 10%, rgba(255,209,102,.10), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(239,71,111,.12), transparent 45%),
    var(--bg);
  position: relative;
  overflow: hidden;
}
.floaties span {
  position: absolute;
  font-size: 42px;
  opacity: .14;
  animation: floaty 14s linear infinite;
}
.floaties span:nth-child(1) { left: 6%; animation-delay: -2s; }
.floaties span:nth-child(2) { left: 18%; animation-delay: -9s; font-size: 30px; }
.floaties span:nth-child(3) { left: 32%; animation-delay: -5s; }
.floaties span:nth-child(4) { left: 64%; animation-delay: -11s; font-size: 34px; }
.floaties span:nth-child(5) { left: 76%; animation-delay: -1s; }
.floaties span:nth-child(6) { left: 88%; animation-delay: -7s; font-size: 50px; }
.floaties span:nth-child(7) { left: 50%; animation-delay: -13s; font-size: 28px; }
.floaties span:nth-child(8) { left: 94%; animation-delay: -4s; font-size: 30px; }
@keyframes floaty {
  from { transform: translateY(110vh) rotate(0deg); }
  to { transform: translateY(-20vh) rotate(360deg); }
}
.home-wrap { width: 100%; max-width: 620px; position: relative; z-index: 1; display: flex; flex-direction: column; gap: 16px; }
.brand { text-align: center; position: relative; padding-top: 10px; }
.brand h1 { font-size: clamp(46px, 9vw, 76px); line-height: .95; margin: 8px 0 12px; font-weight: 700; letter-spacing: -.01em; }
.brand h1 span { color: var(--yellow); display: inline-block; transform: rotate(-3deg); }
.brand p { color: var(--muted); margin: 0; font-size: 17px; line-height: 1.45; }
.sticky {
  display: inline-block;
  background: var(--red);
  color: #fff;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 6px;
  transform: rotate(4deg);
  font-size: 14px;
  letter-spacing: .1em;
}
.setup { display: flex; gap: 20px; align-items: center; }
.setup-left { flex: 0 0 auto; }
#preview { width: 170px; height: 170px; background: radial-gradient(circle, #ece6da 0 55%, #ded6c6 56% 100%); border-radius: 50%; border: 4px solid var(--line); }
.setup-right { flex: 1; min-width: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.swatch.on { border-color: #fff; transform: scale(1.12); }
.hats { display: flex; flex-wrap: wrap; gap: 6px; }
.hat { border: 2px solid var(--line); background: var(--bg2); color: var(--text); border-radius: 10px; padding: 6px 10px; cursor: pointer; font-size: 14px; }
.hat.on { border-color: var(--yellow); color: var(--yellow); }
.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; }
.or { color: var(--muted); }
.join { display: flex; gap: 8px; flex: 1; min-width: 220px; }
#code { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; max-width: 140px; }
.howto { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.howto div { background: rgba(255,255,255,.03); border: 1px dashed var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.howto b { font-weight: 600; }
.howto span { color: var(--muted); font-size: 14px; }

@media (max-width: 600px) {
  .setup { flex-direction: column; }
  .howto { grid-template-columns: 1fr; }
}

/* ---------- lobby ---------- */
#lobby { display: flex; justify-content: center; padding: 24px 16px 40px; }
.lobby-wrap { width: 100%; max-width: 960px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.lobby-top { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room { text-align: center; }
.room-lbl { color: var(--muted); font-size: 13px; letter-spacing: .15em; }
.room-code { font-size: 52px; font-weight: 700; letter-spacing: .25em; color: var(--yellow); line-height: 1; padding-left: .25em; }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; width: 100%; margin-top: 10px; }
.slot { background: var(--card); border: 2px solid var(--line); border-radius: 20px; padding: 14px; text-align: center; min-height: 210px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.slot.me { border-color: var(--yellow); }
.slot.empty { border-style: dashed; opacity: .55; }
.slot canvas { width: 120px; height: 120px; }
.chair { font-size: 54px; height: 120px; display: flex; align-items: center; }
.slot-name { font-weight: 600; font-size: 18px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.slot-sub { color: var(--muted); font-size: 13px; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; margin-top: 10px; }
.lobby-grid h3 { margin: 0 0 10px; font-size: 18px; }
.lobby-grid h3:not(:first-child) { margin-top: 18px; }
.keys, .foes { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; color: var(--muted); font-size: 15px; }
.foes b { color: var(--text); font-weight: 600; margin-right: 4px; }
kbd { background: var(--bg2); border: 1px solid var(--line); border-bottom-width: 3px; border-radius: 6px; padding: 1px 7px; font-family: inherit; font-size: 13px; color: var(--text); margin-right: 2px; }

@media (max-width: 760px) {
  .slots { grid-template-columns: repeat(2, 1fr); }
  .lobby-grid { grid-template-columns: 1fr; }
  .room-code { font-size: 40px; }
}

/* ---------- leaderboard ---------- */
.lb { display: flex; flex-direction: column; gap: 6px; }
.lb-row { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 10px; align-items: center; background: var(--bg2); padding: 8px 12px; border-radius: 10px; font-size: 15px; }
.lb-row.hl { outline: 2px solid var(--yellow); }
.lb-rank { text-align: center; font-weight: 700; }
.lb-names { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-wave { color: var(--yellow); font-weight: 600; }
.lb-score { color: var(--muted); min-width: 60px; text-align: right; }
.lb-empty { color: var(--muted); text-align: center; padding: 20px; }

/* ---------- game ---------- */
#game { position: fixed; inset: 0; min-height: 0; }
#canvas { width: 100%; height: 100%; display: block; cursor: none; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12,14,22,.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 20;
  overflow-y: auto;
}
.overlay.shop { background: rgba(12,14,22,.45); backdrop-filter: none; }
.shop-box { width: 100%; max-width: 860px; text-align: center; }
.shop-head { display: flex; align-items: center; justify-content: center; gap: 16px; }
.shop-head h2 { margin: 0; font-size: 34px; text-shadow: 0 3px 0 #000; }
.shop-timer { background: var(--red); color: #fff; font-weight: 700; padding: 4px 12px; border-radius: 999px; }
.shop-sub { color: #fff; font-size: 18px; margin: 8px 0 18px; text-shadow: 0 2px 0 #000; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.card {
  font: inherit;
}
.cards .card {
  position: relative;
  color: #1b1f2e;
  background: #fff8e1;
  border: 0;
  border-radius: 18px;
  padding: 26px 18px 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 0 #b8892a, 0 14px 30px rgba(0,0,0,.4);
  transform: rotate(-1deg);
  transition: transform .12s, opacity .2s;
}
.cards .card:nth-child(2) { transform: rotate(1deg); background: #e6f7ff; box-shadow: 0 8px 0 #5d9cb8, 0 14px 30px rgba(0,0,0,.4); }
.cards .card:nth-child(3) { transform: rotate(-.5deg); background: #ffe8ee; box-shadow: 0 8px 0 #c06a80, 0 14px 30px rgba(0,0,0,.4); }
.cards .card:hover { transform: translateY(-6px) rotate(0); }
.cards .card.chosen { outline: 4px solid var(--green); transform: scale(1.04); }
.cards .card.dim { opacity: .35; pointer-events: none; }
.card-key { position: absolute; top: 10px; left: 12px; background: #1b1f2e; color: #fff; border-radius: 8px; width: 24px; height: 24px; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.card-icon { font-size: 48px; }
.card-name { font-size: 21px; font-weight: 700; }
.card-desc { font-size: 15px; color: #4a4f63; min-height: 38px; }
.card-lvl { letter-spacing: .2em; color: #b8892a; font-size: 14px; }
@media (max-width: 700px) { .cards { grid-template-columns: 1fr; } }

.over-box {
  width: 100%;
  max-width: 760px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
  margin: auto;
}
.over-box.small { max-width: 420px; }
.over-box h2 { margin: 6px 0; font-size: 30px; }
.over-box h3 { text-align: left; margin: 22px 0 10px; }
.over-emoji { font-size: 56px; }
.quote { color: var(--muted); font-style: italic; font-size: 17px; margin: 6px 0 18px; }
.over-stats { display: flex; justify-content: center; gap: 14px; }
.over-stats div { background: var(--bg2); border-radius: 16px; padding: 12px 28px; display: flex; flex-direction: column; }
.over-stats span { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .1em; }
.over-stats b { font-size: 34px; color: var(--yellow); }
.rank { color: var(--green); font-weight: 600; min-height: 1em; }
.awards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; margin: 14px 0; }
.award { display: flex; gap: 12px; align-items: center; background: var(--bg2); border-radius: 14px; padding: 12px; text-align: left; }
.award-emoji { font-size: 32px; }
.award-title { font-weight: 700; color: var(--yellow); }
.award-who { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.award-who i, .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.stat-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 15px; }
.stat-table th { color: var(--muted); font-weight: 500; font-size: 13px; padding: 6px; }
.stat-table td { padding: 8px 6px; border-top: 1px solid var(--line); }
.stat-table td:first-child, .stat-table th:first-child { text-align: left; }
.over-actions { display: flex; justify-content: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
@media (max-width: 600px) { .stat-table { font-size: 12px; } .over-box { padding: 18px; } }

/* ---------- misc ---------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 120px;
  transform: translate(-50%, 20px);
  background: #fff;
  color: #1b1f2e;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--red); color: #fff; }
.mute {
  position: fixed;
  right: 14px;
  top: 76px;
  z-index: 30;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: rgba(22,25,36,.78);
  font-size: 18px;
  cursor: pointer;
}
