:root {
  --bg: #1b1b2f;
  --panel: rgba(18, 18, 34, 0.72);
  --text: #f4f1de;
  --muted: #b9b6c9;
  --accent: #ffd23f;
  --pink: #ff5d73;
  --radius: 12px;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
body { touch-action: none; -webkit-user-select: none; user-select: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; }

/* ---------- menu ---------- */
#menu {
  background:
    radial-gradient(circle at 20% 20%, rgba(76, 201, 240, 0.25), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(255, 93, 115, 0.25), transparent 40%),
    var(--bg);
  overflow: auto;
  padding: 16px;
}
.menu-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  user-select: text;
}
.logo { margin: 0 0 6px; font-size: clamp(36px, 8vw, 56px); line-height: 1; letter-spacing: -1px; }
.logo span:first-child { color: var(--pink); }
.logo span:last-child { color: #4cc9f0; }
.logo span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.logo span:last-child { animation-delay: 0.3s; }
@keyframes bob { 50% { transform: translateY(-6px); } }
.tag { color: var(--muted); margin: 0 0 22px; line-height: 1.45; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.08em; }
input {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.07);
  border: 2px solid rgba(255, 255, 255, 0.12); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px; outline: none;
}
input:focus { border-color: #4cc9f0; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button {
  width: 38px; height: 38px; border-radius: 10px; border: 3px solid transparent;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.25);
}
.colors button[aria-checked="true"] { border-color: #fff; transform: translateY(-2px); }

.actions { display: grid; gap: 10px; margin-top: 8px; }
.join { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
#code { text-transform: uppercase; letter-spacing: 0.2em; }
.btn {
  min-height: 46px; padding: 0 22px; border-radius: 10px; border: 0; font-weight: 700;
  background: rgba(255, 255, 255, 0.12); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s;
}
.btn:active { transform: translateY(2px); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25); }
.btn.primary { background: var(--pink); color: #fff; font-size: 18px; }
.error { color: #ff8fa0; min-height: 1.2em; margin: 10px 0 0; }

.help { margin-top: 14px; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; color: var(--text); font-weight: 600; }
.help ul { padding-left: 18px; line-height: 1.6; }
kbd {
  display: inline-block; min-width: 20px; padding: 0 5px; margin: 0 1px; border-radius: 4px; font: 12px/18px ui-monospace, monospace;
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.15); text-align: center;
}
.c0 { color: #ff6b6b; } .c1 { color: #4dabf7; } .c2 { color: #51cf66; } .c3 { color: #cc5de8; }

/* ---------- game ---------- */
#game { background: #000; }
#canvas { display: block; image-rendering: auto; }

#hud {
  position: fixed; top: 0; left: 0; right: 0; padding: 10px;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; gap: 8px;
}
.hud-left, .hud-right { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }
.hud-right { justify-content: flex-end; }
.pill {
  background: var(--panel); border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: 15px;
  border: 1px solid rgba(255, 255, 255, 0.08); backdrop-filter: blur(4px);
}
.btn-pill { pointer-events: auto; border: 1px solid rgba(255, 255, 255, 0.08); }
.btn-pill:hover { background: rgba(40, 40, 70, 0.9); }
#lives { color: var(--pink); letter-spacing: 1px; }
#score { color: var(--accent); }
.roster { list-style: none; margin: 0; padding: 6px 10px; border-radius: 12px; display: flex; gap: 10px; flex-wrap: wrap; }
.roster li { display: flex; align-items: center; gap: 5px; font-size: 13px; }
.roster i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.roster .you { text-decoration: underline; text-underline-offset: 3px; }

.banner {
  position: fixed; top: 18%; left: 50%; transform: translateX(-50%); text-align: center;
  background: var(--panel); padding: 16px 28px; border-radius: 16px; max-width: min(680px, 92vw);
  animation: fadeInOut 7s forwards; pointer-events: none;
}
.banner h2 { margin: 0 0 6px; font-size: 30px; }
.banner p { margin: 0; color: var(--muted); line-height: 1.45; }
@keyframes fadeInOut { 0% { opacity: 0; transform: translate(-50%, -10px); } 8%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

.toast {
  position: fixed; top: 64px; left: 50%; transform: translateX(-50%);
  background: #51cf66; color: #102010; font-weight: 800; padding: 8px 18px; border-radius: 999px; pointer-events: none;
}
.netstatus { position: fixed; bottom: 12px; right: 12px; background: #c0392b; padding: 6px 12px; border-radius: 8px; font-weight: 700; }

#chat { position: fixed; left: 10px; bottom: 10px; width: min(380px, 70vw); pointer-events: none; }
#chatlog { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 3px; }
#chatlog li {
  background: rgba(0, 0, 0, 0.45); padding: 3px 8px; border-radius: 6px; font-size: 14px; width: fit-content; max-width: 100%;
  overflow-wrap: anywhere; transition: opacity 1s;
}
#chatlog li.sys { color: var(--muted); font-style: italic; }
#chatlog li.old { opacity: 0; }
#chatinput { pointer-events: auto; background: rgba(0, 0, 0, 0.7); }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 10, 25, 0.55); }
.overlay-card {
  background: var(--panel); border-radius: 20px; padding: 26px 30px; min-width: min(460px, 92vw); max-width: 92vw;
  text-align: center; border: 1px solid rgba(255, 255, 255, 0.1); animation: pop 0.35s ease-out;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.overlay-card h2 { margin: 0 0 4px; font-size: 34px; }
.overlay-card p { color: var(--muted); margin: 4px 0 14px; }
.overlay-card table { margin: 0 auto 14px; border-collapse: collapse; font-size: 15px; }
.overlay-card th, .overlay-card td { padding: 5px 12px; }
.overlay-card th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.overlay-card td:first-child { text-align: left; font-weight: 700; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.big-score { font-size: 42px; font-weight: 800; color: var(--accent); }

.touch { display: none; }
@media (pointer: coarse) {
  .touch {
    display: flex; justify-content: space-between; align-items: flex-end;
    position: fixed; left: 0; right: 0; bottom: 0; padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    pointer-events: none;
  }
  .touch button {
    pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.14); font-size: 28px; touch-action: none;
  }
  .touch button.down { background: rgba(255, 255, 255, 0.35); }
  .touch-left { display: flex; gap: 14px; }
  .touch-jump { width: 92px !important; height: 92px !important; }
  #chat { bottom: 110px; }
}
