:root {
  --bg: #0f1115;
  --panel: rgba(20, 24, 32, 0.82);
  --line: rgba(255, 255, 255, 0.10);
  --ink: #e8eaed;
  --muted: #9aa3b2;
  --accent: #4dd6c1;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}
#renderCanvas { position: fixed; inset: 0; width: 100%; height: 100%; outline: none; display: block; touch-action: none; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

#topbar { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; gap: 8px; }
.badge {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  backdrop-filter: blur(8px);
}
.badge.ok { color: var(--accent); border-color: rgba(77,214,193,.4); }
.badge.err { color: #ff6b6b; border-color: rgba(255,107,107,.4); }
#playerCount { margin-left: auto; }

#chatPanel {
  position: absolute; left: 12px; bottom: 12px; width: min(380px, 72vw);
  display: flex; flex-direction: column; gap: 8px;
}
#chatLog {
  
  max-height: 210px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px;
  padding-right: 4px; mask-image: linear-gradient(to bottom, transparent 0, #000 24px);
  scrollbar-width: none; -ms-overflow-style: none;   
}
#chatLog::-webkit-scrollbar { width: 0; height: 0; }

body.touch #chatLog { max-height: 120px; }

#chatMore {
  align-self: center; display: none; cursor: pointer; user-select: none;
  font-size: 11px; font-weight: 600; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 12px; backdrop-filter: blur(8px);
}
#chatMore.show { display: block; }
.msg {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 12px; font-size: 16.5px; line-height: 1.4; backdrop-filter: blur(8px);
  width: fit-content; max-width: 100%; word-break: break-word;
}
.msg .who { font-weight: 700; margin-right: 6px; }
.msg.system { color: var(--muted); font-style: italic; }
#chatForm { display: flex; gap: 6px; }
#chatInput {
  flex: 1; background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  padding: 11px 13px; border-radius: 10px; font-size: 16.5px; backdrop-filter: blur(8px);
}
#chatInput:focus { outline: none; border-color: var(--accent); }
#chatForm button {
  background: var(--accent); color: #08120f; border: none; border-radius: 10px;
  padding: 0 16px; font-size: 16px; font-weight: 800; cursor: pointer;
}
#emojiBtn {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  border-radius: 10px; padding: 0 10px; font-size: 18px; cursor: pointer;
  backdrop-filter: blur(8px);
}

#emojiPanel {
  position: absolute; left: 0; bottom: 56px; width: min(300px, 72vw); z-index: 5;
  display: none; flex-wrap: wrap; gap: 2px; padding: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  backdrop-filter: blur(10px); max-height: 190px; overflow-y: auto;
  scrollbar-width: thin;
}
#emojiPanel.open { display: flex; }
#emojiPanel .emoji {
  background: transparent; border: none; cursor: pointer; font-size: 22px;
  line-height: 1; padding: 5px; border-radius: 8px;
}
#emojiPanel .emoji:hover { background: rgba(255,255,255,0.10); }

#hint {
  position: absolute; bottom: 14px; right: 14px; color: var(--muted); font-size: 12px;
  background: var(--panel); border: 1px solid var(--line); padding: 6px 10px; border-radius: 8px;
  backdrop-filter: blur(8px); max-width: 40vw; text-align: right;
}

#joystick {
  position: absolute; right: 22px; bottom: 92px; width: 120px; height: 120px;
  border-radius: 50%; background: rgba(20,24,32,0.5); border: 1px solid var(--line);
  display: none; touch-action: none;
}
#stick {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: var(--accent); opacity: .85;
}
body.touch #joystick { display: block; }
body.touch #hint { display: none; }

#emotes {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 16px;
  display: flex; gap: 8px; z-index: 4;
}
.emotebtn {
  width: 44px; height: 44px; border-radius: 50%; padding: 0;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  font-size: 21px; line-height: 1; cursor: pointer; backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
}
.emotebtn:hover { border-color: var(--accent); }
.emotebtn:active { transform: translateY(1px); }

body.touch #emotes { bottom: auto; top: 54px; }

#preloader {
  position: fixed; inset: 0; z-index: 20; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(1000px 600px at 50% 20%, #1a2330, #0b0d11);
  color: var(--ink);
}
#preloader.show { display: flex; }
#preloader p { margin: 0; color: var(--muted); font-size: 16px; letter-spacing: .3px; }
.pl-spinner {
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.12); border-top-color: var(--accent);
  animation: pl-spin .8s linear infinite;
}
@keyframes pl-spin { to { transform: rotate(360deg); } }
.pl-bar {
  width: min(260px, 70vw); height: 8px; border-radius: 999px;
  background: rgba(255,255,255,0.12); overflow: hidden;
}
.pl-fill { height: 100%; width: 0%; background: var(--accent); border-radius: 999px; }
#preloader .pl-pct {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px; color: var(--ink);
}

#nameModal {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  overflow: hidden; background: #06080c;
}

#nameModal::before, #nameModal::after {
  content: ''; position: absolute; width: 66vmax; height: 66vmax; border-radius: 50%;
  filter: blur(85px); opacity: .5; z-index: 0; pointer-events: none;
}
#nameModal::before {
  background: radial-gradient(circle at 30% 30%, #4dd6c1, transparent 62%);
  top: -20vmax; left: -14vmax; animation: aurora1 19s ease-in-out infinite;
}
#nameModal::after {
  background: radial-gradient(circle at 70% 70%, #2f6bff, transparent 62%);
  bottom: -22vmax; right: -16vmax; animation: aurora2 24s ease-in-out infinite;
}
@keyframes aurora1 { 0%,100%{ transform: translate(0,0) scale(1); } 50%{ transform: translate(9vmax,7vmax) scale(1.18); } }
@keyframes aurora2 { 0%,100%{ transform: translate(0,0) scale(1); } 50%{ transform: translate(-8vmax,-6vmax) scale(1.22); } }

