:root {
  --bg: #1a1446;
  --panel: rgba(27, 31, 59, 0.92);
  --ink: #ffffff;
  --muted: #c4b8f5;
  --p1: #ffb84d;
  --p2: #4dd2ff;
  --danger: #ff8a9a;
  --edge: #0e0b2b;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Rubik', Arial, sans-serif;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#game { position: fixed; inset: 0; }
#game canvas { image-rendering: pixelated; }
.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}
.panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 4px solid var(--edge);
  border-radius: 18px;
  box-shadow: 0 8px 0 var(--edge), 0 20px 50px rgba(0, 0, 0, 0.45);
  padding: 26px 24px 22px;
  text-align: center;
}
h1 {
  margin: 0 0 4px;
  font-size: clamp(38px, 9vw, 54px);
  font-weight: 900;
  color: var(--p1);
  text-shadow: 0 4px 0 var(--edge);
  line-height: 1.05;
}
h1 span { color: var(--p2); }
h2 { margin: 0 0 10px; font-size: 30px; font-weight: 900; text-shadow: 0 3px 0 var(--edge); }
.sub { margin: 0 0 20px; color: var(--muted); }
p { margin: 6px 0; font-size: 18px; }

button {
  font: inherit;
  font-weight: 700;
  color: var(--edge);
  background: var(--ink);
  border: 3px solid var(--edge);
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--edge);
  transition: transform 0.08s, box-shadow 0.08s;
}
button:hover { transform: translateY(-1px); box-shadow: 0 5px 0 var(--edge); }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--p2); outline-offset: 2px; }
button.big { display: block; width: 100%; font-size: 22px; padding: 14px; margin: 10px 0; background: var(--p1); }
button.big.alt { background: var(--p2); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--muted); box-shadow: none; }
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row button { margin: 0; }

.join { display: flex; gap: 8px; margin-top: 6px; }
.join input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 6px;
  text-align: center;
  text-transform: uppercase;
  padding: 10px;
  border-radius: 12px;
  border: 3px solid var(--edge);
  background: #f1f2f6;
  color: var(--edge);
}
.join input::placeholder { letter-spacing: 0; font-weight: 400; font-size: 18px; }
.error { color: var(--danger); min-height: 1.4em; font-size: 16px; margin-top: 10px; }

.help { margin-top: 10px; font-size: 14px; color: var(--muted); line-height: 2; }
.help .tip { color: var(--ink); line-height: 1.5; margin-top: 6px; }
kbd {
  display: inline-block;
  min-width: 24px;
  padding: 0 6px;
  margin: 0 2px;
  border-radius: 6px;
  border: 2px solid var(--muted);
  font-family: inherit;
  font-size: 13px;
  line-height: 20px;
  color: var(--ink);
}

.code {
  font-size: 64px;
  font-weight: 900;
  letter-spacing: 12px;
  color: var(--p2);
  text-shadow: 0 4px 0 var(--edge);
  margin: 6px 0 8px;
  user-select: all;
}
.waiting { color: var(--muted); }
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-inline-end: 8px;
  border-radius: 50%;
  background: var(--p1);
  animation: pulse 1s infinite ease-in-out;
}
@keyframes pulse { 50% { opacity: 0.2; transform: scale(0.6); } }

#banner { z-index: 20; background: rgba(14, 11, 43, 0.35); }
.banner-box h2 { color: var(--p1); }

#toasts {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--panel);
  border: 3px solid var(--edge);
  border-radius: 12px;
  padding: 8px 16px;
  font-weight: 700;
  animation: drop 0.25s ease-out;
  transition: opacity 0.4s, transform 0.4s;
  max-width: 90vw;
}
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes drop { from { opacity: 0; transform: translateY(-12px); } }

#btn-exit {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 36px;
  z-index: 15;
  padding: 2px 10px;
  font-size: 16px;
  opacity: 0.6;
}
body.ingame #btn-exit { top: 4px; margin-top: 30px; }

#touch {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px 16px;
  direction: ltr;
  pointer-events: none;
}
#touch button {
  pointer-events: auto;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  font-size: 30px;
  background: rgba(255, 255, 255, 0.25);
  color: var(--ink);
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: none;
  touch-action: none;
}
#touch button.on { background: rgba(255, 255, 255, 0.55); }
#touch .pad { display: flex; gap: 14px; }
#touch .jump { width: 92px; height: 92px; background: rgba(255, 184, 77, 0.45); }
