* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #f3f4f6;
  font-family: 'Segoe UI', 'Tahoma', 'Noto Sans Thai', sans-serif;
  color: #111827;
}

#scene {
  position: fixed;
  inset: 0;
  display: block;
  outline: none;
}

.hidden { display: none !important; }

/* ================= HUD ================= */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
}
/* everything except the chat input should not eat clicks */
#hud > *:not(#chatPanel):not(#logoutBtn) { pointer-events: none; }

#topLeft {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: #111827;
}

#fpsCounter, #connStatus {
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  width: fit-content;
}
#connStatus.online { color: #a7f3d0; }
#connStatus.offline { color: #fecaca; }
#connStatus.connecting { color: #fde68a; }

#playerList {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(15, 23, 42, 0.84);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 12px;
  min-width: 160px;
  max-height: 40vh;
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(15,23,42,0.18);
}
#playerList .plTitle { opacity: 0.8; }
#playerList .plTitle {
  font-weight: 600;
  opacity: 0.75;
  margin-bottom: 4px;
  letter-spacing: 0.02em;
}
#playerList .plRow {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
#playerList .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

#hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  color: #f8fafc;
  white-space: nowrap;
  box-shadow: 0 12px 28px rgba(15,23,42,0.18);
}

#logoutBtn {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: #ffffff;
  color: #111827;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(15,23,42,0.08);
}
#logoutBtn:hover { background: #f3f4f6; }

/* ================= Chat (always visible) ================= */
#chatPanel {
  position: absolute;
  bottom: 16px;
  left: 16px;
  width: min(420px, 44vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: rgba(15,23,42,0.82);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 22px;
  box-shadow: 0 20px 40px rgba(15,23,42,0.2);
  z-index: 15;
}

#chatLog {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 28vh;
  overflow: hidden;
  font-size: 12px;
  color: #f8fafc;
}
#chatLog .chatLine {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 10px;
  border-radius: 12px;
  width: fit-content;
  max-width: 100%;
  word-break: break-word;
  animation: fadeIn 0.15s ease;
}
#chatLog .chatLine .who {
  font-weight: 700;
  margin-right: 6px;
  color: #f8fafc;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

#chatInputRow { pointer-events: auto; }
#chatInput {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  color: #111827;
  font-size: 13px;
  outline: none;
}
#chatInput:focus { border-color: #9ca3af; background: #ffffff; }
#chatInput::placeholder { color: #9ca3af; }

/* ================= Auth screen ================= */
#authScreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(255, 220, 150, 0.15), transparent 60%),
    linear-gradient(180deg, #6ec6e8 0%, #2f8fc4 35%, #0e4a72 75%, #062338 100%);
}

#authPanel {
  width: min(92vw, 380px);
  background: rgba(8, 24, 38, 0.55);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 18px;
  padding: 28px 26px 24px;
  backdrop-filter: blur(10px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  text-align: center;
}

#authPanel h1 { margin: 0 0 6px; font-size: 30px; letter-spacing: 0.02em; }

.heroBadge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.12);
  color: #ffffff;
}

.subtitle { margin: 0 0 18px; font-size: 13px; opacity: 0.85; line-height: 1.6; }

#authTabs {
  display: flex;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 14px;
}
.tabBtn {
  flex: 1;
  padding: 8px 0;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tabBtn.active {
  background: rgba(255,255,255,0.16);
  color: #fff;
}

#authPanel label {
  display: block;
  text-align: left;
  font-size: 12px;
  opacity: 0.75;
  margin: 14px 0 6px;
  color: #374151;
}

#authPanel input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #111827;
  font-size: 14px;
  outline: none;
}
#authPanel input:focus { border-color: #9ca3af; background: #ffffff; }

#charSelect {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin: 14px 0 8px;
}
#skinPreview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.16);
}
#skinPreview canvas,
#skinPreview img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 14px;
  background: rgba(255,255,255,0.12);
}
#skinPreviewLabel {
  font-size: 14px;
  font-weight: 700;
  color: #f8fafc;
}
#skinSelect {
  width: 100%;
  max-width: 260px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #111827;
  font-size: 14px;
  outline: none;
}
#skinSelect:focus {
  border-color: #9ca3af;
  background: #ffffff;
}

#authBtn, .secondaryBtn {
  margin-top: 18px;
  width: 100%;
  padding: 14px;
  border: 1px solid #d1d5db;
  border-radius: 14px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: background-color 0.13s ease, border-color 0.13s ease, transform 0.13s ease;
}

#authBtn {
  background: #111827;
  color: #ffffff;
}

#authBtn:hover { background: #1f2937; }

.secondaryBtn {
  margin-top: 10px;
  background: #f3f4f6;
  color: #111827;
}

.secondaryBtn:hover {
  background: #e5e7eb;
}

#authBtn:disabled, .secondaryBtn:disabled { opacity: 0.65; cursor: default; transform: none; }

#authBtn:active, .secondaryBtn:active { transform: translateY(0); }

#authError {
  margin-top: 14px;
  font-size: 13px;
  min-height: 24px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  color: #b91c1c;
  background: rgba(254, 242, 242, 0.95);
  display: block;
  line-height: 1.4;
}

#authError.error {
  color: #b91c1c;
  background: rgba(254, 242, 242, 0.95);
  border-color: #fca5a5;
}

#authError.success {
  color: #047857;
  background: rgba(236, 253, 245, 0.95);
  border-color: #86efac;
}

#authError.info {
  color: #92400e;
  background: rgba(255, 247, 237, 0.95);
  border-color: #fdba74;
}

#authPanel {
  width: min(92vw, 420px);
  background: rgba(12, 28, 44, 0.80);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 26px;
  padding: 32px 30px 28px;
  backdrop-filter: blur(20px);
  box-shadow: 0 32px 90px rgba(6, 18, 38, 0.35);
  text-align: center;
}

#authScreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(243, 244, 246, 0.95);
}

#authPanel {
  width: min(92vw, 420px);
  background: #ffffff;
  border: 1px solid #d1d5db;
  border-radius: 24px;
  padding: 32px 30px 28px;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
  text-align: center;
}

#authPanel h1 {
  margin: 0 0 8px;
  font-size: 30px;
  color: #111827;
}

#authHint {
  margin-top: 10px;
  font-size: 13px;
  opacity: 0.75;
}