#nameModal .grid-overlay {
  position: absolute; inset: 0; z-index: 0; pointer-events: none; opacity: .5;
  background-image:
    linear-gradient(rgba(255,255,255,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.045) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(circle at 50% 42%, #000 0, transparent 72%);
          mask-image: radial-gradient(circle at 50% 42%, #000 0, transparent 72%);
}
.modal-card {
  position: relative; z-index: 1;
  background: linear-gradient(180deg, rgba(26,32,44,.85), rgba(14,18,26,.82));
  border: 1px solid rgba(255,255,255,.12); border-radius: 20px;
  padding: 34px 30px; width: min(440px, 92vw); text-align: center; backdrop-filter: blur(16px);
  box-shadow:
    0 30px 80px -22px rgba(0,0,0,.75),
    0 0 60px -12px rgba(77,214,193,.18),
    inset 0 1px 0 rgba(255,255,255,.06);
  animation: cardIn .6s cubic-bezier(.2,.85,.25,1) both;
}

.modal-card::before {
  content: ''; position: absolute; top: 0; left: 22%; right: 22%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(77,214,193,.8), transparent);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(16px) scale(.975); } to { opacity: 1; transform: none; } }
.modal-card .logo {
  display: block; margin: 0 auto 14px; max-width: 150px; max-height: 76px; width: auto; height: auto;
  filter: drop-shadow(0 6px 22px rgba(77,214,193,.28));
}
.modal-card h1 { margin: 0 0 6px; font-size: 26px; }
.modal-card p.tagline {
  margin: 4px 0 20px; font-size: 11px; font-weight: 800; letter-spacing: 2.5px; text-transform: uppercase;
  background: linear-gradient(90deg, #ffffff 0%, #7ff0df 50%, #4dd6c1 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
}
@media (min-width: 720px) {
  .modal-card { width: 480px; padding: 48px 42px; }
  .modal-card .logo { max-width: 190px; max-height: 96px; }
  .modal-card p.tagline { font-size: 13px; }
  #nameInput { font-size: 18px; padding: 14px 16px; }
  #enterBtn { font-size: 18px; padding: 16px; }
}
#nameInput {
  width: 100%; background: rgba(8,10,14,.7); border: 1px solid var(--line); color: var(--ink);
  padding: 13px 14px; border-radius: 11px; font-size: 16px; margin-bottom: 14px; text-align: center;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
#nameInput::placeholder { color: #6b7482; }
#nameInput:focus {
  outline: none; border-color: var(--accent); background: rgba(8,10,14,.9);
  box-shadow: 0 0 0 3px rgba(77,214,193,.16);
}

.pick-label { color: var(--muted); font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; margin: 2px 0 10px; }
#charStage { position: relative; margin-bottom: 12px; }
#cpv {
  width: 100%; height: 210px; display: block; border-radius: 14px;
  background: radial-gradient(120% 100% at 50% 18%, #1b2530, #0a0c10);
  border: 1px solid rgba(77,214,193,.18); touch-action: none; outline: none;
  box-shadow: inset 0 0 50px -14px rgba(77,214,193,.28), 0 8px 28px -14px rgba(0,0,0,.6);
}

.char-arrow {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%; z-index: 2;
  background: rgba(12,14,18,.62); border: 1px solid var(--line); color: var(--ink);
  font-size: 26px; line-height: 1; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); transition: border-color .15s, background .15s;
  padding: 0; padding-bottom: 3px;
}
.char-arrow:hover { border-color: var(--accent); background: rgba(12,14,18,.85); }
.char-arrow:active { transform: translateY(-50%) scale(.94); }
.char-arrow.prev { left: 8px; }
.char-arrow.next { right: 8px; }

#charName {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; line-height: 1;
  padding: 6px 11px; border-radius: 999px; font-size: 14px; font-weight: 700;
  color: var(--ink); background: rgba(12,14,18,.66); border: 1px solid var(--line);
  backdrop-filter: blur(6px); pointer-events: none; letter-spacing: .3px;
}
#charName .gi {
  width: 13px; height: 13px; display: block; flex: 0 0 auto;
  fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round;
}
#charName .cg { font-size: 15px; line-height: 1; display: inline-block; }
#charName .cn { line-height: 1; display: inline-block; }

#charDots { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.char-dot {
  width: 9px; height: 9px; padding: 0; border-radius: 50%; cursor: pointer;
  background: rgba(255,255,255,.18); border: 1px solid transparent;
  transition: background .15s, transform .15s;
}
.char-dot:hover { background: rgba(255,255,255,.32); }
.char-dot.active { background: var(--accent); transform: scale(1.25); }
#enterBtn {
  width: 100%; border: none; border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 800;
  cursor: pointer; color: #04110d; letter-spacing: .3px;
  background: linear-gradient(90deg, #4dd6c1, #38b6f0); background-size: 200% 100%;
  box-shadow: 0 12px 32px -10px rgba(77,214,193,.55);
  transition: transform .12s, box-shadow .2s, background-position .5s;
}
#enterBtn:hover {
  background-position: 100% 0; transform: translateY(-1px);
  box-shadow: 0 16px 40px -10px rgba(77,214,193,.7);
}
#enterBtn:active { transform: translateY(1px); }
