:root {
  --ink: #1f1235;
  --bg: #1e1b4b;
  --paper: #fffbf5;
  --accent: #f97316;
  --accent2: #8b5cf6;
  --muted: #6b7280;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Nunito, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.center { text-align: center; }
.sub { color: var(--muted); font-weight: 700; margin: 8px 0; }

#home, #lobby {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px 48px;
  background:
    radial-gradient(circle at 15% 10%, rgba(139, 92, 246, .8) 0, transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(249, 115, 22, .7) 0, transparent 45%),
    var(--bg);
}
.panel {
  width: 100%;
  max-width: 780px;
  background: var(--paper);
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 12px 0 rgba(0, 0, 0, .3);
}
.logo {
  font-family: 'Lilita One', system-ui, sans-serif;
  font-weight: 400;
  font-size: clamp(44px, 10vw, 76px);
  margin: 0;
  text-align: center;
  color: var(--accent2);
  line-height: 1;
  text-shadow: 0 4px 0 var(--ink);
  animation: wobble 2.4s ease-in-out infinite;
}
.logo span { color: var(--accent); }
@keyframes wobble {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(2deg) scale(1.03); }
}
.tag { text-align: center; color: var(--muted); margin: 10px 0 20px; font-weight: 800; }

input, select {
  font: inherit;
  font-weight: 800;
  padding: 10px 14px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
}
.field { display: block; font-weight: 900; margin-bottom: 16px; }
.field input { display: block; width: 100%; margin-top: 6px; font-size: 18px; }
.label { font-weight: 900; margin: 6px 0 8px; }

.chars { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 8px; }
.char {
  background: #fff;
  border: 3px solid #e5e7eb;
  border-radius: 16px;
  padding: 6px 4px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  font: 900 14px Nunito, sans-serif;
  color: var(--ink);
  transition: transform .12s;
}
.char canvas { width: 60px; height: 70px; }
.char:hover { transform: translateY(-2px); }
.char.on { border-color: var(--accent); background: #fff7ed; transform: translateY(-3px); box-shadow: 0 4px 0 var(--accent); }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 20px; }
.card {
  border: 3px solid var(--ink);
  border-radius: 20px;
  padding: 16px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h2 { margin: 0; font: 400 22px 'Lilita One', system-ui, sans-serif; }
.row { display: flex; align-items: center; justify-content: inherit; gap: 10px; flex-wrap: wrap; font-weight: 800; }
.check input { width: 20px; height: 20px; }
.check select { padding: 6px 10px; }

.btn {
  font: 400 20px 'Lilita One', system-ui, sans-serif;
  padding: 12px 18px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.big { font-size: 26px; padding: 14px 28px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; text-decoration: underline; font-size: 16px; }

.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper button {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 3px solid var(--ink);
  background: #fff;
  font: 900 20px Nunito, sans-serif;
  line-height: 1;
  cursor: pointer;
}
.stepper output { min-width: 22px; text-align: center; font-size: 20px; font-weight: 900; }

#code { width: 130px; text-transform: uppercase; letter-spacing: 6px; font-size: 20px; text-align: center; }
.msg { margin: 0; color: #b45309; font-weight: 800; min-height: 1.2em; }

.help { margin-top: 20px; font-weight: 600; }
.help summary { font-weight: 900; cursor: pointer; font-size: 18px; }
.help table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 14px; }
.help th, .help td { text-align: left; padding: 6px 8px; border-bottom: 2px solid #f3e8d8; }

.fame { margin-top: 20px; }
.fame h3 { font: 400 22px 'Lilita One', system-ui, sans-serif; margin: 0 0 8px; }
.fame li { font-weight: 800; margin: 4px 0; }

.code {
  font-family: 'Lilita One', system-ui, sans-serif;
  font-size: 72px;
  letter-spacing: 12px;
  text-align: center;
  color: var(--accent2);
  text-shadow: 0 4px 0 var(--ink);
  margin-bottom: 12px;
}
.members { list-style: none; padding: 0; margin: 16px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.members li {
  background: #fff;
  border: 3px solid #e5e7eb;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  font-weight: 900;
  text-align: center;
}
.members canvas { width: 54px; height: 63px; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* ---------- In game ---------- */
#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: #000;
}
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: 150px;
  pointer-events: none;
}
#roundInfo { font: 400 18px 'Lilita One', system-ui, sans-serif; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .5); }
.scores { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  background: rgba(15, 23, 42, .65);
  color: #fff;
  border-left: 6px solid var(--c);
  padding: 3px 8px;
  border-radius: 10px;
  font-weight: 900;
  font-size: 13px;
}
.chip.out { opacity: .4; text-decoration: line-through; }
.chip.me { background: #fff; color: #111827; }
.topbtns {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 6px;
}
.topbtns button {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 0;
  background: rgba(15, 23, 42, .6);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.banner {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  font: 400 clamp(36px, 8vw, 88px) 'Lilita One', system-ui, sans-serif;
  color: #fde047;
  -webkit-text-stroke: 3px var(--ink);
  text-shadow: 0 6px 0 var(--ink);
  white-space: nowrap;
  pointer-events: none;
  animation: pop .5s cubic-bezier(.2, 1.6, .4, 1);
}
@keyframes pop {
  from { transform: translateX(-50%) scale(.3); }
  to { transform: translateX(-50%) scale(1); }
}

.touch { position: absolute; inset: 0; pointer-events: none; }
#stick-zone { position: absolute; left: 0; top: 20%; bottom: 0; width: 50%; pointer-events: auto; touch-action: none; }
#stick-base {
  position: fixed;
  left: 110px;
  top: calc(100% - 110px);
  width: 110px;
  height: 110px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, .12);
  border: 3px solid rgba(255, 255, 255, .3);
  pointer-events: none;
}
#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
}
.tbtns {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-areas: "special grab punch" ". kick jump";
  gap: 10px;
  align-items: center;
  justify-items: center;
  pointer-events: auto;
}
.tb {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, .6);
  color: #fff;
  font: 400 15px 'Lilita One', system-ui, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.tb.jump { grid-area: jump; background: rgba(34, 197, 94, .55); width: 84px; height: 84px; }
.tb.punch { grid-area: punch; background: rgba(239, 68, 68, .55); }
.tb.grab { grid-area: grab; background: rgba(59, 130, 246, .55); }
.tb.kick { grid-area: kick; background: rgba(249, 115, 22, .55); }
.tb.special { grid-area: special; background: rgba(234, 179, 8, .7); font-size: 26px; }
.tb.special.cool { background: rgba(100, 116, 139, .5); font-size: 20px; }
.power { margin: 10px 2px 0; font-weight: 700; color: var(--ink); min-height: 1.3em; }
.power b { color: var(--accent); }
.spinfo { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.spinfo span {
  background: rgba(15, 23, 42, .65);
  color: #fde047;
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: 900;
  font-size: 13px;
}
.spinfo span.cool { color: #cbd5e1; }
.tb.on { transform: scale(.9); filter: brightness(1.35); }
.rotate {
  display: none;
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, .6);
  color: #fff;
  padding: 8px 14px;
  border-radius: 12px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}
@media (orientation: portrait) and (pointer: coarse) {
  .rotate { display: block; }
}
